You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2013/07/08 13:33:10 UTC

svn commit: r1500670 - in /sling/trunk/bundles/extensions/discovery/impl: pom.xml src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java

Author: rombert
Date: Mon Jul  8 11:33:09 2013
New Revision: 1500670

URL: http://svn.apache.org/r1500670
Log:
SLING-2945 - ClusterLoadTest failures

Replaced Thread.sleep usage with RetryLoop to make the testing runs more
predictable.

Also, wrap dumpRepo calls in try/catch calls since they previously
failed due to (probably) concurrent repo access.

Modified:
    sling/trunk/bundles/extensions/discovery/impl/pom.xml
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java

Modified: sling/trunk/bundles/extensions/discovery/impl/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/pom.xml?rev=1500670&r1=1500669&r2=1500670&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/pom.xml (original)
+++ sling/trunk/bundles/extensions/discovery/impl/pom.xml Mon Jul  8 11:33:09 2013
@@ -179,5 +179,11 @@
         	<type>bundle</type>
         	<scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.tools</artifactId>
+            <version>1.0.2</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java?rev=1500670&r1=1500669&r2=1500670&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java (original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/cluster/ClusterLoadTest.java Mon Jul  8 11:33:09 2013
@@ -11,6 +11,7 @@ import java.util.Random;
 import org.apache.sling.discovery.impl.common.resource.EstablishedInstanceDescription;
 import org.apache.sling.discovery.impl.common.resource.IsolatedInstanceDescription;
 import org.apache.sling.discovery.impl.setup.Instance;
+import org.apache.sling.testing.tools.retry.RetryLoop;
 import org.junit.After;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -18,7 +19,11 @@ import org.slf4j.LoggerFactory;
 
 public class ClusterLoadTest {
 	
-	private final Random random = new Random();
+    // wait up to 4 heartbeat intervals
+    private static final int INSTANCE_VIEW_WAIT_TIME_MILLIS = 5000;
+    private static final int INSTANCE_VIEW_POLL_INTERVAL_MILLIS = 500;
+
+    private final Random random = new Random();
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -109,8 +114,6 @@ public class ClusterLoadTest {
 			logger.info("=====================");
 			logger.info(" START of LOOP "+i);
 			logger.info("=====================");
-			// wait 4 heartbeat intervals to let things settle
-			Thread.sleep(5000);
 			
 			// count how many instances had heartbeats running in the first place
 			int aliveCnt = 0;
@@ -128,21 +131,27 @@ public class ClusterLoadTest {
 				aliveCnt=1;
 			}
 			
+            final int aliveCntFinal = aliveCnt;
+
 			for (Iterator<Instance> it = instances.iterator(); it.hasNext();) {
 				Instance instance = it.next();
-				instance.dumpRepo();
+				try {
+                    instance.dumpRepo();
+                } catch (Exception e) {
+                    logger.error("Failed dumping repo for instance " + instance.getSlingId(), e);
+                }
 			}
 
 			// then verify that each instance sees that many instances
 			for (Iterator<Instance> it = instances.iterator(); it.hasNext();) {
-				Instance instance = it.next();
-				int actualCount = instance.getClusterViewService().getClusterView().getInstances().size();
+                final Instance instance = it.next();
 				if (!instance.isHeartbeatRunning()) {
 					// if the heartbeat is not running, this instance is considered dead
 					// hence we're not doing any assert here (as the count is only
 					// valid if heartbeat/checkView is running and that would void the test)
 				} else {
-					assertEquals(actualCount, aliveCnt);
+                    new RetryLoop(new ConditionImplementation(instance, aliveCntFinal), INSTANCE_VIEW_WAIT_TIME_MILLIS,
+                            INSTANCE_VIEW_POLL_INTERVAL_MILLIS);
 				}
 			}
 			
@@ -164,4 +173,24 @@ public class ClusterLoadTest {
 		}
 	}
 
+    static class ConditionImplementation implements RetryLoop.Condition {
+
+        private final int expectedAliveCount;
+        private final Instance instance;
+
+        private ConditionImplementation(Instance instance, int expectedAliveCount) {
+            this.expectedAliveCount = expectedAliveCount;
+            this.instance = instance;
+        }
+
+        public boolean isTrue() throws Exception {
+            return expectedAliveCount == instance.getClusterViewService().getClusterView().getInstances().size();
+        }
+
+        public String getDescription() {
+            return "Waiting for instance with " + instance.getSlingId() + " to see " + expectedAliveCount
+                    + " instances";
+        }
+    }
+
 }