activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1050087 - in /activemq/trunk/activemq-core/src/test/java/org/apache/activemq: network/DuplexNetworkMBeanTest.java network/NetworkBrokerDetachTest.java usecases/ManagedDurableSubscriptionTest.java
Date Thu, 16 Dec 2010 18:20:56 GMT
Author: gtully
Date: Thu Dec 16 18:20:56 2010
New Revision: 1050087

URL: http://svn.apache.org/viewvc?rev=1050087&view=rev
Log:
allow tests to run if port 1099 is in use

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
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.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=1050087&r1=1050086&r2=1050087&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
Thu Dec 16 18:20:56 2010
@@ -125,13 +125,12 @@ public class DuplexNetworkMBeanTest {
             if (timeout > 0) {
                 Thread.sleep(100);
             }
-            MBeanServerConnection mbsc = getMBeanServerConnection();
-            if (mbsc != null) {
-                LOG.info("Query name: " + beanName);
-                mbeans = mbsc.queryMBeans(beanName, null);
-                if (mbeans != null) {
-                    count = mbeans.size();
-                }
+            LOG.info("Query name: " + beanName);
+            mbeans = broker.getManagementContext().queryNames(beanName, null);
+            if (mbeans != null) {
+                count = mbeans.size();
+            } else {
+                logAllMbeans(broker);
             }
         } while ((mbeans == null || mbeans.isEmpty()) && expiryTime > System.currentTimeMillis());
         
@@ -145,15 +144,10 @@ public class DuplexNetworkMBeanTest {
         return count;
     }
 
-    private MBeanServerConnection getMBeanServerConnection() throws MalformedURLException
{
-        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
-        MBeanServerConnection mbsc = null;
+    private void logAllMbeans(BrokerService broker) throws MalformedURLException {
         try {
-            JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
-            mbsc = jmxc.getMBeanServerConnection();
-
             // trace all existing MBeans
-            Set<?> all = mbsc.queryMBeans(null, null);
+            Set<?> all = broker.getManagementContext().queryNames(null, null);
             LOG.info("Total MBean count=" + all.size());
             for (Object o : all) {
                 ObjectInstance bean = (ObjectInstance)o;
@@ -162,6 +156,5 @@ public class DuplexNetworkMBeanTest {
         } 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=1050087&r1=1050086&r2=1050087&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
Thu Dec 16 18:20:56 2010
@@ -140,7 +140,7 @@ public class NetworkBrokerDetachTest {
         }
         
         assertTrue("got expected consumer count from mbean within time limit", 
-                verifyConsumerCount(1, destination, BROKER_NAME));
+                verifyConsumerCount(1, destination, broker));
         
         
         LOG.info("Stopping Consumer on the networked broker ...");
@@ -148,7 +148,7 @@ public class NetworkBrokerDetachTest {
         consConn.close();
         
         // We should have 0 consumer for the queue on the local broker
-        assertTrue("got expected 0 count from mbean within time limit", verifyConsumerCount(0,
destination, BROKER_NAME));
+        assertTrue("got expected 0 count from mbean within time limit", verifyConsumerCount(0,
destination, broker));
     }
 
     
@@ -167,10 +167,10 @@ public class NetworkBrokerDetachTest {
         registerDurableConsumer(broker, counter);
         
         assertTrue("got expected consumer count from local broker mbean within time limit",
-                verifyConsumerCount(2, destination, BROKER_NAME));
+                verifyConsumerCount(2, destination, broker));
         
         assertTrue("got expected consumer count from network broker mbean within time limit",
-                verifyConsumerCount(2, destination, REM_BROKER_NAME));
+                verifyConsumerCount(2, destination, networkedBroker));
         
         sendMessageTo(destination, broker);
         
@@ -194,14 +194,14 @@ public class NetworkBrokerDetachTest {
         
         // expect similar after restart
         assertTrue("got expected consumer count from local broker mbean within time limit",
-                verifyConsumerCount(2, destination, BROKER_NAME));
+                verifyConsumerCount(2, destination, broker));
  
         // a durable sub is auto bridged on restart unless dynamicOnly=true
         assertTrue("got expected consumer count from network broker mbean within time limit",
-                verifyConsumerCount(2, destination, REM_BROKER_NAME));
+                verifyConsumerCount(2, destination, networkedBroker));
 
-        assertTrue("got no inactive subs on broker", verifyDurableConsumerCount(0, BROKER_NAME));
-        assertTrue("got no inactive subs on other broker", verifyDurableConsumerCount(0,
REM_BROKER_NAME));
+        assertTrue("got no inactive subs on broker", verifyDurableConsumerCount(0, broker));
+        assertTrue("got no inactive subs on other broker", verifyDurableConsumerCount(0,
networkedBroker));
 
         assertTrue("Got two more messages after restart", verifyMessageCount(4, count));
         TimeUnit.SECONDS.sleep(1);
@@ -259,20 +259,20 @@ public class NetworkBrokerDetachTest {
     }
     
     // JMX Helper Methods 
-    private boolean verifyConsumerCount(final long expectedCount, final ActiveMQDestination
destination, final String brokerName) throws Exception {
+    private boolean verifyConsumerCount(final long expectedCount, final ActiveMQDestination
destination, final BrokerService broker) throws Exception {
         return Wait.waitFor(new Wait.Condition() {
             public boolean isSatisified() throws Exception {
                 boolean result = false;
-                MBeanServerConnection mbsc = getMBeanServerConnection();
-                if (mbsc != null) {                
+                try {
                     // We should have 1 consumer for the queue on the local broker
-                    Object consumers = getAttribute(mbsc, brokerName, destination.isQueue()
? "Queue" : "Topic", "Destination=" + destination.getPhysicalName(), "ConsumerCount");
+                    Object consumers = broker.getManagementContext().getAttribute(getObjectName(broker.getBrokerName(),
destination.isQueue() ? "Queue" : "Topic", "Destination=" + destination.getPhysicalName()),
"ConsumerCount");
                     if (consumers != null) {
-                        LOG.info("Consumers for " + destination.getPhysicalName() + " on
" + brokerName + " : " + consumers);
+                        LOG.info("Consumers for " + destination.getPhysicalName() + " on
" + broker + " : " + consumers);
                         if (expectedCount == ((Long)consumers).longValue()) {
                             result = true;
                         }
                     }
+                } catch (Exception ignoreAndRetry) {
                 }
                 return result;
             }      
@@ -280,15 +280,15 @@ public class NetworkBrokerDetachTest {
     }
     
     
-    private boolean verifyDurableConsumerCount(final long expectedCount, final String brokerName)
throws Exception {
+    private boolean verifyDurableConsumerCount(final long expectedCount, final BrokerService
broker) throws Exception {
         return Wait.waitFor(new Wait.Condition() {
             public boolean isSatisified() throws Exception {
                 boolean result = false;
                 MBeanServerConnection mbsc = getMBeanServerConnection();
                 if (mbsc != null) {
-                    Set subs = getMbeans(mbsc, brokerName, "Subscription", "active=false,*");
+                    Set subs = broker.getManagementContext().queryNames(getObjectName(broker.getBrokerName(),
"Subscription", "active=false,*"), null);
                     if (subs != null) {
-                        LOG.info("inactive durable subs on " + brokerName + " : " + subs);
+                        LOG.info("inactive durable subs on " + broker + " : " + subs);
                         if (expectedCount == subs.size()) {
                             result = true;
                         }
@@ -299,7 +299,6 @@ public class NetworkBrokerDetachTest {
         });
     }
 
-    
     private MBeanServerConnection getMBeanServerConnection() throws MalformedURLException
{
         final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
         MBeanServerConnection mbsc = null;
@@ -317,26 +316,6 @@ public class NetworkBrokerDetachTest {
     }
     
     
-    private Set getMbeans(MBeanServerConnection mbsc, String brokerName, String type, String
pattern) throws Exception {
-        Set obj = null;
-        try {
-            obj = mbsc.queryMBeans(getObjectName(brokerName, type, pattern), null);
-        } catch (InstanceNotFoundException ignored) {
-            LOG.warn("getAttribute ex: " + ignored);
-        }
-        return obj;
-    }
-    
-    private Object getAttribute(MBeanServerConnection mbsc, String brokerName, String type,
String pattern, String attrName) throws Exception {
-        Object obj = null;
-        try {
-            obj = mbsc.getAttribute(getObjectName(brokerName, type, pattern), attrName);
-        } catch (InstanceNotFoundException ignored) {
-            LOG.warn("getAttribute ex: " + ignored);
-        }
-        return obj;
-    }
-    
     private ObjectName getObjectName(String brokerName, String type, String pattern) throws
Exception {
       ObjectName beanName = new ObjectName(
         "org.apache.activemq:BrokerName=" + brokerName + ",Type=" + type +"," + pattern

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java?rev=1050087&r1=1050086&r2=1050087&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/ManagedDurableSubscriptionTest.java
Thu Dec 16 18:20:56 2010
@@ -46,10 +46,9 @@ public class ManagedDurableSubscriptionT
         stopBroker();
         startBroker();
 
-        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         ObjectName inactiveSubscriptionObjectName = broker.getAdminView().getInactiveDurableTopicSubscribers()[0];
 
-        Object inactive = mbs.getAttribute(inactiveSubscriptionObjectName, "Active");
+        Object inactive = broker.getManagementContext().getAttribute(inactiveSubscriptionObjectName,
"Active");
         assertTrue("Subscription is active.", Boolean.FALSE.equals(inactive));
 
         // activate
@@ -58,14 +57,14 @@ public class ManagedDurableSubscriptionT
 
         ObjectName activeSubscriptionObjectName = broker.getAdminView().getDurableTopicSubscribers()[0];
 
-        Object active = mbs.getAttribute(activeSubscriptionObjectName, "Active");
+        Object active = broker.getManagementContext().getAttribute(activeSubscriptionObjectName,
"Active");
         assertTrue("Subscription is INactive.", Boolean.TRUE.equals(active));
 
         // deactivate
         connection.close();
         connection = null;
 
-        inactive = mbs.getAttribute(inactiveSubscriptionObjectName, "Active");
+        inactive = broker.getManagementContext().getAttribute(inactiveSubscriptionObjectName,
"Active");
         assertTrue("Subscription is active.", Boolean.FALSE.equals(inactive));
 
     }



Mime
View raw message