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



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TaskExecutionStateTransition;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.runtime.taskmanager.TaskExecutionState;
+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 testFailingStateOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            assertThat(meg.isFailing(), is(true));
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToFailedWhenFailingCompletes() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter(); // transition from RUNNING to FAILING
+            assertThat(meg.isFailing(), is(true));
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+            meg.completeCancellation(); // transition to FAILED
+        }
+    }
+
+    @Test
+    public void testTransitionToCancelingOnCancel() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            ctx.setExpectCanceling(assertNonNull());
+            failing.onEnter();
+            failing.cancel();
+        }
+    }
+
+    @Test
+    public void testTransitionToFinishedOnSuspend() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.SUSPENDED)));
+
+            failing.onEnter();
+            failing.suspend(new RuntimeException("suspend"));
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            failing.handleGlobalFailure(new RuntimeException());
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTaskFailuresAreIgnored() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            // register execution at EG
+            ExecutingTest.MockExecutionJobVertex ejv =
+                    new 
ExecutingTest.MockExecutionJobVertex(failing.getExecutionGraph());
+            TaskExecutionStateTransition update =
+                    new TaskExecutionStateTransition(
+                            new TaskExecutionState(
+                                    failing.getJob().getJobID(),
+                                    ejv.getMockExecutionVertex()
+                                            .getCurrentExecutionAttempt()
+                                            .getAttemptId(),
+                                    ExecutionState.FAILED,
+                                    new RuntimeException()));
+            failing.updateTaskExecutionState(update);
+            ctx.assertNoStateTransition();
+            assertThat(meg.isFailGlobalCalled(), is(true));

Review comment:
       Why are we calling fail global if we receive a task failure?

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TaskExecutionStateTransition;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.runtime.taskmanager.TaskExecutionState;
+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 testFailingStateOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            assertThat(meg.isFailing(), is(true));
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToFailedWhenFailingCompletes() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter(); // transition from RUNNING to FAILING
+            assertThat(meg.isFailing(), is(true));
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.FAILED)));
+            meg.completeCancellation(); // transition to FAILED
+        }
+    }
+
+    @Test
+    public void testTransitionToCancelingOnCancel() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            ctx.setExpectCanceling(assertNonNull());
+            failing.onEnter();
+            failing.cancel();
+        }
+    }
+
+    @Test
+    public void testTransitionToFinishedOnSuspend() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            ctx.setExpectFinished(
+                    archivedExecutionGraph ->
+                            assertThat(archivedExecutionGraph.getState(), 
is(JobStatus.SUSPENDED)));
+
+            failing.onEnter();
+            failing.suspend(new RuntimeException("suspend"));
+        }
+    }
+
+    @Test
+    public void testIgnoreGlobalFailure() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            failing.handleGlobalFailure(new RuntimeException());
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTaskFailuresAreIgnored() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            // register execution at EG
+            ExecutingTest.MockExecutionJobVertex ejv =
+                    new 
ExecutingTest.MockExecutionJobVertex(failing.getExecutionGraph());
+            TaskExecutionStateTransition update =
+                    new TaskExecutionStateTransition(
+                            new TaskExecutionState(
+                                    failing.getJob().getJobID(),
+                                    ejv.getMockExecutionVertex()
+                                            .getCurrentExecutionAttempt()
+                                            .getAttemptId(),
+                                    ExecutionState.FAILED,
+                                    new RuntimeException()));
+            failing.updateTaskExecutionState(update);
+            ctx.assertNoStateTransition();
+            assertThat(meg.isFailGlobalCalled(), is(true));

Review comment:
       I think we are doing this because `updateTaskExecutionState` fails with 
a `NPE`.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/declarative/FailingTest.java
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TaskExecutionStateTransition;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+import org.apache.flink.runtime.taskmanager.TaskExecutionState;
+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 testFailingStateOnEnter() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter();
+            assertThat(meg.isFailing(), is(true));
+            ctx.assertNoStateTransition();
+        }
+    }
+
+    @Test
+    public void testTransitionToFailedWhenFailingCompletes() throws Exception {
+        try (MockFailingContext ctx = new MockFailingContext()) {
+            MockExecutionGraph meg = new MockExecutionGraph();
+            Failing failing = createFailingState(ctx, meg);
+            failing.onEnter(); // transition from RUNNING to FAILING
+            assertThat(meg.isFailing(), is(true));

Review comment:
       This has already been tested in `testFailingStateOnEnter`




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to