19
19
package org .apache .flink .runtime .executiongraph ;
20
20
21
21
import org .apache .flink .api .common .JobStatus ;
22
- import org .apache .flink .runtime .concurrent .ComponentMainThreadExecutorServiceAdapter ;
23
22
import org .apache .flink .runtime .concurrent .ManuallyTriggeredScheduledExecutorService ;
24
23
import org .apache .flink .runtime .execution .ExecutionState ;
25
24
import org .apache .flink .runtime .executiongraph .failover .FixedDelayRestartBackoffTimeStrategy ;
35
34
import org .apache .flink .runtime .scheduler .TestingPhysicalSlot ;
36
35
import org .apache .flink .runtime .scheduler .TestingPhysicalSlotProvider ;
37
36
import org .apache .flink .runtime .taskmanager .TaskManagerLocation ;
38
- import org .apache .flink .runtime .testutils .DirectScheduledExecutorService ;
39
37
import org .apache .flink .testutils .TestingUtils ;
40
38
import org .apache .flink .testutils .executor .TestExecutorExtension ;
41
39
import org .apache .flink .util .FlinkException ;
@@ -58,6 +56,13 @@ class ExecutionGraphCoLocationRestartTest {
58
56
static final TestExecutorExtension <ScheduledExecutorService > EXECUTOR_RESOURCE =
59
57
TestingUtils .defaultExecutorExtension ();
60
58
59
+ @ RegisterExtension
60
+ static final TestingComponentMainThreadExecutor .Extension MAIN_EXECUTOR_RESOURCE =
61
+ new TestingComponentMainThreadExecutor .Extension ();
62
+
63
+ private final TestingComponentMainThreadExecutor mainThreadExecutor =
64
+ MAIN_EXECUTOR_RESOURCE .getComponentMainThreadTestExecutor ();
65
+
61
66
private static final int NUM_TASKS = 31 ;
62
67
63
68
@ Test
@@ -83,11 +88,10 @@ void testConstraintsAfterRestart() throws Exception {
83
88
84
89
final ManuallyTriggeredScheduledExecutorService delayExecutor =
85
90
new ManuallyTriggeredScheduledExecutorService ();
86
- final DirectScheduledExecutorService futureExecutor = new DirectScheduledExecutorService ();
87
91
final SchedulerBase scheduler =
88
92
new DefaultSchedulerBuilder (
89
93
jobGraph ,
90
- ComponentMainThreadExecutorServiceAdapter . forMainThread (),
94
+ mainThreadExecutor . getMainThreadExecutor (),
91
95
EXECUTOR_RESOURCE .getExecutor ())
92
96
.setExecutionSlotAllocatorFactory (
93
97
SchedulerTestingUtils .newSlotSharingExecutionSlotAllocatorFactory (
@@ -97,7 +101,6 @@ void testConstraintsAfterRestart() throws Exception {
97
101
TestingPhysicalSlot .builder ()
98
102
.build ()))))
99
103
.setDelayExecutor (delayExecutor )
100
- .setFutureExecutor (futureExecutor )
101
104
.setRestartBackoffTimeStrategy (
102
105
new FixedDelayRestartBackoffTimeStrategy
103
106
.FixedDelayRestartBackoffTimeStrategyFactory (1 , 0 )
@@ -109,7 +112,7 @@ void testConstraintsAfterRestart() throws Exception {
109
112
// enable the queued scheduling for the slot pool
110
113
assertThat (eg .getState ()).isEqualTo (JobStatus .CREATED );
111
114
112
- scheduler . startScheduling ( );
115
+ mainThreadExecutor . execute ( scheduler :: startScheduling );
113
116
114
117
Predicate <AccessExecution > isDeploying =
115
118
ExecutionGraphTestUtils .isInExecutionState (ExecutionState .DEPLOYING );
@@ -120,19 +123,28 @@ void testConstraintsAfterRestart() throws Exception {
120
123
// sanity checks
121
124
validateConstraints (eg );
122
125
123
- eg .getAllExecutionVertices ().iterator ().next ().fail (new FlinkException ("Test exception" ));
126
+ mainThreadExecutor .execute (
127
+ () -> {
128
+ eg .getAllExecutionVertices ()
129
+ .iterator ()
130
+ .next ()
131
+ .fail (new FlinkException ("Test exception" ));
132
+ });
124
133
125
134
assertThat (eg .getState ()).isEqualTo (JobStatus .RESTARTING );
126
135
127
136
// trigger registration of restartTasks(...) callback to cancelFuture before completing the
128
137
// cancellation. This ensures the restarting actions to be performed in main thread.
129
138
delayExecutor .triggerNonPeriodicScheduledTask ();
130
139
131
- for (ExecutionVertex vertex : eg .getAllExecutionVertices ()) {
132
- if (vertex .getExecutionState () == ExecutionState .CANCELING ) {
133
- vertex .getCurrentExecutionAttempt ().completeCancelling ();
134
- }
135
- }
140
+ mainThreadExecutor .execute (
141
+ () -> {
142
+ for (ExecutionVertex vertex : eg .getAllExecutionVertices ()) {
143
+ if (vertex .getExecutionState () == ExecutionState .CANCELING ) {
144
+ vertex .getCurrentExecutionAttempt ().completeCancelling ();
145
+ }
146
+ }
147
+ });
136
148
137
149
// wait until we have restarted
138
150
ExecutionGraphTestUtils .waitUntilJobStatus (eg , JobStatus .RUNNING , timeout );
@@ -142,7 +154,10 @@ void testConstraintsAfterRestart() throws Exception {
142
154
// checking execution vertex properties
143
155
validateConstraints (eg );
144
156
145
- ExecutionGraphTestUtils .finishAllVertices (eg );
157
+ mainThreadExecutor .execute (
158
+ () -> {
159
+ ExecutionGraphTestUtils .finishAllVertices (eg );
160
+ });
146
161
147
162
assertThat (eg .getState ()).isEqualTo (FINISHED );
148
163
}
0 commit comments