activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1404348 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/DuplexNetworkMBeanTest.java
Date Wed, 31 Oct 2012 21:06:15 GMT
Author: tabish
Date: Wed Oct 31 21:06:15 2012
New Revision: 1404348

URL: http://svn.apache.org/viewvc?rev=1404348&view=rev
Log:
fix brokerSerivce instances left running if assertions fail

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=1404348&r1=1404347&r2=1404348&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 Oct 31 21:06:15 2012
@@ -22,19 +22,14 @@ import static org.junit.Assume.assumeNot
 import java.net.MalformedURLException;
 import java.util.Set;
 
-import javax.management.MBeanServerConnection;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
 
 import org.apache.activemq.broker.BrokerService;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.junit.Test;
-
 public class DuplexNetworkMBeanTest {
 
     protected static final Logger LOG = LoggerFactory.getLogger(DuplexNetworkMBeanTest.class);
@@ -44,10 +39,10 @@ public class DuplexNetworkMBeanTest {
         BrokerService broker = new BrokerService();
         broker.setBrokerName("broker");
         broker.addConnector("tcp://localhost:61617?transport.reuseAddress=true");
-        
+
         return broker;
     }
-    
+
     protected BrokerService createNetworkedBroker() throws Exception {
         BrokerService broker = new BrokerService();
         broker.setBrokerName("networkedBroker");
@@ -56,65 +51,72 @@ public class DuplexNetworkMBeanTest {
         networkConnector.setDuplex(true);
         return broker;
     }
-    
+
     @Test
     public void testMbeanPresenceOnNetworkBrokerRestart() throws Exception {
         BrokerService broker = createBroker();
-        broker.start();
-        assertEquals(1, countMbeans(broker, "Connector", 30000));
-        assertEquals(0, countMbeans(broker, "Connection"));
-        BrokerService networkedBroker = null;
-        for (int i=0; i<numRestarts; i++) {       
-            networkedBroker = createNetworkedBroker();
-            networkedBroker.start();
-            assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 2000));
-            assertEquals(1, countMbeans(broker, "NetworkBridge", 2000));
-            assertEquals(1, countMbeans(broker, "Connection"));
-            networkedBroker.stop();
-            networkedBroker.waitUntilStopped();
-            assertEquals(0, countMbeans(networkedBroker, "stopped"));
-            assertEquals(0, countMbeans(broker, "NetworkBridge"));
+        try {
+            broker.start();
+            assertEquals(1, countMbeans(broker, "Connector", 30000));
+            assertEquals(0, countMbeans(broker, "Connection"));
+            BrokerService networkedBroker = null;
+            for (int i=0; i<numRestarts; i++) {
+                networkedBroker = createNetworkedBroker();
+                networkedBroker.start();
+                assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 2000));
+                assertEquals(1, countMbeans(broker, "NetworkBridge", 2000));
+                assertEquals(1, countMbeans(broker, "Connection"));
+                networkedBroker.stop();
+                networkedBroker.waitUntilStopped();
+                assertEquals(0, countMbeans(networkedBroker, "stopped"));
+                assertEquals(0, countMbeans(broker, "NetworkBridge"));
+            }
+
+            assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
+            assertEquals(0, countMbeans(networkedBroker, "Connector"));
+            assertEquals(0, countMbeans(networkedBroker, "Connection"));
+            assertEquals(1, countMbeans(broker, "Connector"));
+        } finally {
+            broker.stop();
+            broker.waitUntilStopped();
         }
-        
-        assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
-        assertEquals(0, countMbeans(networkedBroker, "Connector"));
-        assertEquals(0, countMbeans(networkedBroker, "Connection"));
-        assertEquals(1, countMbeans(broker, "Connector"));
-        broker.stop();
-        broker.waitUntilStopped();
     }
 
     @Test
     public void testMbeanPresenceOnBrokerRestart() throws Exception {
-        
+
         BrokerService networkedBroker = createNetworkedBroker();
-        networkedBroker.start();
-        assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
-        assertEquals(0, countMbeans(networkedBroker, "Connection"));
-        
-        BrokerService broker = null;
-        for (int i=0; i<numRestarts; i++) {
-            broker = createBroker();
-            broker.start();
-            assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 5000));
-            assertEquals("restart number: " + i, 1, countMbeans(broker, "Connection", 10000));
-            
-            broker.stop();
-            broker.waitUntilStopped();
-            assertEquals(0, countMbeans(broker, "stopped"));
+        try {
+            networkedBroker.start();
+            assertEquals(1, countMbeans(networkedBroker, "Connector", 30000));
+            assertEquals(0, countMbeans(networkedBroker, "Connection"));
+
+            BrokerService broker = null;
+            for (int i=0; i<numRestarts; i++) {
+                broker = createBroker();
+                try {
+                    broker.start();
+                    assertEquals(1, countMbeans(networkedBroker, "NetworkBridge", 5000));
+                    assertEquals("restart number: " + i, 1, countMbeans(broker, "Connection",
10000));
+                } finally {
+                    broker.stop();
+                    broker.waitUntilStopped();
+                }
+                assertEquals(0, countMbeans(broker, "stopped"));
+            }
+
+            //assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
+            assertEquals(1, countMbeans(networkedBroker, "Connector"));
+            assertEquals(0, countMbeans(networkedBroker, "Connection"));
+            assertEquals(0, countMbeans(broker, "Connection"));
+        } finally {
+            networkedBroker.stop();
+            networkedBroker.waitUntilStopped();
         }
-        
-        //assertEquals(0, countMbeans(networkedBroker, "NetworkBridge"));
-        assertEquals(1, countMbeans(networkedBroker, "Connector"));
-        assertEquals(0, countMbeans(networkedBroker, "Connection"));
-        assertEquals(0, countMbeans(broker, "Connection"));
-        
-        networkedBroker.stop();
-        networkedBroker.waitUntilStopped();
     }
-    
+
     private int countMbeans(BrokerService broker, String type) throws Exception {
-        return countMbeans(broker, type, 0); 
+        return countMbeans(broker, type, 0);
     }
 
     private int countMbeans(BrokerService broker, String type, int timeout) throws Exception
{
@@ -135,14 +137,14 @@ public class DuplexNetworkMBeanTest {
                 logAllMbeans(broker);
             }
         } while ((mbeans == null || mbeans.isEmpty()) && expiryTime > System.currentTimeMillis());
-        
+
         // If port 1099 is in use when the Broker starts, starting the jmx
         // connector will fail.  So, if we have no mbsc to query, skip the
         // test.
         if (timeout > 0) {
             assumeNotNull(mbeans);
         }
-        
+
         return count;
     }
 



Mime
View raw message