You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2023/08/23 13:41:51 UTC

[flink] branch master updated (582457c6fef -> 4aebc437218)

This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


    from 582457c6fef [hotfix] keep 1.17 as the stable doc version
     new 79356ccd010 [hotfix][scheduler] Remove the unused method and add the @Nullable inside the WaitingForResources
     new 4dd0912bb8a [hotfix][JUnit5 Migration] Migrate some state tests of adaptive scheduler to junit5
     new 4aebc437218 [FLINK-32859][scheduler] Introduce the StateWithoutExecutionGraph

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../flink/runtime/scheduler/adaptive/Created.java  |  53 +--
 .../scheduler/adaptive/CreatingExecutionGraph.java |  69 +---
 ...reated.java => StateWithoutExecutionGraph.java} |  50 +--
 .../scheduler/adaptive/WaitingForResources.java    |  60 +--
 .../runtime/scheduler/adaptive/CreatedTest.java    | 102 ++---
 .../adaptive/CreatingExecutionGraphTest.java       | 272 +++++---------
 .../MockStateWithoutExecutionGraphContext.java     |  72 ++++
 .../runtime/scheduler/adaptive/StateTest.java      |  96 ++---
 .../adaptive/StateWithoutExecutionGraphTest.java   | 104 ++++++
 .../adaptive/WaitingForResourcesTest.java          | 411 ++++++++-------------
 10 files changed, 513 insertions(+), 776 deletions(-)
 copy flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/{Created.java => StateWithoutExecutionGraph.java} (62%)
 create mode 100644 flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockStateWithoutExecutionGraphContext.java
 create mode 100644 flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraphTest.java


[flink] 01/03: [hotfix][scheduler] Remove the unused method and add the @Nullable inside the WaitingForResources

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 79356ccd010f1fb29b72300c143cce37fea3301f
Author: 1996fanrui <19...@gmail.com>
AuthorDate: Mon Aug 14 01:02:37 2023 +0800

    [hotfix][scheduler] Remove the unused method and add the @Nullable inside the WaitingForResources
---
 .../flink/runtime/scheduler/adaptive/WaitingForResources.java      | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
index 10eb79d3709..434b0741a28 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
@@ -237,7 +237,7 @@ class WaitingForResources implements State, ResourceListener {
                 Logger log,
                 Duration initialResourceAllocationTimeout,
                 Duration resourceStabilizationTimeout,
-                ExecutionGraph previousExecutionGraph) {
+                @Nullable ExecutionGraph previousExecutionGraph) {
             this.context = context;
             this.log = log;
             this.initialResourceAllocationTimeout = initialResourceAllocationTimeout;
@@ -259,9 +259,4 @@ class WaitingForResources implements State, ResourceListener {
                     previousExecutionGraph);
         }
     }
-
-    @Nullable
-    public ExecutionGraph getPreviousExecutionGraph() {
-        return previousExecutionGraph;
-    }
 }


[flink] 02/03: [hotfix][JUnit5 Migration] Migrate some state tests of adaptive scheduler to junit5

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 4dd0912bb8a809b533fe15665899dc1638253e4d
Author: 1996fanrui <19...@gmail.com>
AuthorDate: Mon Aug 14 22:10:50 2023 +0800

    [hotfix][JUnit5 Migration] Migrate some state tests of adaptive scheduler to junit5
---
 .../runtime/scheduler/adaptive/CreatedTest.java    | 115 +++---
 .../adaptive/CreatingExecutionGraphTest.java       | 316 +++++++--------
 .../runtime/scheduler/adaptive/StateTest.java      |  96 ++---
 .../adaptive/WaitingForResourcesTest.java          | 430 ++++++++++-----------
 4 files changed, 474 insertions(+), 483 deletions(-)

diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
index ee1ee2b7c1d..302fb471c3e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
@@ -23,82 +23,97 @@ import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.failure.FailureEnricherUtils;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.FlinkException;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nullable;
 
 import java.util.function.Consumer;
 
