activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kea...@apache.org
Subject git commit: Fix for AMQ-5113. Fixed race condition in onMessage for testSimulatenousCron which caused intermittent failures
Date Thu, 20 Mar 2014 12:33:13 GMT
Repository: activemq
Updated Branches:
  refs/heads/trunk 4ba4aa21d -> cbb46ea7d


Fix for AMQ-5113. Fixed race condition in onMessage for testSimulatenousCron which caused
intermittent failures


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

Branch: refs/heads/trunk
Commit: cbb46ea7d3d4bea81a86b85c85110872b839e83a
Parents: 4ba4aa2
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Thu Mar 20 13:33:03 2014 +0100
Committer: Kevin Earls <kevin@kevinearls.com>
Committed: Thu Mar 20 13:33:03 2014 +0100

----------------------------------------------------------------------
 .../broker/scheduler/JmsCronSchedulerTest.java  | 39 +++++++++++++++++---
 1 file changed, 34 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/cbb46ea7/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JmsCronSchedulerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JmsCronSchedulerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JmsCronSchedulerTest.java
index 2bf84b2..7bfdeb4 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JmsCronSchedulerTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/scheduler/JmsCronSchedulerTest.java
@@ -17,12 +17,14 @@
 package org.apache.activemq.broker.scheduler;
 
 import java.io.File;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jms.Connection;
+import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageListener;
@@ -34,13 +36,25 @@ import org.apache.activemq.EmbeddedBrokerTestSupport;
 import org.apache.activemq.ScheduledMessage;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.util.IOHelper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@RunWith(BlockJUnit4ClassRunner.class)
 public class JmsCronSchedulerTest extends EmbeddedBrokerTestSupport {
 
+    @Rule
+    public TestName testName = new TestName();
+
     private static final Logger LOG = LoggerFactory.getLogger(JmsCronSchedulerTest.class);
 
+    @Test
     public void testSimulatenousCron() throws Exception {
 
         final int COUNT = 10;
@@ -55,18 +69,26 @@ public class JmsCronSchedulerTest extends EmbeddedBrokerTestSupport {
         consumer.setMessageListener(new MessageListener() {
             @Override
             public void onMessage(Message message) {
-                latch.countDown();
                 count.incrementAndGet();
-                LOG.debug("Received one Message, count is at: " + count.get());
+                latch.countDown();
+                assertTrue(message instanceof TextMessage);
+                TextMessage tm = (TextMessage) message;
+                try {
+                    LOG.info("Received [{}] count: {} ", tm.getText(), count.get());
+                } catch (JMSException e) {
+                    LOG.error("Unexpected exception in onMessage", e);
+                    fail("Unexpected exception in onMessage: " + e.getMessage());
+                }
             }
         });
 
         connection.start();
         for (int i = 0; i < COUNT; i++) {
             MessageProducer producer = session.createProducer(destination);
-            TextMessage message = session.createTextMessage("test msg "+i);
+            TextMessage message = session.createTextMessage("test msg "+ i);
             message.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_CRON, "* * * * *");
             producer.send(message);
+            LOG.info("Message {} sent at {}", i, new Date().toString());
             producer.close();
             //wait a couple sec so cron start time is different for next message
             Thread.sleep(2000);
@@ -80,6 +102,7 @@ public class JmsCronSchedulerTest extends EmbeddedBrokerTestSupport {
         assertEquals(COUNT, count.get());
     }
 
+    @Test
     public void testCronScheduleWithTtlSet() throws Exception {
 
         Connection connection = createConnection();
@@ -101,12 +124,18 @@ public class JmsCronSchedulerTest extends EmbeddedBrokerTestSupport
{
         assertNull(consumer.receiveNoWait());
     }
 
-    @Override
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
+        LOG.info("Starting test {}", testName.getMethodName());
         bindAddress = "vm://localhost";
         super.setUp();
     }
 
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
     @Override
     protected BrokerService createBroker() throws Exception {
         return createBroker(true);


Mime
View raw message