You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ke...@apache.org on 2013/11/14 15:55:11 UTC
git commit: See AMQ-4886. Updated tearDown so it can't hang,
reduced timeouts, updated to JUnit4
Updated Branches:
refs/heads/trunk e57aeb378 -> c60af6416
See AMQ-4886. Updated tearDown so it can't hang, reduced timeouts, updated to JUnit4
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/c60af641
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/c60af641
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/c60af641
Branch: refs/heads/trunk
Commit: c60af641653d69a0a7fce6088f2954f41b204a0a
Parents: e57aeb3
Author: Kevin Earls <ke...@kevinearls.com>
Authored: Thu Nov 14 15:55:04 2013 +0100
Committer: Kevin Earls <ke...@kevinearls.com>
Committed: Thu Nov 14 15:55:04 2013 +0100
----------------------------------------------------------------------
.../org/apache/activemq/bugs/AMQ2149Test.java | 79 ++++++++++++++++----
1 file changed, 64 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/c60af641/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2149Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2149Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2149Test.java
index a1b1058..891822f 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2149Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2149Test.java
@@ -23,27 +23,43 @@ import java.util.HashSet;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import javax.jms.*;
-import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.AutoFailTestSupport;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.DestinationStatistics;
import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.broker.util.LoggingBrokerPlugin;
import org.apache.activemq.command.ActiveMQDestination;
+import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.junit.Assert.*;
+
interface Configurer {
public void configure(BrokerService broker) throws Exception;
}
-public class AMQ2149Test extends AutoFailTestSupport {
+public class AMQ2149Test {
private static final Logger LOG = LoggerFactory.getLogger(AMQ2149Test.class);
+ @Rule
+ public TestName testName = new TestName();
private static final String BROKER_CONNECTOR = "tcp://localhost:61617";
private static final String DEFAULT_BROKER_URL = "failover:("+ BROKER_CONNECTOR
@@ -80,7 +96,7 @@ public class AMQ2149Test extends AutoFailTestSupport {
broker.getSystemUsage().getMemoryUsage().setLimit(MESSAGE_LENGTH_BYTES * 200 * NUM_SENDERS_AND_RECEIVERS);
broker.addConnector(BROKER_CONNECTOR);
- broker.setBrokerName(getName());
+ broker.setBrokerName(testName.getMethodName());
broker.setDataDirectoryFile(dataDirFile);
if (configurer != null) {
configurer.configure(broker);
@@ -91,23 +107,31 @@ public class AMQ2149Test extends AutoFailTestSupport {
protected void configurePersistenceAdapter(BrokerService brokerService) throws Exception {
}
+ @Before
public void setUp() throws Exception {
- setMaxTestTime(30*60*1000);
- setAutoFail(true);
- dataDirFile = new File("target/"+ getName());
+ LOG.debug("Starting test {}", testName.getMethodName());
+ dataDirFile = new File("target/"+ testName.getMethodName());
numtoSend = DEFAULT_NUM_TO_SEND;
brokerStopPeriod = DEFAULT_BROKER_STOP_PERIOD;
sleepBetweenSend = SLEEP_BETWEEN_SEND_MS;
brokerURL = DEFAULT_BROKER_URL;
}
-
+
+ @After
public void tearDown() throws Exception {
- synchronized(brokerLock) {
- if (broker!= null) {
- broker.stop();
- broker.waitUntilStopped();
- }
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ Future<Boolean> future = executor.submit(new TeardownTask(brokerLock, broker));
+ try {
+ LOG.debug("Teardown started.");
+ long start = System.currentTimeMillis();
+ Boolean result = future.get(30, TimeUnit.SECONDS);
+ long finish = System.currentTimeMillis();
+ LOG.debug("Result of teardown: {} after {} ms ", result, (finish - start));
+ } catch (TimeoutException e) {
+ fail("Teardown timed out");
+ AutoFailTestSupport.dumpAllThreads(testName.getMethodName());
}
+ executor.shutdownNow();
exceptions.clear();
}
@@ -339,6 +363,7 @@ public class AMQ2149Test extends AutoFailTestSupport {
verifyStats(false);
}
+ @Test(timeout = 5 * 60 * 1000)
public void testOrderWithRestart() throws Exception {
createBroker(new Configurer() {
public void configure(BrokerService broker) throws Exception {
@@ -360,7 +385,8 @@ public class AMQ2149Test extends AutoFailTestSupport {
verifyStats(true);
}
-
+
+ @Test(timeout = 5 * 60 * 1000)
public void testTopicOrderWithRestart() throws Exception {
createBroker(new Configurer() {
public void configure(BrokerService broker) throws Exception {
@@ -380,10 +406,12 @@ public class AMQ2149Test extends AutoFailTestSupport {
verifyStats(true);
}
+ @Test(timeout = 5 * 60 * 1000)
public void testQueueTransactionalOrderWithRestart() throws Exception {
doTestTransactionalOrderWithRestart(ActiveMQDestination.QUEUE_TYPE);
}
-
+
+ @Test(timeout = 5 * 60 * 1000)
public void testTopicTransactionalOrderWithRestart() throws Exception {
doTestTransactionalOrderWithRestart(ActiveMQDestination.TOPIC_TYPE);
}
@@ -477,7 +505,7 @@ public class AMQ2149Test extends AutoFailTestSupport {
}
private void verifyOrderedMessageReceipt(byte destinationType, int concurrentPairs, boolean transactional) throws Exception {
-
+
Vector<Thread> threads = new Vector<Thread>();
Vector<Receiver> receivers = new Vector<Receiver>();
@@ -529,3 +557,24 @@ public class AMQ2149Test extends AutoFailTestSupport {
}
}
+
+class TeardownTask implements Callable<Boolean> {
+ private Object brokerLock;
+ private BrokerService broker;
+
+ public TeardownTask(Object brokerLock, BrokerService broker) {
+ this.brokerLock = brokerLock;
+ this.broker = broker;
+ }
+
+ @Override
+ public Boolean call() throws Exception {
+ synchronized(brokerLock) {
+ if (broker!= null) {
+ broker.stop();
+ broker.waitUntilStopped();
+ }
+ }
+ return Boolean.TRUE;
+ }
+}