From fef16bf95723601b2ee739186d5c0d278380f451 Mon Sep 17 00:00:00 2001 From: John Blum Date: Mon, 20 Sep 2021 10:44:32 -0700 Subject: [PATCH] Add overloaded closeGemFireCacheWaitOnCacheClosedEvent(..) methods accepting a Supplier for a GemFireCache object to close. --- .../tests/integration/IntegrationTestsSupport.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java index f018bff..c41d54c 100644 --- a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/IntegrationTestsSupport.java @@ -36,6 +36,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import org.junit.AfterClass; @@ -85,6 +86,7 @@ import org.springframework.util.ReflectionUtils; * @see java.io.File * @see java.time.LocalDateTime * @see java.util.concurrent.TimeUnit + * @see java.util.function.Function * @see java.util.function.Predicate * @see org.apache.geode.DataSerializer * @see org.apache.geode.cache.GemFireCache @@ -415,12 +417,20 @@ public abstract class IntegrationTestsSupport { } public static void closeGemFireCacheWaitOnCacheClosedEvent(long duration) { + closeGemFireCacheWaitOnCacheClosedEvent(GemfireUtils::resolveGemFireCache, duration); + } + + public static void closeGemFireCacheWaitOnCacheClosedEvent(@NonNull Supplier cacheSupplier) { + closeGemFireCacheWaitOnCacheClosedEvent(cacheSupplier, DEFAULT_WAIT_DURATION); + } + + public static void closeGemFireCacheWaitOnCacheClosedEvent(@NonNull Supplier cacheSupplier, long duration) { AtomicBoolean closed = new AtomicBoolean(false); waitOn(() -> { try { - return Optional.ofNullable(GemfireUtils.resolveGemFireCache()) + return Optional.ofNullable(cacheSupplier.get()) .filter(cache -> !closed.get()) .map(IntegrationTestsSupport::close) .map(cacheLifecycleListener::isClosed)