-import static org.apache.flink.runtime.scheduler.adaptive.WaitingForResourcesTest.assertNonNull;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link Created} state. */
-public class CreatedTest extends TestLogger {
+class CreatedTest {
 
-    @Test
-    public void testCancel() throws Exception {
-        try (MockCreatedContext ctx = new MockCreatedContext()) {
-            Created created = new Created(ctx, log);
+    private static final Logger LOG = LoggerFactory.getLogger(CreatedTest.class);
 
-            ctx.setExpectFinished(assertNonNull());
+    @RegisterExtension MockCreatedContext ctx = new MockCreatedContext();
 
-            created.cancel();
-        }
+    @Test
+    void testCancel() {
+        Created created = new Created(ctx, LOG);
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
+                });
+        created.cancel();
     }
 
     @Test
-    public void testStartScheduling() throws Exception {
-        try (MockCreatedContext ctx = new MockCreatedContext()) {
-            Created created = new Created(ctx, log);
+    void testStartScheduling() {
+        Created created = new Created(ctx, LOG);
 
-            ctx.setExpectWaitingForResources();
+        ctx.setExpectWaitingForResources();
 
-            created.startScheduling();
-        }
+        created.startScheduling();
     }
 
     @Test
-    public void testSuspend() throws Exception {
-        try (MockCreatedContext ctx = new MockCreatedContext()) {
-            Created created = new Created(ctx, log);
-
-            ctx.setExpectFinished(
-                    archivedExecutionGraph -> {
-                        assertThat(archivedExecutionGraph.getState(), is(JobStatus.SUSPENDED));
-                    });
-
-            created.suspend(new RuntimeException("Suspend"));
-        }
+    void testSuspend() {
+        FlinkException expectedException = new FlinkException("This is a test exception");
+        Created created = new Created(ctx, LOG);
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        created.suspend(expectedException);
     }
 
     @Test
-    public void testFailure() throws Exception {
-        try (MockCreatedContext ctx = new MockCreatedContext()) {
-            Created created = new Created(ctx, log);
-
-            ctx.setExpectFinished(
-                    archivedExecutionGraph -> {
-                        assertThat(archivedExecutionGraph.getState(), is(JobStatus.FAILED));
-                    });
-
-            created.handleGlobalFailure(
-                    new RuntimeException("Global"), FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-        }
+    void testFailure() {
+        Created created = new Created(ctx, LOG);
+        RuntimeException expectedException = new RuntimeException("This is a test exception");
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        created.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
     }
 
     @Test
-    public void testJobInformation() throws Exception {
-        try (MockCreatedContext ctx = new MockCreatedContext()) {
-            Created created = new Created(ctx, log);
-            ArchivedExecutionGraph job = created.getJob();
-            assertThat(job.getState(), is(JobStatus.INITIALIZING));
-        }
+    void testJobInformation() {
+        Created created = new Created(ctx, LOG);
+        ArchivedExecutionGraph job = created.getJob();
+        assertThat(job.getState()).isEqualTo(JobStatus.INITIALIZING);
     }
 
-    static class MockCreatedContext implements Created.Context, AutoCloseable {
+    static class MockCreatedContext implements Created.Context, AfterEachCallback {
         private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
                 new StateValidator<>("finished");
         private final StateValidator<Void> waitingForResourcesStateValidator =
@@ -130,7 +145,7 @@ public class CreatedTest extends TestLogger {
         }
 
         @Override
-        public void close() throws Exception {
+        public void afterEach(ExtensionContext extensionContext) throws Exception {
             finishedStateValidator.close();
             waitingForResourcesStateValidator.close();
         }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
index 2375a194206..833835b7d22 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
@@ -33,12 +33,14 @@ import org.apache.flink.runtime.scheduler.GlobalFailureHandler;
 import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
 import org.apache.flink.runtime.scheduler.exceptionhistory.ExceptionHistoryEntry;
 import org.apache.flink.util.FlinkException;
-import org.apache.flink.util.TestLogger;
-import org.apache.flink.util.TestLoggerExtension;
 import org.apache.flink.util.concurrent.Executors;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nullable;
 
@@ -54,167 +56,171 @@ import java.util.function.Function;
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link CreatingExecutionGraph} state. */
-@ExtendWith(TestLoggerExtension.class)
-public class CreatingExecutionGraphTest extends TestLogger {
+class CreatingExecutionGraphTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CreatingExecutionGraphTest.class);
+
+    @RegisterExtension
+    MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext();
 
     @Test
-    public void testCancelTransitionsToFinished() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CreatingExecutionGraph creatingExecutionGraph =
-                    new CreatingExecutionGraph(
-                            context,
-                            new CompletableFuture<>(),
-                            log,
-                            CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                            null);
-
-            context.setExpectFinished(
-                    archivedExecutionGraph ->
-                            assertThat(archivedExecutionGraph.getState())
-                                    .isEqualTo(JobStatus.CANCELED));
-
-            creatingExecutionGraph.cancel();
-        }
+    void testCancelTransitionsToFinished() {
+        final CreatingExecutionGraph creatingExecutionGraph =
+                new CreatingExecutionGraph(
+                        context,
+                        new CompletableFuture<>(),
+                        LOG,
+                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                        null);
+
+        context.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
+                });
+        creatingExecutionGraph.cancel();
     }
 
     @Test
-    public void testSuspendTransitionsToFinished() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CreatingExecutionGraph creatingExecutionGraph =
-                    new CreatingExecutionGraph(
-                            context,
-                            new CompletableFuture<>(),
-                            log,
-                            CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                            null);
-
-            context.setExpectFinished(
-                    archivedExecutionGraph ->
-                            assertThat(archivedExecutionGraph.getState())
-                                    .isEqualTo(JobStatus.SUSPENDED));
-
-            creatingExecutionGraph.suspend(new FlinkException("Job has been suspended."));
-        }
+    void testSuspendTransitionsToFinished() {
+        final CreatingExecutionGraph creatingExecutionGraph =
+                new CreatingExecutionGraph(
+                        context,
+                        new CompletableFuture<>(),
+                        LOG,
+                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                        null);
+
+        FlinkException expectedException = new FlinkException("This is a test exception");
+
+        context.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        creatingExecutionGraph.suspend(expectedException);
     }
 
     @Test
-    public void testGlobalFailureTransitionsToFinished() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CreatingExecutionGraph creatingExecutionGraph =
-                    new CreatingExecutionGraph(
-                            context,
-                            new CompletableFuture<>(),
-                            log,
-                            CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                            null);
-
-            context.setExpectFinished(
-                    archivedExecutionGraph ->
-                            assertThat(archivedExecutionGraph.getState())
-                                    .isEqualTo(JobStatus.FAILED));
-
-            creatingExecutionGraph.handleGlobalFailure(
-                    new FlinkException("Test exception"),
-                    FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-        }
+    void testGlobalFailureTransitionsToFinished() {
+        final CreatingExecutionGraph creatingExecutionGraph =
+                new CreatingExecutionGraph(
+                        context,
+                        new CompletableFuture<>(),
+                        LOG,
+                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                        null);
+
+        RuntimeException expectedException = new RuntimeException("This is a test exception");
+
+        context.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        creatingExecutionGraph.handleGlobalFailure(
+                expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
     }
 
     @Test
-    public void testFailedExecutionGraphCreationTransitionsToFinished() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
-                    executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
-            new CreatingExecutionGraph(
-                    context,
-                    executionGraphWithVertexParallelismFuture,
-                    log,
-                    CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                    null);
-
-            context.setExpectFinished(
-                    archivedExecutionGraph ->
-                            assertThat(archivedExecutionGraph.getState())
-                                    .isEqualTo(JobStatus.FAILED));
-
-            executionGraphWithVertexParallelismFuture.completeExceptionally(
-                    new FlinkException("Test exception"));
-        }
+    void testFailedExecutionGraphCreationTransitionsToFinished() {
+        final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
+                executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
+        new CreatingExecutionGraph(
+                context,
+                executionGraphWithVertexParallelismFuture,
+                LOG,
+                CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                null);
+
+        context.setExpectFinished(
+                archivedExecutionGraph ->
+                        assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED));
+
+        executionGraphWithVertexParallelismFuture.completeExceptionally(
+                new FlinkException("Test exception"));
     }
 
     @Test
-    public void testNotPossibleSlotAssignmentTransitionsToWaitingForResources() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
-                    executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
-            new CreatingExecutionGraph(
-                    context,
-                    executionGraphWithVertexParallelismFuture,
-                    log,
-                    CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                    null);
-
-            context.setTryToAssignSlotsFunction(
-                    ignored -> CreatingExecutionGraph.AssignmentResult.notPossible());
-            context.setExpectWaitingForResources();
-
-            executionGraphWithVertexParallelismFuture.complete(
-                    getGraph(new StateTrackingMockExecutionGraph()));
-        }
+    void testNotPossibleSlotAssignmentTransitionsToWaitingForResources() {
+        final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
+                executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
+        new CreatingExecutionGraph(
+                context,
+                executionGraphWithVertexParallelismFuture,
+                LOG,
+                CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                null);
+
+        context.setTryToAssignSlotsFunction(
+                ignored -> CreatingExecutionGraph.AssignmentResult.notPossible());
+        context.setExpectWaitingForResources();
+
+        executionGraphWithVertexParallelismFuture.complete(
+                getGraph(new StateTrackingMockExecutionGraph()));
     }
 
     @Test
-    public void testSuccessfulSlotAssignmentTransitionsToExecuting() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
-                    executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
-            new CreatingExecutionGraph(
-                    context,
-                    executionGraphWithVertexParallelismFuture,
-                    log,
-                    CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                    null);
-
-            final StateTrackingMockExecutionGraph executionGraph =
-                    new StateTrackingMockExecutionGraph();
-
-            context.setTryToAssignSlotsFunction(CreatingExecutionGraphTest::successfulAssignment);
-            context.setExpectedExecuting(
-                    actualExecutionGraph ->
-                            assertThat(actualExecutionGraph).isEqualTo(executionGraph));
-
-            executionGraphWithVertexParallelismFuture.complete(getGraph(executionGraph));
-        }
+    void testSuccessfulSlotAssignmentTransitionsToExecuting() {
+        final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
+                executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
+        new CreatingExecutionGraph(
+                context,
+                executionGraphWithVertexParallelismFuture,
+                LOG,
+                CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
+                null);
+
+        final StateTrackingMockExecutionGraph executionGraph =
+                new StateTrackingMockExecutionGraph();
+
+        context.setTryToAssignSlotsFunction(CreatingExecutionGraphTest::successfulAssignment);
+        context.setExpectedExecuting(
+                actualExecutionGraph -> assertThat(actualExecutionGraph).isEqualTo(executionGraph));
+
+        executionGraphWithVertexParallelismFuture.complete(getGraph(executionGraph));
     }
 
     @Test
-    public void testOperatorCoordinatorUsesFailureHandlerOfTheCurrentState() throws Exception {
-        try (MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext()) {
-            final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
-                    executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
-            final AtomicReference<GlobalFailureHandler> operatorCoordinatorGlobalFailureHandlerRef =
-                    new AtomicReference<>();
-            new CreatingExecutionGraph(
-                    context,
-                    executionGraphWithVertexParallelismFuture,
-                    log,
-                    (executionGraph, errorHandler) -> {
-                        operatorCoordinatorGlobalFailureHandlerRef.set(errorHandler);
-                        return new TestingOperatorCoordinatorHandler();
-                    },
-                    null);
-
-            final StateTrackingMockExecutionGraph executionGraph =
-                    new StateTrackingMockExecutionGraph();
-
-            context.setTryToAssignSlotsFunction(CreatingExecutionGraphTest::successfulAssignment);
-            context.setExpectedExecuting(
-                    actualExecutionGraph ->
-                            assertThat(actualExecutionGraph).isEqualTo(executionGraph));
-
-            executionGraphWithVertexParallelismFuture.complete(getGraph(executionGraph));
-
-            assertThat(operatorCoordinatorGlobalFailureHandlerRef.get()).isSameAs(context);
-        }
+    void testOperatorCoordinatorUsesFailureHandlerOfTheCurrentState() {
+        final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
+                executionGraphWithVertexParallelismFuture = new CompletableFuture<>();
+        final AtomicReference<GlobalFailureHandler> operatorCoordinatorGlobalFailureHandlerRef =
+                new AtomicReference<>();
+        new CreatingExecutionGraph(
+                context,
+                executionGraphWithVertexParallelismFuture,
+                LOG,
+                (executionGraph, errorHandler) -> {
+                    operatorCoordinatorGlobalFailureHandlerRef.set(errorHandler);
+                    return new TestingOperatorCoordinatorHandler();
+                },
+                null);
+
+        final StateTrackingMockExecutionGraph executionGraph =
+                new StateTrackingMockExecutionGraph();
+
+        context.setTryToAssignSlotsFunction(CreatingExecutionGraphTest::successfulAssignment);
+        context.setExpectedExecuting(
+                actualExecutionGraph -> assertThat(actualExecutionGraph).isEqualTo(executionGraph));
+
+        executionGraphWithVertexParallelismFuture.complete(getGraph(executionGraph));
+
+        assertThat(operatorCoordinatorGlobalFailureHandlerRef.get()).isSameAs(context);
     }
 
     private static CreatingExecutionGraph.AssignmentResult successfulAssignment(
@@ -230,7 +236,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
     }
 
     static class MockCreatingExecutionGraphContext
-            implements CreatingExecutionGraph.Context, AutoCloseable {
+            implements CreatingExecutionGraph.Context, AfterEachCallback {
         private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
                 new StateValidator<>("Finished");
         private final StateValidator<Void> waitingForResourcesStateValidator =
@@ -249,7 +255,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
                     // No-op.
                 };
 
-        private boolean hadStateTransitionHappened = false;
+        private boolean hasStateTransition = false;
 
         public void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
             finishedStateValidator.expectInput(asserter);
@@ -278,7 +284,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
         @Override
         public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
             finishedStateValidator.validateInput(archivedExecutionGraph);
-            hadStateTransitionHappened = true;
+            registerStateTransition();
         }
 
         @Override
@@ -288,7 +294,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
                 OperatorCoordinatorHandler operatorCoordinatorHandler,
                 List<ExceptionHistoryEntry> failureCollection) {
             executingStateValidator.validateInput(executionGraph);
-            hadStateTransitionHappened = true;
+            registerStateTransition();
         }
 
         @Override
@@ -300,7 +306,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
 
         @Override
         public ScheduledFuture<?> runIfState(State expectedState, Runnable action, Duration delay) {
-            if (!hadStateTransitionHappened) {
+            if (!hasStateTransition()) {
                 action.run();
             }
 
@@ -322,7 +328,7 @@ public class CreatingExecutionGraphTest extends TestLogger {
         @Override
         public void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGraph) {
             waitingForResourcesStateValidator.validateInput(null);
-            hadStateTransitionHappened = true;
+            hasStateTransition = true;
         }
 
         @Override
@@ -341,11 +347,19 @@ public class CreatingExecutionGraphTest extends TestLogger {
         }
 
         @Override
-        public void close() throws Exception {
+        public void afterEach(ExtensionContext extensionContext) throws Exception {
             finishedStateValidator.close();
             waitingForResourcesStateValidator.close();
             executingStateValidator.close();
         }
+
+        public boolean hasStateTransition() {
+            return hasStateTransition;
+        }
+
+        public void registerStateTransition() {
+            hasStateTransition = true;
+        }
     }
 
     private static CreatingExecutionGraph.ExecutionGraphWithVertexParallelism getGraph(
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateTest.java
index fc3b0f6731c..568ed8a2c6c 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateTest.java
@@ -18,85 +18,71 @@
 
 package org.apache.flink.runtime.scheduler.adaptive;
 
-import org.apache.flink.util.TestLogger;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 
 /**
  * Tests for the default methods on the {@link State} interface, based on the {@link Created} state,
  * as it is a simple state.
  */
-public class StateTest extends TestLogger {
+class StateTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(StateTest.class);
+
+    @RegisterExtension CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext();
+
     @Test
-    public void testEmptyAs() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            assertThat(state.as(WaitingForResources.class), is(Optional.empty()));
-        }
+    void testEmptyAs() {
+        State state = new Created(ctx, LOG);
+        assertThat(state.as(WaitingForResources.class)).isEmpty();
     }
 
     @Test
-    public void testCast() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            assertThat(state.as(Created.class), is(Optional.of(state)));
-        }
+    void testCast() {
+        Created state = new Created(ctx, LOG);
+        assertThat(state.as(Created.class)).hasValue(state);
     }
 
     @Test
-    public void testTryRunStateMismatch() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            state.tryRun(
-                    WaitingForResources.class, (waiting -> fail("Unexpected execution")), "test");
-        }
+    void testTryRunStateMismatch() {
+        State state = new Created(ctx, LOG);
+        state.tryRun(WaitingForResources.class, waiting -> fail("Unexpected execution"), "test");
     }
 
     @Test
-    public void testTryRun() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            AtomicBoolean called = new AtomicBoolean(false);
-            state.tryRun(Created.class, created -> called.set(true), "test");
-            assertThat(called.get(), is(true));
-        }
+    void testTryRun() {
+        State state = new Created(ctx, LOG);
+        AtomicBoolean called = new AtomicBoolean(false);
+        state.tryRun(Created.class, created -> called.set(true), "test");
+        assertThat(called).isTrue();
     }
 
     @Test
-    public void testTryCallStateMismatch() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            Optional<String> result =
-                    state.tryCall(
-                            WaitingForResources.class,
-                            Waiting -> {
-                                fail("Unexpected execution");
-                                return "nope";
-                            },
-                            "test");
-            assertThat(result, is(Optional.empty()));
-        }
+    void testTryCallStateMismatch() {
+        State state = new Created(ctx, LOG);
+        Optional<String> result =
+                state.tryCall(
+                        WaitingForResources.class,
+                        Waiting -> {
+                            fail("Unexpected execution");
+                            return "nope";
+                        },
+                        "test");
+        assertThat(result).isEmpty();
     }
 
     @Test
