Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15D4310ACA for ; Thu, 14 Nov 2013 14:55:16 +0000 (UTC) Received: (qmail 53647 invoked by uid 500); 14 Nov 2013 14:55:15 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 53557 invoked by uid 500); 14 Nov 2013 14:55:12 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 53550 invoked by uid 99); 14 Nov 2013 14:55:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Nov 2013 14:55:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 83C388A9835; Thu, 14 Nov 2013 14:55:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kearls@apache.org To: commits@activemq.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: See AMQ-4886. Updated tearDown so it can't hang, reduced timeouts, updated to JUnit4 Date: Thu, 14 Nov 2013 14:55:11 +0000 (UTC) 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 Authored: Thu Nov 14 15:55:04 2013 +0100 Committer: Kevin Earls 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 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 threads = new Vector(); Vector receivers = new Vector(); @@ -529,3 +557,24 @@ public class AMQ2149Test extends AutoFailTestSupport { } } + +class TeardownTask implements Callable { + 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; + } +}