incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1075353 - in /sling/trunk/testing: junit/core/src/main/java/org/apache/sling/junit/ samples/integration-tests/ samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/ samples/integration-tests/src/test/java/org/...
Date Mon, 28 Feb 2011 14:39:29 GMT
Author: bdelacretaz
Date: Mon Feb 28 14:39:28 2011
New Revision: 1075353

URL: http://svn.apache.org/viewvc?rev=1075353&view=rev
Log:
SLING-1963 - TimeoutsProvider added for variable timeouts depending on testing system speed

Added:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
  (with props)
Modified:
    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/JSONResponseTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java

Added: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java?rev=1075353&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
(added)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
Mon Feb 28 14:39:28 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.junit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Return timeout values that can be multiplied by a configurable
+ *  factor. Useful to cope with slower integration testing systems:
+ *  use timeout constants in your code that work for usual development
+ *  systems, and set a multiplier when running on a slower system.
+ */
+public class TimeoutsProvider {
+    private static final Logger log = LoggerFactory.getLogger(TimeoutsProvider.class);
+    public static final String PROP_TIMEOUT_MULTIPLIER = "sling.testing.timeout.multiplier";
+    private static float timeoutFactor = -1;
+    private static TimeoutsProvider INSTANCE;
+    
+    private TimeoutsProvider() {
+        if(timeoutFactor < 0) {
+            timeoutFactor = 1;
+            final String str = System.getProperty(PROP_TIMEOUT_MULTIPLIER);
+            if(str != null) {
+                try {
+                    timeoutFactor = Float.valueOf(str.trim());
+                    log.info("Timeout factor set to {} from system property {}", 
+                            timeoutFactor, PROP_TIMEOUT_MULTIPLIER);
+                } catch(NumberFormatException nfe) {
+                    throw new IllegalStateException("Invalid timeout factor: " + PROP_TIMEOUT_MULTIPLIER
+ "=" + str);
+                }
+            }
+        }
+    }
+    
+    public static TimeoutsProvider getInstance() {
+        if(INSTANCE == null) {
+            synchronized (TimeoutsProvider.class) {
+                INSTANCE = new TimeoutsProvider();
+            }
+        }
+        return INSTANCE;
+    }
+    
+    public long getTimeout(long nomimalValue) {
+        final long result = (long)(nomimalValue * timeoutFactor);
+        return result;
+    }
+    
+    public int getTimeout(int nomimalValue) {
+        final int result = (int)(nomimalValue * timeoutFactor);
+        return result;
+    }
+}

Propchange: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TimeoutsProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/testing/samples/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1075353&r1=1075352&r2=1075353&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/pom.xml (original)
+++ sling/trunk/testing/samples/integration-tests/pom.xml Mon Feb 28 14:39:28 2011
@@ -50,6 +50,9 @@
         
         <!-- 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>
     
     <scm>
@@ -148,6 +151,7 @@
                         <additional.bundles.path>${project.basedir}/target/sling/additional-bundles</additional.bundles.path>
                         <keepJarRunning>${keepJarRunning}</keepJarRunning>
                         <server.ready.timeout.seconds>60</server.ready.timeout.seconds>
+                        <sling.testing.timeout.multiplier>${sling.testing.timeout.multiplier}</sling.testing.timeout.multiplier>
                         <server.ready.path.1>/:script src="system/sling.js"</server.ready.path.1>
                         <server.ready.path.2>/.explorer.html:href="/libs/sling/explorer/css/explorer.css"</server.ready.path.2>
                         <server.ready.path.3>/sling-test/sling/sling-test.html:Sling
client library tests</server.ready.path.3>

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=1075353&r1=1075352&r2=1075353&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
Mon Feb 28 14:39:28 2011
@@ -27,6 +27,7 @@ import org.apache.http.entity.mime.Multi
 import org.apache.http.entity.mime.content.FileBody;
 import org.apache.http.entity.mime.content.StringBody;
 import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.sling.junit.TimeoutsProvider;
 import org.apache.sling.testing.tools.http.RequestBuilder;
 import org.apache.sling.testing.tools.http.RequestExecutor;
 import org.apache.sling.testing.tools.jarexec.JarExecutor;
