Skip to content

Commit

Permalink
[RESTEASY-2003] Isolate container standalone dir in tests
Browse files Browse the repository at this point in the history
* [RESTEASY-2003] Make sure distribution is downloaded before any config changes
* [RESTEASY-2003] Use isolated standalone dirs for containers running simultaneously
  • Loading branch information
jbliznak authored and asoldano committed Sep 11, 2018
1 parent 95db3c7 commit fbd36ac
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 68 deletions.
Expand Up @@ -20,16 +20,27 @@ public class LogCounter {
private boolean onServer;


public LogCounter(String message, boolean onServer) {
/**
* Container qualifier when arquillian starts multiple instance, null otherwise.
*/
private String containerQualifier;


public LogCounter(String message, boolean onServer, String containerQualifier) {
this.message = message;
this.onServer = onServer;
initCount = TestUtil.getWarningCount(message, onServer);
this.containerQualifier = containerQualifier;
this.initCount = TestUtil.getWarningCount(message, onServer, containerQualifier);
}

public LogCounter(String message, boolean onServer) {
this(message, onServer, null);
}

/**
* Get count of examined log message, logged after creation of this LogCounter
*/
public int count() {
return TestUtil.getWarningCount(message, onServer) - initCount;
return TestUtil.getWarningCount(message, onServer, containerQualifier) - initCount;
}
}
Expand Up @@ -245,6 +245,40 @@ public static String getJbossHome(boolean onServer) {
return System.getProperty("jboss.home.dir", "");
}

/**
* Get the path to the containers base dir for standalone mode (configuration, logs, etc..).
* When arquillian.xml contains more containers that could be started simultaneously the parameter containerQualifier
* is used to determine which base dir to get.
* @param containerQualifier container qualifier or null if the arquillian.xml contains max 1 container available
* to be running at time
* @return absolute path to base dir
*/
public static String getStandaloneDir(String containerQualifier) {
return getStandaloneDir(false, containerQualifier);
}

/**
* Get the path to the containers base dir for standalone mode (configuration, logs, etc..).
* When arquillian.xml contains more containers that could be started simultaneously the parameter containerQualifier
* is used to determine which base dir to get.
* @param onServer whether the check is made from client side (the path is constructed) or from deployment (the path
* is read from actual runtime value)
* @param containerQualifier container qualifier or null if the arquillian.xml contains max 1 container available
* to be running at time; this has no effect when onServer is true
* @return absolute path to base dir
*/
public static String getStandaloneDir(boolean onServer, String containerQualifier) {
if (onServer == false) {
if (containerQualifier == null) {
return new File(getJbossHome(), "standalone").getAbsolutePath();
} else {
return new File("target", containerQualifier).getAbsolutePath();
}
} else {
return System.getProperty("jboss.server.base.dir", "");
}
}

public static boolean isOpenJDK() {
return System.getProperty("java.runtime.name").toLowerCase().contains("openjdk");
}
Expand Down Expand Up @@ -286,10 +320,14 @@ public static List<String> readServerLogLines() {
}

public static List<String> readServerLogLines(boolean onServer) {
String jbossHome = TestUtil.getJbossHome(onServer);
String logPath = String.format("%s%sstandalone%slog%sserver.log", jbossHome,
(jbossHome.endsWith(File.separator) || jbossHome.endsWith("/")) ? "" : File.separator,
File.separator, File.separator);
return readServerLogLines(onServer, null);
}

public static List<String> readServerLogLines(boolean onServer, String containerQualifier) {
String standaloneDir = TestUtil.getStandaloneDir(onServer, containerQualifier);
String logPath = String.format("%s%slog%sserver.log", standaloneDir,
(standaloneDir.endsWith(File.separator) || standaloneDir.endsWith("/")) ? "" : File.separator,
File.separator);
logPath = logPath.replace('/', File.separatorChar);
try {
return Files.readAllLines(Paths.get(logPath)); // UTF8 is used by default
Expand All @@ -310,8 +348,15 @@ public static List<String> readServerLogLines(boolean onServer) {
* Get count of lines with specific string in log
*/
public static int getWarningCount(String findedString, boolean onServer) {
return getWarningCount(findedString, onServer, null);
}

/**
* Get count of lines with specific string in log
*/
public static int getWarningCount(String findedString, boolean onServer, String containerQualifier) {
int count = 0;
List<String> lines = TestUtil.readServerLogLines(onServer);
List<String> lines = TestUtil.readServerLogLines(onServer, containerQualifier);
for (String line : lines) {
if (line.contains(findedString)) {
count++;
Expand Down
6 changes: 3 additions & 3 deletions testsuite/integration-tests-spring/deployment/pom.xml
Expand Up @@ -33,7 +33,7 @@
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
Expand All @@ -57,8 +57,8 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>unpack resteasy</id>
<phase>process-test-classes</phase>
<id>unpack-resteasy</id>
<phase>generate-test-resources</phase>
<configuration>
<target>
<!-- Explicitly remove resteasy-spring contents as the module.xml does not reference resource jars in this case
Expand Down
6 changes: 3 additions & 3 deletions testsuite/integration-tests-spring/inmodule/pom.xml
Expand Up @@ -39,7 +39,7 @@
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
Expand All @@ -63,8 +63,8 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>unpack resteasy</id>
<phase>process-test-classes</phase>
<id>unpack-resteasy</id>
<phase>generate-test-resources</phase>
<configuration>
<target>
<!-- Explicitly remove resteasy-spring contents as the module.xml does not reference resource jars in this case
Expand Down
45 changes: 42 additions & 3 deletions testsuite/integration-tests/pom.xml
Expand Up @@ -13,6 +13,14 @@

<properties>
<maven.compiler.parameters>true</maven.compiler.parameters>
<container.base.dir.managed>${project.build.directory}${file.separator}${container.qualifier.managed}</container.base.dir.managed>
<container.base.dir.manual.gzip>${project.build.directory}${file.separator}${container.qualifier.manual.gzip}</container.base.dir.manual.gzip>
<container.offset.managed>0</container.offset.managed>
<container.offset.manual.gzip>1000</container.offset.manual.gzip>
<container.management.port.managed>9990</container.management.port.managed><!-- keep in sync with port offset -->
<container.management.port.manual.gzip>10990</container.management.port.manual.gzip><!-- keep in sync with port offset -->
<container.qualifier.managed>jbossas-managed</container.qualifier.managed>
<container.qualifier.manual.gzip>jbossas-manual-gzip</container.qualifier.manual.gzip>
</properties>

<artifactId>resteasy-integration-tests</artifactId>
Expand All @@ -37,7 +45,7 @@
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
Expand All @@ -61,8 +69,8 @@
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>unpack resteasy</id>
<phase>process-test-classes</phase>
<id>unpack-resteasy</id>
<phase>generate-test-resources</phase>
<configuration>
<target>
<!-- Explicitly remove resteasy-spring contents as the module.xml does not reference resource jars in this case
Expand Down Expand Up @@ -406,6 +414,37 @@
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>initialize-basedirs</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<!-- Initialize basedir for tested container by copying
the original into new place.
This helps to isolate the multiple running instances.
One copy per each container in arquillian.xml -->

<delete quiet="true" dir="${container.base.dir.managed}" />
<copy todir="${container.base.dir.managed}" overwrite="true" failonerror="true">
<fileset dir="${jboss.home}/standalone"/>
</copy>

<delete quiet="true" dir="${container.base.dir.manual.gzip}" />
<copy todir="${container.base.dir.manual.gzip}" overwrite="true" failonerror="true">
<fileset dir="${jboss.home}/standalone"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
Expand Down
@@ -0,0 +1,16 @@
package org.jboss.resteasy.test;

import java.io.File;

/**
* Various contants for containers defined in arquillian.xml. Keep this file in sync with the values there.
*/
public class ContainerConstants {

public static final String DEFAULT_CONTAINER_QUALIFIER = "jbossas-managed";

public static final String GZIP_CONTAINER_QUALIFIER = "jbossas-manual-gzip";

public static final int GZIP_CONTAINER_PORT_OFFSET = 1000;

}
Expand Up @@ -8,6 +8,7 @@
import org.apache.logging.log4j.Logger;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.resteasy.test.ContainerConstants;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.jboss.resteasy.utils.PermissionUtil;
import org.jboss.resteasy.utils.PortProviderUtil;
Expand Down Expand Up @@ -58,8 +59,7 @@ public class CDIResourceTest {

static {
toStr = new StringBuilder()
.append(TestUtil.getJbossHome()).append(File.separator)
.append("standalone").append(File.separator)
.append(TestUtil.getStandaloneDir(ContainerConstants.DEFAULT_CONTAINER_QUALIFIER)).append(File.separator)
.append("deployments").append(File.separator)
.append(WAR_NAME).toString();
exportFile = new File(FileSystems.getDefault().getPath("target").toFile(), WAR_NAME);
Expand Down
Expand Up @@ -22,6 +22,8 @@
import java.util.PropertyPermission;
import java.util.logging.LoggingPermission;

import static org.jboss.resteasy.test.ContainerConstants.DEFAULT_CONTAINER_QUALIFIER;

/**
* @tpSubChapter Resteasy-client
* @tpChapter Unit tests
Expand All @@ -38,7 +40,7 @@ public static Archive<?> deploy() {
war.addClass(NotForForwardCompatibility.class);
// Arquillian in the deployment and use of TestUtil
war.addAsManifestResource(PermissionUtil.createPermissionsXmlAsset(new ReflectPermission("suppressAccessChecks"),
new FilePermission(TestUtil.getJbossHome() + File.separator + "standalone" + File.separator + "log" +
new FilePermission(TestUtil.getStandaloneDir(DEFAULT_CONTAINER_QUALIFIER) + File.separator + "log" +
File.separator + "server.log", "read"),
new LoggingPermission("control", ""),
new PropertyPermission("arquillian.*", "read"),
Expand All @@ -58,7 +60,7 @@ public boolean configure(FeatureContext context) {
}

private int getWarningCount() {
return TestUtil.getWarningCount("RESTEASY002155", true);
return TestUtil.getWarningCount("RESTEASY002155", true, DEFAULT_CONTAINER_QUALIFIER);
}

/**
Expand Down Expand Up @@ -86,16 +88,16 @@ public void testDoubleClassRegistration() {
@Test
@Category({NotForForwardCompatibility.class})
public void testDoubleRegistration() {
int countRESTEASY002160 = TestUtil.getWarningCount("RESTEASY002160", true);
int countRESTEASY002155 = TestUtil.getWarningCount("RESTEASY002155", true);
int countRESTEASY002160 = TestUtil.getWarningCount("RESTEASY002160", true, DEFAULT_CONTAINER_QUALIFIER);
int countRESTEASY002155 = TestUtil.getWarningCount("RESTEASY002155", true, DEFAULT_CONTAINER_QUALIFIER);
Client client = ClientBuilder.newClient();
int count = client.getConfiguration().getInstances().size();
Object reg = new FeatureReturningFalse();

client.register(reg).register(reg);
client.register(FeatureReturningFalse.class).register(FeatureReturningFalse.class);
Assert.assertEquals("Expect 1 warnining messages of Provider instance is already registered", 1, TestUtil.getWarningCount("RESTEASY002160", true) - countRESTEASY002160);
Assert.assertEquals("Expect 1 warnining messages of Provider class is already registered", 2, TestUtil.getWarningCount("RESTEASY002155", true) - countRESTEASY002155);
Assert.assertEquals("Expect 1 warnining messages of Provider instance is already registered", 1, TestUtil.getWarningCount("RESTEASY002160", true, DEFAULT_CONTAINER_QUALIFIER) - countRESTEASY002160);
Assert.assertEquals("Expect 1 warnining messages of Provider class is already registered", 2, TestUtil.getWarningCount("RESTEASY002155", true, DEFAULT_CONTAINER_QUALIFIER) - countRESTEASY002155);
Assert.assertEquals(count + 1, client.getConfiguration().getInstances().size());

client.close();
Expand Down
Expand Up @@ -19,6 +19,8 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static org.jboss.resteasy.test.ContainerConstants.DEFAULT_CONTAINER_QUALIFIER;

/**
* @tpSubChapter Response
* @tpChapter Integration tests
Expand All @@ -31,7 +33,7 @@ public class DuplicateDeploymentTest {
private static int initWarningCount = 0;

private static int getWarningCount() {
return TestUtil.getWarningCount("RESTEASY002172", false);
return TestUtil.getWarningCount("RESTEASY002172", false, DEFAULT_CONTAINER_QUALIFIER);
}

@Deployment
Expand Down

0 comments on commit fbd36ac

Please sign in to comment.