activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1429149 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java
Date Fri, 04 Jan 2013 21:58:25 GMT
Author: tabish
Date: Fri Jan  4 21:58:25 2013
New Revision: 1429149

URL: http://svn.apache.org/viewvc?rev=1429149&view=rev
Log:
attempt to fix test case after changes in https://issues.apache.org/jira/browse/AMQ-4237 broke
the test's MBean lookup, not quite there but close.

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java?rev=1429149&r1=1429148&r2=1429149&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java
Fri Jan  4 21:58:25 2013
@@ -30,8 +30,6 @@ import org.apache.activemq.broker.jmx.Ma
 import org.apache.activemq.transport.discovery.multicast.MulticastDiscoveryAgentFactory;
 import org.apache.activemq.util.SocketProxy;
 import org.apache.activemq.util.Wait;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.jmock.Expectations;
@@ -45,6 +43,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 @RunWith(JMock.class)
@@ -61,27 +61,34 @@ public class DiscoveryNetworkReconnectTe
     ManagementContext managementContext;
     DiscoveryAgent agent;
     SocketProxy proxy;
-    
+
     // ignore the hostname resolution component as this is machine dependent
     class NetworkBridgeObjectNameMatcher<T> extends BaseMatcher<T> {
         T name;
         NetworkBridgeObjectNameMatcher(T o) {
             name = o;
         }
-        
+
+        @Override
         public boolean matches(Object arg0) {
             ObjectName other = (ObjectName) arg0;
             ObjectName mine = (ObjectName) name;
             LOG.info("Match: " + mine + " vs: " + other);
-            return other.getKeyProperty("Type").equals(mine.getKeyProperty("Type")) &&
-                other.getKeyProperty("NetworkConnectorName").equals(mine.getKeyProperty("NetworkConnectorName"));
+
+            if (other.getKeyProperty("service") == null) {
+                return false;
+            }
+
+            return other.getKeyProperty("service").equals(mine.getKeyProperty("service"))
&&
+                other.getKeyProperty("networkConnectorName").equals(mine.getKeyProperty("networkConnectorName"));
         }
 
+        @Override
         public void describeTo(Description arg0) {
             arg0.appendText(this.getClass().getName());
-        }       
+        }
     }
