diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/Wait.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/Wait.java index ab5826b72e..85e72bb228 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/Wait.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/Wait.java @@ -39,6 +39,10 @@ public class Wait { long getCount() throws Exception; } + public interface ObjectCondition { + Object getObject() throws Exception; + } + public interface IntCondition { int getCount() throws Exception; } @@ -47,6 +51,10 @@ public class Wait { return waitFor(condition, MAX_WAIT_MILLIS); } + public static void assertEquals(Object obj, ObjectCondition condition) throws Exception { + assertEquals(obj, condition, MAX_WAIT_MILLIS, SLEEP_MILLIS); + } + public static void assertEquals(long size, LongCondition condition) throws Exception { assertEquals(size, condition, MAX_WAIT_MILLIS); @@ -73,6 +81,15 @@ public class Wait { assertEquals(size, condition, timeout, SLEEP_MILLIS); } + + public static void assertEquals(Object obj, ObjectCondition condition, long timeout, long sleepMillis) throws Exception { + boolean result = waitFor(() -> (obj == condition || obj.equals(condition.getObject())), timeout, sleepMillis); + + if (!result) { + Assert.assertEquals(obj, condition.getObject()); + } + } + public static void assertEquals(int size, IntCondition condition, long timeout, long sleepMillis) throws Exception { boolean result = waitFor(() -> condition.getCount() == size, timeout, sleepMillis); diff --git a/artemis-rest/pom.xml b/artemis-rest/pom.xml index 305a2847bc..9d62a30ef9 100644 --- a/artemis-rest/pom.xml +++ b/artemis-rest/pom.xml @@ -124,6 +124,12 @@ artemis-commons ${project.version} + + org.apache.activemq + artemis-commons + ${project.version} + test-jar + org.apache.geronimo.specs geronimo-jms_2.0_spec diff --git a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/SelectorTest.java b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/SelectorTest.java index 111d26a783..babf9950d1 100644 --- a/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/SelectorTest.java +++ b/artemis-rest/src/test/java/org/apache/activemq/artemis/rest/test/SelectorTest.java @@ -33,6 +33,7 @@ import org.apache.activemq.artemis.rest.HttpHeaderProperty; import org.apache.activemq.artemis.rest.queue.push.xml.XmlLink; import org.apache.activemq.artemis.rest.topic.PushTopicRegistration; import org.apache.activemq.artemis.rest.topic.TopicDeployment; +import org.apache.activemq.artemis.utils.Wait; import org.jboss.logging.Logger; import org.jboss.resteasy.client.ClientRequest; import org.jboss.resteasy.client.ClientResponse; @@ -207,33 +208,27 @@ public class SelectorTest extends MessageTestBase { order.setName("1"); order.setAmount("$5.00"); publish(prefixedTopicName, order, null, "1"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.oneOrder); + Wait.assertEquals(order, () -> PushReceiver.oneOrder); order.setName("2"); publish(prefixedTopicName, order, null, "2"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.twoOrder); + Wait.assertEquals(order, () -> PushReceiver.twoOrder); order.setName("3"); publish(prefixedTopicName, order, null, "2"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.twoOrder); + Wait.assertEquals(order, () -> PushReceiver.twoOrder); order.setName("4"); publish(prefixedTopicName, order, null, "1"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.oneOrder); + Wait.assertEquals(order, () -> PushReceiver.oneOrder); order.setName("5"); publish(prefixedTopicName, order, null, "1"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.oneOrder); + Wait.assertEquals(order, () -> PushReceiver.oneOrder); order.setName("6"); publish(prefixedTopicName, order, null, "1"); - Thread.sleep(200); - Assert.assertEquals(order, PushReceiver.oneOrder); + Wait.assertEquals(order, () -> PushReceiver.oneOrder); response = oneSubscription.request().delete(); response.releaseConnection();