Skip to content

Commit

Permalink
Changing container output to be class based
Browse files Browse the repository at this point in the history
* Changed containers so that they installed in seperate directory across classes. Meaning that client server and peer to peer tests now use separate installs.
* Cache XML files now also create separate instances for each test.
  • Loading branch information
DivineEnder committed Jun 29, 2017
1 parent 23b8aa3 commit 5636b92
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.Logger;
import org.codehaus.cargo.container.configuration.LocalConfiguration;
Expand Down Expand Up @@ -111,6 +112,33 @@ public String getInstallPath() {
*/
public abstract void setLocator(String address, int port) throws Exception;

/**
* Sets up the cache XML files
*/
public abstract void setupCacheXMLFile(String newXMLFilePath) throws IOException;

/**
* Sets the XML file which contains cache properties.
*
* Normally this XML file would be set to the cache-client.xml or cache-peer.xml files located in
* the module's conf directory (located in build/install/apache-geode/tools/Modules/... for
* geode-assembly). However, this allows containers to have different XML files so that locators
* will not accidentally overwrite each other's when tests are run concurrently.
*
* The originalXMLFilePath is used to copy the original XML file to the newXMLFilePath so that all
* settings previously there are saved and copied over.
*/
public void setCacheXMLFile(String originalXMLFilePath, String newXMLFilePath)
throws IOException {
File moduleXMLFile = new File(originalXMLFilePath);
File installXMLFile = new File(newXMLFilePath);

installXMLFile.getParentFile().mkdirs();
FileUtils.copyFile(moduleXMLFile, installXMLFile);

setSystemProperty("cache-xml-file", installXMLFile.getAbsolutePath());
}

/**
* Set a geode session replication property. For example enableLocalCache.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -190,11 +191,10 @@ public void startContainer(int index) {
ContainerInstall install = getContainerInstall(index);
String containerDescription = getContainerDescription(index);

long guid = System.nanoTime();
String logFilePath = new File(
"cargo_logs/containers/" + install.getContainerDescription() + "_" + testName + "_" + index)
String logFilePath =
new File("cargo_logs/containers/" + getUniqueContainerDescription(index) + ".log")
.getAbsolutePath();
container.setOutput(logFilePath + "." + guid);
container.setOutput(logFilePath);
logger.info("Sending log file output to " + logFilePath);

if (!container.getState().isStarted()) {
Expand Down Expand Up @@ -284,46 +284,56 @@ private void clean(int index) throws IOException {
String configLogFolderPath = baseLogFilePath + "/configs/";

File configDir = new File(getContainer(index).getConfiguration().getHome());
File configLogDir = new File(
configLogFolderPath + configDir.getName() + "_" + testName + "_" + System.nanoTime());
File configLogDir = new File(configLogFolderPath + configDir.getName());

if (configDir.exists()) {
configLogDir.mkdirs();

logger.info("Configuration in " + configDir.getAbsolutePath());
FileUtils.copyDirectory(configDir, configLogDir);
logger.info("Copied configuration to " + configLogDir.getAbsolutePath());
logger.info("Deleting configuration folder " + configDir.getAbsolutePath());
FileUtils.deleteDirectory(configDir);
}
}

File cacheXMLFile = new File(install.getSystemProperty("cache-xml-file"));
File cacheXMLLogFile = new File(baseLogFilePath + "/XMLs/" + configLogDir.getName() + ".xml");
cacheXMLLogFile.getParentFile().mkdirs();
private String getUniqueContainerDescription(int index) {
return getUniqueContainerDescription(index, getContainerInstall(index));
}

logger.info("Cache XML file: " + cacheXMLFile.getAbsolutePath());
logger.info("Copied cache XML file to " + cacheXMLLogFile.getAbsolutePath());
FileUtils.copyFile(cacheXMLFile, cacheXMLLogFile);
/**
* Get a human readable unique container description for container storage.
*
* Unique descriptions currently are generated by joining
* {@link ContainerInstall#getContainerDescription()}, the index passed in, {@link #testName}, and
* the {@link System#nanoTime()} with '_' characters
*/
private String getUniqueContainerDescription(int index, ContainerInstall install) {
return String.join("_", Arrays.asList(install.getContainerDescription(),
Integer.toString(index), testName, Long.toString(System.nanoTime())));
}

/**
* Create a container to manage, given an installation.
*/
private InstalledLocalContainer addContainer(ContainerInstall install, int index)
throws IOException {
String uniqueName = getUniqueContainerDescription(index, install);

// Create the Cargo Container instance wrapping our physical container
LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()
.createConfiguration(install.getContainerId(), ContainerType.INSTALLED,
ConfigurationType.STANDALONE, install.getContainerConfigHome() + "_" + index);
ConfigurationType.STANDALONE, "/tmp/cargo_configs/" + uniqueName);
configuration.setProperty(GeneralPropertySet.LOGGING, install.getLoggingLevel());

File gemfireLogFile = new File("cargo_logs/gemfire_modules/" + install.getContainerDescription()
+ "_" + index + "_" + testName + "." + System.nanoTime());
install.setupCacheXMLFile("cargo_logs/XMLs/" + uniqueName + ".xml");
install.modifyConfiguration(configuration);

File gemfireLogFile = new File("cargo_logs/gemfire_modules/" + uniqueName);
gemfireLogFile.getParentFile().mkdirs();
install.setSystemProperty("log-file", gemfireLogFile.getAbsolutePath());
logger.info("Gemfire logs in " + gemfireLogFile.getAbsolutePath());

install.modifyConfiguration(configuration);

// Removes secureRandom generation so that container startup is much faster
configuration.setProperty(GeneralPropertySet.JVMARGS,
"-Djava.security.egd=file:/dev/./urandom");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,26 @@ public GenericAppServerInstall(Server server, CacheType cacheType, String instal
this.cacheType = cacheType;

appServerModulePath = findAndExtractModule(GEODE_BUILD_HOME, "appserver");
setSystemProperty("cache-xml-file",
appServerModulePath + "/conf/" + cacheType.getXMLTypeFile());
// Default properties
setCacheProperty("enable_local_cache", "false");

warFile = File.createTempFile("session-testing", ".war", new File("/tmp"));
warFile.deleteOnExit();
}

/**
* Sets the XML file to use for cache settings
*
* Calls {@link ContainerInstall#setCacheXMLFile(String, String)} with the default original cache
* file located in the conf folder of the {@link #appServerModulePath} and the given
* newXMLFilePath.
*/
@Override
public void setupCacheXMLFile(String newXMLFilePath) throws IOException {
super.setCacheXMLFile(appServerModulePath + "/conf/" + cacheType.getXMLTypeFile(),
newXMLFilePath);
}

/**
* Build the command list used to modify/build the WAR file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Jetty 9 Client Server tests
*
Expand All @@ -29,7 +30,8 @@ public class Jetty9ClientServerTest extends GenericAppServerClientServerTest {
@BeforeClass
public static void setupJettyInstall() throws Exception {
install = new GenericAppServerInstall(GenericAppServerInstall.Server.JETTY9,
GenericAppServerInstall.CacheType.CLIENT_SERVER);
GenericAppServerInstall.CacheType.CLIENT_SERVER,
ContainerInstall.DEFAULT_INSTALL_DIR + "Jetty9ClientServerTest");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Jetty 9 Peer to Peer tests
*
Expand All @@ -28,7 +29,8 @@ public class Jetty9Test extends CargoTestBase {

@BeforeClass
public static void setupJettyInstall() throws Exception {
install = new GenericAppServerInstall(GenericAppServerInstall.Server.JETTY9);
install = new GenericAppServerInstall(GenericAppServerInstall.Server.JETTY9,
ContainerInstall.DEFAULT_INSTALL_DIR + "Jetty9Test");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 6 Client Server test
*
Expand All @@ -29,7 +30,8 @@ public class Tomcat6ClientServerTest extends TomcatClientServerTest {
@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT6,
TomcatInstall.TomcatConfig.CLIENT_SERVER);
TomcatInstall.TomcatConfig.CLIENT_SERVER,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat6ClientServerTest");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 6 Peer to Peer tests
*
Expand All @@ -28,7 +29,8 @@ public class Tomcat6Test extends CargoTestBase {

@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT6);
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT6,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat6Test");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 7 Client Server tests
*
Expand All @@ -29,7 +30,8 @@ public class Tomcat7ClientServerTest extends TomcatClientServerTest {
@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT7,
TomcatInstall.TomcatConfig.CLIENT_SERVER);
TomcatInstall.TomcatConfig.CLIENT_SERVER,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat7ClientServerTest");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 7 Peer to Peer tests
*
Expand All @@ -28,7 +29,8 @@ public class Tomcat7Test extends CargoTestBase {

@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT7);
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT7,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat7Test");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 8 Client Server tests
*
Expand All @@ -29,7 +30,8 @@ public class Tomcat8ClientServerTest extends TomcatClientServerTest {
@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT8,
TomcatInstall.TomcatConfig.CLIENT_SERVER);
TomcatInstall.TomcatConfig.CLIENT_SERVER,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat8ClientServerTest");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
*/
package org.apache.geode.session.tests;

import org.apache.geode.test.dunit.DUnitEnv;
import org.junit.BeforeClass;

import org.apache.geode.test.dunit.DUnitEnv;

/**
* Tomcat 8 Peer to Peer tests
*
Expand All @@ -28,7 +29,8 @@ public class Tomcat8Test extends CargoTestBase {

@BeforeClass
public static void setupTomcatInstall() throws Exception {
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT8);
install = new TomcatInstall(TomcatInstall.TomcatVersion.TOMCAT8,
ContainerInstall.DEFAULT_INSTALL_DIR + "Tomcat8Test");
install.setLocator(DUnitEnv.get().getLocatorAddress(), DUnitEnv.get().getLocatorPort());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public TomcatInstall(TomcatVersion version, TomcatConfig config) throws Exceptio
this(version, config, DEFAULT_INSTALL_DIR);
}

private TomcatInstall(TomcatVersion version, TomcatConfig config, String installDir)
public TomcatInstall(TomcatVersion version, TomcatConfig config, String installDir)
throws Exception {
// Does download and install from URL
super(installDir, version.downloadURL());
Expand All @@ -189,7 +189,6 @@ private TomcatInstall(TomcatVersion version, TomcatConfig config, String install
// Get tomcat module path
tomcatModulePath = findAndExtractModule(GEODE_BUILD_HOME, "tomcat");
// Default properties
setSystemProperty("cache-xml-file", tomcatModulePath + "/conf/" + config.getXMLFile());
setCacheProperty("enableLocalCache", "false");

// Install geode sessions into tomcat install
Expand All @@ -201,6 +200,17 @@ private TomcatInstall(TomcatVersion version, TomcatConfig config, String install
}
}

/**
* Sets the XML file to use for cache settings
*
* Calls {@link ContainerInstall#setCacheXMLFile(String, String)} with the default original cache
* file located in the conf folder of the {@link #tomcatModulePath} and the given newXMLFilePath.
*/
@Override
public void setupCacheXMLFile(String newXMLFilePath) throws IOException {
super.setCacheXMLFile(tomcatModulePath + "/conf/" + config.getXMLFile(), newXMLFilePath);
}

/**
* Copies jars specified by {@link #tomcatRequiredJars} from the {@link #tomcatModulePath} and the
* specified other directory passed to the function.
Expand Down

0 comments on commit 5636b92

Please sign in to comment.