This is an automated email from the ASF dual-hosted git repository. boglesby pushed a commit to branch feature/GEODE-9040 in repository https://gitbox.apache.org/repos/asf/geode.git
commit 46270d29384937a4d31548af221f5753201cf987 Author: Barry Oglesby <[email protected]> AuthorDate: Mon Mar 15 16:25:12 2021 -0700 GEODE-9040: Shutdown ExecutorService when the SingleThreadColocationLogger is stopped --- .../colocation/SingleThreadColocationLogger.java | 8 +++++++- .../colocation/SingleThreadColocationLoggerTest.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLogger.java b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLogger.java index 6d74f74..247fb9d 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLogger.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLogger.java @@ -63,7 +63,7 @@ public class SingleThreadColocationLogger implements ColocationLogger { this(region, delayMillis, intervalMillis, LOGGER::warn, pr -> getAllColocationRegions(pr).keySet(), newSingleThreadExecutor( - runnable -> new LoggingThread("ColocationLogger for " + region.getName(), false, + runnable -> new LoggingThread("ColocationLogger for " + region.getName(), true, runnable))); } @@ -95,6 +95,7 @@ public class SingleThreadColocationLogger implements ColocationLogger { public void stop() { synchronized (lock) { missingChildren.clear(); + executorService.shutdownNow(); lock.notifyAll(); } } @@ -151,6 +152,11 @@ public class SingleThreadColocationLogger implements ColocationLogger { return new ArrayList<>(missingChildren); } + @VisibleForTesting + ExecutorService getExecutorService() { + return executorService; + } + private Runnable checkForMissingColocatedRegionRunnable() { return this::checkForMissingColocatedRegion; } diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLoggerTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLoggerTest.java index 81d043c..4b4fd11 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLoggerTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/colocation/SingleThreadColocationLoggerTest.java @@ -18,6 +18,7 @@ import static java.lang.System.lineSeparator; import static java.util.Collections.singleton; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.apache.geode.cache.Region.SEPARATOR; +import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.ArgumentMatchers.anyString; @@ -213,4 +214,18 @@ public class SingleThreadColocationLoggerTest { assertThat(colocationLogger.getMissingChildren()) .isEmpty(); } + + @Test + public void stopTerminatesExecutorService() { + SingleThreadColocationLogger colocationLogger = + new SingleThreadColocationLogger(region, 500, 1000, logger, + allColocationRegionsProvider, executorService); + colocationLogger.start(); + + colocationLogger.stop(); + + // Wait until the ExecutorService is terminated + await().untilAsserted( + () -> assertThat(colocationLogger.getExecutorService().isTerminated()).isTrue()); + } }
