activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] 02/03: NO-JIRA Fixing intermittent failure on a REST test
Date Tue, 15 Sep 2020 15:08:29 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit c0c638d61f09c50b50ab8a037505917e346248c3
Author: Clebert Suconic <clebertsuconic@apache.org>
AuthorDate: Tue Sep 15 08:56:07 2020 -0400

    NO-JIRA Fixing intermittent failure on a REST test
---
 .../java/org/apache/activemq/artemis/utils/Wait.java  | 17 +++++++++++++++++
 artemis-rest/pom.xml                                  |  6 ++++++
 .../activemq/artemis/rest/test/SelectorTest.java      | 19 +++++++------------
 3 files changed, 30 insertions(+), 12 deletions(-)

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 ab5826b..85e72bb 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 305a284..9d62a30 100644
--- a/artemis-rest/pom.xml
+++ b/artemis-rest/pom.xml
@@ -125,6 +125,12 @@
          <version>${project.version}</version>
       </dependency>
       <dependency>
+         <groupId>org.apache.activemq</groupId>
+         <artifactId>artemis-commons</artifactId>
+         <version>${project.version}</version>
+         <type>test-jar</type>
+      </dependency>
+      <dependency>
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jms_2.0_spec</artifactId>
       </dependency>
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 111d26a..babf995 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();


Mime
View raw message