activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject [1/4] activemq git commit: fix intermittent failure - wait rather than sleep which also speeds up the test run
Date Fri, 19 Jun 2015 11:47:40 GMT
Repository: activemq
Updated Branches:
  refs/heads/master cd32c60f3 -> 1a3ade041


fix intermittent failure - wait rather than sleep which also speeds up the test run


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/1a3ade04
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/1a3ade04
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/1a3ade04

Branch: refs/heads/master
Commit: 1a3ade04140acd7c63e999a9032f8ce1c3b57c2e
Parents: b22184e
Author: gtully <gary.tully@gmail.com>
Authored: Fri Jun 19 12:35:44 2015 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Fri Jun 19 12:36:32 2015 +0100

----------------------------------------------------------------------
 .../failover/FailoverClusterTestSupport.java    | 40 +++++++++++---------
 .../failover/FailoverComplexClusterTest.java    | 10 -----
 2 files changed, 23 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/1a3ade04/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverClusterTestSupport.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverClusterTestSupport.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverClusterTestSupport.java
index b277636..c5e9665 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverClusterTestSupport.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverClusterTestSupport.java
@@ -36,6 +36,7 @@ import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.TransportConnector;
 import org.apache.activemq.network.NetworkConnector;
+import org.apache.activemq.util.Wait;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,26 +50,31 @@ public class FailoverClusterTestSupport extends TestCase {
     private final Map<String, BrokerService> brokers = new HashMap<String, BrokerService>();
     private final List<ActiveMQConnection> connections = new ArrayList<ActiveMQConnection>();
 
-    protected void assertClientsConnectedToTwoBrokers() {
-        Set<String> set = new HashSet<String>();
-        for (ActiveMQConnection c : connections) {
-            if (c.getTransportChannel().getRemoteAddress() != null) {
-                set.add(c.getTransportChannel().getRemoteAddress());
-            }
-        }
-        assertTrue("Only 2 connections should be found: " + set,
-                set.size() == 2);
+    protected void assertClientsConnectedToTwoBrokers() throws Exception {
+        assertClientsConnectedToXBrokers(2);
     }
 
-    protected void assertClientsConnectedToThreeBrokers() {
-        Set<String> set = new HashSet<String>();
-        for (ActiveMQConnection c : connections) {
-            if (c.getTransportChannel().getRemoteAddress() != null) {
-                set.add(c.getTransportChannel().getRemoteAddress());
+    protected void assertClientsConnectedToThreeBrokers() throws Exception {
+        assertClientsConnectedToXBrokers(3);
+    }
+
+    protected void assertClientsConnectedToXBrokers(final int x) throws Exception {
+        final Set<String> set = new HashSet<String>();
+        Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                set.clear();
+                for (ActiveMQConnection c : connections) {
+                    if (c.getTransportChannel().getRemoteAddress() != null) {
+                        set.add(c.getTransportChannel().getRemoteAddress());
+                    }
+                }
+                return set.size() == x;
             }
-        }
-        assertTrue("Only 3 connections should be found: " + set,
-                set.size() == 3);
+        });
+
+        assertTrue("Only " + x + " connections should be found: " + set,
+                set.size() == x);
     }
 
     protected void assertClientsConnectionsEvenlyDistributed(double minimumPercentage) {

http://git-wip-us.apache.org/repos/asf/activemq/blob/1a3ade04/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java
index 74fc0b5..a92ceec 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/failover/FailoverComplexClusterTest.java
@@ -147,7 +147,6 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport
{
 
         setClientUrl("failover://(" + BROKER_A_CLIENT_TC_ADDRESS + "," + BROKER_B_CLIENT_TC_ADDRESS
+ ")");
         createClients();
-        Thread.sleep(2000);
 
         assertClientsConnectedToThreeBrokers();
 
@@ -155,13 +154,10 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport
{
         getBroker(BROKER_A_NAME).waitUntilStopped();
         removeBroker(BROKER_A_NAME);
 
-        Thread.sleep(5000);
-
         assertClientsConnectedToTwoBrokers();
 
         createBrokerA(false, null, null, null);
         getBroker(BROKER_A_NAME).waitUntilStarted();
-        Thread.sleep(5000);
 
         assertClientsConnectedToThreeBrokers();
     }
@@ -264,14 +260,11 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport
{
         getBroker(BROKER_C_NAME).waitUntilStopped();
         removeBroker(BROKER_C_NAME);
 
-        Thread.sleep(5000);
-
         assertClientsConnectedToTwoBrokers();
 
         LOG.info("Recreating BrokerC after stop");
         createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
         getBroker(BROKER_C_NAME).waitUntilStarted();
-        Thread.sleep(5000);
 
         assertClientsConnectedToThreeBrokers();
     }
@@ -292,14 +285,11 @@ public class FailoverComplexClusterTest extends FailoverClusterTestSupport
{
         getBroker(BROKER_C_NAME).waitUntilStopped();
         removeBroker(BROKER_C_NAME);
 
-        Thread.sleep(5000);
-
         assertClientsConnectedToTwoBrokers();
         assertClientsConnectionsEvenlyDistributed(.35);
 
         createBrokerC(multi, tcParams, clusterFilter, destinationFilter);
         getBroker(BROKER_C_NAME).waitUntilStarted();
-        Thread.sleep(5000);
 
         assertClientsConnectedToThreeBrokers();
         assertClientsConnectionsEvenlyDistributed(.20);


Mime
View raw message