Author: bdelacretaz
Date: Fri Nov 15 10:53:26 2013
New Revision: 1542223

URL: http://svn.apache.org/r1542223
Log:
SLING-3235 - additional readyness checks to cope with async config install at 
startup

Modified:
    
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
    sling/trunk/launchpad/testing/pom.xml

Modified: 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=1542223&r1=1542222&r2=1542223&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
 (original)
+++ 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
 Fri Nov 15 10:53:26 2013
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -57,6 +58,9 @@ public class HttpTestBase extends TestCa
     public static final String HTTP_BASE_URL = removePath(HTTP_URL);
     public static final String WEBDAV_BASE_URL = 
removeEndingSlash(System.getProperty("launchpad.webdav.server.url", 
HTTP_BASE_URL));
     public static final String SERVLET_CONTEXT = 
removeEndingSlash(System.getProperty("launchpad.servlet.context", 
getPath(HTTP_URL)));
+    
+    public static final String READY_URL_PROP_PREFIX = "launchpad.ready.";
+    public static final int MAX_READY_URL_INDEX = 50;
 
     /** base path for test files */
     public static final String TEST_PATH = "/launchpad-integration-tests";
@@ -313,7 +317,31 @@ public class HttpTestBase extends TestCa
                 throw new IOException("Allow header (" + h.getValue() + " does 
not contain PROPFIND, at URL=" + webDavUrl);
             }
         }
-
+        
+        // And check optional additional URLs for readyness
+        // Defined by system properties like
+        //  launchpad.ready.1 = GET:/tmp/someUrl:200:expectedRegexpInResponse
+        {
+            for(int i=0; i <= MAX_READY_URL_INDEX ; i++) {
+                final String propName = READY_URL_PROP_PREFIX + i;
+                final String readyDef = System.getProperty(propName, "");
+                final String [] parts = readyDef.split(":");
+                if(parts.length == 4) {
+                    final String info = propName + "=" + readyDef;
+                    final HttpAnyMethod m = new 
HttpAnyMethod(parts[0],HTTP_BASE_URL + parts[1]);
+                    final int expectedStatus = Integer.valueOf(parts[2]);
+                    final int status = httpClient.executeMethod(m);
+                    if(expectedStatus != status) {
+                        throw new IOException("Status " + status + " does not 
match expected value: " + info); 
+                    }
+                    final String content = m.getResponseBodyAsString();
+                    final Pattern p = Pattern.compile("(?s).*" + parts[3] + 
".*");
+                    if(!p.matcher(content).matches()) {
+                        throw new IOException("Content does not match expected 
regexp:" + info  + ", content=" + content);
+                    }
+                }
+            }
+        }
 
         return true;
     }
@@ -518,4 +546,4 @@ public class HttpTestBase extends TestCa
         }
         return content.toString();
     }
-}
+}
\ No newline at end of file

Modified: sling/trunk/launchpad/testing/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/pom.xml?rev=1542223&r1=1542222&r2=1542223&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/pom.xml (original)
+++ sling/trunk/launchpad/testing/pom.xml Fri Nov 15 10:53:26 2013
@@ -242,6 +242,10 @@
                                 
<launchpad.http.server.url>http://${test.host}:${http.port}/</launchpad.http.server.url>
                                 
<launchpad.webdav.server.url>http://${test.host}:${http.port}/${webdav.workspace.path}</launchpad.webdav.server.url>
                                 
<HttpTestBase.readyTimeoutSeconds>${HttpTestBase.readyTimeoutSeconds}</HttpTestBase.readyTimeoutSeconds>
+                                
+                                <!-- Additional readyness checks, SLING-3235 
-->
+                                
<launchpad.ready.1>GET:/system/console/status-Configurations/configuration-status-20131115-101714.txt:200:config.comment.*setup
 the JSP engine for running tests</launchpad.ready.1>
+                                
<launchpad.ready.2>GET:/.EXPORTED_PACKAGES.txt?package=org.apache.sling.api:200:PACKAGE
 FOUND.*org.apache.sling.api</launchpad.ready.2>
                             </systemPropertyVariables>
                         </configuration>
                     </plugin>


Reply via email to