|
23 | 23 | import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
|
24 | 24 | import org.apache.flink.runtime.executiongraph.ExecutionGraph;
|
25 | 25 | import org.apache.flink.runtime.failure.FailureEnricherUtils;
|
26 |
| -import org.apache.flink.util.TestLogger; |
| 26 | +import org.apache.flink.util.FlinkException; |
27 | 27 |
|
28 |
| -import org.junit.Test; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.extension.AfterEachCallback; |
| 30 | +import org.junit.jupiter.api.extension.ExtensionContext; |
| 31 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 32 | +import org.slf4j.Logger; |
| 33 | +import org.slf4j.LoggerFactory; |
29 | 34 |
|
30 | 35 | import javax.annotation.Nullable;
|
31 | 36 |
|
32 | 37 | import java.util.function.Consumer;
|
33 | 38 |
|
34 |
| -import static org.apache.flink.runtime.scheduler.adaptive.WaitingForResourcesTest.assertNonNull; |
35 |
| -import static org.hamcrest.CoreMatchers.is; |
36 |
| -import static org.junit.Assert.assertThat; |
| 39 | +import static org.assertj.core.api.Assertions.assertThat; |
37 | 40 |
|
38 | 41 | /** Tests for the {@link Created} state. */
|
39 |
| -public class CreatedTest extends TestLogger { |
| 42 | +class CreatedTest { |
40 | 43 |
|
41 |
| - @Test |
42 |
| - public void testCancel() throws Exception { |
43 |
| - try (MockCreatedContext ctx = new MockCreatedContext()) { |
44 |
| - Created created = new Created(ctx, log); |
| 44 | + private static final Logger LOG = LoggerFactory.getLogger(CreatedTest.class); |
45 | 45 |
|
46 |
| - ctx.setExpectFinished(assertNonNull()); |
| 46 | + @RegisterExtension MockCreatedContext ctx = new MockCreatedContext(); |
47 | 47 |
|
48 |
| - created.cancel(); |
49 |
| - } |
| 48 | + @Test |
| 49 | + void testCancel() { |
| 50 | + Created created = new Created(ctx, LOG); |
| 51 | + |
| 52 | + ctx.setExpectFinished( |
| 53 | + archivedExecutionGraph -> { |
| 54 | + assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.CANCELED); |
| 55 | + assertThat(archivedExecutionGraph.getFailureInfo()).isNull(); |
| 56 | + }); |
| 57 | + created.cancel(); |
50 | 58 | }
|
51 | 59 |
|
52 | 60 | @Test
|
53 |
| - public void testStartScheduling() throws Exception { |
54 |
| - try (MockCreatedContext ctx = new MockCreatedContext()) { |
55 |
| - Created created = new Created(ctx, log); |
| 61 | + void testStartScheduling() { |
| 62 | + Created created = new Created(ctx, LOG); |
56 | 63 |
|
57 |
| - ctx.setExpectWaitingForResources(); |
| 64 | + ctx.setExpectWaitingForResources(); |
58 | 65 |
|
59 |
| - created.startScheduling(); |
60 |
| - } |
| 66 | + created.startScheduling(); |
61 | 67 | }
|
62 | 68 |
|
63 | 69 | @Test
|
64 |
| - public void testSuspend() throws Exception { |
65 |
| - try (MockCreatedContext ctx = new MockCreatedContext()) { |
66 |
| - Created created = new Created(ctx, log); |
67 |
| - |
68 |
| - ctx.setExpectFinished( |
69 |
| - archivedExecutionGraph -> { |
70 |
| - assertThat(archivedExecutionGraph.getState(), is(JobStatus.SUSPENDED)); |
71 |
| - }); |
72 |
| - |
73 |
| - created.suspend(new RuntimeException("Suspend")); |
74 |
| - } |
| 70 | + void testSuspend() { |
| 71 | + FlinkException expectedException = new FlinkException("This is a test exception"); |
| 72 | + Created created = new Created(ctx, LOG); |
| 73 | + |
| 74 | + ctx.setExpectFinished( |
| 75 | + archivedExecutionGraph -> { |
| 76 | + assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.SUSPENDED); |
| 77 | + assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull(); |
| 78 | + assertThat( |
| 79 | + archivedExecutionGraph |
| 80 | + .getFailureInfo() |
| 81 | + .getException() |
| 82 | + .deserializeError(this.getClass().getClassLoader())) |
| 83 | + .isEqualTo(expectedException); |
| 84 | + }); |
| 85 | + |
| 86 | + created.suspend(expectedException); |
75 | 87 | }
|
76 | 88 |
|
77 | 89 | @Test
|
78 |
| - public void testFailure() throws Exception { |
79 |
| - try (MockCreatedContext ctx = new MockCreatedContext()) { |
80 |
| - Created created = new Created(ctx, log); |
81 |
| - |
82 |
| - ctx.setExpectFinished( |
83 |
| - archivedExecutionGraph -> { |
84 |
| - assertThat(archivedExecutionGraph.getState(), is(JobStatus.FAILED)); |
85 |
| - }); |
86 |
| - |
87 |
| - created.handleGlobalFailure( |
88 |
| - new RuntimeException("Global"), FailureEnricherUtils.EMPTY_FAILURE_LABELS); |
89 |
| - } |
| 90 | + void testFailure() { |
| 91 | + Created created = new Created(ctx, LOG); |
| 92 | + RuntimeException expectedException = new RuntimeException("This is a test exception"); |
| 93 | + |
| 94 | + ctx.setExpectFinished( |
| 95 | + archivedExecutionGraph -> { |
| 96 | + assertThat(archivedExecutionGraph.getState()).isEqualTo(JobStatus.FAILED); |
| 97 | + assertThat(archivedExecutionGraph.getFailureInfo()).isNotNull(); |
| 98 | + assertThat( |
| 99 | + archivedExecutionGraph |
| 100 | + .getFailureInfo() |
| 101 | + .getException() |
| 102 | + .deserializeError(this.getClass().getClassLoader())) |
| 103 | + .isEqualTo(expectedException); |
| 104 | + }); |
| 105 | + |
| 106 | + created.handleGlobalFailure(expectedException, FailureEnricherUtils.EMPTY_FAILURE_LABELS); |
90 | 107 | }
|
91 | 108 |
|
92 | 109 | @Test
|
93 |
| - public void testJobInformation() throws Exception { |
94 |
| - try (MockCreatedContext ctx = new MockCreatedContext()) { |
95 |
| - Created created = new Created(ctx, log); |
96 |
| - ArchivedExecutionGraph job = created.getJob(); |
97 |
| - assertThat(job.getState(), is(JobStatus.INITIALIZING)); |
98 |
| - } |
| 110 | + void testJobInformation() { |
| 111 | + Created created = new Created(ctx, LOG); |
| 112 | + ArchivedExecutionGraph job = created.getJob(); |
| 113 | + assertThat(job.getState()).isEqualTo(JobStatus.INITIALIZING); |
99 | 114 | }
|
100 | 115 |
|
101 |
| - static class MockCreatedContext implements Created.Context, AutoCloseable { |
| 116 | + static class MockCreatedContext implements Created.Context, AfterEachCallback { |
102 | 117 | private final StateValidator<ArchivedExecutionGraph> finishedStateValidator =
|
103 | 118 | new StateValidator<>("finished");
|
104 | 119 | private final StateValidator<Void> waitingForResourcesStateValidator =
|
@@ -130,7 +145,7 @@ public void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGr
|
130 | 145 | }
|
131 | 146 |
|
132 | 147 | @Override
|
133 |
| - public void close() throws Exception { |
| 148 | + public void afterEach(ExtensionContext extensionContext) throws Exception { |
134 | 149 | finishedStateValidator.close();
|
135 | 150 | waitingForResourcesStateValidator.close();
|
136 | 151 | }
|
|
0 commit comments