@@ -103,7 +104,7 @@ public class SlingTestBase {
         
         // Timeout for readiness test
         final String sec = System.getProperty(SERVER_READY_TIMEOUT_PROP);
-        final int timeoutSec = sec == null ? 60 : Integer.valueOf(sec);
+        final int timeoutSec = TimeoutsProvider.getInstance().getTimeout(sec == null ? 60
: Integer.valueOf(sec));
         log.info("Will wait up to " + timeoutSec + " seconds for server to become ready");
         final long endTime = System.currentTimeMillis() + timeoutSec * 1000L;
 
@@ -148,7 +149,7 @@ public class SlingTestBase {
                 log.info("All {} paths return expected content, server ready", testPaths.size());
                 break;
             }
-            Thread.sleep(1000L);
+            Thread.sleep(TimeoutsProvider.getInstance().getTimeout(1000L));
         }
         
         if(serverReady) {

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java?rev=1075353&r1=1075352&r2=1075353&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
Mon Feb 28 14:39:28 2011
@@ -25,6 +25,7 @@ import org.apache.sling.commons.json.JSO
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.JSONObject;
 import org.apache.sling.commons.json.JSONTokener;
+import org.apache.sling.junit.TimeoutsProvider;
 import org.apache.sling.testing.tools.http.Request;
 import org.apache.sling.testing.tools.retry.RetryLoop;
 import org.junit.Test;
@@ -38,9 +39,7 @@ public class JSONResponseTest extends Se
     
     private final Logger log = LoggerFactory.getLogger(getClass());
     
-    // TODO compute those timeouts based on a configured factor
-    // to cope with slower testing systems??
-    public static final int TEST_LIST_TIMEOUT_SECONDS = 30;
+    public static final int TEST_LIST_TIMEOUT_SECONDS = TimeoutsProvider.getInstance().getTimeout(30);
     
     @Test
     public void testWithRetries() {
@@ -61,7 +60,7 @@ public class JSONResponseTest extends Se
         };
 
         log.info("{} (timeout={} seconds)", c.getDescription(), TEST_LIST_TIMEOUT_SECONDS);
-        new RetryLoop(c, TEST_LIST_TIMEOUT_SECONDS, 500);
+        new RetryLoop(c, TEST_LIST_TIMEOUT_SECONDS, TimeoutsProvider.getInstance().getTimeout(500));
     }
     
     private boolean findTestName(JSONArray json, String name) throws JSONException {

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=1075353&r1=1075352&r2=1075353&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
Mon Feb 28 14:39:28 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.testing.samples.testtools.serverside;
 
+import org.apache.sling.junit.TimeoutsProvider;
 import org.apache.sling.testing.samples.testtools.SlingTestBase;
 import org.apache.sling.testing.tools.retry.RetryLoop;
 import org.slf4j.Logger;
@@ -29,10 +30,7 @@ public class ServerSideTestsBase extends
     
     private static boolean junitServletOk;
     private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    // TODO compute those timeouts based on a configured factor
-    // to cope with slower testing systems??
-    public static final int JUNIT_SERVLET_TIMEOUT_SECONDS = 60;
+    public static final int JUNIT_SERVLET_TIMEOUT_SECONDS = TimeoutsProvider.getInstance().getTimeout(60);
 
     protected ServerSideTestsBase() {
         try {
@@ -65,7 +63,7 @@ public class ServerSideTestsBase extends
         };
         
         log.info(c.getDescription());
-        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, 500); 
+        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, TimeoutsProvider.getInstance().getTimeout(500));

         junitServletOk = true;
     }
 }



Mime
View raw message