qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1736550 - in /qpid/java/branches/6.0.x: ./ systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
Date Fri, 25 Mar 2016 10:15:12 GMT
Author: kwall
Date: Fri Mar 25 10:15:12 2016
New Revision: 1736550

URL: http://svn.apache.org/viewvc?rev=1736550&view=rev
Log:
NO-JIRA: [Java System Tests] Increase wiggle room in Heartbeat test

Merged from trunk:

svn merge -c 1728651    ^/qpid/java/trunk



Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Mar 25 10:15:12 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729657,1729
 783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732525,1734452
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732525,1734452
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java?rev=1736550&r1=1736549&r2=1736550&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
(original)
+++ qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
Fri Mar 25 10:15:12 2016
@@ -20,6 +20,8 @@ package org.apache.qpid.client;
 
 import static org.apache.qpid.configuration.ClientProperties.QPID_HEARTBEAT_INTERVAL;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jms.Destination;
@@ -38,7 +40,8 @@ public class HeartbeatTest extends QpidB
     private static final Logger LOGGER = LoggerFactory.getLogger(HeartbeatTest.class);
 
     private static final String CONNECTION_URL_WITH_HEARTBEAT = "amqp://guest:guest@clientid/?brokerlist='localhost:%d?heartbeat='%d''";
-    private TestListener _listener = new TestListener("listener");
+    private static final int MAXIMUM_WAIT_TIME = 2900;
+    private TestListener _listener = new TestListener("listener", 2, 2);
 
     @Override
     public void setUp() throws Exception
@@ -57,7 +60,7 @@ public class HeartbeatTest extends QpidB
         conn.setHeartbeatListener(_listener);
         conn.start();
 
-        Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(MAXIMUM_WAIT_TIME);
 
         assertTrue("Too few heartbeats received: "+_listener.getHeartbeatsReceived() +" (expected
at least 2)", _listener.getHeartbeatsReceived() >=2);
         assertTrue("Too few heartbeats sent "+_listener.getHeartbeatsSent() +" (expected
at least 2)", _listener.getHeartbeatsSent() >=2);
@@ -72,7 +75,7 @@ public class HeartbeatTest extends QpidB
         conn.setHeartbeatListener(_listener);
         conn.start();
 
-        Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(MAXIMUM_WAIT_TIME);
 
         assertTrue("Too few heartbeats received: "+_listener.getHeartbeatsReceived() +" (expected
at least 2)", _listener.getHeartbeatsReceived() >=2);
         assertTrue("Too few heartbeats sent "+_listener.getHeartbeatsSent() +" (expected
at least 2)", _listener.getHeartbeatsSent() >=2);
@@ -87,7 +90,7 @@ public class HeartbeatTest extends QpidB
          conn.setHeartbeatListener(_listener);
          conn.start();
 
-         Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(2000);
 
          assertEquals("Heartbeats unexpectedly received", 0, _listener.getHeartbeatsReceived());
          assertEquals("Heartbeats unexpectedly sent ", 0, _listener.getHeartbeatsSent());
@@ -106,8 +109,8 @@ public class HeartbeatTest extends QpidB
         AMQConnection receiveConn = (AMQConnection) getConnection();
         AMQConnection sendConn = (AMQConnection) getConnection();
         Destination destination = getTestQueue();
-        TestListener receiveListener = new TestListener("receiverListener");
-        TestListener sendListener = new TestListener("senderListener");
+        TestListener receiveListener = new TestListener("receiverListener", 2, 0);
+        TestListener sendListener = new TestListener("senderListener", 0, 2);
 
 
         Session receiveSession = receiveConn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
@@ -148,7 +151,7 @@ public class HeartbeatTest extends QpidB
         conn.setHeartbeatListener(_listener);
         conn.start();
 
-        Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(MAXIMUM_WAIT_TIME);
 
         assertTrue("Too few heartbeats received: "+_listener.getHeartbeatsReceived() +" (expected
at least 2)", _listener.getHeartbeatsReceived()>=2);
         assertTrue("Too few heartbeats sent "+ _listener.getHeartbeatsSent() +" (expected
at least 2)", _listener.getHeartbeatsSent() >=2);
@@ -165,7 +168,7 @@ public class HeartbeatTest extends QpidB
         conn.setHeartbeatListener(_listener);
         conn.start();
 
-        Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(MAXIMUM_WAIT_TIME);
 
         assertTrue("Too few heartbeats received: "+_listener.getHeartbeatsReceived()+" (expected
at least 2)", _listener.getHeartbeatsReceived()>=2);
         assertTrue("Too few heartbeats sent "+_listener.getHeartbeatsSent() +" (expected
at least 2)", _listener.getHeartbeatsSent()>=2);
@@ -181,7 +184,7 @@ public class HeartbeatTest extends QpidB
         conn.setHeartbeatListener(_listener);
         conn.start();
 
-        Thread.sleep(2500);
+        _listener.awaitExpectedHeartbeats(MAXIMUM_WAIT_TIME);
 
         assertTrue("Too few heartbeats received: "+_listener.getHeartbeatsReceived() +" (expected
at least 2)", _listener.getHeartbeatsReceived()>=2);
         assertTrue("Too few heartbeats sent "+_listener.getHeartbeatsSent() +" (expected
at least 2)", _listener.getHeartbeatsSent()>=2);
@@ -194,10 +197,14 @@ public class HeartbeatTest extends QpidB
         private final String _name;
         private final AtomicInteger _heartbeatsReceived = new AtomicInteger(0);
         private final AtomicInteger _heartbeatsSent = new AtomicInteger(0);
+        private final CountDownLatch _expectedReceivedHeartbeats;
+        private final CountDownLatch _expectedSentHeartbeats;
 
-        public TestListener(String name)
+        public TestListener(String name, int expectedSentHeartbeats, int expectedReceivedHeartbeats)
         {
             _name = name;
+            _expectedReceivedHeartbeats = new CountDownLatch(expectedReceivedHeartbeats);
+            _expectedSentHeartbeats = new CountDownLatch(expectedSentHeartbeats);
         }
 
         @Override
@@ -205,6 +212,7 @@ public class HeartbeatTest extends QpidB
         {
             LOGGER.debug(_name + " heartbeat received");
             _heartbeatsReceived.incrementAndGet();
+            _expectedReceivedHeartbeats.countDown();
         }
 
         public int getHeartbeatsReceived()
@@ -217,11 +225,24 @@ public class HeartbeatTest extends QpidB
         {
             LOGGER.debug(_name + " heartbeat sent");
             _heartbeatsSent.incrementAndGet();
+            _expectedSentHeartbeats.countDown();
         }
 
         public int getHeartbeatsSent()
         {
             return _heartbeatsSent.get();
         }
+
+        public void awaitExpectedHeartbeats(final long maximumWaitTime) throws InterruptedException
+        {
+            long startTime = System.currentTimeMillis();
+            _expectedSentHeartbeats.await(maximumWaitTime, TimeUnit.MILLISECONDS);
+
+            long remainingTime = maximumWaitTime - (System.currentTimeMillis() - startTime);
+            if (remainingTime > 0)
+            {
+                _expectedReceivedHeartbeats.await(remainingTime, TimeUnit.MILLISECONDS);
+            }
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message