-    public void testTryCall() throws Exception {
-        try (CreatedTest.MockCreatedContext ctx = new CreatedTest.MockCreatedContext()) {
-            State state = new Created(ctx, log);
-            Optional<String> result =
-                    state.tryCall(
-                            Created.class,
-                            created -> {
-                                return "yes";
-                            },
-                            "test");
-            assertThat(result, is(Optional.of("yes")));
-        }
+    void testTryCall() {
+        State state = new Created(ctx, LOG);
+        Optional<String> result = state.tryCall(Created.class, created -> "yes", "test");
+        assertThat(result).hasValue("yes");
     }
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
index 2f60b4aeac5..bdcc73f5c9d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
@@ -25,11 +25,14 @@ import org.apache.flink.runtime.executiongraph.ErrorInfo;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.failure.FailureEnricherUtils;
 import org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.FlinkException;
 import org.apache.flink.util.clock.Clock;
 import org.apache.flink.util.clock.ManualClock;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -45,256 +48,234 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 
 /** Tests for the WaitingForResources state. */
-public class WaitingForResourcesTest extends TestLogger {
+class WaitingForResourcesTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(WaitingForResourcesTest.class);
+
     private static final Duration STABILIZATION_TIMEOUT = Duration.ofSeconds(1);
 
+    @RegisterExtension MockContext ctx = new MockContext();
+
     /** WaitingForResources is transitioning to Executing if there are enough resources. */
     @Test
-    public void testTransitionToCreatingExecutionGraph() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> true);
+    void testTransitionToCreatingExecutionGraph() {
+        ctx.setHasDesiredResources(() -> true);
 
-            ctx.setExpectCreatingExecutionGraph();
+        ctx.setExpectCreatingExecutionGraph();
 
-            new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
+        new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
 
-            ctx.runScheduledTasks();
-        }
+        ctx.runScheduledTasks();
     }
 
     @Test
-    public void testNotEnoughResources() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-            // we expect no state transition.
-            wfr.onNewResourcesAvailable();
-        }
+    void testNotEnoughResources() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
+
+        // we expect no state transition.
+        wfr.onNewResourcesAvailable();
     }
 
     @Test
-    public void testNotifyNewResourcesAvailable() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false); // initially, not enough resources
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
-            ctx.setHasDesiredResources(() -> true); // make resources available
-            ctx.setExpectCreatingExecutionGraph();
-            wfr.onNewResourcesAvailable(); // .. and notify
-        }
+    void testNotifyNewResourcesAvailable() {
+        ctx.setHasDesiredResources(() -> false); // initially, not enough resources
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
+        ctx.setHasDesiredResources(() -> true); // make resources available
+        ctx.setExpectCreatingExecutionGraph();
+        wfr.onNewResourcesAvailable(); // .. and notify
     }
 
     @Test
-    public void testSchedulingWithSufficientResourcesAndNoStabilizationTimeout() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-
-            Duration noStabilizationTimeout = Duration.ofMillis(0);
-            WaitingForResources wfr =
-                    new WaitingForResources(
-                            ctx, log, Duration.ofSeconds(1000), noStabilizationTimeout);
-
-            ctx.setHasDesiredResources(() -> false);
-            ctx.setHasSufficientResources(() -> true);
-            ctx.setExpectCreatingExecutionGraph();
-            wfr.onNewResourcesAvailable();
-        }
+    void testSchedulingWithSufficientResourcesAndNoStabilizationTimeout() {
+        Duration noStabilizationTimeout = Duration.ofMillis(0);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ofSeconds(1000), noStabilizationTimeout);
+
+        ctx.setHasDesiredResources(() -> false);
+        ctx.setHasSufficientResources(() -> true);
+        ctx.setExpectCreatingExecutionGraph();
+        wfr.onNewResourcesAvailable();
     }
 
     @Test
-    public void testNoSchedulingIfStabilizationTimeoutIsConfigured() throws Exception {
-        try (MockContext ctx = new MockContext()) {
+    void testNoSchedulingIfStabilizationTimeoutIsConfigured() {
+        Duration stabilizationTimeout = Duration.ofMillis(50000);
 
-            Duration stabilizationTimeout = Duration.ofMillis(50000);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ofSeconds(1000), stabilizationTimeout);
 
-            WaitingForResources wfr =
-                    new WaitingForResources(
-                            ctx, log, Duration.ofSeconds(1000), stabilizationTimeout);
+        ctx.setHasDesiredResources(() -> false);
+        ctx.setHasSufficientResources(() -> true);
+        wfr.onNewResourcesAvailable();
+        // we are not triggering the scheduled tasks, to simulate a long stabilization timeout
 
-            ctx.setHasDesiredResources(() -> false);
-            ctx.setHasSufficientResources(() -> true);
-            wfr.onNewResourcesAvailable();
-            // we are not triggering the scheduled tasks, to simulate a long stabilization timeout
-
-            assertThat(ctx.hasStateTransition(), is(false));
-        }
+        assertThat(ctx.hasStateTransition()).isFalse();
     }
 
     @Test
