incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1537945 - in /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest: VanityPathTest.java util/EventsCounterUtil.java
Date Fri, 01 Nov 2013 14:28:37 GMT
Author: bdelacretaz
Date: Fri Nov  1 14:28:37 2013
New Revision: 1537945

URL: http://svn.apache.org/r1537945
Log:
SLING-2788 - Use more robust event-based sync in VanityPathTest instead of fixed sleep time

Modified:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/VanityPathTest.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/EventsCounterUtil.java

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/VanityPathTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/VanityPathTest.java?rev=1537945&r1=1537944&r2=1537945&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/VanityPathTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/VanityPathTest.java
Fri Nov  1 14:28:37 2013
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.EventsCounterUtil;
 import org.apache.sling.servlets.post.SlingPostConstants;
 
 /**
@@ -35,7 +36,9 @@ public class VanityPathTest extends Http
     private String postUrl;
     private String vanityPath;
     private String vanityUrl;
-
+    private int mappingEventCount;
+    public static final String MAPPING_UPDATE_TOPIC = "org/apache/sling/api/resource/ResourceResolverMapping/CHANGED";
+    
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -47,10 +50,10 @@ public class VanityPathTest extends Http
             + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
         vanityPath = "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis()
+ "/vanity";
         vanityUrl = HTTP_BASE_URL + vanityPath;
-
-
+        
+        mappingEventCount = EventsCounterUtil.getEventsCount(this, MAPPING_UPDATE_TOPIC);
     }
-
+    
     /** test vanity path with internal redirect */
     public void testInternalRedirect() throws IOException {
         // create a node with a vanity path
@@ -190,9 +193,6 @@ public class VanityPathTest extends Http
      * MapEntries to reinitialize.
      */
     private void waitForMapReload() {
-        try {
-            Thread.sleep(750L);
-        } catch (InterruptedException e) {
-        }
+        EventsCounterUtil.waitForEvent(this, MAPPING_UPDATE_TOPIC, 5000, mappingEventCount);
     }
 }

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/EventsCounterUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/EventsCounterUtil.java?rev=1537945&r1=1537944&r2=1537945&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/EventsCounterUtil.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/EventsCounterUtil.java
Fri Nov  1 14:28:37 2013
@@ -24,6 +24,8 @@ import org.apache.sling.commons.json.JSO
 import org.apache.sling.commons.json.JSONObject;
 import org.apache.sling.commons.testing.integration.HttpTest;
 import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.testing.tools.retry.RetryLoop;
+import org.apache.sling.testing.tools.retry.RetryLoop.Condition;
 
 /** Give access to info provided by the test-services EventsCounterServlet */
 public class EventsCounterUtil {
@@ -31,4 +33,17 @@ public class EventsCounterUtil {
         final JSONObject json = new JSONObject(b.getContent(HttpTest.HTTP_BASE_URL + "/testing/EventsCounter.json",
HttpTest.CONTENT_TYPE_JSON));
         return json.has(topic) ? json.getInt(topic) : 0;
     }
+    
+    public static void waitForEvent(final HttpTestBase b, final String topic, int timeoutMsec,
final int previousCount) {
+        final Condition c = new Condition() {
+            public String getDescription() {
+                return "Wait for OSGi event on topic " + topic; 
+            }
+
+            public boolean isTrue() throws Exception {
+                return getEventsCount(b, topic) > previousCount;
+            }
+        };
+        new RetryLoop(c, timeoutMsec, 500);
+    }
 }
\ No newline at end of file



Mime
View raw message