fix issue with test, checking for the presence of Mbeans before the rmi transport for the mbean server is fully active

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@705636 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2008-10-17 15:10:08 +00:00
parent d81ce2e276
commit eabb5156ad
1 changed files with 33 additions and 18 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.network;
import java.net.MalformedURLException;
import java.util.Set;
import javax.management.MBeanServerConnection;
@ -56,7 +57,7 @@ public class DuplexNetworkMBeanTest extends TestCase {
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
BrokerService broker = createBroker();
broker.start();
assertEquals(1, countMbeans(broker, "Connector"));
assertEquals(1, countMbeans(broker, "Connector", 2000));
assertEquals(0, countMbeans(broker, "Connection"));
BrokerService networkedBroker = null;
for (int i=0; i<numRestarts; i++) {
@ -74,13 +75,14 @@ public class DuplexNetworkMBeanTest extends TestCase {
assertEquals(0, countMbeans(networkedBroker, "Connection"));
assertEquals(1, countMbeans(broker, "Connector"));
broker.stop();
broker.waitUntilStopped();
}
public void testMbeanPresenceOnBrokerRestart() throws Exception {
BrokerService networkedBroker = createNetworkedBroker();
networkedBroker.start();
assertEquals(1, countMbeans(networkedBroker, "Connector"));
assertEquals(1, countMbeans(networkedBroker, "Connector", 2000));
assertEquals(0, countMbeans(networkedBroker, "Connection"));
BrokerService broker = null;
@ -93,7 +95,6 @@ public class DuplexNetworkMBeanTest extends TestCase {
broker.stop();
broker.waitUntilStopped();
assertEquals(0, countMbeans(broker, "stopped"));
Thread.sleep(1000);
}
//assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
@ -102,6 +103,7 @@ public class DuplexNetworkMBeanTest extends TestCase {
assertEquals(0, countMbeans(broker, "Connection"));
networkedBroker.stop();
networkedBroker.waitUntilStopped();
}
private int countMbeans(BrokerService broker, String type) throws Exception {
@ -110,25 +112,38 @@ public class DuplexNetworkMBeanTest extends TestCase {
private int countMbeans(BrokerService broker, String type, int timeout) throws Exception {
final long expiryTime = System.currentTimeMillis() + timeout;
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
Set all = mbsc.queryMBeans(null, null);
LOG.info("MBean total=" + all.size());
for (Object o : all) {
ObjectInstance bean = (ObjectInstance)o;
LOG.info(bean.getObjectName());
}
ObjectName beanName = new ObjectName("org.apache.activemq:BrokerName="
final ObjectName beanName = new ObjectName("org.apache.activemq:BrokerName="
+ broker.getBrokerName() + ",Type=" + type +",*");
Set mbeans = null;
do {
Set<?> mbeans = null;
do {
if (timeout > 0) {
Thread.sleep(100);
}
mbeans = mbsc.queryMBeans(beanName, null);
} while (mbeans.isEmpty() && expiryTime > System.currentTimeMillis());
MBeanServerConnection mbsc = getMBeanServerConnection();
if (mbsc != null) {
mbeans = mbsc.queryMBeans(beanName, null);
}
} while (mbeans == null || mbeans.isEmpty() && expiryTime > System.currentTimeMillis());
return mbeans.size();
}
private MBeanServerConnection getMBeanServerConnection() throws MalformedURLException {
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
MBeanServerConnection mbsc = null;
try {
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
mbsc = jmxc.getMBeanServerConnection();
// trace all existing MBeans
Set<?> all = mbsc.queryMBeans(null, null);
LOG.info("Total MBean count=" + all.size());
for (Object o : all) {
ObjectInstance bean = (ObjectInstance)o;
LOG.info(bean.getObjectName());
}
} catch (Exception ignored) {
}
return mbsc;
}
}