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);
@ -60,57 +55,64 @@ public class DuplexNetworkMBeanTest {
@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"));
broker.stop();
broker.waitUntilStopped();
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();
}
}
@Test
public void testMbeanPresenceOnBrokerRestart() throws Exception {
BrokerService networkedBroker = createNetworkedBroker();
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
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();
broker.start();
assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 5000));
assertEquals("restart number: " + i, 1, countMbeans(broker, "Connection", 10000));
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"));
}
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 {