SGF-409 - Modify the GemfireDataSourcePostProcessor (basis for <gfe:datasource>) to not assume a GemFire Server was configured and bootstrapped with Spring and subsequently that the SDG ListRegionsOnServerFunction was registered.
Fixed up the GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest to customize the classpath in order to exlude the Spring Data GemFire dependency from the non-Spring-configured GemFire Server's classpath thereby removing any presence of the ListRegionsOnServerFunction GemFire Function; made use of the com.gemstone.gemfire.distributed.ServerLauncher class for launching the non-Spring-configured GemFire Server and finally, wrote the gemfire-datasource-integration-test-cache.xml as an cache.xml file to the non-Spring-configured GemFire Server's working directory to properly configure the GemFire Server.
This commit is contained in:
@@ -24,6 +24,7 @@ import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -36,6 +37,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.gemfire.fork.GemFireBasedServerProcess;
|
||||
import org.springframework.data.gemfire.process.ProcessExecutor;
|
||||
import org.springframework.data.gemfire.process.ProcessWrapper;
|
||||
@@ -44,9 +46,12 @@ import org.springframework.data.gemfire.test.support.ThreadUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.distributed.ServerLauncher;
|
||||
|
||||
/**
|
||||
* The GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTest class is a test suite of test cases
|
||||
@@ -89,14 +94,20 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
||||
|
||||
Assert.isTrue(serverWorkingDirectory.isDirectory() || serverWorkingDirectory.mkdirs());
|
||||
|
||||
writeAsCacheXmlFileToDirectory("gemfire-datasource-integration-test-cache.xml", serverWorkingDirectory);
|
||||
|
||||
Assert.isTrue(new File(serverWorkingDirectory, "cache.xml").isFile(), String.format(
|
||||
"Expected a cache.xml file to exist in directory (%1$s)!", serverWorkingDirectory));
|
||||
|
||||
List<String> arguments = new ArrayList<String>(5);
|
||||
|
||||
arguments.add(ServerLauncher.Command.START.getName());
|
||||
arguments.add(String.format("-Dgemfire.name=%1$s", serverName));
|
||||
arguments.add(String.format("-Dgemfire.mcast-port=%1$s", "0"));
|
||||
arguments.add(String.format("-Dgemfire.log-level=%1$s", "warning"));
|
||||
arguments.add(String.format("-Dgemfire.cache-xml-file=%1$s", "gemfire-datasource-integration-test-cache.xml"));
|
||||
//arguments.add(String.format("-Dgemfire.cache-xml-file=%1$s", "gemfire-datasource-integration-test-cache.xml"));
|
||||
|
||||
serverProcess = ProcessExecutor.launch(serverWorkingDirectory, GemFireBasedServerProcess.class,
|
||||
serverProcess = ProcessExecutor.launch(serverWorkingDirectory, customClasspath(), ServerLauncher.class,
|
||||
arguments.toArray(new String[arguments.size()]));
|
||||
|
||||
waitForProcessStart(TimeUnit.SECONDS.toMillis(20), serverProcess, GemFireBasedServerProcess.getServerProcessControlFilename());
|
||||
@@ -104,6 +115,25 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
||||
System.out.println("GemFire-based Cache Server Process for ClientCache DataSource Test should be running and connected...");
|
||||
}
|
||||
|
||||
private static void writeAsCacheXmlFileToDirectory(String classpathResource, File serverWorkingDirectory) throws IOException {
|
||||
FileCopyUtils.copy(new ClassPathResource(classpathResource).getInputStream(),
|
||||
new FileOutputStream(new File(serverWorkingDirectory, "cache.xml")));
|
||||
}
|
||||
|
||||
private static String customClasspath() {
|
||||
String[] classpathElements = ProcessExecutor.JAVA_CLASSPATH.split(File.pathSeparator);
|
||||
|
||||
List<String> customClasspath = new ArrayList<String>(classpathElements.length);
|
||||
|
||||
for (String classpathElement : classpathElements) {
|
||||
if (!classpathElement.contains("spring-data-gemfire")) {
|
||||
customClasspath.add(classpathElement);
|
||||
}
|
||||
}
|
||||
|
||||
return StringUtils.collectionToDelimitedString(customClasspath, File.pathSeparator);
|
||||
}
|
||||
|
||||
private static void waitForProcessStart(final long milliseconds, final ProcessWrapper process, final String processControlFilename) {
|
||||
ThreadUtils.timedWait(milliseconds, TimeUnit.MILLISECONDS.toMillis(500), new ThreadUtils.WaitCondition() {
|
||||
private File processControlFile = new File(process.getWorkingDirectory(), processControlFilename);
|
||||
|
||||
@@ -40,21 +40,25 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class ProcessExecutor {
|
||||
|
||||
protected static final File JAVA_EXE = new File(new File(FileSystemUtils.JAVA_HOME, "bin"), "java");
|
||||
public static final File JAVA_EXE = new File(new File(FileSystemUtils.JAVA_HOME, "bin"), "java");
|
||||
|
||||
protected static final String JAVA_CLASSPATH = System.getProperty("java.class.path");
|
||||
public static final String JAVA_CLASSPATH = System.getProperty("java.class.path");
|
||||
|
||||
protected static final String SPRING_GEMFIRE_SYSTEM_PROPERTY_PREFIX = "spring.gemfire.";
|
||||
|
||||
public static ProcessWrapper launch(final Class<?> type, final String... args) throws IOException {
|
||||
public static ProcessWrapper launch(Class<?> type, String... args) throws IOException {
|
||||
return launch(FileSystemUtils.WORKING_DIRECTORY, type, args);
|
||||
}
|
||||
|
||||
public static ProcessWrapper launch(final File workingDirectory, final Class<?> type, final String... args)
|
||||
throws IOException
|
||||
{
|
||||
public static ProcessWrapper launch(File workingDirectory, Class<?> type, String... args) throws IOException {
|
||||
return launch(workingDirectory, JAVA_CLASSPATH, type, args);
|
||||
}
|
||||
|
||||
public static ProcessWrapper launch(File workingDirectory, String classpath, Class<?> type, String... args)
|
||||
throws IOException {
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder()
|
||||
.command(buildCommand(type, args))
|
||||
.command(buildCommand(classpath, type, args))
|
||||
.directory(validateDirectory(workingDirectory))
|
||||
.redirectErrorStream(true);
|
||||
|
||||
@@ -71,8 +75,8 @@ public abstract class ProcessExecutor {
|
||||
return processWrapper;
|
||||
}
|
||||
|
||||
protected static String[] buildCommand(final Class<?> type, final String... args) {
|
||||
Assert.notNull(type != null, "The main Class to launch must not be null!");
|
||||
protected static String[] buildCommand(String classpath, Class<?> type, String... args) {
|
||||
Assert.notNull(type, "The main Java class to launch must not be null!");
|
||||
|
||||
List<String> command = new ArrayList<String>();
|
||||
List<String> programArgs = Collections.emptyList();
|
||||
@@ -80,7 +84,7 @@ public abstract class ProcessExecutor {
|
||||
command.add(JAVA_EXE.getAbsolutePath());
|
||||
command.add("-server");
|
||||
command.add("-classpath");
|
||||
command.add(JAVA_CLASSPATH);
|
||||
command.add(StringUtils.hasText(classpath) ? classpath : JAVA_CLASSPATH);
|
||||
command.addAll(getSpringGemFireSystemProperties());
|
||||
|
||||
if (args != null) {
|
||||
|
||||
Reference in New Issue
Block a user