Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 66014 invoked from network); 1 Mar 2011 13:33:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Mar 2011 13:33:12 -0000 Received: (qmail 47425 invoked by uid 500); 1 Mar 2011 13:33:12 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 47339 invoked by uid 500); 1 Mar 2011 13:33:09 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 47331 invoked by uid 99); 1 Mar 2011 13:33:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Mar 2011 13:33:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Mar 2011 13:33:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5FB0023889B2; Tue, 1 Mar 2011 13:32:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1075815 - in /sling/trunk/testing: junit/core/src/main/java/org/apache/sling/junit/impl/ samples/integration-tests/ samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/ samples/integration-tests/src/test/java... Date: Tue, 01 Mar 2011 13:32:44 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110301133244.5FB0023889B2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Tue Mar 1 13:32:43 2011 New Revision: 1075815 URL: http://svn.apache.org/viewvc?rev=1075815&view=rev Log: SLING-1963 - improve keepJarRunning behavior Added: sling/trunk/testing/samples/integration-tests/README.txt (with props) Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java sling/trunk/testing/samples/integration-tests/pom.xml sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java?rev=1075815&r1=1075814&r2=1075815&view=diff ============================================================================== --- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java (original) +++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java Tue Mar 1 13:32:43 2011 @@ -37,6 +37,9 @@ public class AnnotationsProcessor implem protected void activate(ComponentContext ctx) { bundleContext = ctx.getBundleContext(); + if(bundleContext == null) { + throw new IllegalArgumentException("Null BundleContext in activate()"); + } } protected void deactivate(ComponentContext ctx) { @@ -55,6 +58,10 @@ public class AnnotationsProcessor implem /** Process the TestReference annotation to inject services into fields */ private void processTestReference(Object testObject, Field f) throws Exception { + if(bundleContext == null) { + throw new IllegalArgumentException("Null BundleContext in processTestReference(), not activated?"); + } + final Class serviceType = f.getType(); final Object service = getService(serviceType); if(service != null) { @@ -70,17 +77,15 @@ public class AnnotationsProcessor implem private Object getService(Class c) { Object result = null; - if(bundleContext != null) { - // BundleContext is not a service, but can be injected - if(c.equals(BundleContext.class)) { - result = bundleContext; - } else { - ServiceReference ref = bundleContext.getServiceReference(c.getName()); - if(ref != null) { - result = bundleContext.getService(ref); - } + // BundleContext is not a service, but can be injected + if(c.equals(BundleContext.class)) { + result = bundleContext; + } else { + ServiceReference ref = bundleContext.getServiceReference(c.getName()); + if(ref != null) { + result = bundleContext.getService(ref); } } return result; } -} +} \ No newline at end of file Added: sling/trunk/testing/samples/integration-tests/README.txt URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/README.txt?rev=1075815&view=auto ============================================================================== --- sling/trunk/testing/samples/integration-tests/README.txt (added) +++ sling/trunk/testing/samples/integration-tests/README.txt Tue Mar 1 13:32:43 2011 @@ -0,0 +1,7 @@ +Sling sample integration tests +----------------------------- + +Use "mvn clean install" to start a Sling instance and +run the tests defined in this module. + +See comments in the pom.xml for options and test parameters. Propchange: sling/trunk/testing/samples/integration-tests/README.txt ------------------------------------------------------------------------------ svn:eol-style = native Modified: sling/trunk/testing/samples/integration-tests/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1075815&r1=1075814&r2=1075815&view=diff ============================================================================== --- sling/trunk/testing/samples/integration-tests/pom.xml (original) +++ sling/trunk/testing/samples/integration-tests/pom.xml Tue Mar 1 13:32:43 2011 @@ -38,19 +38,32 @@ bundles and server-side scriptable tests. + + false + + -Xmx512m - - false - 1.0 Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java?rev=1075815&r1=1075814&r2=1075815&view=diff ============================================================================== --- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java (original) +++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java Tue Mar 1 13:32:43 2011 @@ -21,7 +21,6 @@ import static org.junit.Assert.fail; import java.io.File; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.TreeSet; @@ -54,6 +53,7 @@ public class SlingTestBase { protected static RequestExecutor executor = new RequestExecutor(httpClient); private static boolean serverStarted; + private static boolean serverStartedByThisClass; private static boolean serverReady; private static boolean serverReadyTestFailed; private static final Logger log = LoggerFactory.getLogger(SlingTestBase.class); @@ -62,12 +62,14 @@ public class SlingTestBase { try { startRunnableJar(); waitForServerReady(); + blockIfRequested(); } catch(Exception e) { - throw new IllegalStateException("JUnit Servlet not ready: ", e); + throw new IllegalStateException("Exception in SlingTestBase constructor", e); } } - - public static synchronized void startRunnableJar() throws Exception { + + /** Start the configured runnable jar and initialize our http client */ + private synchronized void startRunnableJar() throws Exception { if(serverStarted) { return; } @@ -81,23 +83,32 @@ public class SlingTestBase { log.info(TEST_SERVER_URL_PROP + " not set, starting server jar {}", j); j.start(); serverBaseUrl = "http://localhost:" + j.getServerPort(); - - // Optionally block here so that the runnable jar stays up - we can - // then run tests against it from another VM - if ("true".equals(System.getProperty(KEEP_JAR_RUNNING_PROP))) { - log.info(KEEP_JAR_RUNNING_PROP + " set to true - entering infinite loop" - + " so that runnable jar stays up. Kill this process to exit."); - while (true) { - Thread.sleep(1000L); - } - } + serverStartedByThisClass = true; } serverStarted = true; builder = new RequestBuilder(serverBaseUrl); } - public void waitForServerReady() throws Exception { + /** Optionally block here so that the runnable jar stays up - we can + * then run tests against it from another VM. + */ + private void blockIfRequested() { + if ("true".equals(System.getProperty(KEEP_JAR_RUNNING_PROP))) { + log.info(KEEP_JAR_RUNNING_PROP + " set to true - entering infinite loop" + + " so that runnable jar stays up. Kill this process to exit."); + synchronized (this) { + try { + wait(); + } catch(InterruptedException iex) { + log.info("InterruptedException in blockIfRequested"); + } + } + } + } + + /** Check a number of server URLs for readyness */ + private void waitForServerReady() throws Exception { if(serverReady) { return; } @@ -170,7 +181,13 @@ public class SlingTestBase { * method. */ protected void onServerReady() throws Exception { - installExtraBundles(); + 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 */ @@ -240,4 +257,8 @@ public class SlingTestBase { .withEntity(entity) ).assertStatus(302); } + + protected boolean isServerStartedByThisClass() { + return serverStartedByThisClass; + } } \ No newline at end of file Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java?rev=1075815&r1=1075814&r2=1075815&view=diff ============================================================================== --- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java (original) +++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java Tue Mar 1 13:32:43 2011 @@ -39,7 +39,7 @@ public class ServerSideTestsBase extends throw new IllegalStateException("JUnit Servlet not ready: ", e); } } - + private void checkJunitServletPresent() throws Exception { if(junitServletOk) { return;