activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r832829 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network: DuplexNetworkMBeanTest.java NetworkBrokerDetachTest.java
Date Wed, 04 Nov 2009 18:15:57 GMT
Author: gtully
Date: Wed Nov  4 18:15:57 2009
New Revision: 832829

URL: http://svn.apache.org/viewvc?rev=832829&view=rev
Log:
add some resilience to slow mbean registration

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.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=832829&r1=832828&r2=832829&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
Wed Nov  4 18:15:57 2009
@@ -57,7 +57,7 @@
     public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
         BrokerService broker = createBroker();
         broker.start();
-        assertEquals(1, countMbeans(broker, "Connector", 10000));
+        assertEquals(1, countMbeans(broker, "Connector", 30000));
         assertEquals(0, countMbeans(broker, "Connection"));
         BrokerService networkedBroker = null;
         for (int i=0; i<numRestarts; i++) {       
@@ -82,7 +82,7 @@
         
         BrokerService networkedBroker = createNetworkedBroker();
         networkedBroker.start();
-        assertEquals(1, countMbeans(networkedBroker, "Connector", 10000));
+        assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
         assertEquals(0, countMbeans(networkedBroker, "Connection"));
         
         BrokerService broker = null;
@@ -147,6 +147,7 @@
                 LOG.info(bean.getObjectName());
             }
         } catch (Exception ignored) {
+            LOG.warn("getMBeanServer ex: " + ignored);
         }
         return mbsc;
     }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java?rev=832829&r1=832828&r2=832829&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/NetworkBrokerDetachTest.java
Wed Nov  4 18:15:57 2009
@@ -22,6 +22,7 @@
 import javax.jms.ConnectionFactory;
 import javax.jms.MessageConsumer;
 import javax.jms.Session;
+import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
@@ -34,6 +35,7 @@
 import org.apache.activemq.ActiveMQPrefetchPolicy;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.TransportConnector;
+import org.apache.activemq.util.Wait;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -77,29 +79,52 @@
         Session consSession = consConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         
         for(int i=0; i<NUM_CONSUMERS; i++) {
-          MessageConsumer consumer = consSession.createConsumer(consSession.createQueue(QUEUE_NAME));
+          consSession.createConsumer(consSession.createQueue(QUEUE_NAME));
         }
-
-        
-        Thread.sleep(5000);
         
-        MBeanServerConnection mbsc = getMBeanServerConnection();
-        // We should have 1 consumer for the queue on the local broker
-        Object consumers = getAttribute(mbsc, "Queue", "Destination=" + QUEUE_NAME, "ConsumerCount");
-        LOG.info("Consumers for " + QUEUE_NAME + " on " + BROKER_NAME + " : " + consumers);
-        assertEquals(1L, ((Long)consumers).longValue());       
+        assertTrue("got expected consumer count from mbean within time limit", Wait.waitFor(new
Wait.Condition() {
+
+            public boolean isSatisified() throws Exception {
+                boolean result = false;
+                MBeanServerConnection mbsc = getMBeanServerConnection();
+                if (mbsc != null) {                
+                    // We should have 1 consumer for the queue on the local broker
+                    Object consumers = getAttribute(mbsc, "Queue", "Destination=" + QUEUE_NAME,
"ConsumerCount");
+                    if (consumers != null) {
+                        LOG.info("Consumers for " + QUEUE_NAME + " on " + BROKER_NAME + "
: " + consumers);
+                        if (1L == ((Long)consumers).longValue()) {
+                            result = true;
+                        }
+                    }
+                }
+                return result;
+            }      
+        }));
         
         
         LOG.info("Stopping Consumer on the networked broker ...");
         // Closing the connection will also close the consumer 
         consConn.close();
         
-        Thread.sleep(5000);
-        
         // We should have 0 consumer for the queue on the local broker
-        consumers = getAttribute(mbsc, "Queue", "Destination=" + QUEUE_NAME, "ConsumerCount");
-        LOG.info("Consumers for " + QUEUE_NAME + " on " + BROKER_NAME + " : " + consumers);
-        assertEquals(0L, ((Long)consumers).longValue());       
+        assertTrue("got expected 0 count from mbean within time limit", Wait.waitFor(new
Wait.Condition() {
+
+            public boolean isSatisified() throws Exception {
+                boolean result = false;
+                MBeanServerConnection mbsc = getMBeanServerConnection();
+                if (mbsc != null) {                
+                    // We should have 1 consumer for the queue on the local broker
+                    Object consumers = getAttribute(mbsc, "Queue", "Destination=" + QUEUE_NAME,
"ConsumerCount");
+                    if (consumers != null) {
+                        LOG.info("Consumers for " + QUEUE_NAME + " on " + BROKER_NAME + "
: " + consumers);
+                        if (0L == ((Long)consumers).longValue()) {
+                            result = true;
+                        }
+                    }
+                }
+                return result;
+            }      
+        }));
         
         networkedBroker.stop();
         networkedBroker.waitUntilStopped();
@@ -134,21 +159,19 @@
         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) {
+            LOG.warn("getMBeanServer ex: " + ignored);
         }
         return mbsc;
     }
     
     private Object getAttribute(MBeanServerConnection mbsc, String type, String pattern,
String attrName) throws Exception {
-        Object obj = mbsc.getAttribute(getObjectName(BROKER_NAME, type, pattern), attrName);
+        Object obj = null;
+        try {
+            obj = mbsc.getAttribute(getObjectName(BROKER_NAME, type, pattern), attrName);
+        } catch (InstanceNotFoundException ignored) {
+            LOG.warn("getAttribute ex: " + ignored);
+        }
         return obj;
     }
     



Mime
View raw message