Refactor forked Apache Geode server process (test) working directory cleanup.

This commit is contained in:
John Blum
2022-10-13 14:20:17 -07:00
parent 60e8b2196f
commit d1959de07b
15 changed files with 145 additions and 27 deletions

View File

@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,6 +35,7 @@ import org.apache.geode.cache.query.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -57,22 +59,31 @@ import org.springframework.test.context.junit4.SpringRunner;
@SuppressWarnings("unused")
public class ClientCacheIndexingIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
@Autowired
private ClientCache clientCache;
@Autowired
private Index exampleIndex;
private static File serverWorkingDirectory;
@BeforeClass
public static void startGeodeServer() throws IOException {
File serverWorkingDirectory = createDirectory(new File(new File(FileSystemUtils.WORKING_DIRECTORY,
serverWorkingDirectory = createDirectory(new File(new File(FileSystemUtils.WORKING_DIRECTORY,
asDirectoryName(ClientCacheIndexingIntegrationTests.class)), UUID.randomUUID().toString()));
startGemFireServer(serverWorkingDirectory, ServerProcess.class,
getServerContextXmlFileLocation(ClientCacheIndexingIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
private ClientCache clientCache;
@Autowired
private Index exampleIndex;
private Index getIndex(GemFireCache gemfireCache, String indexName) {
QueryService queryService = gemfireCache instanceof ClientCache

View File

@@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -68,6 +70,13 @@ public class ClientCachePoolIntegrationTests extends ForkingClientServerIntegrat
getServerContextXmlFileLocation(ClientCachePoolIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
@Qualifier("Factorials")
private Region<Long, Long> factorials;

View File

@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,6 +38,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -78,6 +80,13 @@ public class ClientCacheSecurityIntegrationTests extends ForkingClientServerInte
System.setProperty("javax.net.ssl.keyStore", trustedKeystore.getFile().getAbsolutePath());
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
@Qualifier("Example")
private Region<String, String> example;

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -38,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -74,6 +76,13 @@ public class ClientCacheVariableLocatorsIntegrationTests extends ForkingClientSe
getServerContextXmlFileLocation(ClientCacheVariableLocatorsIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
@Qualifier("Example")
private Region<String, Integer> example;

View File

@@ -46,6 +46,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.util.CollectionUtils;
import org.springframework.test.context.ContextConfiguration;
@@ -95,6 +96,13 @@ public class ClientCacheVariableServersIntegrationTests extends ForkingClientSer
startGemFireServer(serverWorkingDirectory, ServerProcess.class, arguments.toArray(new String[0]));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@AfterClass
public static void cleanup() {
Arrays.asList("test.cache.server.port.one", "test.cache.server.port.two").forEach(System::clearProperty);

View File

@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +33,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -63,6 +65,13 @@ public class ClientSubRegionIntegrationTests extends ForkingClientServerIntegrat
getServerContextXmlFileLocation(ClientSubRegionIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
private ClientCache clientCache;

View File

@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -57,6 +58,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.util.DistributedSystemUtils;
import org.springframework.test.annotation.DirtiesContext;
@@ -111,6 +113,13 @@ public class DurableClientCacheIntegrationTests extends ForkingClientServerInteg
getServerContextXmlFileLocation(DurableClientCacheIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
private static boolean isAfterDirtiesContext() {
return dirtiesContext.get();
}

View File

@@ -38,9 +38,9 @@ import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.FileSystemUtils;
/**
* Integration Tests with test cases testing the contract and functionality of the &lt;gfe-data:datasource&gt; element
@@ -81,13 +81,10 @@ public class GemFireDataSourceIntegrationTest extends ForkingClientServerIntegra
}
@AfterClass
public static void stopGemFireServer() {
if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(workingDirectory -> FileSystemUtils.deleteRecursively(workingDirectory));
}
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired

View File

@@ -20,6 +20,7 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +36,7 @@ import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.repository.sample.Person;
import org.springframework.data.gemfire.repository.sample.PersonRepository;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -68,6 +70,13 @@ public class GemFireDataSourceIntegrationTests extends ForkingClientServerIntegr
getServerContextXmlFileLocation(GemFireDataSourceIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
private ApplicationContext applicationContext;

View File

@@ -133,12 +133,8 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
public static void stopGemFireServer() {
stop(gemfireServer);
System.clearProperty("CACHE_SERVER_PORT");
if (Boolean.parseBoolean(System.getProperty("spring.gemfire.fork.clean", String.valueOf(true)))) {
org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory());
}
org.springframework.util.FileSystemUtils.deleteRecursively(gemfireServer.getWorkingDirectory());
}
@Autowired

View File

@@ -17,9 +17,12 @@ package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -44,6 +47,8 @@ import org.springframework.data.gemfire.config.admin.GemfireAdminOperations;
import org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate;
import org.springframework.data.gemfire.support.ConnectionEndpoint;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -80,7 +85,19 @@ public class EnableClusterConfigurationIntegrationTests extends ForkingClientSer
@BeforeClass
public static void startGemFireServer() throws Exception {
startGemFireServer(GeodeServerTestConfiguration.class);
File serverWorkingDirectory = createDirectory(new File(new File(
org.springframework.data.gemfire.tests.util.FileSystemUtils.WORKING_DIRECTORY,
asDirectoryName(EnableClusterConfigurationIntegrationTests.class)), UUID.randomUUID().toString()));
startGemFireServer(serverWorkingDirectory, GeodeServerTestConfiguration.class);
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Before

View File

@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,6 +45,7 @@ import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
import org.springframework.data.gemfire.function.sample.ApplicationDomainFunctionExecutions;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -77,10 +79,10 @@ import org.springframework.util.ObjectUtils;
public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ForkingClientServerIntegrationTestsSupport {
@Autowired
private ClientCache gemfireClientCache;
private ApplicationDomainFunctionExecutions functionExecutions;
@Autowired
private ApplicationDomainFunctionExecutions functionExecutions;
private ClientCache gemfireClientCache;
@BeforeClass
public static void startGemFireServer() throws Exception {
@@ -92,6 +94,13 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ForkingC
getServerContextXmlFileLocation(ClientCacheFunctionExecutionWithPdxIntegrationTest.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
private PdxInstance toPdxInstance(Map<String, Object> pdxData) {
PdxInstanceFactory pdxInstanceFactory =

View File

@@ -21,6 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -60,11 +61,11 @@ import org.springframework.test.context.junit4.SpringRunner;
@SuppressWarnings("unused")
public class ExceptionThrowingFunctionExecutionIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
private static ProcessWrapper gemfireServer;
@Autowired
private ExceptionThrowingFunctionExecution exceptionThrowingFunctionExecution;
private static ProcessWrapper gemfireServer;
@BeforeClass
public static void startGeodeServer() throws IOException {
@@ -75,6 +76,13 @@ public class ExceptionThrowingFunctionExecutionIntegrationTests extends ForkingC
getServerContextXmlFileLocation(ExceptionThrowingFunctionExecutionIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Test(expected = FunctionException.class)
public void exceptionThrowingFunctionExecutionRethrowsException() {

View File

@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -36,6 +37,7 @@ import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.function.annotation.GemfireFunction;
import org.springframework.data.gemfire.function.annotation.RegionData;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
@@ -69,6 +71,13 @@ public class FunctionIntegrationTests extends ForkingClientServerIntegrationTest
getServerContextXmlFileLocation(FunctionIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
@Qualifier("TestRegion")
private Region<String, Integer> region;

View File

@@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,6 +31,7 @@ import org.springframework.data.gemfire.repository.sample.Person;
import org.springframework.data.gemfire.repository.sample.PersonRepository;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.objects.geode.cache.RegionDataInitializingPostProcessor;
import org.springframework.data.gemfire.tests.process.ProcessWrapper;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -52,9 +54,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@SuppressWarnings("unused")
public class ClientRegionNamespaceRepositoryIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
@Autowired
private PersonRepository repository;
@BeforeClass
public static void startGemFireServer() throws Exception {
@@ -65,6 +64,16 @@ public class ClientRegionNamespaceRepositoryIntegrationTests extends ForkingClie
getServerContextXmlFileLocation(ClientRegionNamespaceRepositoryIntegrationTests.class));
}
@AfterClass
public static void removeServerWorkingDirectory() {
getGemFireServerProcess()
.map(ProcessWrapper::getWorkingDirectory)
.ifPresent(FileSystemUtils::deleteRecursive);
}
@Autowired
private PersonRepository repository;
@Test
public void findAllAndCountMatch() {