tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject tomee git commit: another try to fix that test.
Date Thu, 06 Apr 2017 13:48:46 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x e47e5a276 -> 77109e43d


another try to fix that test.

Might have happened that the messages got received so quickly
that one message got overwritten before the test code could
pick it up -> switching to a queue.


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/77109e43
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/77109e43
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/77109e43

Branch: refs/heads/tomee-1.7.x
Commit: 77109e43dfe82751764a806a83314f3e08cf3f68
Parents: e47e5a2
Author: Mark Struberg <struberg@apache.org>
Authored: Thu Apr 6 15:47:41 2017 +0200
Committer: Mark Struberg <struberg@apache.org>
Committed: Thu Apr 6 15:47:41 2017 +0200

----------------------------------------------------------------------
 .../ActiveMQResourceAdapterControlTest.java     | 26 +++++++++++---------
 1 file changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/77109e43/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapterControlTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapterControlTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapterControlTest.java
index 09d8e4b..338e4c2 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapterControlTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapterControlTest.java
@@ -42,6 +42,7 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.management.ObjectName;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
@@ -91,32 +92,32 @@ public class ActiveMQResourceAdapterControlTest {
 
     @Test
     public void ensureControl() throws Exception {
-        assertFalse(Mdb.awaiter.message, sendAndWait("Will be received after", 10, TimeUnit.SECONDS));
+        Mdb.awaiter.messages.clear();
+
+        assertFalse(Mdb.awaiter.messages.poll(), sendAndWait("Will be received after", 10,
TimeUnit.SECONDS));
 
         setControl("start");
         assertTrue(Mdb.awaiter.semaphore.tryAcquire(1, TimeUnit.MINUTES));
-        assertEquals("Will be received after", Mdb.awaiter.message);
+        assertEquals("Will be received after", Mdb.awaiter.messages.poll());
 
         final long start = System.currentTimeMillis();
         assertTrue(sendAndWait("First", 1, TimeUnit.MINUTES));
-        assertEquals("First", Mdb.awaiter.message);
+        assertEquals("First", Mdb.awaiter.messages.poll());
         final long end = System.currentTimeMillis();
 
-        Mdb.awaiter.message = null;
         setControl("stop");
         // default would be wait 10s, but if machine is slow we compute it from the first
msg stats
-        final long waitWithoutResponse = Math.max(10, 1+ 5 * (end - start) / 1000);
+        final long waitWithoutResponse = Math.max(10, 5 * (end - start) / 1000);
         System.out.println("We'll wait " + waitWithoutResponse + "s to get a message on a
stopped listener");
-        assertFalse(Mdb.awaiter.message, sendAndWait("Will be received after", waitWithoutResponse,
TimeUnit.SECONDS));
-        assertNull(Mdb.awaiter.message);
+        assertFalse(Mdb.awaiter.messages.poll(), sendAndWait("Will be received after", waitWithoutResponse,
TimeUnit.SECONDS));
+        assertNull(Mdb.awaiter.messages.poll());
 
         setControl("start");
         assertTrue(sendAndWait("Second", 1, TimeUnit.MINUTES));
-        assertEquals("Will be received after", Mdb.awaiter.message);
+        assertEquals("Will be received after", Mdb.awaiter.messages.poll());
 
-        Mdb.awaiter.message = null;
         assertTrue(Mdb.awaiter.semaphore.tryAcquire(1, TimeUnit.MINUTES));
-        assertEquals("Second", Mdb.awaiter.message);
+        assertEquals("Second", Mdb.awaiter.messages.poll());
     }
 
     private void setControl(final String action) throws Exception {
@@ -141,6 +142,7 @@ public class ActiveMQResourceAdapterControlTest {
         try {
             c = connectionFactory.createConnection();
             Session session = null;
+
             try {
                 session = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
                 MessageProducer producer = null;
@@ -171,7 +173,7 @@ public class ActiveMQResourceAdapterControlTest {
         @Override
         public synchronized void onMessage(final Message message) {
             try {
-                awaiter.message = TextMessage.class.cast(message).getText();
+                awaiter.messages.add(TextMessage.class.cast(message).getText());
             } catch (final JMSException e) {
                 throw new IllegalStateException(e);
             } finally {
@@ -182,6 +184,6 @@ public class ActiveMQResourceAdapterControlTest {
 
     public static class MessageAwaiter {
         private final Semaphore semaphore = new Semaphore(0);
-        private volatile String message;
+        private ConcurrentLinkedQueue<String> messages = new ConcurrentLinkedQueue<String>();
     }
 }


Mime
View raw message