From 3070d33275dc03fea5068975d2dba36ff59fd37d Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Sun, 31 Dec 2006 17:33:56 +0000 Subject: [PATCH] Wait the perfect amount of time by using count down latches. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@491455 13f79535-47bb-0310-9956-ffa450edef68 --- .../JmsMultipleBrokersTestSupport.java | 22 +++++++--- .../MultiBrokersMultiClientsTest.java | 41 ++++++++++++------- .../apache/activemq/util/MessageIdList.java | 10 +++++ 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsMultipleBrokersTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/JmsMultipleBrokersTestSupport.java index d925a46e72..2e97955da4 100644 --- a/activemq-core/src/test/java/org/apache/activemq/JmsMultipleBrokersTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsMultipleBrokersTestSupport.java @@ -43,6 +43,7 @@ import java.util.Iterator; import java.util.Collections; import java.util.Arrays; import java.util.Collection; +import java.util.concurrent.CountDownLatch; import java.net.URI; /** @@ -178,10 +179,14 @@ public class JmsMultipleBrokersTestSupport extends CombinationTestSupport { return null; } - protected MessageConsumer createConsumer(String brokerName, Destination dest) throws Exception { + protected MessageConsumer createConsumer(String brokerName, Destination dest) throws Exception { + return createConsumer(brokerName, dest, null); + } + + protected MessageConsumer createConsumer(String brokerName, Destination dest, CountDownLatch latch) throws Exception { BrokerItem brokerItem = (BrokerItem)brokers.get(brokerName); if (brokerItem != null) { - return brokerItem.createConsumer(dest); + return brokerItem.createConsumer(dest, latch); } return null; } @@ -321,19 +326,26 @@ public class JmsMultipleBrokersTestSupport extends CombinationTestSupport { } public MessageConsumer createConsumer(Destination dest) throws Exception { + return createConsumer(dest, null); + } + + public MessageConsumer createConsumer(Destination dest, CountDownLatch latch) throws Exception { Connection c = createConnection(); c.start(); Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE); - return createConsumer(dest, s); + return createConsumerWithSession(dest, s, latch); } - public MessageConsumer createConsumer(Destination dest, Session sess) throws Exception { + public MessageConsumer createConsumerWithSession(Destination dest, Session sess) throws Exception { + return createConsumerWithSession(dest, sess, null); + } + public MessageConsumer createConsumerWithSession(Destination dest, Session sess, CountDownLatch latch) throws Exception { MessageConsumer client = sess.createConsumer(dest); MessageIdList messageIdList = new MessageIdList(); + messageIdList.setCountDownLatch(latch); messageIdList.setParent(allMessages); client.setMessageListener(messageIdList); consumers.put(client, messageIdList); - return client; } diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsTest.java index 63b7b729e4..b72f1550c2 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/MultiBrokersMultiClientsTest.java @@ -17,14 +17,17 @@ */ package org.apache.activemq.usecases; -import org.apache.activemq.util.MessageIdList; -import org.apache.activemq.JmsMultipleBrokersTestSupport; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import javax.jms.Destination; import javax.jms.MessageConsumer; -import java.util.Map; -import java.util.HashMap; -import java.net.URI; + +import org.apache.activemq.JmsMultipleBrokersTestSupport; +import org.apache.activemq.util.MessageIdList; /** * @version $Revision: 1.1.1.1 $ @@ -45,14 +48,20 @@ public class MultiBrokersMultiClientsTest extends JmsMultipleBrokersTestSupport // Setup topic destination Destination dest = createDestination("TEST.FOO", true); + CountDownLatch latch = new CountDownLatch( + BROKER_COUNT * PRODUCER_COUNT * + BROKER_COUNT * CONSUMER_COUNT * + MESSAGE_COUNT); + // Setup consumers for (int i=1; i<=BROKER_COUNT; i++) { for (int j=0; j