Fix tests for executorService.shutdown()
Even if `Executors.newSingleThreadExecutor()` returns a `FinalizableDelegatedExecutorService`,
an instance is kept in the memory until JVM exists.
That may lead to memory leak since we have a lot of threads in memory.
(cherry picked from commit fdac8f1634)
This commit is contained in:
committed by
Spring Builds
parent
6a7581e6cc
commit
ec2cfeb9b8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -48,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Artem Bilan
|
||||
* @author Bojan Vukasovic
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PersistentAcceptOnceFileListFilterExternalStoreTests implements RedisContainerTest {
|
||||
@@ -139,7 +141,8 @@ public class PersistentAcceptOnceFileListFilterExternalStoreTests implements Red
|
||||
suspend.set(true);
|
||||
assertThat(file.setLastModified(file.lastModified() + 5000L)).isTrue();
|
||||
|
||||
Future<Integer> result = Executors.newSingleThreadExecutor()
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
Future<Integer> result = executorService
|
||||
.submit(() -> filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
store.put("foo:" + file.getAbsolutePath(), "43");
|
||||
@@ -149,6 +152,7 @@ public class PersistentAcceptOnceFileListFilterExternalStoreTests implements Red
|
||||
|
||||
assertThat(file.delete()).isTrue();
|
||||
filter.close();
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.Flushable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -82,8 +83,8 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
suspend.set(true);
|
||||
file.setLastModified(file.lastModified() + 5000L);
|
||||
|
||||
Future<Integer> result = Executors.newSingleThreadExecutor()
|
||||
.submit(() -> filter.filterFiles(new File[] {file}).size());
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
Future<Integer> result = executorService.submit(() -> filter.filterFiles(new File[] {file}).size());
|
||||
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
store.put("foo:" + file.getAbsolutePath(), "43");
|
||||
latch1.countDown();
|
||||
@@ -92,6 +93,7 @@ public class PersistentAcceptOnceFileListFilterTests extends AcceptOnceFileListF
|
||||
|
||||
file.delete();
|
||||
filter.close();
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user