activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject git commit: Updated link stealing test to account for isConnected state not being immediately updated which can lead to failure on a very fast machine.
Date Tue, 29 Jul 2014 19:09:34 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk 27a5f6b9d -> b11fc8faf


Updated link stealing test to account for isConnected state not being
immediately updated which can lead to failure on a very fast machine.  

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

Branch: refs/heads/trunk
Commit: b11fc8faf4c1a24da6f893dbb9e9d3d2059d5b3c
Parents: 27a5f6b
Author: Timothy Bish <tabish121@gmail.com>
Authored: Tue Jul 29 15:08:52 2014 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Tue Jul 29 15:08:52 2014 -0400

----------------------------------------------------------------------
 .../activemq/transport/mqtt/MQTTTest.java       | 53 ++++++++++++--------
 1 file changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/b11fc8fa/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
----------------------------------------------------------------------
diff --git a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
index fc04978..bf81e98 100644
--- a/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
+++ b/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
@@ -16,6 +16,14 @@
  */
 package org.apache.activemq.transport.mqtt;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.net.ProtocolException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -27,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
+
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.Destination;
@@ -35,14 +44,6 @@ import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.broker.region.policy.LastImageSubscriptionRecoveryPolicy;
 import org.apache.activemq.broker.region.policy.PolicyEntry;
@@ -1088,18 +1089,30 @@ public class MQTTTest extends MQTTTestSupport {
         final String clientId = "duplicateClient";
         MQTT mqtt = createMQTTConnection(clientId, false);
         mqtt.setKeepAlive((short) 2);
-        BlockingConnection connection = mqtt.blockingConnection();
+        final BlockingConnection connection = mqtt.blockingConnection();
         connection.connect();
         final String TOPICA = "TopicA";
         connection.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
 
         MQTT mqtt1 = createMQTTConnection(clientId, false);
         mqtt1.setKeepAlive((short) 2);
-        BlockingConnection connection1 = mqtt1.blockingConnection();
+        final BlockingConnection connection1 = mqtt1.blockingConnection();
         connection1.connect();
 
-        assertTrue("Duplicate client disconnected", connection1.isConnected());
-        assertFalse("Old client still connected", connection.isConnected());
+        assertTrue("Duplicate client disconnected", Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return connection1.isConnected();
+            }
+        }));
+
+        assertTrue("Old client still connected", Wait.waitFor(new Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return !connection.isConnected();
+            }
+        }));
+
         connection1.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
         connection1.disconnect();
 
@@ -1110,23 +1123,23 @@ public class MQTTTest extends MQTTTestSupport {
 
         mqtt = createMQTTConnection(clientId, false);
         mqtt.setKeepAlive((short) 2);
-        connection = mqtt.blockingConnection();
-        connection.connect();
-        connection.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
+        final BlockingConnection connection2 = mqtt.blockingConnection();
+        connection2.connect();
+        connection2.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
 
         mqtt1 = createMQTTConnection(clientId, false);
         mqtt1.setKeepAlive((short) 2);
-        connection1 = mqtt1.blockingConnection();
+        final BlockingConnection connection3 = mqtt1.blockingConnection();
         try {
-            connection1.connect();
+            connection3.connect();
             fail("Duplicate client connected");
         } catch (Exception e) {
             // ignore
         }
 
-        assertTrue("Old client disconnected", connection.isConnected());
-        connection.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
-        connection.disconnect();
+        assertTrue("Old client disconnected", connection2.isConnected());
+        connection2.publish(TOPICA, TOPICA.getBytes(), QoS.EXACTLY_ONCE, true);
+        connection2.disconnect();
     }
 
     @Test(timeout = 30 * 10000)


Mime
View raw message