Skip to content

Commit

Permalink
ISPN-11290 Optionally use a prebuilt server from the supplied container
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant committed Feb 6, 2020
1 parent 3525174 commit da34143
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -703,7 +703,7 @@
<versionx.org.springframework.spring-web>${version.spring5}</versionx.org.springframework.spring-web>
<versionx.org.springframework.spring-webmvc>${version.spring5}</versionx.org.springframework.spring-webmvc>
<versionx.org.syslog4j.syslog4j>0.9.30</versionx.org.syslog4j.syslog4j>
<versionx.org.testcontainers.testcontainers>1.12.4</versionx.org.testcontainers.testcontainers>
<versionx.org.testcontainers.testcontainers>1.12.5</versionx.org.testcontainers.testcontainers>
<versionx.org.testng.testng>6.14.3</versionx.org.testng.testng>
<versionx.org.tukaani.xz>1.0</versionx.org.tukaani.xz>
<versionx.org.twdata.maven.mojo-executor>2.2.0</versionx.org.twdata.maven.mojo-executor>
Expand Down
4 changes: 3 additions & 1 deletion server/runtime/TESTING.md
Expand Up @@ -122,7 +122,9 @@ The default is to run all categories, but this can be overridden by setting the

The following is a list of properties which affect the build:

* `org.infinispan.test.server.baseImageName` the base image to use for the server. Defaults to `jboss/base-jdk:11`.
* `org.infinispan.test.server.container.baseImageName` the base image to use for the server. Defaults to `jboss/base-jdk:11`.
* `org.infinispan.test.server.container.usePrebuiltServer` whether to use a prebuilt server from the supplied image above.
* `org.infinispan.test.server.container.preserveImage` whether to preserve the created image after the test has run.
* `org.infinispan.test.server.driver` the driver to use, `EMBEDDED` or `CONTAINER`. Defaults to the `EMBEDDED` driver.
* `org.infinispan.test.server.extension.libs` locates artifact defined by G:A:V, you can pass a list of libraries (comma separeted) to be copied to the server. Only needed for container mode.
* `org.infinispan.test.server.jdbc.databases` database name to be used during persistence tests.
Expand Down
Expand Up @@ -42,6 +42,7 @@
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.model.ContainerNetwork;
import com.github.dockerjava.api.model.Network;
import com.sun.org.apache.xpath.internal.operations.Bool;

