From 218aec18ea3134b9cacc9e98b25828a3a6b50e37 Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 13 Oct 2022 15:58:06 -0700 Subject: [PATCH] Conditionally (and recursively) remove the test directory of the forked GemFire/Geode server process. --- .../ClientServerIntegrationTestsSupport.java | 3 +-- ...ngClientServerIntegrationTestsSupport.java | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ClientServerIntegrationTestsSupport.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ClientServerIntegrationTestsSupport.java index 24b458a..3f5ee44 100644 --- a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ClientServerIntegrationTestsSupport.java +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ClientServerIntegrationTestsSupport.java @@ -36,7 +36,6 @@ import org.apache.geode.cache.server.CacheServer; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.gemfire.tests.process.ProcessWrapper; -import org.springframework.data.gemfire.tests.util.FileSystemUtils; import org.springframework.data.gemfire.tests.util.SocketUtils; import org.springframework.data.gemfire.util.ArrayUtils; import org.springframework.lang.NonNull; @@ -172,7 +171,7 @@ public abstract class ClientServerIntegrationTestsSupport extends IntegrationTes it.stop(duration); if (it.isNotRunning() && isDeleteDirectoryOnExit()) { - FileSystemUtils.deleteRecursive(it.getWorkingDirectory()); + removeRecursiveDirectory(it.getWorkingDirectory()); } return it.isRunning(); diff --git a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ForkingClientServerIntegrationTestsSupport.java b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ForkingClientServerIntegrationTestsSupport.java index edff237..95404c7 100644 --- a/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ForkingClientServerIntegrationTestsSupport.java +++ b/spring-data-geode-test/src/main/java/org/springframework/data/gemfire/tests/integration/ForkingClientServerIntegrationTestsSupport.java @@ -55,8 +55,15 @@ import org.springframework.lang.Nullable; * and bootstrap Apache Geode or VMware GemFire Server {@link Cache} and {@link ClientCache} applications. * * @author John Blum + * @see java.io.File + * @see java.net.InetAddress * @see org.apache.geode.cache.Cache * @see org.apache.geode.cache.client.ClientCache + * @see org.springframework.context.ApplicationContext + * @see org.springframework.context.annotation.Bean + * @see org.springframework.context.annotation.Configuration + * @see org.springframework.context.event.ContextRefreshedEvent + * @see org.springframework.context.event.EventListener * @see org.springframework.data.gemfire.config.annotation.CacheServerApplication * @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication * @see org.springframework.data.gemfire.config.annotation.EnablePdx @@ -70,6 +77,8 @@ import org.springframework.lang.Nullable; @SuppressWarnings("unused") public abstract class ForkingClientServerIntegrationTestsSupport extends ClientServerIntegrationTestsSupport { + protected static final String REMOVE_TEST_DIRECTORY_PROPERTY = "spring.data.gemfire.test.directory.remove"; + private static ProcessWrapper gemfireServer; public static @NonNull ProcessWrapper startGemFireServer(@NonNull Class gemfireServerMainClass, @@ -222,7 +231,15 @@ public abstract class ForkingClientServerIntegrationTestsSupport extends ClientS @AfterClass public static void stopGemFireServer() { + getGemFireServerProcess().ifPresent(ForkingClientServerIntegrationTestsSupport::stop); + + if (Boolean.parseBoolean(System.getProperty(REMOVE_TEST_DIRECTORY_PROPERTY, Boolean.TRUE.toString()))) { + getGemFireServerProcess() + .map(ProcessWrapper::getWorkingDirectory) + .ifPresent(IntegrationTestsSupport::removeRecursiveDirectory); + } + setGemFireServerProcess(null); } @@ -242,9 +259,7 @@ public abstract class ForkingClientServerIntegrationTestsSupport extends ClientS @EnablePdx @ClientCacheApplication - public static class BaseGemFireClientConfiguration extends ClientServerIntegrationTestsConfiguration { - - } + public static class BaseGemFireClientConfiguration extends ClientServerIntegrationTestsConfiguration { } @EnablePdx @CacheServerApplication(name = "ForkingClientServerIntegrationTestsSupport")