From e88525c27a251ba8908567ee29f4167cc83cf9b6 Mon Sep 17 00:00:00 2001 From: Barry Oglesby Date: Thu, 18 Mar 2021 09:34:38 -0700 Subject: [PATCH] GEODE-9040: Shutdown ExecutorService when the SingleThreadColocationLogger is stopped (cherry picked from commit 3b422bbe9631b7531633671a3938ed9600cfbc6e) --- .../colocation/SingleThreadColocationLogger.java | 8 +++++++- .../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 6d74f7474c4e..247fb9df6e4d 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 ColocationLogger start() { public void stop() { synchronized (lock) { missingChildren.clear(); + executorService.shutdownNow(); lock.notifyAll(); } } @@ -151,6 +152,11 @@ List getMissingChildren() { 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 ef909ca5e58d..e9cfc365597a 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 @@ -17,6 +17,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.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 void updateAndGetMissingChildRegionsUpdatesMissingChildren() { 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()); + } }