incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
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 GMT
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.
     </description>
     
+    <!-- 
+        To keep the instance under test running and run individual tests
+        against it, use:
+        
+            mvn clean test -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
+            
+        optionally using -Dmaven.surefire.debug to enable debugging.            
+     -->
     <properties>
         <!-- Set this to run the server on a specific port -->
         <http.port></http.port>
         
         <!-- Set this to run tests against an existing server instance -->
+        <keepJarRunning>false</keepJarRunning>
+        
+        <!-- URL of a server against which to run tests -->
         <test.server.url></test.server.url>
         
         <!-- Options for the VM that executes our runnable jar -->
         <jar.executor.vm.options>-Xmx512m</jar.executor.vm.options>
         
-        <!-- Set this to true to keep the runnable jar running - useful to debug tests
-->
-        <keepJarRunning>false</keepJarRunning>
-        
         <!-- Change this to use longer or shorter timeouts for testing -->
         <sling.testing.timeout.multiplier>1.0</sling.testing.timeout.multiplier>
     </properties>

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;



Mime
View raw message