1717
1818package org .apache .seatunnel .engine .server .checkpoint ;
1919
20- import org .apache .seatunnel .common .utils .ReflectionUtils ;
2120import org .apache .seatunnel .engine .checkpoint .storage .exception .CheckpointStorageException ;
2221import org .apache .seatunnel .engine .common .config .server .CheckpointConfig ;
2322import org .apache .seatunnel .engine .common .config .server .CheckpointStorageConfig ;
24- import org .apache .seatunnel .engine .common .utils .concurrent .CompletableFuture ;
2523import org .apache .seatunnel .engine .core .checkpoint .CheckpointType ;
2624import org .apache .seatunnel .engine .server .AbstractSeaTunnelServerTest ;
2725import org .apache .seatunnel .engine .server .checkpoint .operation .TaskAcknowledgeOperation ;
2826import org .apache .seatunnel .engine .server .execution .TaskGroupLocation ;
2927import org .apache .seatunnel .engine .server .execution .TaskLocation ;
3028
31- import org .junit .jupiter .api .Assertions ;
3229import org .junit .jupiter .api .Test ;
33- import org .mockito .MockedStatic ;
34- import org .mockito .Mockito ;
3530
36- import java .time .Instant ;
3731import java .util .ArrayList ;
38- import java .util .Collections ;
3932import java .util .HashMap ;
4033import java .util .Map ;
41- import java .util .concurrent .ExecutionException ;
42- import java .util .concurrent .ExecutorService ;
43- import java .util .concurrent .Executors ;
44- import java .util .concurrent .TimeUnit ;
45- import java .util .concurrent .TimeoutException ;
46- import java .util .concurrent .atomic .AtomicLong ;
4734
4835import static org .apache .seatunnel .engine .common .Constant .IMAP_RUNNING_JOB_STATE ;
4936
@@ -64,7 +51,6 @@ void testACKNotExistPendingCheckpoint() throws CheckpointStorageException {
6451 null ,
6552 planMap ,
6653 checkpointConfig ,
67- server .getCheckpointService ().getCheckpointStorage (),
6854 instance .getExecutorService ("test" ),
6955 nodeEngine .getHazelcastInstance ().getMap (IMAP_RUNNING_JOB_STATE ));
7056 checkpointManager .acknowledgeTask (
@@ -74,94 +60,4 @@ void testACKNotExistPendingCheckpoint() throws CheckpointStorageException {
7460 999 , System .currentTimeMillis (), CheckpointType .CHECKPOINT_TYPE ),
7561 new ArrayList <>()));
7662 }
77-
78- @ Test
79- void testSchedulerThreadShouldNotBeInterruptedBeforeJobMasterCleaned ()
80- throws CheckpointStorageException , ExecutionException , InterruptedException ,
81- TimeoutException {
82- CheckpointConfig checkpointConfig = new CheckpointConfig ();
83- // quickly fail the checkpoint
84- checkpointConfig .setCheckpointTimeout (5000 );
85- checkpointConfig .setStorage (new CheckpointStorageConfig ());
86- Map <Integer , CheckpointPlan > planMap = new HashMap <>();
87- planMap .put (
88- 1 ,
89- CheckpointPlan .builder ()
90- .pipelineId (1 )
91- .pipelineSubtasks (Collections .singleton (new TaskLocation ()))
92- .build ());
93- CompletableFuture <Boolean > threadIsInterrupted = new CompletableFuture <>();
94- ExecutorService executorService = Executors .newCachedThreadPool ();
95- try {
96- CheckpointManager checkpointManager =
97- new CheckpointManager (
98- 1L ,
99- false ,
100- nodeEngine ,
101- null ,
102- planMap ,
103- checkpointConfig ,
104- server .getCheckpointService ().getCheckpointStorage (),
105- executorService ,
106- nodeEngine .getHazelcastInstance ().getMap (IMAP_RUNNING_JOB_STATE )) {
107-
108- @ Override
109- protected void handleCheckpointError (int pipelineId , boolean neverRestore ) {
110- threadIsInterrupted .complete (Thread .interrupted ());
111- }
112- };
113- checkpointManager .reportedPipelineRunning (1 , true );
114- Assertions .assertFalse (threadIsInterrupted .get (1 , TimeUnit .MINUTES ));
115- } finally {
116- executorService .shutdownNow ();
117- }
118- }
119-
120- @ Test
121- void testCheckpointContinuesWorkAfterClockDrift ()
122- throws CheckpointStorageException , ExecutionException , InterruptedException ,
123- TimeoutException {
124- CheckpointConfig checkpointConfig = new CheckpointConfig ();
125- checkpointConfig .setStorage (new CheckpointStorageConfig ());
126- checkpointConfig .setCheckpointTimeout (5000 );
127- checkpointConfig .setCheckpointInterval (5000 );
128- Map <Integer , CheckpointPlan > planMap = new HashMap <>();
129- planMap .put (
130- 1 ,
131- CheckpointPlan .builder ()
132- .pipelineId (1 )
133- .pipelineSubtasks (Collections .singleton (new TaskLocation ()))
134- .build ());
135- ExecutorService executorService = Executors .newCachedThreadPool ();
136- CompletableFuture <Boolean > invokedHandleCheckpointError = new CompletableFuture <>();
137- Instant now = Instant .now ();
138- Instant startTime = now .minusSeconds (10 );
139- try (MockedStatic <Instant > mockedInstant = Mockito .mockStatic (Instant .class )) {
140- mockedInstant .when (Instant ::now ).thenReturn (startTime );
141- CheckpointManager checkpointManager =
142- new CheckpointManager (
143- 1L ,
144- false ,
145- nodeEngine ,
146- null ,
147- planMap ,
148- checkpointConfig ,
149- server .getCheckpointService ().getCheckpointStorage (),
150- executorService ,
151- nodeEngine .getHazelcastInstance ().getMap (IMAP_RUNNING_JOB_STATE )) {
152- @ Override
153- protected void handleCheckpointError (int pipelineId , boolean neverRestore ) {
154- invokedHandleCheckpointError .complete (true );
155- }
156- };
157- ReflectionUtils .setField (
158- checkpointManager .getCheckpointCoordinator (1 ),
159- "latestTriggerTimestamp" ,
160- new AtomicLong (startTime .toEpochMilli ()));
161- checkpointManager .reportedPipelineRunning (1 , true );
162- Assertions .assertTrue (invokedHandleCheckpointError .get (1 , TimeUnit .MINUTES ));
163- } finally {
164- executorService .shutdownNow ();
165- }
166- }
16763}
0 commit comments