From 17322fb57a38633edb2f754ffb97bbd2dd08bed8 Mon Sep 17 00:00:00 2001 From: Erich Duda Date: Wed, 18 May 2016 15:54:48 +0200 Subject: [PATCH] ARTEMIS-527 - [Artemis Testsuite] TopicControlTest fails --- .../server/management/TopicControlTest.java | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlTest.java index a23f06779a..238aaa05b0 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlTest.java @@ -133,9 +133,9 @@ public class TopicControlTest extends ManagementTestBase { JMSUtil.sendMessages(topic, 2); - Assert.assertEquals(3 * 2, topicControl.getMessageCount()); - Assert.assertEquals(1 * 2, topicControl.getNonDurableMessageCount()); - Assert.assertEquals(2 * 2, topicControl.getDurableMessageCount()); + waitForMessageCount(3 * 2, topicControl, 3000); + waitForNonDurableMessageCount(1 * 2, topicControl, 3000); + waitForDurableMessageCount(2 * 2, topicControl, 3000); connection_1.close(); connection_2.close(); @@ -406,7 +406,7 @@ public class TopicControlTest extends ManagementTestBase { JMSUtil.sendMessages(topic, 3); TopicControl topicControl = createManagementControl(); - Assert.assertEquals(3 * 2, topicControl.getMessageCount()); + waitForMessageCount(3 * 2, topicControl, 3000); int removedCount = topicControl.removeMessages(null); Assert.assertEquals(3 * 2, removedCount); @@ -494,7 +494,7 @@ public class TopicControlTest extends ManagementTestBase { JMSUtil.sendMessages(topic, 2); - Assert.assertEquals(3 * 2, topicControl.getMessagesAdded()); + waitForAddedMessageCount(3 * 2, topicControl, 3000); connection_1.close(); connection_2.close(); @@ -619,6 +619,54 @@ public class TopicControlTest extends ManagementTestBase { // Private ------------------------------------------------------- + private void waitForMessageCount(long expected, TopicControl topicControl, long timeout) throws Exception { + long timeToWait = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() < timeToWait) { + if (expected == topicControl.getMessageCount()) { + return; + } + Thread.sleep(100); + } + assertEquals(expected, topicControl.getMessageCount()); + } + + private void waitForNonDurableMessageCount(long expected, TopicControl topicControl, long timeout) throws Exception { + long timeToWait = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() < timeToWait) { + if (expected == topicControl.getNonDurableMessageCount()) { + return; + } + Thread.sleep(100); + } + assertEquals(expected, topicControl.getNonDurableMessageCount()); + } + + private void waitForDurableMessageCount(long expected, TopicControl topicControl, long timeout) throws Exception { + long timeToWait = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() < timeToWait) { + if (expected == topicControl.getDurableMessageCount()) { + return; + } + Thread.sleep(100); + } + assertEquals(expected, topicControl.getDurableMessageCount()); + } + + private void waitForAddedMessageCount(long expected, TopicControl topicControl, long timeout) throws Exception { + long timeToWait = System.currentTimeMillis() + timeout; + + while (System.currentTimeMillis() < timeToWait) { + if (expected == topicControl.getMessagesAdded()) { + return; + } + Thread.sleep(100); + } + assertEquals(expected, topicControl.getMessagesAdded()); + } + // Inner classes ------------------------------------------------- }