activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r705636 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
Date Fri, 17 Oct 2008 15:10:09 GMT
Author: gtully
Date: Fri Oct 17 08:10:08 2008
New Revision: 705636

URL: http://svn.apache.org/viewvc?rev=705636&view=rev
Log:
fix issue with test, checking for the presence of Mbeans before the rmi transport for the
mbean server is fully active

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java?rev=705636&r1=705635&r2=705636&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
Fri Oct 17 08:10:08 2008
@@ -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 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 @@
         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 @@
             broker.stop();
             broker.waitUntilStopped();
             assertEquals(0, countMbeans(broker, "stopped"));
-            Thread.sleep(1000);
         }
         
         //assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
@@ -102,6 +103,7 @@
         assertEquals(0, countMbeans(broker, "Connection"));
         
         networkedBroker.stop();
+        networkedBroker.waitUntilStopped();
     }
     
     private int countMbeans(BrokerService broker, String type) throws Exception {
@@ -110,25 +112,38 @@
 
     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;
+    }
 }



Mime
View raw message