diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java index cf976703a7..a9158cc0ea 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/BrokerTestSupport.java @@ -99,6 +99,7 @@ public class BrokerTestSupport extends CombinationTestSupport { protected void tearDown() throws Exception { broker.stop(); + broker.waitUntilStopped(); broker = null; regionBroker = null; persistenceAdapter = null; diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java b/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java index 551e6eaa11..9a70c4ee08 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/StubConnection.java @@ -52,6 +52,11 @@ public class StubConnection implements Service { } public StubConnection(Transport transport) throws Exception { + this(transport, null); + } + + public StubConnection(Transport transport, TransportListener transportListener) throws Exception { + listener = transportListener; this.transport = transport; transport.setTransportListener(new DefaultTransportListener() { public void onCommand(Object command) { diff --git a/activemq-core/src/test/java/org/apache/activemq/network/NetworkTestSupport.java b/activemq-core/src/test/java/org/apache/activemq/network/NetworkTestSupport.java index b416b438ce..4b1c865b34 100755 --- a/activemq-core/src/test/java/org/apache/activemq/network/NetworkTestSupport.java +++ b/activemq-core/src/test/java/org/apache/activemq/network/NetworkTestSupport.java @@ -167,6 +167,7 @@ public class NetworkTestSupport extends BrokerTestSupport { connector.stop(); remoteBroker.stop(); + remoteBroker.waitUntilStopped(); remotePersistenceAdapter.stop(); super.tearDown(); } diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java index 61736c5107..2e8831feac 100755 --- a/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTransportBrokerTest.java @@ -75,7 +75,7 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport { // Start a failover publisher. LOG.info("Starting the failover connection."); - StubConnection connection3 = createFailoverConnection(); + StubConnection connection3 = createFailoverConnection(null); ConnectionInfo connectionInfo3 = createConnectionInfo(); SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3); ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3); @@ -119,8 +119,7 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport { public void testNoBrokersInBrokerInfo() throws Exception { final BrokerInfo info[] = new BrokerInfo[1]; - StubConnection c = createFailoverConnection(); - c.setListener(new TransportListener() { + TransportListener listener = new TransportListener() { @Override public void onCommand(Object command) { LOG.info("Got command: " + command); @@ -143,8 +142,8 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport { public void transportResumed() { //To change body of implemented methods use File | Settings | File Templates. } - }); - c.start(); + }; + StubConnection c = createFailoverConnection(listener); int count = 0; while(count++ < 20 && info[0] == null) { TimeUnit.SECONDS.sleep(1); @@ -161,10 +160,10 @@ public class FailoverTransportBrokerTest extends NetworkTestSupport { return "tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true"; } - protected StubConnection createFailoverConnection() throws Exception { + protected StubConnection createFailoverConnection(TransportListener listener) throws Exception { URI failoverURI = new URI("failover://" + connector.getServer().getConnectURI() + "," + remoteConnector.getServer().getConnectURI() + ""); Transport transport = TransportFactory.connect(failoverURI); - StubConnection connection = new StubConnection(transport); + StubConnection connection = new StubConnection(transport, listener); connections.add(connection); return connection; }