fix brokerSerivce instances left running if assertions fail

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1404348 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2012-10-31 21:06:15 +00:00
parent 13270e4e74
commit 0ad3cfc11e
1 changed files with 59 additions and 57 deletions

View File

@ -22,19 +22,14 @@ import static org.junit.Assume.assumeNotNull;
import java.net.MalformedURLException;
import java.util.Set;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.apache.activemq.broker.BrokerService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Test;
public class DuplexNetworkMBeanTest {
protected static final Logger LOG = LoggerFactory.getLogger(DuplexNetworkMBeanTest.class);
@ -44,10 +39,10 @@ public class DuplexNetworkMBeanTest {
BrokerService broker = new BrokerService();
broker.setBrokerName("broker");
broker.addConnector("tcp://localhost:61617?transport.reuseAddress=true");
return broker;
}
protected BrokerService createNetworkedBroker() throws Exception {
BrokerService broker = new BrokerService();
broker.setBrokerName("networkedBroker");
@ -56,65 +51,72 @@ public class DuplexNetworkMBeanTest {
networkConnector.setDuplex(true);
return broker;
}
@Test
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
BrokerService broker = createBroker();
broker.start();
assertEquals(1, countMbeans(broker, "Connector", 30000));
assertEquals(0, countMbeans(broker, "Connection"));
BrokerService networkedBroker = null;
for (int i=0; i<numRestarts; i++) {
networkedBroker = createNetworkedBroker();
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 2000));
assertEquals(1, countMbeans(broker, "NetworkBridge", 2000));
assertEquals(1, countMbeans(broker, "Connection"));
networkedBroker.stop();
networkedBroker.waitUntilStopped();
assertEquals(0, countMbeans(networkedBroker, "stopped"));
assertEquals(0, countMbeans(broker, "NetworkBridge"));
try {
broker.start();
assertEquals(1, countMbeans(broker, "Connector", 30000));
assertEquals(0, countMbeans(broker, "Connection"));
BrokerService networkedBroker = null;
for (int i=0; i<numRestarts; i++) {
networkedBroker = createNetworkedBroker();
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 2000));
assertEquals(1, countMbeans(broker, "NetworkBridge", 2000));
assertEquals(1, countMbeans(broker, "Connection"));
networkedBroker.stop();
networkedBroker.waitUntilStopped();
assertEquals(0, countMbeans(networkedBroker, "stopped"));
assertEquals(0, countMbeans(broker, "NetworkBridge"));
}
assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
assertEquals(0, countMbeans(networkedBroker, "Connector"));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
assertEquals(1, countMbeans(broker, "Connector"));
} finally {
broker.stop();
broker.waitUntilStopped();
}
assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
assertEquals(0, countMbeans(networkedBroker, "Connector"));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
assertEquals(1, countMbeans(broker, "Connector"));
broker.stop();
broker.waitUntilStopped();
}
@Test
public void testMbeanPresenceOnBrokerRestart() throws Exception {
BrokerService networkedBroker = createNetworkedBroker();
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
BrokerService broker = null;
for (int i=0; i<numRestarts; i++) {
broker = createBroker();
broker.start();
assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 5000));
assertEquals("restart number: " + i, 1, countMbeans(broker, "Connection", 10000));
broker.stop();
broker.waitUntilStopped();
assertEquals(0, countMbeans(broker, "stopped"));
try {
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
BrokerService broker = null;
for (int i=0; i<numRestarts; i++) {
broker = createBroker();
try {
broker.start();
assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 5000));
assertEquals("restart number: " + i, 1, countMbeans(broker, "Connection", 10000));
} finally {
broker.stop();
broker.waitUntilStopped();
}
assertEquals(0, countMbeans(broker, "stopped"));
}
//assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
assertEquals(1, countMbeans(networkedBroker, "Connector"));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
assertEquals(0, countMbeans(broker, "Connection"));
} finally {
networkedBroker.stop();
networkedBroker.waitUntilStopped();
}
//assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
assertEquals(1, countMbeans(networkedBroker, "Connector"));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
assertEquals(0, countMbeans(broker, "Connection"));
networkedBroker.stop();
networkedBroker.waitUntilStopped();
}
private int countMbeans(BrokerService broker, String type) throws Exception {
return countMbeans(broker, type, 0);
return countMbeans(broker, type, 0);
}
private int countMbeans(BrokerService broker, String type, int timeout) throws Exception {
@ -135,14 +137,14 @@ public class DuplexNetworkMBeanTest {
logAllMbeans(broker);
}
} while ((mbeans == null || mbeans.isEmpty()) && expiryTime > System.currentTimeMillis());
// If port 1099 is in use when the Broker starts, starting the jmx
// connector will fail. So, if we have no mbsc to query, skip the
// test.
if (timeout > 0) {
assumeNotNull(mbeans);
}
return count;
}