Author: bdelacretaz
Date: Mon Mar 7 17:26:47 2011
New Revision: 1078856
URL: http://svn.apache.org/viewvc?rev=1078856&view=rev
Log:
SLING-2023 - run sample tests in the integration-test phase, and fix
initialization bugs that the different order of tests execution exposed
Modified:
sling/trunk/testing/samples/integration-tests/pom.xml
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
Modified: sling/trunk/testing/samples/integration-tests/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/pom.xml (original)
+++ sling/trunk/testing/samples/integration-tests/pom.xml Mon Mar 7 17:26:47
2011
@@ -42,12 +42,12 @@
To keep the instance under test running and run individual tests
against it, use:
- mvn clean test -DkeepJarRunning=true -Dhttp.port=8080
+ mvn clean verify -DkeepJarRunning=true -Dhttp.port=8080
optionally using jar.executor.vm.options to enable remote debugging,
and in another console:
- mvn -o test -Dtest=**Test -Dtest.server.url=http://localhost:8080
+ mvn -o verify -Dtests.to.run=**/**Test.java
-Dtest.server.url=http://localhost:8080
optionally using -Dmaven.surefire.debug to enable debugging.
-->
@@ -74,6 +74,9 @@
<!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced
by the
selected port number -->
<jar.executor.jar.options>-p
$JAREXEC_SERVER_PORT$</jar.executor.jar.options>
+
+ <!-- Change this to run selected tests only -->
+ <tests.to.run>**/**Test.java</tests.to.run>
</properties>
<scm>
@@ -160,6 +163,35 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
+ <!-- We run all tests in the integration-tests phase -->
+ <excludes>
+ <exclude>**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.7.2</version>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>verify</id>
+ <goals>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+
<debugForkedProcess>${maven.surefire.debug}</debugForkedProcess>
+ <includes>
+ <include>${tests.to.run}</include>
+ </includes>
<systemPropertyVariables>
<test.server.url>${test.server.url}</test.server.url>
<jar.executor.server.port>${http.port}</jar.executor.server.port>
Modified:
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
---
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
(original)
+++
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
Mon Mar 7 17:26:47 2011
@@ -36,9 +36,8 @@ public class ServerSideTestsBase extends
private final Logger log = LoggerFactory.getLogger(getClass());
public static final int JUNIT_SERVLET_TIMEOUT_SECONDS =
TimeoutsProvider.getInstance().getTimeout(60);
- @Override
- protected void onServerReady(boolean serverStartedByThisClass) throws
Exception {
- super.onServerReady(serverStartedByThisClass);
+ /** Verify that JUnit servlet is started before running these tests */
+ public ServerSideTestsBase() {
if(junitServletCheckFailed) {
fail("Previous check of JUnit servlet failed, cannot run tests");
}
Modified:
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
---
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
(original)
+++
sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
Mon Mar 7 17:26:47 2011
@@ -16,6 +16,9 @@
*/
package org.apache.sling.testing.samples.integrationtests.serverside.sling;
+import static org.junit.Assert.fail;
+
+import org.apache.sling.testing.tools.http.RequestExecutor;
import org.apache.sling.testing.tools.http.RetryingContentChecker;
import org.apache.sling.testing.tools.sling.SlingClient;
import org.apache.sling.testing.tools.sling.SlingTestBase;
@@ -23,8 +26,6 @@ import org.apache.sling.testing.tools.sl
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.fail;
-
/** Test server-side tests using the Sling JUnit servlet, as opposed
* to the plain JUnit servlet.
*/
@@ -36,20 +37,15 @@ public class SlingServerSideTestsBase ex
public static final String SLING_JUNIT_SERVLET_PATH = SERVLET_NODE_PATH +
".junit";
private final Logger log = LoggerFactory.getLogger(getClass());
- private RetryingContentChecker servletChecker;
- private boolean servletCheckFailed;
- private boolean servletOk;
- private SlingClient slingClient;
+ private static boolean servletCheckFailed;
+ private static boolean servletOk;
private static boolean servletNodeCreated;
- /** At startup, setup a node that gives access to the Sling JUnit servlet,
+ /** Before running tests, setup a node that gives access to the Sling
JUnit servlet,
* and check (with timeout) that the servlet is ready */
- @Override
- protected void onServerReady(boolean serverStartedByThisClass) throws
Exception {
- super.onServerReady(serverStartedByThisClass);
-
+ public SlingServerSideTestsBase() {
if(!servletNodeCreated) {
- slingClient = new SlingClient(getServerBaseUrl(), ADMIN, ADMIN);
+ final SlingClient slingClient = new
SlingClient(getServerBaseUrl(), ADMIN, ADMIN);
try {
slingClient.createNode(SERVLET_NODE_PATH,
"sling:resourceType", "sling/junit/testing");
servletNodeCreated = true;
@@ -63,14 +59,19 @@ public class SlingServerSideTestsBase ex
}
if(!servletOk) {
- if(servletChecker == null) {
- servletChecker = new
RetryingContentChecker(getRequestExecutor(), getRequestBuilder()) {
- @Override
- public void onTimeout() {
- servletCheckFailed = true;
- }
- };
- }
+ final RetryingContentChecker servletChecker = new
RetryingContentChecker(getRequestExecutor(), getRequestBuilder())
+ {
+ @Override
+ public void onTimeout() {
+ servletCheckFailed = true;
+ }
+
+ @Override
+ protected boolean assertMore(RequestExecutor e) throws
Exception {
+ e.assertContentContains("SlingJUnitServlet");
+ return true;
+ }
+ };
final String path = SLING_JUNIT_SERVLET_PATH;
final int status = 200;
@@ -80,6 +81,7 @@ public class SlingServerSideTestsBase ex
new Object[] { path, status, timeout });
servletChecker.check(path, status, timeout, intervalMsec);
servletOk = true;
+ log.info("{} is ready, returns expected content", path);
}
}
}
\ No newline at end of file
Modified:
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
---
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
(original)
+++
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
Mon Mar 7 17:26:47 2011
@@ -39,7 +39,7 @@ public class RetryingContentChecker {
public boolean isTrue() throws Exception {
executor.execute(builder.buildGetRequest(path)).assertStatus(expectedStatus);
- return true;
+ return assertMore(executor);
}
};
@@ -51,6 +51,12 @@ public class RetryingContentChecker {
};
}
+ /** Optionally perform additional tests in retry condition */
+ protected boolean assertMore(RequestExecutor executor) throws Exception {
+ return true;
+ }
+
+ /** Called if a timeout occurs */
protected void onTimeout() {
}
}
Modified:
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
---
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
(original)
+++
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/jarexec/JarExecutor.java
Mon Mar 7 17:26:47 2011
@@ -64,6 +64,11 @@ public class JarExecutor {
}
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": " + jarToExecute.getName() + "
(port " + serverPort + ")";
+ }
+
public int getServerPort() {
return serverPort;
}
Modified:
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java?rev=1078856&r1=1078855&r2=1078856&view=diff
==============================================================================
---
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
(original)
+++
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
Mon Mar 7 17:26:47 2011
@@ -46,7 +46,7 @@ public class SlingTestBase {
public static final String ADMIN = "admin";
private static final boolean keepJarRunning =
"true".equals(System.getProperty(KEEP_JAR_RUNNING_PROP));
- private static String serverBaseUrl;
+ private final String serverBaseUrl;
private static RequestBuilder builder;
private static DefaultHttpClient httpClient = new DefaultHttpClient();
private static RequestExecutor executor = new RequestExecutor(httpClient);
@@ -55,17 +55,56 @@ public class SlingTestBase {
private static boolean serverStartedByThisClass;
private static boolean serverReady;
private static boolean serverReadyTestFailed;
+ private static boolean extraBundlesInstalled;
+ private static boolean startupInfoProvided;
+
private static final Logger log =
LoggerFactory.getLogger(SlingTestBase.class);
+ private static JarExecutor jarExecutor;
+
+ /** Get configuration but do not start server yet, that's done on demand */
+ public SlingTestBase() {
+ if(jarExecutor == null) {
+ synchronized(this) {
+ try {
+ jarExecutor = new JarExecutor(System.getProperties());
+ } catch(Exception e) {
+ log.error("JarExecutor setup failed", e);
+ fail("JarExecutor setup failed: " + e);
+ }
+ }
+ }
+
+ final String configuredUrl = System.getProperty(TEST_SERVER_URL_PROP);
+ if(configuredUrl != null) {
+ serverBaseUrl = configuredUrl;
+ serverStarted = true;
+ } else {
+ serverBaseUrl = "http://localhost:" + jarExecutor.getServerPort();
+ }
+
+ builder = new RequestBuilder(serverBaseUrl);
+ webconsoleClient = new WebconsoleClient(serverBaseUrl, ADMIN, ADMIN);
+ builder = new RequestBuilder(serverBaseUrl);
+ }
/** Start the server, if not done yet */
- private void startServer() {
+ private void startServerIfNeeded() {
try {
- startRunnableJar();
- builder = new RequestBuilder(serverBaseUrl);
- webconsoleClient = new WebconsoleClient(serverBaseUrl, ADMIN,
ADMIN);
- builder = new RequestBuilder(serverBaseUrl);
+ if(serverStarted && !serverStartedByThisClass &&
!startupInfoProvided) {
+ log.info(TEST_SERVER_URL_PROP + " was set: not starting server
jar (" + serverBaseUrl + ")");
+ }
+ if(!serverStarted) {
+ synchronized (jarExecutor) {
+ if(!serverStarted) {
+ jarExecutor.start();
+ serverStartedByThisClass = true;
+ serverStarted = true;
+ }
+ }
+ }
+ startupInfoProvided = true;
waitForServerReady();
- onServerReady(serverStartedByThisClass);
+ installExtraBundles();
blockIfRequested();
} catch(Exception e) {
log.error("Exception in maybeStartServer()", e);
@@ -75,41 +114,16 @@ public class SlingTestBase {
/** Start server if needed, and return a RequestBuilder that points to it
*/
protected RequestBuilder getRequestBuilder() {
- if(builder == null) {
- startServer();
- }
+ startServerIfNeeded();
return builder;
}
/** Start server if needed, and return its base URL */
protected String getServerBaseUrl() {
- if(serverBaseUrl == null) {
- startServer();
- }
+ startServerIfNeeded();
return serverBaseUrl;
}
- /** Start the configured runnable jar and initialize our http client */
- protected synchronized void startRunnableJar() throws Exception {
- if(serverStarted) {
- return;
- }
-
- final String configuredUrl = System.getProperty(TEST_SERVER_URL_PROP);
- if(configuredUrl != null) {
- serverBaseUrl = configuredUrl;
- log.info(TEST_SERVER_URL_PROP + " is set: not starting server jar
(" + serverBaseUrl + ")");
- } else {
- final JarExecutor j = new JarExecutor(System.getProperties());
- log.info(TEST_SERVER_URL_PROP + " not set, starting server jar
{}", j);
- j.start();
- serverBaseUrl = "http://localhost:" + j.getServerPort();
- serverStartedByThisClass = true;
- }
-
- serverStarted = true;
- }
-
/** Optionally block here so that the runnable jar stays up - we can
* then run tests against it from another VM.
*/
@@ -195,25 +209,18 @@ public class SlingTestBase {
}
}
- /** Called once when the server is found to be ready, can be used for
additional
- * server setup (extra bundles etc.). If overridden, must be called by
overriding
- * method.
- *
- * @param serverStartedByThisClass true if we started the server, in
which case
- * additional setup might be needed
- */
- protected void onServerReady(boolean serverStartedByThisClass) throws
Exception {
- if(serverStartedByThisClass) {
- installExtraBundles();
- } else {
- // Assume extra bundles are already in place, avoid transient
effects
- // caused by updating them
- log.info("Server was not started here, additional bundles will not
be installed");
- }
- }
-
/** Install all bundles found under our additional bundles path */
protected void installExtraBundles() throws Exception {
+ if(extraBundlesInstalled) {
+ return;
+ }
+ extraBundlesInstalled = true;
+
+ if(!serverStartedByThisClass) {
+ log.info("Server was not started here, additional bundles will not
be installed");
+ return;
+ }
+
final String path = System.getProperty(ADDITONAL_BUNDLES_PATH);
if(path == null) {
log.info("System property {} not set, additional bundles won't be
installed",
@@ -274,9 +281,7 @@ public class SlingTestBase {
}
protected WebconsoleClient getWebconsoleClient() {
- if(webconsoleClient == null) {
- startServer();
- }
+ startServerIfNeeded();
return webconsoleClient;
}
}
\ No newline at end of file