From acbe5499b5ff07f1cbae42dd6ecdbcb9edaa64b4 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Tue, 23 Jul 2013 16:33:13 +0000 Subject: [PATCH] convert to JUnit 4 test and add a timeout git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1506149 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/bugs/AMQ2021Test.java | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2021Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2021Test.java index 1f0a174fb3..9abab3f607 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2021Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2021Test.java @@ -16,6 +16,10 @@ */ package org.apache.activemq.bugs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.lang.Thread.UncaughtExceptionHandler; import java.util.ArrayList; import java.util.Vector; @@ -32,28 +36,33 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import junit.framework.TestCase; - import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This is a test case for the issue reported at: - * https://issues.apache.org/activemq/browse/AMQ-2021 - * Bug is modification of inflight message properties so the failure can manifest itself in a bunch - * or ways, from message receipt with null properties to marshall errors + * This is a test case for the issue reported at: https://issues.apache.org/activemq/browse/AMQ-2021 Bug is modification + * of inflight message properties so the failure can manifest itself in a bunch or ways, from message receipt with null + * properties to marshall errors */ -public class AMQ2021Test extends TestCase implements ExceptionListener, UncaughtExceptionHandler { +public class AMQ2021Test implements ExceptionListener, UncaughtExceptionHandler { private static final Logger log = LoggerFactory.getLogger(AMQ2021Test.class); BrokerService brokerService; ArrayList threads = new ArrayList(); Vector exceptions; + @Rule + public TestName name = new TestName(); + AMQ2021Test testCase; private final String ACTIVEMQ_BROKER_BIND = "tcp://localhost:0"; @@ -62,14 +71,14 @@ public class AMQ2021Test extends TestCase implements ExceptionListener, Uncaught private final int numMessages = 1000; private final int numConsumers = 2; - private final int dlqMessages = numMessages/2; + private final int dlqMessages = numMessages / 2; private CountDownLatch receivedLatch; private ActiveMQTopic destination; private CountDownLatch started; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { Thread.setDefaultUncaughtExceptionHandler(this); testCase = this; @@ -78,19 +87,18 @@ public class AMQ2021Test extends TestCase implements ExceptionListener, Uncaught brokerService.setDeleteAllMessagesOnStartup(true); brokerService.addConnector(ACTIVEMQ_BROKER_BIND); brokerService.start(); - destination = new ActiveMQTopic(getName()); + destination = new ActiveMQTopic(name.getMethodName()); exceptions = new Vector(); CONSUMER_BROKER_URL = brokerService.getTransportConnectors().get(0).getPublishableConnectString() + CONSUMER_BROKER_URL; PRODUCER_BROKER_URL = brokerService.getTransportConnectors().get(0).getPublishableConnectString(); - receivedLatch = - new CountDownLatch(numConsumers * (numMessages + dlqMessages)); + receivedLatch = new CountDownLatch(numConsumers * (numMessages + dlqMessages)); started = new CountDownLatch(1); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { for (Thread t : threads) { t.interrupt(); t.join(); @@ -98,9 +106,10 @@ public class AMQ2021Test extends TestCase implements ExceptionListener, Uncaught brokerService.stop(); } + @Test(timeout=240000) public void testConcurrentTopicResendToDLQ() throws Exception { - for (int i=0; i