mirror of https://github.com/apache/activemq.git
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:
parent
d81ce2e276
commit
eabb5156ad
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.network;
|
package org.apache.activemq.network;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
|
@ -56,7 +57,7 @@ public class DuplexNetworkMBeanTest extends TestCase {
|
||||||
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
|
public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
|
||||||
BrokerService broker = createBroker();
|
BrokerService broker = createBroker();
|
||||||
broker.start();
|
broker.start();
|
||||||
assertEquals(1, countMbeans(broker, "Connector"));
|
assertEquals(1, countMbeans(broker, "Connector", 2000));
|
||||||
assertEquals(0, countMbeans(broker, "Connection"));
|
assertEquals(0, countMbeans(broker, "Connection"));
|
||||||
BrokerService networkedBroker = null;
|
BrokerService networkedBroker = null;
|
||||||
for (int i=0; i<numRestarts; i++) {
|
for (int i=0; i<numRestarts; i++) {
|
||||||
|
@ -74,13 +75,14 @@ public class DuplexNetworkMBeanTest extends TestCase {
|
||||||
assertEquals(0, countMbeans(networkedBroker, "Connection"));
|
assertEquals(0, countMbeans(networkedBroker, "Connection"));
|
||||||
assertEquals(1, countMbeans(broker, "Connector"));
|
assertEquals(1, countMbeans(broker, "Connector"));
|
||||||
broker.stop();
|
broker.stop();
|
||||||
|
broker.waitUntilStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMbeanPresenceOnBrokerRestart() throws Exception {
|
public void testMbeanPresenceOnBrokerRestart() throws Exception {
|
||||||
|
|
||||||
BrokerService networkedBroker = createNetworkedBroker();
|
BrokerService networkedBroker = createNetworkedBroker();
|
||||||
networkedBroker.start();
|
networkedBroker.start();
|
||||||
assertEquals(1, countMbeans(networkedBroker, "Connector"));
|
assertEquals(1, countMbeans(networkedBroker, "Connector", 2000));
|
||||||
assertEquals(0, countMbeans(networkedBroker, "Connection"));
|
assertEquals(0, countMbeans(networkedBroker, "Connection"));
|
||||||
|
|
||||||
BrokerService broker = null;
|
BrokerService broker = null;
|
||||||
|
@ -93,7 +95,6 @@ public class DuplexNetworkMBeanTest extends TestCase {
|
||||||
broker.stop();
|
broker.stop();
|
||||||
broker.waitUntilStopped();
|
broker.waitUntilStopped();
|
||||||
assertEquals(0, countMbeans(broker, "stopped"));
|
assertEquals(0, countMbeans(broker, "stopped"));
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
|
//assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
|
||||||
|
@ -102,6 +103,7 @@ public class DuplexNetworkMBeanTest extends TestCase {
|
||||||
assertEquals(0, countMbeans(broker, "Connection"));
|
assertEquals(0, countMbeans(broker, "Connection"));
|
||||||
|
|
||||||
networkedBroker.stop();
|
networkedBroker.stop();
|
||||||
|
networkedBroker.waitUntilStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countMbeans(BrokerService broker, String type) throws Exception {
|
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 {
|
private int countMbeans(BrokerService broker, String type, int timeout) throws Exception {
|
||||||
final long expiryTime = System.currentTimeMillis() + timeout;
|
final long expiryTime = System.currentTimeMillis() + timeout;
|
||||||
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
|
final ObjectName beanName = new ObjectName("org.apache.activemq:BrokerName="
|
||||||
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="
|
|
||||||
+ broker.getBrokerName() + ",Type=" + type +",*");
|
+ broker.getBrokerName() + ",Type=" + type +",*");
|
||||||
Set mbeans = null;
|
Set<?> mbeans = null;
|
||||||
do {
|
|
||||||
|
do {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
mbeans = mbsc.queryMBeans(beanName, null);
|
MBeanServerConnection mbsc = getMBeanServerConnection();
|
||||||
} while (mbeans.isEmpty() && expiryTime > System.currentTimeMillis());
|
if (mbsc != null) {
|
||||||
|
mbeans = mbsc.queryMBeans(beanName, null);
|
||||||
|
}
|
||||||
|
} while (mbeans == null || mbeans.isEmpty() && expiryTime > System.currentTimeMillis());
|
||||||
return mbeans.size();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue