From 2a238f7c71313fae825a5cec2251c0bbdc5f6187 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Fri, 20 Nov 2009 11:34:14 +0000 Subject: [PATCH] some more resiliance to slow hardware for this test git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@882510 13f79535-47bb-0310-9956-ffa450edef68 --- .../usecases/ExpiredMessagesTest.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/activemq-core/src/test/java/org/apache/activemq/usecases/ExpiredMessagesTest.java b/activemq-core/src/test/java/org/apache/activemq/usecases/ExpiredMessagesTest.java index cbd0bb118b..66d5531cda 100644 --- a/activemq-core/src/test/java/org/apache/activemq/usecases/ExpiredMessagesTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/usecases/ExpiredMessagesTest.java @@ -37,6 +37,7 @@ import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; +import javax.management.InstanceNotFoundException; import javax.management.ObjectName; import junit.framework.Test; @@ -243,25 +244,27 @@ public class ExpiredMessagesTest extends CombinationTestSupport { final boolean deleteAllMessages = false; broker = createBroker(deleteAllMessages, 5000); - view = createView(destination); - LOG.info("Stats: size: " + view.getQueueSize() + ", enqueues: " - + view.getDequeueCount() + ", dequeues: " - + view.getDequeueCount() + ", dispatched: " - + view.getDispatchCount() + ", inflight: " - + view.getInFlightCount() + ", expiries: " - + view.getExpiredCount()); + Wait.waitFor(new Wait.Condition() { + public boolean isSatisified() throws Exception { + boolean result = false; + try { + DestinationViewMBean view = createView(destination); + LOG.info("Stats: size: " + view.getQueueSize() + ", enqueues: " + + view.getDequeueCount() + ", dequeues: " + + view.getDequeueCount() + ", dispatched: " + + view.getDispatchCount() + ", inflight: " + + view.getInFlightCount() + ", expiries: " + + view.getExpiredCount()); - long expiry = System.currentTimeMillis() + 30000; - while (view.getQueueSize() > 0 && System.currentTimeMillis() < expiry) { - Thread.sleep(500); - } - LOG.info("Stats: size: " + view.getQueueSize() + ", enqueues: " - + view.getDequeueCount() + ", dequeues: " - + view.getDequeueCount() + ", dispatched: " - + view.getDispatchCount() + ", inflight: " - + view.getInFlightCount() + ", expiries: " - + view.getExpiredCount()); - assertEquals("Wrong QueueSize: ", 0, view.getQueueSize()); + result = view.getQueueSize() == 0; + } catch (InstanceNotFoundException expectedOnSlowMachines) { + } + return result; + } + }); + + view = createView(destination); + assertEquals("Expect empty queue, QueueSize: ", 0, view.getQueueSize()); assertEquals("all dequeues were expired", view.getDequeueCount(), view.getExpiredCount()); }