You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2007/01/19 14:49:03 UTC
svn commit: r497813 -
/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
Author: ritchiem
Date: Fri Jan 19 05:49:02 2007
New Revision: 497813
URL: http://svn.apache.org/viewvc?view=rev&rev=497813
Log:
Removed mandatory 6 second sleep! replaced with a countdown latch that will wait for a max of 2 seconds
Modified:
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java?view=diff&rev=497813&r1=497812&r2=497813
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/client/MessageListenerMultiConsumerTest.java Fri Jan 19 05:49:02 2007
@@ -36,6 +36,8 @@
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* QPID-293 Setting MessageListener after connection has started can cause messages to be "lost" on a internal delivery queue
@@ -63,6 +65,7 @@
private MessageConsumer _consumer2;
private boolean _testAsync;
+ private final CountDownLatch _allMessagesSent = new CountDownLatch(2); //all messages Sent Lock
protected void setUp() throws Exception
{
@@ -72,7 +75,7 @@
InitialContextFactory factory = new PropertiesFileInitialContextFactory();
Hashtable<String, String> env = new Hashtable<String, String>();
-
+
env.put("connectionfactory.connection", "amqp://client:client@MLT_ID/tests?brokerlist='vm://:1'");
env.put("queue.queue", "direct://amq.direct//MessageListenerTest");
@@ -121,7 +124,7 @@
{
assertEquals(MSG_COUNT, receivedCount1 + receivedCount2);
}
- _clientConnection.close();
+ _clientConnection.close();
super.tearDown();
TransportConnection.killAllVMBrokers();
@@ -165,6 +168,12 @@
_logger.info("Client 1 Received Message(" + receivedCount1 + "):" + message);
receivedCount1++;
+
+ if (receivedCount1 == MSG_COUNT / 2)
+ {
+ _allMessagesSent.countDown();
+ }
+
}
});
@@ -175,15 +184,19 @@
_logger.info("Client 2 Received Message(" + receivedCount2 + "):" + message);
receivedCount2++;
+ if (receivedCount2 == MSG_COUNT / 2)
+ {
+ _allMessagesSent.countDown();
+ }
}
});
- _logger.info("Waiting 3 seconds for messages");
+ _logger.info("Waiting upto 2 seconds for messages");
try
{
- Thread.sleep(6000);
+ _allMessagesSent.await(2000, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e)
{