Test can leave a dangling BrokerSerive instance running if it get an assertion at the right time. Make sure all started brokers get stopped.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1370576 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-08-07 22:28:26 +00:00
parent 205d02598d
commit b6e82fec92
1 changed files with 11 additions and 2 deletions

View File

@ -19,13 +19,16 @@ package org.apache.activemq.transport.failover;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Queue; import javax.jms.Queue;
import javax.jms.Session; import javax.jms.Session;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
@ -40,12 +43,16 @@ public class FailoverUpdateURIsTest extends TestCase {
String firstTcpUri = "tcp://localhost:61616"; String firstTcpUri = "tcp://localhost:61616";
String secondTcpUri = "tcp://localhost:61626"; String secondTcpUri = "tcp://localhost:61626";
Connection connection = null; Connection connection = null;
BrokerService bs1 = null;
BrokerService bs2 = null; BrokerService bs2 = null;
public void tearDown() throws Exception { public void tearDown() throws Exception {
if (connection != null) { if (connection != null) {
connection.close(); connection.close();
} }
if (bs1 != null) {
bs1.stop();
}
if (bs2 != null) { if (bs2 != null) {
bs2.stop(); bs2.stop();
} }
@ -64,7 +71,7 @@ public class FailoverUpdateURIsTest extends TestCase {
out.write(firstTcpUri.getBytes()); out.write(firstTcpUri.getBytes());
out.close(); out.close();
BrokerService bs1 = createBroker("bs1", firstTcpUri); bs1 = createBroker("bs1", firstTcpUri);
bs1.start(); bs1.start();
// no failover uri's to start with, must be read from file... // no failover uri's to start with, must be read from file...
@ -82,6 +89,7 @@ public class FailoverUpdateURIsTest extends TestCase {
bs1.stop(); bs1.stop();
bs1.waitUntilStopped(); bs1.waitUntilStopped();
bs1 = null;
bs2 = createBroker("bs2", secondTcpUri); bs2 = createBroker("bs2", secondTcpUri);
bs2.start(); bs2.start();
@ -108,7 +116,7 @@ public class FailoverUpdateURIsTest extends TestCase {
public void testAutoUpdateURIs() throws Exception { public void testAutoUpdateURIs() throws Exception {
BrokerService bs1 = new BrokerService(); bs1 = new BrokerService();
bs1.setUseJmx(false); bs1.setUseJmx(false);
TransportConnector transportConnector = bs1.addConnector(firstTcpUri); TransportConnector transportConnector = bs1.addConnector(firstTcpUri);
transportConnector.setUpdateClusterClients(true); transportConnector.setUpdateClusterClients(true);
@ -138,6 +146,7 @@ public class FailoverUpdateURIsTest extends TestCase {
LOG.info("stopping brokerService 1"); LOG.info("stopping brokerService 1");
bs1.stop(); bs1.stop();
bs1.waitUntilStopped(); bs1.waitUntilStopped();
bs1 = null;
producer.send(message); producer.send(message);
msg = consumer.receive(4000); msg = consumer.receive(4000);