-    public void testSchedulingWithSufficientResourcesAfterStabilizationTimeout() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-
-            Duration initialResourceTimeout = Duration.ofMillis(-1);
-            Duration stabilizationTimeout = Duration.ofMillis(50_000L);
-
-            WaitingForResources wfr =
-                    new WaitingForResources(
-                            ctx,
-                            log,
-                            initialResourceTimeout,
-                            stabilizationTimeout,
-                            ctx.getClock(),
-                            null);
-            // sufficient resources available
-            ctx.setHasDesiredResources(() -> false);
-            ctx.setHasSufficientResources(() -> true);
-
-            // notify about sufficient resources
-            wfr.onNewResourcesAvailable();
-
-            ctx.setExpectCreatingExecutionGraph();
-
-            // execute all runnables and trigger expected state transition
-            final Duration afterStabilizationTimeout = stabilizationTimeout.plusMillis(1);
-            ctx.advanceTimeByMillis(afterStabilizationTimeout.toMillis());
-
-            ctx.runScheduledTasks(afterStabilizationTimeout.toMillis());
-
-            assertThat(ctx.hasStateTransition(), is(true));
-        }
+    void testSchedulingWithSufficientResourcesAfterStabilizationTimeout() {
+        Duration initialResourceTimeout = Duration.ofMillis(-1);
+        Duration stabilizationTimeout = Duration.ofMillis(50_000L);
+
+        WaitingForResources wfr =
+                new WaitingForResources(
+                        ctx,
+                        LOG,
+                        initialResourceTimeout,
+                        stabilizationTimeout,
+                        ctx.getClock(),
+                        null);
+        // sufficient resources available
+        ctx.setHasDesiredResources(() -> false);
+        ctx.setHasSufficientResources(() -> true);
+
+        // notify about sufficient resources
+        wfr.onNewResourcesAvailable();
+
+        ctx.setExpectCreatingExecutionGraph();
+
+        // execute all runnables and trigger expected state transition
+        final Duration afterStabilizationTimeout = stabilizationTimeout.plusMillis(1);
+        ctx.advanceTimeByMillis(afterStabilizationTimeout.toMillis());
+
+        ctx.runScheduledTasks(afterStabilizationTimeout.toMillis());
+
+        assertThat(ctx.hasStateTransition()).isTrue();
     }
 
     @Test
-    public void testStabilizationTimeoutReset() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-
-            Duration initialResourceTimeout = Duration.ofMillis(-1);
-            Duration stabilizationTimeout = Duration.ofMillis(50L);
-
-            WaitingForResources wfr =
-                    new WaitingForResources(
-                            ctx,
-                            log,
-                            initialResourceTimeout,
-                            stabilizationTimeout,
-                            ctx.getClock(),
-                            null);
-
-            ctx.setHasDesiredResources(() -> false);
-
-            // notify about resources, trigger stabilization timeout
-            ctx.setHasSufficientResources(() -> true);
-            ctx.advanceTimeByMillis(40); // advance time, but don't trigger stabilizationTimeout
-            wfr.onNewResourcesAvailable();
-
-            // notify again, but insufficient (reset stabilization timeout)
-            ctx.setHasSufficientResources(() -> false);
-            ctx.advanceTimeByMillis(40);
-            wfr.onNewResourcesAvailable();
-
-            // notify again, but sufficient, trigger timeout
-            ctx.setHasSufficientResources(() -> true);
-            ctx.advanceTimeByMillis(40);
-            wfr.onNewResourcesAvailable();
-
-            // sanity check: no state transition has been triggered so far
-            assertThat(ctx.hasStateTransition(), is(false));
-            assertThat(ctx.getTestDuration(), greaterThan(stabilizationTimeout));
-
-            ctx.setExpectCreatingExecutionGraph();
-
-            ctx.advanceTimeByMillis(1);
-            assertThat(ctx.hasStateTransition(), is(false));
-
-            ctx.advanceTimeByMillis(stabilizationTimeout.toMillis());
-            assertThat(ctx.hasStateTransition(), is(true));
-        }
+    void testStabilizationTimeoutReset() {
+        Duration initialResourceTimeout = Duration.ofMillis(-1);
+        Duration stabilizationTimeout = Duration.ofMillis(50L);
+
+        WaitingForResources wfr =
+                new WaitingForResources(
+                        ctx,
+                        LOG,
+                        initialResourceTimeout,
+                        stabilizationTimeout,
+                        ctx.getClock(),
+                        null);
+
+        ctx.setHasDesiredResources(() -> false);
+
+        // notify about resources, trigger stabilization timeout
+        ctx.setHasSufficientResources(() -> true);
+        ctx.advanceTimeByMillis(40); // advance time, but don't trigger stabilizationTimeout
+        wfr.onNewResourcesAvailable();
+
+        // notify again, but insufficient (reset stabilization timeout)
+        ctx.setHasSufficientResources(() -> false);
+        ctx.advanceTimeByMillis(40);
+        wfr.onNewResourcesAvailable();
+
+        // notify again, but sufficient, trigger timeout
+        ctx.setHasSufficientResources(() -> true);
+        ctx.advanceTimeByMillis(40);
+        wfr.onNewResourcesAvailable();
+
+        // sanity check: no state transition has been triggered so far
+        assertThat(ctx.hasStateTransition()).isFalse();
+        assertThat(ctx.getTestDuration()).isGreaterThan(stabilizationTimeout);
+
+        ctx.setExpectCreatingExecutionGraph();
+
+        ctx.advanceTimeByMillis(1);
+        assertThat(ctx.hasStateTransition()).isFalse();
+
+        ctx.advanceTimeByMillis(stabilizationTimeout.toMillis());
+        assertThat(ctx.hasStateTransition()).isTrue();
     }
 
     @Test
-    public void testNoStateTransitionOnNoResourceTimeout() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ofMillis(-1), STABILIZATION_TIMEOUT);
-
-            ctx.runScheduledTasks();
-            assertThat(ctx.hasStateTransition(), is(false));
-        }
+    void testNoStateTransitionOnNoResourceTimeout() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ofMillis(-1), STABILIZATION_TIMEOUT);
+
+        ctx.runScheduledTasks();
+        assertThat(ctx.hasStateTransition()).isFalse();
     }
 
     @Test
-    public void testStateTransitionOnResourceTimeout() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
+    void testStateTransitionOnResourceTimeout() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
 
-            ctx.setExpectCreatingExecutionGraph();
+        ctx.setExpectCreatingExecutionGraph();
 
-            ctx.runScheduledTasks();
-        }
+        ctx.runScheduledTasks();
     }
 
     @Test
-    public void testTransitionToFinishedOnGlobalFailure() throws Exception {
-        final String testExceptionString = "This is a test exception";
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-            ctx.setExpectFinished(
-                    archivedExecutionGraph -> {
-                        assertThat(archivedExecutionGraph.getState(), is(JobStatus.FAILED));
-                        assertThat(archivedExecutionGraph.getFailureInfo(), notNullValue());
-                        assertTrue(
-                                archivedExecutionGraph
-                                        .getFailureInfo()
-                                        .getExceptionAsString()
-                                        .contains(testExceptionString));
-                    });
-
-            wfr.handleGlobalFailure(
-                    new RuntimeException(testExceptionString),
-                    FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-        }
+    void testTransitionToFinishedOnGlobalFailure() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
+        RuntimeException expectedException = new RuntimeException("This is a test exception");
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        wfr.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
     }
 
     @Test
-    public void testCancel() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-            ctx.setExpectFinished(
-                    (archivedExecutionGraph -> {
-                        assertThat(archivedExecutionGraph.getState(), is(JobStatus.CANCELED));
-                    }));
-            wfr.cancel();
-        }
+    void testCancel() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
+                });
+        wfr.cancel();
     }
 
     @Test
