Skip to content

Commit c3d56df

Browse files
committed
[FLINK-28091][tests] Replaces ForkJoinPool by TestExecutorExtension
1 parent 81f882b commit c3d56df

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

flink-runtime/src/test/java/org/apache/flink/runtime/dispatcher/cleanup/CheckpointResourcesCleanupRunnerTest.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,22 @@
3737
import org.apache.flink.runtime.scheduler.ExecutionGraphInfo;
3838
import org.apache.flink.runtime.state.SharedStateRegistry;
3939
import org.apache.flink.runtime.state.SharedStateRegistryFactory;
40+
import org.apache.flink.testutils.executor.TestExecutorExtension;
4041
import org.apache.flink.util.FlinkException;
4142
import org.apache.flink.util.Preconditions;
4243
import org.apache.flink.util.SerializedThrowable;
4344
import org.apache.flink.util.concurrent.Executors;
4445
import org.apache.flink.util.function.ThrowingConsumer;
4546

4647
import org.junit.jupiter.api.Test;
48+
import org.junit.jupiter.api.extension.RegisterExtension;
4749

4850
import java.time.Duration;
4951
import java.util.Objects;
5052
import java.util.concurrent.CompletableFuture;
5153
import java.util.concurrent.ExecutionException;
5254
import java.util.concurrent.Executor;
53-
import java.util.concurrent.ForkJoinPool;
55+
import java.util.concurrent.ExecutorService;
5456
import java.util.function.Function;
5557

5658
import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
@@ -63,6 +65,10 @@
6365
*/
6466
class CheckpointResourcesCleanupRunnerTest {
6567

68+
@RegisterExtension
69+
private static final TestExecutorExtension<ExecutorService> EXECUTOR_EXTENSION =
70+
new TestExecutorExtension<>(java.util.concurrent.Executors::newCachedThreadPool);
71+
6672
private static final Duration TIMEOUT_FOR_REQUESTS = Duration.ofMillis(0);
6773

6874
private static final ThrowingConsumer<CheckpointResourcesCleanupRunner, ? extends Exception>
@@ -120,7 +126,7 @@ void testSuccessfulCloseAsyncAfterStart() throws Exception {
120126
final CheckpointResourcesCleanupRunner testInstance =
121127
new TestInstanceBuilder()
122128
.withCheckpointRecoveryFactory(checkpointRecoveryFactory)
123-
.withExecutor(ForkJoinPool.commonPool())
129+
.withExecutor(EXECUTOR_EXTENSION.getExecutor())
124130
.build();
125131
testInstance.start();
126132

@@ -169,7 +175,7 @@ void testCloseAsyncAfterStartAndErrorInCompletedCheckpointStoreShutdown() throws
169175
final CheckpointResourcesCleanupRunner testInstance =
170176
new TestInstanceBuilder()
171177
.withCheckpointRecoveryFactory(checkpointRecoveryFactory)
172-
.withExecutor(ForkJoinPool.commonPool())
178+
.withExecutor(EXECUTOR_EXTENSION.getExecutor())
173179
.build();
174180
testInstance.start();
175181

@@ -214,7 +220,7 @@ void testCloseAsyncAfterStartAndErrorInCheckpointIDCounterShutdown() throws Exce
214220
final CheckpointResourcesCleanupRunner testInstance =
215221
new TestInstanceBuilder()
216222
.withCheckpointRecoveryFactory(checkpointRecoveryFactory)
217-
.withExecutor(ForkJoinPool.commonPool())
223+
.withExecutor(EXECUTOR_EXTENSION.getExecutor())
218224
.build();
219225
testInstance.start();
220226

@@ -242,7 +248,7 @@ void testCloseAsyncAfterStartAndErrorInCheckpointIDCounterShutdown() throws Exce
242248
@Test
243249
void testCancellationBeforeStart() throws Exception {
244250
final CheckpointResourcesCleanupRunner testInstance =
245-
new TestInstanceBuilder().withExecutor(ForkJoinPool.commonPool()).build();
251+
new TestInstanceBuilder().withExecutor(EXECUTOR_EXTENSION.getExecutor()).build();
246252

247253
assertThatFuture(testInstance.cancel(TIMEOUT_FOR_REQUESTS))
248254
.eventuallyFailsWith(ExecutionException.class)
@@ -262,7 +268,7 @@ void testCancellationAfterStart() throws Exception {
262268
final CheckpointResourcesCleanupRunner testInstance =
263269
new TestInstanceBuilder()
264270
.withCheckpointRecoveryFactory(checkpointRecoveryFactory)
265-
.withExecutor(ForkJoinPool.commonPool())
271+
.withExecutor(EXECUTOR_EXTENSION.getExecutor())
266272
.build();
267273
AFTER_START.accept(testInstance);
268274
assertThatFuture(testInstance.cancel(TIMEOUT_FOR_REQUESTS))
@@ -278,7 +284,7 @@ void testCancellationAfterStart() throws Exception {
278284
@Test
279285
void testCancellationAfterClose() throws Exception {
280286
final CheckpointResourcesCleanupRunner testInstance =
281-
new TestInstanceBuilder().withExecutor(ForkJoinPool.commonPool()).build();
287+
new TestInstanceBuilder().withExecutor(EXECUTOR_EXTENSION.getExecutor()).build();
282288
AFTER_CLOSE.accept(testInstance);
283289
assertThatFuture(testInstance.cancel(TIMEOUT_FOR_REQUESTS))
284290
.eventuallyFailsWith(ExecutionException.class)

0 commit comments

Comments
 (0)