Additional changes to the CacheClusterConfigurationIntegrationTest to ascertain the test case (testClusterConfiguration) failure in the Bamboo CI environment. Modified ProcessExecutor to add to the Java launcher command-line of the forked Java process any System Properties that start with 'spring.gemfire.' Added a write(:File, contents:String) method to the FileUtils utility class.

This commit is contained in:
John Blum
2014-08-13 16:11:56 -07:00
parent 2eeb590d43
commit dccdefe351
4 changed files with 71 additions and 13 deletions

View File

@@ -30,7 +30,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
@@ -81,19 +80,37 @@ public class CacheClusterConfigurationIntegrationTest {
@Rule
public TestRule watchman = new TestWatcher() {
@Override protected void failed(final Throwable t, final Description description) {
try {
System.out.println(String.format("Test '%1$s' failed...", description.getDisplayName()));
System.out.println(ThrowableUtils.toString(t));
System.out.println("Locator process log file contents were...");
@Override
protected void failed(final Throwable t, final Description description) {
System.err.println(String.format("Test '%1$s' failed...", description.getDisplayName()));
System.err.println(ThrowableUtils.toString(t));
System.err.println("Locator process log file contents were...");
System.err.println(getLocatorProcessOutput(description));
}
@Override
protected void finished(final Description description) {
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
try {
FileUtils.write(new File(locatorWorkingDirectory.getParent(),
String.format("%1$s-clusterconfiglocator.log", description.getMethodName())),
getLocatorProcessOutput(description));
}
catch (IOException e) {
throw new RuntimeException("Failed the write the contents of the Locator process log to a file!", e);
}
}
}
private String getLocatorProcessOutput(final Description description) {
try {
String locatorProcessOutputString = StringUtils.collectionToDelimitedString(locatorProcessOutput,
FileUtils.LINE_SEPARATOR, String.format("[%1$s] - ", description.getMethodName()), "");
locatorProcessOutputString = (StringUtils.hasText(locatorProcessOutputString) ?
locatorProcessOutputString : locatorProcess.readLogFile());
System.out.println(locatorProcessOutputString);
return locatorProcessOutputString;
}
catch (IOException e) {
throw new RuntimeException("Failed to read the contents of the Locator process log file!", e);
@@ -128,9 +145,9 @@ public class CacheClusterConfigurationIntegrationTest {
}
});
waitForLocatorStart(TimeUnit.SECONDS.toMillis(60));
waitForLocatorStart(TimeUnit.SECONDS.toMillis(30));
//System.out.println("Cluster Configuration Locator should be running!");
System.out.println("Cluster Configuration Locator should be running!");
}
private static void waitForLocatorStart(final long milliseconds) {
@@ -145,7 +162,9 @@ public class CacheClusterConfigurationIntegrationTest {
@AfterClass
public static void testSuiteTearDown() {
locatorProcess.shutdown();
FileSystemUtils.deleteRecursively(locatorWorkingDirectory);
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
FileSystemUtils.deleteRecursively(locatorWorkingDirectory);
}
}
protected Region assertRegion(final Region actualRegion, final String expectedRegionName) {
@@ -183,7 +202,6 @@ public class CacheClusterConfigurationIntegrationTest {
}
@Test
@Ignore
public void testClusterConfiguration() {
ConfigurableApplicationContext applicationContext = newApplicationContext(
getLocation("cacheUsingClusterConfigurationIntegrationTest.xml"));

View File

@@ -141,7 +141,9 @@ public class LocatorProcess {
SharedConfiguration sharedConfiguration = locator.getSharedConfiguration();
if (sharedConfiguration != null) {
sharedConfiguration.destroySharedConfiguration();
if (Boolean.valueOf(System.getProperty("spring.gemfire.fork.clean", Boolean.TRUE.toString()))) {
sharedConfiguration.destroySharedConfiguration();
}
}
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.process;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -26,7 +27,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* The ProcessLauncher class is a utility class for launching Java processes.
* The ProcessExecutor class is a utility class for launching and running Java processes.
*
* @author John Blum
* @see java.lang.Process
@@ -45,6 +46,8 @@ public abstract class ProcessExecutor {
protected static final String JAVA_EXE = JAVA_HOME.concat(File.separator).concat("bin")
.concat(File.separator).concat("java");
protected static final String SPRING_GEMFIRE_SYSTEM_PROPERTY_PREFIX = "spring.gemfire.";
protected static final String USER_HOME = System.getProperty("user.home");
protected static final String USER_WORKING_DIRECTORY = System.getProperty("user.dir");
@@ -84,6 +87,7 @@ public abstract class ProcessExecutor {
command.add("-server");
command.add("-classpath");
command.add(JAVA_CLASSPATH);
command.addAll(getSpringGemFireSystemProperties());
if (args != null) {
programArgs = new ArrayList<String>(args.length);
@@ -104,6 +108,18 @@ public abstract class ProcessExecutor {
return command.toArray(new String[command.size()]);
}
protected static Collection<? extends String> getSpringGemFireSystemProperties() {
List<String> springGemfireSystemProperties = new ArrayList<String>();
for (String property : System.getProperties().stringPropertyNames()) {
if (property.startsWith(SPRING_GEMFIRE_SYSTEM_PROPERTY_PREFIX)) {
springGemfireSystemProperties.add(String.format("-D%1$s=%2$s", property, System.getProperty(property)));
}
}
return springGemfireSystemProperties;
}
protected static boolean isJvmOption(final String option) {
return (!StringUtils.isEmpty(option) && (option.startsWith("-D") || option.startsWith("-X")));
}

View File

@@ -17,12 +17,16 @@
package org.springframework.data.gemfire.test.support;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.springframework.util.Assert;
import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
/**
* The FileUtils class is a utility class for processing files, working with java.io.File objects.
*
@@ -36,6 +40,7 @@ public abstract class FileUtils extends IOUtils {
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
// TODO refactor and perhaps replace with org.springframework.util.FileCopytUtils.copyToString(:Reader)
public static String read(final File file) throws IOException {
Assert.isTrue(file != null && file.isFile(), String.format(
"The File reference (%1$s) from which to read the contents is not a valid file!", file));
@@ -59,4 +64,21 @@ public abstract class FileUtils extends IOUtils {
}
}
// TODO refactor and perhaps replace with org.springframework.util.FileCopytUtils.copy(:String, :Writer)
public static void write(final File file, final String contents) throws IOException {
Assert.notNull(file, "The File to write to must not be null!");
Assert.isTrue(StringUtils.hasText(contents), "The 'contents' of the file cannot be null or empty!");
BufferedWriter fileWriter = null;
try {
fileWriter = new BufferedWriter(new FileWriter(file));
fileWriter.write(contents);
fileWriter.flush();
}
finally {
IOUtils.close(fileWriter);
}
}
}