-    public void testSuspend() throws Exception {
-        try (MockContext ctx = new MockContext()) {
-            ctx.setHasDesiredResources(() -> false);
-            WaitingForResources wfr =
-                    new WaitingForResources(ctx, log, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-            ctx.setExpectFinished(
-                    (archivedExecutionGraph -> {
-                        assertThat(archivedExecutionGraph.getState(), is(JobStatus.SUSPENDED));
-                        assertThat(archivedExecutionGraph.getFailureInfo(), notNullValue());
-                    }));
-
-            wfr.suspend(new RuntimeException("suspend"));
-        }
+    void testSuspend() {
+        ctx.setHasDesiredResources(() -> false);
+        WaitingForResources wfr =
+                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
+
+        FlinkException expectedException = new FlinkException("This is a test exception");
+
+        ctx.setExpectFinished(
+                archivedExecutionGraph -> {
+                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
+                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
+                    assertThat(
+                                    archivedExecutionGraph
+                                            .getFailureInfo()
+                                            .getException()
+                                            .deserializeError(this.getClass().getClassLoader()))
+                            .isEqualTo(expectedException);
+                });
+
+        wfr.suspend(expectedException);
     }
 
     @Test
-    public void testInternalRunScheduledTasks_correctExecutionOrder() {
-        MockContext ctx = new MockContext();
+    void testInternalRunScheduledTasks_correctExecutionOrder() {
         AtomicBoolean firstRun = new AtomicBoolean(false);
         AtomicBoolean secondRun = new AtomicBoolean(false);
         AtomicBoolean thirdRun = new AtomicBoolean(false);
@@ -302,16 +283,12 @@ public class WaitingForResourcesTest extends TestLogger {
         Runnable runFirstBecauseOfLowDelay = () -> firstRun.set(true);
         Runnable runSecondBecauseOfScheduleOrder =
                 () -> {
-                    if (!firstRun.get()) {
-                        fail("order violated");
-                    }
+                    assertThat(firstRun).as("order violated").isTrue();
                     secondRun.set(true);
                 };
         Runnable runLastBecauseOfHighDelay =
                 () -> {
-                    if (!secondRun.get()) {
-                        fail("order violated");
-                    }
+                    assertThat(secondRun).as("order violated").isTrue();
                     thirdRun.set(true);
                 };
 
@@ -328,19 +305,15 @@ public class WaitingForResourcesTest extends TestLogger {
 
         ctx.runScheduledTasks();
 
-        assertThat(thirdRun.get(), is(true));
+        assertThat(thirdRun).isTrue();
     }
 
     @Test
-    public void testInternalRunScheduledTasks_tasksAreRemovedAfterExecution() {
-        MockContext ctx = new MockContext();
-
+    void testInternalRunScheduledTasks_tasksAreRemovedAfterExecution() {
         AtomicBoolean executed = new AtomicBoolean(false);
         Runnable executeOnce =
                 () -> {
-                    if (executed.get()) {
-                        fail("Multiple executions");
-                    }
+                    assertThat(executed).as("Multiple executions").isFalse();
                     executed.set(true);
                 };
 
@@ -349,12 +322,11 @@ public class WaitingForResourcesTest extends TestLogger {
         // execute at least twice
         ctx.runScheduledTasks();
         ctx.runScheduledTasks();
+        assertThat(executed).isTrue();
     }
 
     @Test
-    public void testInternalRunScheduledTasks_upperBoundRespected() {
-        MockContext ctx = new MockContext();
-
+    void testInternalRunScheduledTasks_upperBoundRespected() {
         Runnable executeNever = () -> fail("Not expected");
 
         ctx.runIfState(new AdaptiveSchedulerTest.DummyState(), executeNever, Duration.ofMillis(10));
@@ -363,8 +335,7 @@ public class WaitingForResourcesTest extends TestLogger {
     }
 
     @Test
-    public void testInternalRunScheduledTasks_scheduleTaskFromRunnable() {
-        MockContext ctx = new MockContext();
+    void testInternalRunScheduledTasks_scheduleTaskFromRunnable() {
         final State state = new AdaptiveSchedulerTest.DummyState();
 
         AtomicBoolean executed = new AtomicBoolean(false);
@@ -378,10 +349,11 @@ public class WaitingForResourcesTest extends TestLogger {
 
         // choose time that includes inner execution as well
         ctx.runScheduledTasks(10);
-        assertThat(executed.get(), is(true));
+        assertThat(executed).isTrue();
     }
 
-    private static class MockContext implements WaitingForResources.Context, AutoCloseable {
+    private static class MockContext implements WaitingForResources.Context, AfterEachCallback {
+
         private static final Logger LOG = LoggerFactory.getLogger(MockContext.class);
 
         private final StateValidator<Void> creatingExecutionGraphStateValidator =
@@ -441,7 +413,7 @@ public class WaitingForResourcesTest extends TestLogger {
         }
 
         @Override
-        public void close() throws Exception {
+        public void afterEach(ExtensionContext extensionContext) throws Exception {
             creatingExecutionGraphStateValidator.close();
             finishedStateValidator.close();
         }
@@ -474,7 +446,7 @@ public class WaitingForResourcesTest extends TestLogger {
             final ScheduledTask<Void> scheduledTask =
                     new ScheduledTask<>(
                             () -> {
-                                if (!hasStateTransition) {
+                                if (!hasStateTransition()) {
                                     action.run();
                                 }
 
@@ -490,19 +462,23 @@ public class WaitingForResourcesTest extends TestLogger {
         @Override
         public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
             finishedStateValidator.validateInput(archivedExecutionGraph);
-            hasStateTransition = true;
+            registerStateTransition();
         }
 
         @Override
         public void goToCreatingExecutionGraph(@Nullable ExecutionGraph previousExecutionGraph) {
             creatingExecutionGraphStateValidator.validateInput(null);
-            hasStateTransition = true;
+            registerStateTransition();
         }
 
         public boolean hasStateTransition() {
             return hasStateTransition;
         }
 
+        public void registerStateTransition() {
+            hasStateTransition = true;
+        }
+
         public Clock getClock() {
             return testTime.getClock();
         }
@@ -550,6 +526,6 @@ public class WaitingForResourcesTest extends TestLogger {
     }
 
     static <T> Consumer<T> assertNonNull() {
-        return (item) -> assertThat(item, notNullValue());
+        return (item) -> assertThat(item).isNotNull();
     }
 }


[flink] 03/03: [FLINK-32859][scheduler] Introduce the StateWithoutExecutionGraph

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mapohl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 4aebc43721873480dfbbaf2cfe784c3833f1cdc9
Author: 1996fanrui <19...@gmail.com>
AuthorDate: Mon Aug 14 22:10:50 2023 +0800

    [FLINK-32859][scheduler] Introduce the StateWithoutExecutionGraph
---
 .../flink/runtime/scheduler/adaptive/Created.java  |  53 +---------
 .../scheduler/adaptive/CreatingExecutionGraph.java |  69 +++----------
 ...reated.java => StateWithoutExecutionGraph.java} |  50 +++------
 .../scheduler/adaptive/WaitingForResources.java    |  53 ++--------
 .../runtime/scheduler/adaptive/CreatedTest.java    |  81 +--------------
 .../adaptive/CreatingExecutionGraphTest.java       | 114 +--------------------
 .../MockStateWithoutExecutionGraphContext.java     |  72 +++++++++++++
 ...st.java => StateWithoutExecutionGraphTest.java} |  87 ++++------------
 .../adaptive/WaitingForResourcesTest.java          | 101 +-----------------
 9 files changed, 139 insertions(+), 541 deletions(-)

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java
index 3cbb51edb63..04147774074 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java
@@ -19,35 +19,17 @@
 package org.apache.flink.runtime.scheduler.adaptive;
 
 import org.apache.flink.api.common.JobStatus;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 
 import org.slf4j.Logger;
 
-import javax.annotation.Nullable;
-
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
-
 /** Initial state of the {@link AdaptiveScheduler}. */
-class Created implements State {
+class Created extends StateWithoutExecutionGraph {
 
     private final Context context;
 
-    private final Logger logger;
-
     Created(Context context, Logger logger) {
+        super(context, logger);
         this.context = context;
-        this.logger = logger;
-    }
-
-    @Override
-    public void cancel() {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.CANCELED, null));
-    }
-
-    @Override
-    public void suspend(Throwable cause) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.SUSPENDED, cause));
     }
 
     @Override
@@ -55,41 +37,14 @@ class Created implements State {
         return JobStatus.INITIALIZING;
     }
 
-    @Override
-    public ArchivedExecutionGraph getJob() {
-        return context.getArchivedExecutionGraph(getJobStatus(), null);
-    }
-
-    @Override
-    public void handleGlobalFailure(
-            Throwable cause, CompletableFuture<Map<String, String>> failureLabels) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.FAILED, cause));
-    }
-
-    @Override
-    public Logger getLogger() {
-        return logger;
-    }
-
     /** Starts the scheduling by going into the {@link WaitingForResources} state. */
     void startScheduling() {
         context.goToWaitingForResources(null);
     }
 
     /** Context of the {@link Created} state. */
-    interface Context extends StateTransitions.ToFinished, StateTransitions.ToWaitingForResources {
-
-        /**
-         * Creates an {@link ArchivedExecutionGraph} for the given jobStatus and failure cause.
-         *
-         * @param jobStatus jobStatus to create the {@link ArchivedExecutionGraph} with
-         * @param cause cause represents the failure cause for the {@link ArchivedExecutionGraph};
-         *     {@code null} if there is no failure cause
-         * @return the created {@link ArchivedExecutionGraph}
-         */
-        ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause);
-    }
+    interface Context
+            extends StateWithoutExecutionGraph.Context, StateTransitions.ToWaitingForResources {}
 
     static class Factory implements StateFactory<Created> {
 
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraph.java b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraph.java
index c876fe6ad1d..da90ef1468d 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraph.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraph.java
@@ -21,7 +21,6 @@ package org.apache.flink.runtime.scheduler.adaptive;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
 import org.apache.flink.runtime.execution.ExecutionState;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionJobVertex;
 import org.apache.flink.runtime.executiongraph.ExecutionVertex;
@@ -43,7 +42,6 @@ import javax.annotation.Nullable;
 
 import java.time.Duration;
 import java.util.Collections;
-import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ScheduledFuture;
@@ -56,10 +54,9 @@ import java.util.concurrent.ScheduledFuture;
  * If there are enough slots for the {@link ExecutionGraph} to run, the state transitions to {@link
  * Executing}.
  */
-public class CreatingExecutionGraph implements State {
+public class CreatingExecutionGraph extends StateWithoutExecutionGraph {
 
     private final Context context;
-    private final Logger logger;
     private final OperatorCoordinatorHandlerFactory operatorCoordinatorHandlerFactory;
 
     private final @Nullable ExecutionGraph previousExecutionGraph;
@@ -71,8 +68,8 @@ public class CreatingExecutionGraph implements State {
             Logger logger,
             OperatorCoordinatorHandlerFactory operatorCoordinatorFactory,
             ExecutionGraph previousExecutionGraph1) {
+        super(context, logger);
         this.context = context;
-        this.logger = logger;
         this.operatorCoordinatorHandlerFactory = operatorCoordinatorFactory;
 
         FutureUtils.assertNoException(
@@ -93,11 +90,12 @@ public class CreatingExecutionGraph implements State {
             @Nullable ExecutionGraphWithVertexParallelism executionGraphWithVertexParallelism,
             @Nullable Throwable throwable) {
         if (throwable != null) {
-            logger.info(
-                    "Failed to go from {} to {} because the ExecutionGraph creation failed.",
-                    CreatingExecutionGraph.class.getSimpleName(),
-                    Executing.class.getSimpleName(),
-                    throwable);
+            getLogger()
+                    .info(
+                            "Failed to go from {} to {} because the ExecutionGraph creation failed.",
+                            CreatingExecutionGraph.class.getSimpleName(),
+                            Executing.class.getSimpleName(),
+                            throwable);
             context.goToFinished(context.getArchivedExecutionGraph(JobStatus.FAILED, throwable));
         } else {
             for (ExecutionVertex vertex :
@@ -109,8 +107,9 @@ public class CreatingExecutionGraph implements State {
                     context.tryToAssignSlots(executionGraphWithVertexParallelism);
 
             if (result.isSuccess()) {
-                logger.debug(
-                        "Successfully reserved and assigned the required slots for the ExecutionGraph.");
+                getLogger()
+                        .debug(
+                                "Successfully reserved and assigned the required slots for the ExecutionGraph.");
                 final ExecutionGraph executionGraph = result.getExecutionGraph();
                 final ExecutionGraphHandler executionGraphHandler =
                         new ExecutionGraphHandler(
@@ -144,62 +143,26 @@ public class CreatingExecutionGraph implements State {
                         operatorCoordinatorHandler,
                         Collections.emptyList());
             } else {
-                logger.debug(
-                        "Failed to reserve and assign the required slots. Waiting for new resources.");
+                getLogger()
+                        .debug(
+                                "Failed to reserve and assign the required slots. Waiting for new resources.");
                 context.goToWaitingForResources(previousExecutionGraph);
             }
         }
     }
 
-    @Override
-    public void cancel() {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.CANCELED, null));
-    }
-
-    @Override
-    public void suspend(Throwable cause) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.SUSPENDED, cause));
-    }
-
     @Override
     public JobStatus getJobStatus() {
         return JobStatus.CREATED;
     }
 
-    @Override
-    public ArchivedExecutionGraph getJob() {
-        return context.getArchivedExecutionGraph(getJobStatus(), null);
-    }
-
-    @Override
-    public void handleGlobalFailure(
-            Throwable cause, CompletableFuture<Map<String, String>> failureLabels) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.FAILED, cause));
-    }
-
-    @Override
-    public Logger getLogger() {
-        return logger;
-    }
-
     /** Context for the {@link CreatingExecutionGraph} state. */
     interface Context
-            extends GlobalFailureHandler,
+            extends StateWithoutExecutionGraph.Context,
+                    GlobalFailureHandler,
                     StateTransitions.ToExecuting,
-                    StateTransitions.ToFinished,
                     StateTransitions.ToWaitingForResources {
 
-        /**
-         * Creates the {@link ArchivedExecutionGraph} for the given job status and cause. Cause can
-         * be null if there is no failure.
-         *
-         * @param jobStatus jobStatus to initialize the {@link ArchivedExecutionGraph} with
-         * @param cause cause describing a failure cause; {@code null} if there is none
-         * @return the created {@link ArchivedExecutionGraph}
-         */
-        ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause);
-
         /**
          * Runs the given action after a delay if the state at this time equals the expected state.
          *
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraph.java
similarity index 62%
copy from flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java
copy to flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraph.java
index 3cbb51edb63..16769e310df 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Created.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraph.java
@@ -28,14 +28,17 @@ import javax.annotation.Nullable;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 
-/** Initial state of the {@link AdaptiveScheduler}. */
-class Created implements State {
+/**
+ * Abstract state class which contains its {@link Context} and {@link #logger} to execute common
+ * operations.
+ */
+abstract class StateWithoutExecutionGraph implements State {
 
     private final Context context;
 
     private final Logger logger;
 
-    Created(Context context, Logger logger) {
+    StateWithoutExecutionGraph(Context context, Logger logger) {
         this.context = context;
         this.logger = logger;
     }
@@ -50,11 +53,6 @@ class Created implements State {
         context.goToFinished(context.getArchivedExecutionGraph(JobStatus.SUSPENDED, cause));
     }
 
-    @Override
-    public JobStatus getJobStatus() {
-        return JobStatus.INITIALIZING;
-    }
-
     @Override
     public ArchivedExecutionGraph getJob() {
         return context.getArchivedExecutionGraph(getJobStatus(), null);
@@ -71,42 +69,18 @@ class Created implements State {
         return logger;
     }
 
-    /** Starts the scheduling by going into the {@link WaitingForResources} state. */
-    void startScheduling() {
-        context.goToWaitingForResources(null);
-    }
-
-    /** Context of the {@link Created} state. */
-    interface Context extends StateTransitions.ToFinished, StateTransitions.ToWaitingForResources {
+    /** Context of the {@link StateWithoutExecutionGraph} state. */
+    interface Context extends StateTransitions.ToFinished {
 
         /**
-         * Creates an {@link ArchivedExecutionGraph} for the given jobStatus and failure cause.
+         * Creates the {@link ArchivedExecutionGraph} for the given job status and cause. Cause can
+         * be null if there is no failure.
          *
-         * @param jobStatus jobStatus to create the {@link ArchivedExecutionGraph} with
-         * @param cause cause represents the failure cause for the {@link ArchivedExecutionGraph};
-         *     {@code null} if there is no failure cause
+         * @param jobStatus jobStatus to initialize the {@link ArchivedExecutionGraph} with
+         * @param cause cause describing a failure cause; {@code null} if there is none
          * @return the created {@link ArchivedExecutionGraph}
          */
         ArchivedExecutionGraph getArchivedExecutionGraph(
                 JobStatus jobStatus, @Nullable Throwable cause);
     }
-
-    static class Factory implements StateFactory<Created> {
-
-        private final Context context;
-        private final Logger log;
-
-        public Factory(Context context, Logger log) {
-            this.context = context;
-            this.log = log;
-        }
-
-        public Class<Created> getStateClass() {
-            return Created.class;
-        }
-
-        public Created getState() {
-            return new Created(this.context, this.log);
-        }
-    }
 }
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
index 434b0741a28..d7933984db3 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java
@@ -21,7 +21,6 @@ package org.apache.flink.runtime.scheduler.adaptive;
 import org.apache.flink.annotation.VisibleForTesting;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.api.common.time.Deadline;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.util.Preconditions;
 import org.apache.flink.util.clock.Clock;
@@ -32,19 +31,15 @@ import org.slf4j.Logger;
 import javax.annotation.Nullable;
 
 import java.time.Duration;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ScheduledFuture;
 
 /**
  * State which describes that the scheduler is waiting for resources in order to execute the job.
  */
-class WaitingForResources implements State, ResourceListener {
+class WaitingForResources extends StateWithoutExecutionGraph implements ResourceListener {
 
     private final Context context;
 
-    private final Logger log;
-
     private final Clock clock;
 
     /** If set, there's an ongoing deadline waiting for a resource stabilization. */
@@ -78,8 +73,8 @@ class WaitingForResources implements State, ResourceListener {
             Duration resourceStabilizationTimeout,
             Clock clock,
             @Nullable ExecutionGraph previousExecutionGraph) {
+        super(context, log);
         this.context = Preconditions.checkNotNull(context);
-        this.log = Preconditions.checkNotNull(log);
         this.resourceStabilizationTimeout =
                 Preconditions.checkNotNull(resourceStabilizationTimeout);
         this.clock = clock;
@@ -106,37 +101,11 @@ class WaitingForResources implements State, ResourceListener {
         }
     }
 
-    @Override
-    public void cancel() {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.CANCELED, null));
-    }
-
-    @Override
-    public void suspend(Throwable cause) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.SUSPENDED, cause));
-    }
-
     @Override
     public JobStatus getJobStatus() {
         return JobStatus.CREATED;
     }
 
-    @Override
-    public ArchivedExecutionGraph getJob() {
-        return context.getArchivedExecutionGraph(getJobStatus(), null);
-    }
-
-    @Override
-    public void handleGlobalFailure(
-            Throwable cause, CompletableFuture<Map<String, String>> failureLabels) {
-        context.goToFinished(context.getArchivedExecutionGraph(JobStatus.FAILED, cause));
-    }
-
-    @Override
-    public Logger getLogger() {
-        return log;
-    }
-
     @Override
     public void onNewResourcesAvailable() {
         checkDesiredOrSufficientResourcesAvailable();
@@ -174,8 +143,9 @@ class WaitingForResources implements State, ResourceListener {
     }
 
     private void resourceTimeout() {
-        log.debug(
-                "Initial resource allocation timeout triggered: Creating ExecutionGraph with available resources.");
+        getLogger()
+                .debug(
+                        "Initial resource allocation timeout triggered: Creating ExecutionGraph with available resources.");
         createExecutionGraphWithAvailableResources();
     }
 
@@ -185,18 +155,7 @@ class WaitingForResources implements State, ResourceListener {
 
     /** Context of the {@link WaitingForResources} state. */
     interface Context
-            extends StateTransitions.ToCreatingExecutionGraph, StateTransitions.ToFinished {
-
-        /**
-         * Creates the {@link ArchivedExecutionGraph} for the given job status and cause. Cause can
-         * be null if there is no failure.
-         *
-         * @param jobStatus jobStatus to initialize the {@link ArchivedExecutionGraph} with
-         * @param cause cause describing a failure cause; {@code null} if there is none
-         * @return the created {@link ArchivedExecutionGraph}
-         */
-        ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause);
+            extends StateWithoutExecutionGraph.Context, StateTransitions.ToCreatingExecutionGraph {
 
         /**
          * Checks whether we have the desired resources.
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
index 302fb471c3e..9a13f5deb6e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
@@ -18,15 +18,11 @@
 
 package org.apache.flink.runtime.scheduler.adaptive;
 
-import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
-import org.apache.flink.runtime.failure.FailureEnricherUtils;
-import org.apache.flink.util.FlinkException;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
@@ -34,8 +30,6 @@ import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nullable;
 
-import java.util.function.Consumer;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for the {@link Created} state. */
@@ -45,18 +39,6 @@ class CreatedTest {
 
     @RegisterExtension MockCreatedContext ctx = new MockCreatedContext();
 
-    @Test
-    void testCancel() {
-        Created created = new Created(ctx, LOG);
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
-                });
-        created.cancel();
-    }
-
     @Test
     void testStartScheduling() {
         Created created = new Created(ctx, LOG);
@@ -66,46 +48,6 @@ class CreatedTest {
         created.startScheduling();
     }
 
-    @Test
-    void testSuspend() {
-        FlinkException expectedException = new FlinkException("This is a test exception");
-        Created created = new Created(ctx, LOG);
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        created.suspend(expectedException);
-    }
-
-    @Test
-    void testFailure() {
-        Created created = new Created(ctx, LOG);
-        RuntimeException expectedException = new RuntimeException("This is a test exception");
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        created.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-    }
-
     @Test
     void testJobInformation() {
         Created created = new Created(ctx, LOG);
@@ -113,32 +55,15 @@ class CreatedTest {
         assertThat(job.getState()).isEqualTo(JobStatus.INITIALIZING);
     }
 
-    static class MockCreatedContext implements Created.Context, AfterEachCallback {
-        private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
-                new StateValidator<>("finished");
+    static class MockCreatedContext extends MockStateWithoutExecutionGraphContext
+            implements Created.Context {
         private final StateValidator<Void> waitingForResourcesStateValidator =
                 new StateValidator<>("WaitingForResources");
 
-        public void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
-            finishedStateValidator.expectInput(asserter);
-        }
-
         public void setExpectWaitingForResources() {
             waitingForResourcesStateValidator.expectInput((none) -> {});
         }
 
-        @Override
-        public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
-            finishedStateValidator.validateInput(archivedExecutionGraph);
-        }
-
-        @Override
-        public ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause) {
-            return ArchivedExecutionGraph.createSparseArchivedExecutionGraph(
-                    new JobID(), "testJob", jobStatus, cause, null, 0L);
-        }
-
         @Override
         public void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGraph) {
             waitingForResourcesStateValidator.validateInput(null);
@@ -146,7 +71,7 @@ class CreatedTest {
 
         @Override
         public void afterEach(ExtensionContext extensionContext) throws Exception {
-            finishedStateValidator.close();
+            super.afterEach(extensionContext);
             waitingForResourcesStateValidator.close();
         }
     }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
index 833835b7d22..b831b3bb62f 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatingExecutionGraphTest.java
@@ -18,14 +18,11 @@
 
 package org.apache.flink.runtime.scheduler.adaptive;
 
-import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.core.testutils.CompletedScheduledFuture;
 import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
 import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
-import org.apache.flink.runtime.failure.FailureEnricherUtils;
 import org.apache.flink.runtime.metrics.groups.JobManagerJobMetricGroup;
 import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
 import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
@@ -36,7 +33,6 @@ import org.apache.flink.util.FlinkException;
 import org.apache.flink.util.concurrent.Executors;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
@@ -63,79 +59,6 @@ class CreatingExecutionGraphTest {
     @RegisterExtension
     MockCreatingExecutionGraphContext context = new MockCreatingExecutionGraphContext();
 
-    @Test
-    void testCancelTransitionsToFinished() {
-        final CreatingExecutionGraph creatingExecutionGraph =
-                new CreatingExecutionGraph(
-                        context,
-                        new CompletableFuture<>(),
-                        LOG,
-                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                        null);
-
-        context.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
-                });
-        creatingExecutionGraph.cancel();
-    }
-
-    @Test
-    void testSuspendTransitionsToFinished() {
-        final CreatingExecutionGraph creatingExecutionGraph =
-                new CreatingExecutionGraph(
-                        context,
-                        new CompletableFuture<>(),
-                        LOG,
-                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                        null);
-
-        FlinkException expectedException = new FlinkException("This is a test exception");
-
-        context.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        creatingExecutionGraph.suspend(expectedException);
-    }
-
-    @Test
-    void testGlobalFailureTransitionsToFinished() {
-        final CreatingExecutionGraph creatingExecutionGraph =
-                new CreatingExecutionGraph(
-                        context,
-                        new CompletableFuture<>(),
-                        LOG,
-                        CreatingExecutionGraphTest::createTestingOperatorCoordinatorHandler,
-                        null);
-
-        RuntimeException expectedException = new RuntimeException("This is a test exception");
-
-        context.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        creatingExecutionGraph.handleGlobalFailure(
-                expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-    }
-
     @Test
     void testFailedExecutionGraphCreationTransitionsToFinished() {
         final CompletableFuture<CreatingExecutionGraph.ExecutionGraphWithVertexParallelism>
@@ -235,10 +158,8 @@ class CreatingExecutionGraphTest {
         return new TestingOperatorCoordinatorHandler();
     }
 
-    static class MockCreatingExecutionGraphContext
-            implements CreatingExecutionGraph.Context, AfterEachCallback {
-        private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
-                new StateValidator<>("Finished");
+    static class MockCreatingExecutionGraphContext extends MockStateWithoutExecutionGraphContext
+            implements CreatingExecutionGraph.Context {
         private final StateValidator<Void> waitingForResourcesStateValidator =
                 new StateValidator<>("WaitingForResources");
         private final StateValidator<ExecutionGraph> executingStateValidator =
@@ -255,12 +176,6 @@ class CreatingExecutionGraphTest {
                     // No-op.
                 };
 
-        private boolean hasStateTransition = false;
-
-        public void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
-            finishedStateValidator.expectInput(asserter);
-        }
-
         public void setExpectWaitingForResources() {
             waitingForResourcesStateValidator.expectInput((none) -> {});
         }
@@ -281,12 +196,6 @@ class CreatingExecutionGraphTest {
             this.globalFailureHandler = globalFailureHandler;
         }
 
-        @Override
-        public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
-            finishedStateValidator.validateInput(archivedExecutionGraph);
-            registerStateTransition();
-        }
-
         @Override
         public void goToExecuting(
                 ExecutionGraph executionGraph,
@@ -297,13 +206,6 @@ class CreatingExecutionGraphTest {
             registerStateTransition();
         }
 
-        @Override
-        public ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause) {
-            return ArchivedExecutionGraph.createSparseArchivedExecutionGraph(
-                    new JobID(), "testJob", jobStatus, cause, null, 0L);
-        }
-
         @Override
         public ScheduledFuture<?> runIfState(State expectedState, Runnable action, Duration delay) {
             if (!hasStateTransition()) {
@@ -328,7 +230,7 @@ class CreatingExecutionGraphTest {
         @Override
         public void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGraph) {
             waitingForResourcesStateValidator.validateInput(null);
-            hasStateTransition = true;
+            registerStateTransition();
         }
 
         @Override
@@ -348,18 +250,10 @@ class CreatingExecutionGraphTest {
 
         @Override
         public void afterEach(ExtensionContext extensionContext) throws Exception {
-            finishedStateValidator.close();
+            super.afterEach(extensionContext);
             waitingForResourcesStateValidator.close();
             executingStateValidator.close();
         }
-
-        public boolean hasStateTransition() {
-            return hasStateTransition;
-        }
-
-        public void registerStateTransition() {
-            hasStateTransition = true;
-        }
     }
 
     private static CreatingExecutionGraph.ExecutionGraphWithVertexParallelism getGraph(
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockStateWithoutExecutionGraphContext.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockStateWithoutExecutionGraphContext.java
new file mode 100644
index 00000000000..75dbab9a804
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockStateWithoutExecutionGraphContext.java
@@ -0,0 +1,72 @@
+/*
+ * 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.adaptive;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
+import org.apache.flink.runtime.executiongraph.ErrorInfo;
+import org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
+
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import java.util.function.Consumer;
+
+/** Mock the {@link StateWithoutExecutionGraph.Context}. */
+class MockStateWithoutExecutionGraphContext
+        implements StateWithoutExecutionGraph.Context, AfterEachCallback {
+
+    private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
+            new StateValidator<>("Finished");
+
+    private boolean hasStateTransition = false;
+
+    public void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
+        finishedStateValidator.expectInput(asserter);
+    }
+
+    @Override
+    public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
+        finishedStateValidator.validateInput(archivedExecutionGraph);
+        registerStateTransition();
+    }
+
+    @Override
+    public ArchivedExecutionGraph getArchivedExecutionGraph(
+            JobStatus jobStatus, @Nullable Throwable cause) {
+        return new ArchivedExecutionGraphBuilder()
+                .setState(jobStatus)
+                .setFailureCause(cause == null ? null : new ErrorInfo(cause, 1337))
+                .build();
+    }
+
+    @Override
+    public void afterEach(ExtensionContext extensionContext) throws Exception {
+        finishedStateValidator.close();
+    }
+
+    public boolean hasStateTransition() {
+        return hasStateTransition;
+    }
+
+    public void registerStateTransition() {
+        hasStateTransition = true;
+    }
+}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraphTest.java
similarity index 53%
copy from flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
copy to flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraphTest.java
index 302fb471c3e..349371180a0 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/CreatedTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/StateWithoutExecutionGraphTest.java
@@ -18,58 +18,41 @@
 
 package org.apache.flink.runtime.scheduler.adaptive;
 
-import org.apache.flink.api.common.JobID;
 import org.apache.flink.api.common.JobStatus;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
-import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.failure.FailureEnricherUtils;
 import org.apache.flink.util.FlinkException;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.AfterEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.annotation.Nullable;
-
-import java.util.function.Consumer;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
-/** Tests for the {@link Created} state. */
-class CreatedTest {
+/** Tests for the {@link StateWithoutExecutionGraph} state. */
+public class StateWithoutExecutionGraphTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(CreatedTest.class);
 
-    @RegisterExtension MockCreatedContext ctx = new MockCreatedContext();
+    @RegisterExtension
+    MockStateWithoutExecutionGraphContext ctx = new MockStateWithoutExecutionGraphContext();
 
     @Test
-    void testCancel() {
-        Created created = new Created(ctx, LOG);
+    void testCancelTransitionsToFinished() {
+        TestingStateWithoutExecutionGraph state = new TestingStateWithoutExecutionGraph(ctx, LOG);
 
         ctx.setExpectFinished(
                 archivedExecutionGraph -> {
                     assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
                     assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
                 });
-        created.cancel();
+        state.cancel();
     }
 
     @Test
-    void testStartScheduling() {
-        Created created = new Created(ctx, LOG);
-
-        ctx.setExpectWaitingForResources();
-
-        created.startScheduling();
-    }
-
-    @Test
-    void testSuspend() {
+    void testSuspendTransitionsToFinished() {
         FlinkException expectedException = new FlinkException("This is a test exception");
-        Created created = new Created(ctx, LOG);
+        TestingStateWithoutExecutionGraph state = new TestingStateWithoutExecutionGraph(ctx, LOG);
 
         ctx.setExpectFinished(
                 archivedExecutionGraph -> {
@@ -83,12 +66,12 @@ class CreatedTest {
                             .isEqualTo(expectedException);
                 });
 
-        created.suspend(expectedException);
+        state.suspend(expectedException);
     }
 
     @Test
-    void testFailure() {
-        Created created = new Created(ctx, LOG);
+    void testTransitionToFinishedOnGlobalFailure() {
+        TestingStateWithoutExecutionGraph state = new TestingStateWithoutExecutionGraph(ctx, LOG);
         RuntimeException expectedException = new RuntimeException("This is a test exception");
 
         ctx.setExpectFinished(
@@ -103,51 +86,19 @@ class CreatedTest {
                             .isEqualTo(expectedException);
                 });
 
-        created.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
+        state.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
     }
 
-    @Test
-    void testJobInformation() {
-        Created created = new Created(ctx, LOG);
-        ArchivedExecutionGraph job = created.getJob();
-        assertThat(job.getState()).isEqualTo(JobStatus.INITIALIZING);
-    }
+    private static final class TestingStateWithoutExecutionGraph
+            extends StateWithoutExecutionGraph {
 
-    static class MockCreatedContext implements Created.Context, AfterEachCallback {
-        private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
-                new StateValidator<>("finished");
-        private final StateValidator<Void> waitingForResourcesStateValidator =
-                new StateValidator<>("WaitingForResources");
-
-        public void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
-            finishedStateValidator.expectInput(asserter);
-        }
-
-        public void setExpectWaitingForResources() {
-            waitingForResourcesStateValidator.expectInput((none) -> {});
-        }
-
-        @Override
-        public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
-            finishedStateValidator.validateInput(archivedExecutionGraph);
-        }
-
-        @Override
-        public ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause) {
-            return ArchivedExecutionGraph.createSparseArchivedExecutionGraph(
-                    new JobID(), "testJob", jobStatus, cause, null, 0L);
-        }
-
-        @Override
-        public void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGraph) {
-            waitingForResourcesStateValidator.validateInput(null);
+        TestingStateWithoutExecutionGraph(Context context, Logger logger) {
+            super(context, logger);
         }
 
         @Override
-        public void afterEach(ExtensionContext extensionContext) throws Exception {
-            finishedStateValidator.close();
-            waitingForResourcesStateValidator.close();
+        public JobStatus getJobStatus() {
+            return null;
         }
     }
 }
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
index bdcc73f5c9d..9c7aab6901b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResourcesTest.java
@@ -18,19 +18,12 @@
 
 package org.apache.flink.runtime.scheduler.adaptive;
 
-import org.apache.flink.api.common.JobStatus;
 import org.apache.flink.core.testutils.ScheduledTask;
-import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
-import org.apache.flink.runtime.executiongraph.ErrorInfo;
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
-import org.apache.flink.runtime.failure.FailureEnricherUtils;
-import org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
-import org.apache.flink.util.FlinkException;
 import org.apache.flink.util.clock.Clock;
 import org.apache.flink.util.clock.ManualClock;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.RegisterExtension;
 import org.slf4j.Logger;
@@ -215,65 +208,6 @@ class WaitingForResourcesTest {
         ctx.runScheduledTasks();
     }
 
-    @Test
-    void testTransitionToFinishedOnGlobalFailure() {
-        ctx.setHasDesiredResources(() -> false);
-        WaitingForResources wfr =
-                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
-        RuntimeException expectedException = new RuntimeException("This is a test exception");
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        wfr.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS);
-    }
-
-    @Test
-    void testCancel() {
-        ctx.setHasDesiredResources(() -> false);
-        WaitingForResources wfr =
-                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNull();
-                });
-        wfr.cancel();
-    }
-
-    @Test
-    void testSuspend() {
-        ctx.setHasDesiredResources(() -> false);
-        WaitingForResources wfr =
-                new WaitingForResources(ctx, LOG, Duration.ZERO, STABILIZATION_TIMEOUT);
-
-        FlinkException expectedException = new FlinkException("This is a test exception");
-
-        ctx.setExpectFinished(
-                archivedExecutionGraph -> {
-                    assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED);
-                    assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull();
-                    assertThat(
-                                    archivedExecutionGraph
-                                            .getFailureInfo()
-                                            .getException()
-                                            .deserializeError(this.getClass().getClassLoader()))
-                            .isEqualTo(expectedException);
-                });
-
-        wfr.suspend(expectedException);
-    }
-
     @Test
     void testInternalRunScheduledTasks_correctExecutionOrder() {
         AtomicBoolean firstRun = new AtomicBoolean(false);
@@ -352,14 +286,13 @@ class WaitingForResourcesTest {
         assertThat(executed).isTrue();
     }
 
-    private static class MockContext implements WaitingForResources.Context, AfterEachCallback {
+    private static class MockContext extends MockStateWithoutExecutionGraphContext
+            implements WaitingForResources.Context {
 
         private static final Logger LOG = LoggerFactory.getLogger(MockContext.class);
 
         private final StateValidator<Void> creatingExecutionGraphStateValidator =
                 new StateValidator<>("executing");
-        private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
-                new StateValidator<>("finished");
 
         private Supplier<Boolean> hasDesiredResourcesSupplier = () -> false;
         private Supplier<Boolean> hasSufficientResourcesSupplier = () -> false;
@@ -367,7 +300,6 @@ class WaitingForResourcesTest {
         private final Queue<ScheduledTask<Void>> scheduledTasks =
                 new PriorityQueue<>(
                         Comparator.comparingLong(o -> o.getDelay(TimeUnit.MILLISECONDS)));
-        private boolean hasStateTransition = false;
 
         private final ManualTestTime testTime =
                 new ManualTestTime(
@@ -382,10 +314,6 @@ class WaitingForResourcesTest {
             hasSufficientResourcesSupplier = sup;
         }
 
-        void setExpectFinished(Consumer<ArchivedExecutionGraph> asserter) {
-            finishedStateValidator.expectInput(asserter);
-        }
-
         void setExpectCreatingExecutionGraph() {
             creatingExecutionGraphStateValidator.expectInput(none -> {});
         }
@@ -414,17 +342,8 @@ class WaitingForResourcesTest {
 
         @Override
         public void afterEach(ExtensionContext extensionContext) throws Exception {
+            super.afterEach(extensionContext);
             creatingExecutionGraphStateValidator.close();
-            finishedStateValidator.close();
-        }
-
-        @Override
-        public ArchivedExecutionGraph getArchivedExecutionGraph(
-                JobStatus jobStatus, @Nullable Throwable cause) {
-            return new ArchivedExecutionGraphBuilder()
-                    .setState(jobStatus)
-                    .setFailureCause(cause == null ? null : new ErrorInfo(cause, 1337))
-                    .build();
         }
 
         @Override
@@ -459,26 +378,12 @@ class WaitingForResourcesTest {
             return scheduledTask;
         }
 
-        @Override
-        public void goToFinished(ArchivedExecutionGraph archivedExecutionGraph) {
-            finishedStateValidator.validateInput(archivedExecutionGraph);
-            registerStateTransition();
-        }
-
         @Override
         public void goToCreatingExecutionGraph(@Nullable ExecutionGraph previousExecutionGraph) {
             creatingExecutionGraphStateValidator.validateInput(null);
             registerStateTransition();
         }
 
-        public boolean hasStateTransition() {
-            return hasStateTransition;
-        }
-
-        public void registerStateTransition() {
-            hasStateTransition = true;
-        }
-
         public Clock getClock() {
             return testTime.getClock();
         }