/**
* WARNING: Work in progress. Does not work yet.
Expand All @@ -56,19 +57,19 @@ public class ContainerInfinispanServerDriver extends InfinispanServerDriver {
public static final String INFINISPAN_SERVER_HOME = "/opt/infinispan";
public static final int JMX_PORT = 9999;
private final List<GenericContainer> containers;
private static final String EXTRA_LIBS = "org.infinispan.test.server.extension.libs";
private final boolean preferContainerExposedPorts;
private String name;
CountdownLatchLoggingConsumer latch;
ImageFromDockerfile image;
private File rootDir;
private final boolean preferContainerExposedPorts = Boolean.getBoolean("org.infinispan.test.server.container.preferContainerExposedPorts");

protected ContainerInfinispanServerDriver(InfinispanServerTestConfiguration configuration) {
super(
configuration,
getDockerBridgeAddress()
);
this.containers = new ArrayList<>(configuration.numServers());
this.preferContainerExposedPorts = Boolean.getBoolean(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_CONTAINER_PREFER_CONTAINER_EXPOSED_PORTS);
}

static InetAddress getDockerBridgeAddress() {
Expand All @@ -84,7 +85,8 @@ protected void start(String name, File rootDir, String configurationFile) {
this.rootDir = rootDir;
// Build a skeleton server layout
createServerHierarchy(rootDir);
String baseImageName = System.getProperty("org.infinispan.test.server.baseImageName", "jboss/base-jdk:11");
String baseImageName = System.getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_BASE_IMAGE_NAME, "jboss/base-jdk:11");
boolean usePrebuiltServerFromImage = Boolean.getBoolean(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_PREBUILT);
Path serverOutputDir = Paths.get(System.getProperty("server.output.dir"));

List<String> args = new ArrayList<>();
Expand All @@ -106,39 +108,46 @@ protected void start(String name, File rootDir, String configurationFile) {
properties.setProperty(Server.INFINISPAN_CLUSTER_NAME, name);
properties.setProperty(TEST_HOST_ADDRESS, testHostAddress.getHostName());
configuration.properties().forEach((k, v) -> args.add("-D" + k + "=" + StringPropertyReplacer.replaceProperties((String) v, properties)));

image = new ImageFromDockerfile("testcontainers/" + Base58.randomString(16).toLowerCase(), false)
.withFileFromPath("build", serverOutputDir)
boolean preserveImageAfterTest = Boolean.getBoolean(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_PRESERVE_IMAGE);
image = new ImageFromDockerfile("testcontainers/" + Base58.randomString(16).toLowerCase(), !preserveImageAfterTest)
.withFileFromPath("test", rootDir.toPath())
.withFileFromPath("target", serverOutputDir.getParent())
.withFileFromPath("src", serverOutputDir.getParent().getParent().resolve("src"))
.withDockerfileFromBuilder(builder ->
builder
.from(baseImageName)
.env("INFINISPAN_SERVER_HOME", INFINISPAN_SERVER_HOME)
.env("INFINISPAN_VERSION", Version.getVersion())
.label("name", "Infinispan Server")
.label("version", Version.getVersion())
.label("release", Version.getVersion())
.label("architecture", "x86_64")
.user("root")
.copy("build", INFINISPAN_SERVER_HOME)
.copy("test", INFINISPAN_SERVER_HOME + "/server")
.copy("src/test/resources/bin", INFINISPAN_SERVER_HOME + "/bin")
.run("chown", "-R", "jboss:jboss", INFINISPAN_SERVER_HOME)
.workDir(INFINISPAN_SERVER_HOME)
.user("jboss")
.cmd(
args.toArray(new String[]{})
)
.expose(
11222, // Protocol endpoint
11221, // Memcached endpoint
7800, // JGroups TCP
43366, // JGroups MPING
9999 // JMX Remoting
)
.build());
.withFileFromPath("src", serverOutputDir.getParent().getParent().resolve("src"));
if (!usePrebuiltServerFromImage) {
image.withFileFromPath("build", serverOutputDir);
}

image.withDockerfileFromBuilder(builder -> {
builder
.from(baseImageName)
.env("INFINISPAN_SERVER_HOME", INFINISPAN_SERVER_HOME)
.env("INFINISPAN_VERSION", Version.getVersion())
.label("name", "Infinispan Server")
.label("version", Version.getVersion())
.label("release", Version.getVersion())
.label("architecture", "x86_64")
.user("root");
if (!usePrebuiltServerFromImage) {
builder
.copy("build", INFINISPAN_SERVER_HOME)
.run("chown", "-R", "jboss:jboss", INFINISPAN_SERVER_HOME)
.user("jboss");
}
builder.copy("test", INFINISPAN_SERVER_HOME + "/server")
.copy("src/test/resources/bin", INFINISPAN_SERVER_HOME + "/bin")
.workDir(INFINISPAN_SERVER_HOME)
.cmd(
args.toArray(new String[]{})
)
.expose(
11222, // Protocol endpoint
11221, // Memcached endpoint
7800, // JGroups TCP
43366, // JGroups MPING
9999 // JMX Remoting
)
.build();
});
latch = new CountdownLatchLoggingConsumer(configuration.numServers(), STARTUP_MESSAGE_REGEX);
for (int i = 0; i < configuration.numServers(); i++) {
GenericContainer container = createContainer(i, rootDir);
Expand Down Expand Up @@ -171,7 +180,7 @@ private GenericContainer createContainer(int i, File rootDir) {

private void copyArtifactsToUserLibDir(File libDir) {
// Maven artifacts
String propertyArtifacts = System.getProperty(EXTRA_LIBS);
String propertyArtifacts = System.getProperty(TestSystemPropertyNames.EXTRA_LIBS);
String[] artifacts = propertyArtifacts != null ? propertyArtifacts.replaceAll("\\s+", "").split(",") : configuration.mavenArtifacts();
if (artifacts != null && artifacts.length > 0) {
MavenResolvedArtifact[] archives = Maven.resolver().resolve(artifacts).withoutTransitivity().asResolvedArtifact();
Expand Down
Expand Up @@ -20,7 +20,7 @@ InfinispanServerDriver newDriver(InfinispanServerTestConfiguration configuration
DEFAULT {
@Override
InfinispanServerDriver newDriver(InfinispanServerTestConfiguration configuration) {
String driverName = System.getProperty("org.infinispan.test.server.driver", EMBEDDED.name());
String driverName = System.getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_DRIVER, EMBEDDED.name());
ServerRunMode driver = ServerRunMode.valueOf(driverName);
return driver.newDriver(configuration);
}
Expand Down
@@ -0,0 +1,33 @@
package org.infinispan.server.test;

/**
* @author Tristan Tarrant &lt;tristan@infinispan.org&gt;
* @since 11.0
**/
public class TestSystemPropertyNames {
/**
* Specifies the name of the base image to use for the server container
*/
public static final String INFINISPAN_TEST_SERVER_BASE_IMAGE_NAME = "org.infinispan.test.server.container.baseImageName";
/**
* Specifies whether to use the ports exposed by the container
*/
public static final String INFINISPAN_TEST_SERVER_CONTAINER_PREFER_CONTAINER_EXPOSED_PORTS = "org.infinispan.test.server.container.preferContainerExposedPorts";
/**
* Specifies whether the base image contains a prebuilt server to use instead of using the one built locally
*/
public static final String INFINISPAN_TEST_SERVER_PREBUILT = "org.infinispan.test.server.container.usePrebuiltServer";
/**
* Specifies whether the base image contains a prebuilt server to use instead of using the one built locally
*/
public static final String INFINISPAN_TEST_SERVER_PRESERVE_IMAGE = "org.infinispan.test.server.container.preserveImage";
/**
* Specifies a comma-separated list of extra libraries (jars) to deploy into the server/lib directory
*/
public static final String EXTRA_LIBS = "org.infinispan.test.server.extension.libs";
/**
* The driver to use for running the server tests. Will override the default driver. Can be either EMBEDDED or CONTAINER
*/
public static final String INFINISPAN_TEST_SERVER_DRIVER = "org.infinispan.test.server.driver";

}

0 comments on commit da34143

Please sign in to comment.