tillrohrmann commented on a change in pull request #14910:
URL: https://github.com/apache/flink/pull/14910#discussion_r573738229



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.function.Consumer;
+
+import static 
org.apache.flink.runtime.scheduler.declarative.WaitingForResourcesTest.assertNonNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Tests for the {@link Failing} state of the declarative scheduler. */
+public class FailingTest extends TestLogger {
+    private final Throwable testFailureCause = new RuntimeException();
+
+    @Test
+    public void testFailJobOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+
+            failing.onEnter();
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);

Review comment:
       I guess `onEnter()` is missing here. By not sticking to the contract, we 
are testing scenarios which should not happen in "production".

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/declarative/StateWithExecutionGraph.java
##########
@@ -138,7 +138,9 @@ public JobStatus getJobStatus() {
     @Override
     public void suspend(Throwable cause) {
         executionGraph.suspend(cause);
-        Preconditions.checkState(executionGraph.getState() == 
JobStatus.SUSPENDED);
+        Preconditions.checkState(
+                executionGraph.getState() == JobStatus.SUSPENDED
+                        || executionGraph.getState().isTerminalState());

Review comment:
       Why is this change necessary?

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.function.Consumer;
+
+import static 
org.apache.flink.runtime.scheduler.declarative.WaitingForResourcesTest.assertNonNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Tests for the {@link Failing} state of the declarative scheduler. */
+public class FailingTest extends TestLogger {
+    private final Throwable testFailureCause = new RuntimeException();
+
+    @Test
+    public void testFailJobOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+
+            failing.onEnter();
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            failing.handleGlobalFailure(new RuntimeException());
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToCancelOnCancel() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);

Review comment:
       `onEnter()` is missing

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.function.Consumer;
+
+import static 
org.apache.flink.runtime.scheduler.declarative.WaitingForResourcesTest.assertNonNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Tests for the {@link Failing} state of the declarative scheduler. */
+public class FailingTest extends TestLogger {
+    private final Throwable testFailureCause = new RuntimeException();
+
+    @Test
+    public void testFailJobOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+
+            failing.onEnter();
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            failing.handleGlobalFailure(new RuntimeException());
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToCancelOnCancel() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectCanceling(assertNonNull());
+            failing.cancel();
+        }
+    }
+
+    @Test
+    public void testTransitionToFinishedOnSuspend() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));

Review comment:
       The final `JobStatus` should be `SUSPENDED`.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.function.Consumer;
+
+import static 
org.apache.flink.runtime.scheduler.declarative.WaitingForResourcesTest.assertNonNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Tests for the {@link Failing} state of the declarative scheduler. */
+public class FailingTest extends TestLogger {
+    private final Throwable testFailureCause = new RuntimeException();
+
+    @Test
+    public void testFailJobOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);

Review comment:
       I guess that this creates an `ExecutionGraph` which directly goes to 
`FAILED` when calling `ExecutionGraph.fail` because there are no 
deployed/running `Executions`. I think this is a good example what a proper 
testing abstraction of the `ExecutionGraph` could help us with. We would no 
longer bind the logic of the tests to the underlying `ExecutionGraph` 
implementation.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TestingExecutionGraphBuilder;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.function.Consumer;
+
+import static 
org.apache.flink.runtime.scheduler.declarative.WaitingForResourcesTest.assertNonNull;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/** Tests for the {@link Failing} state of the declarative scheduler. */
+public class FailingTest extends TestLogger {
+    private final Throwable testFailureCause = new RuntimeException();
+
+    @Test
+    public void testFailJobOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+
+            failing.onEnter();
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            Failing failing = createFailingState(ctx);
+            failing.handleGlobalFailure(new RuntimeException());
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToCancelOnCancel() throws Exception {

Review comment:
       `testTransitionToCancelingOnCancel`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to