-    
+
     @Before
     public void setUp() throws Exception {
         context = new JUnit4Mockery() {{
@@ -93,35 +100,38 @@ public class DiscoveryNetworkReconnectTe
         brokerA.addConnector("tcp://localhost:0");
         brokerA.start();
         brokerA.waitUntilStarted();
-        
+
         proxy = new SocketProxy(brokerA.getTransportConnectors().get(0).getConnectUri());
         managementContext = context.mock(ManagementContext.class);
-        
+
         context.checking(new Expectations(){{
-            allowing (managementContext).getJmxDomainName(); will (returnValue("Test"));
-            allowing (managementContext).setBrokerName("BrokerNC");
-            allowing (managementContext).start();
-            allowing (managementContext).isCreateConnector();
-            allowing (managementContext).stop();
-            allowing (managementContext).isConnectorStarted();
-            
+            allowing(managementContext).getJmxDomainName(); will (returnValue("Test"));
+            allowing(managementContext).setBrokerName("BrokerNC");
+            allowing(managementContext).start();
+            allowing(managementContext).isCreateConnector();
+            allowing(managementContext).stop();
+            allowing(managementContext).isConnectorStarted();
+
             // expected MBeans
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Broker"))));
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Health"))));
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkConnector,NetworkConnectorName=NC"))));
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
           
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Topic,Destination=ActiveMQ.Advisory.Connection"))));
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Topic,Destination=ActiveMQ.Advisory.NetworkBridge"))));
-            allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
           
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=jobScheduler,jobSchedulerName=JMS"))));
-            
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
+            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=jobScheduler,jobSchedulerName=JMS"))));
+
             atLeast(maxReconnects - 1).of (managementContext).registerMBean(with(any(Object.class)),
with(new NetworkBridgeObjectNameMatcher<ObjectName>(
-                        new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkBridge,NetworkConnectorName=NC,Name=localhost/127.0.0.1_"

+                        new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=NetworkBridge,networkConnectorName=NC,networkBridgeName=localhost/127.0.0.1_"
                             + proxy.getUrl().getPort())))); will(new CustomAction("signal
register network mbean") {
+                                @Override
                                 public Object invoke(Invocation invocation) throws Throwable
{
                                     LOG.info("Mbean Registered: " + invocation.getParameter(0));
                                     mbeanRegistered.release();
@@ -129,27 +139,30 @@ public class DiscoveryNetworkReconnectTe
                                 }
                             });
             atLeast(maxReconnects - 1).of (managementContext).unregisterMBean(with(new NetworkBridgeObjectNameMatcher<ObjectName>(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkBridge,NetworkConnectorName=NC,Name=localhost/127.0.0.1_"

+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=NetworkBridge,networkConnectorName=NC,networkBridgeName=localhost/127.0.0.1_"
                             + proxy.getUrl().getPort())))); will(new CustomAction("signal
unregister network mbean") {
+                                @Override
                                 public Object invoke(Invocation invocation) throws Throwable
{
                                     LOG.info("Mbean Unregistered: " + invocation.getParameter(0));
                                     mbeanUnregistered.release();
                                     return null;
                                 }
                             });
-           
-            allowing (managementContext).unregisterMBean(with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Broker"))));
-            allowing (managementContext).unregisterMBean(with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Health"))));
-            allowing (managementContext).unregisterMBean(with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkConnector,NetworkConnectorName=NC"))));
-            allowing (managementContext).unregisterMBean(with(equal(            
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Topic,Destination=ActiveMQ.Advisory.Connection"))));
-            allowing (managementContext).unregisterMBean(with(equal(
-                    new ObjectName("Test:BrokerName=BrokerNC,Type=Topic,Destination=ActiveMQ.Advisory.NetworkBridge"))));
+
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
+            allowing(managementContext).unregisterMBean(with(equal(
+                    new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
         }});
-        
+
         brokerB = new BrokerService();
         brokerB.setManagementContext(managementContext);
         brokerB.setBrokerName("BrokerNC");
@@ -164,15 +177,15 @@ public class DiscoveryNetworkReconnectTe
         brokerB.waitUntilStopped();
         proxy.close();
     }
-    
+
     private void configure(BrokerService broker) {
         broker.setPersistent(false);
-        broker.setUseJmx(true);      
+        broker.setUseJmx(true);
     }
-    
+
     @Test
-    public void testMulicastReconnect() throws Exception {     
-        
+    public void testMulicastReconnect() throws Exception {
+
         // control multicast advertise agent to inject proxy
         agent = MulticastDiscoveryAgentFactory.createDiscoveryAgent(new URI(discoveryAddress));
         agent.registerService(proxy.getUrl().toString());
@@ -183,42 +196,41 @@ public class DiscoveryNetworkReconnectTe
         brokerB.waitUntilStarted();
         doReconnect();
     }
-    
-    
 
     @Test
     public void testSimpleReconnect() throws Exception {
-        brokerB.addNetworkConnector("simple://(" + proxy.getUrl() 
+        brokerB.addNetworkConnector("simple://(" + proxy.getUrl()
                 + ")?useExponentialBackOff=false&initialReconnectDelay=500&wireFormat.maxInactivityDuration=1000&wireFormat.maxInactivityDurationInitalDelay=1000");
-        brokerB.start();   
+        brokerB.start();
         brokerB.waitUntilStarted();
         doReconnect();
     }
 
     private void doReconnect() throws Exception {
-        
+
         for (int i=0; i<maxReconnects; i++) {
             // Wait for connection
             assertTrue("we got a network connection in a timely manner", Wait.waitFor(new
Wait.Condition() {
+                @Override
                 public boolean isSatisified() throws Exception {
                    return proxy.connections.size() >= 1;
                 }
             }));
-            
+
             // wait for network connector
             assertTrue("network connector mbean registered within 1 minute", mbeanRegistered.tryAcquire(60,
TimeUnit.SECONDS));
-            
+
             // force an inactivity timeout via the proxy
             proxy.pause();
-        
+
             // wait for the inactivity timeout and network shutdown
             assertTrue("network connector mbean unregistered within 1 minute", mbeanUnregistered.tryAcquire(60,
TimeUnit.SECONDS));
-            
+
             // whack all connections
             proxy.close();
-            
+
             // let a reconnect succeed
-            proxy.reopen();       
+            proxy.reopen();
         }
     }
 }



Mime
View raw message