activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r812046 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.java
Date Mon, 07 Sep 2009 09:12:34 GMT
Author: gtully
Date: Mon Sep  7 09:12:34 2009
New Revision: 812046

URL: http://svn.apache.org/viewvc?rev=812046&view=rev
Log:
remove dependence on host name resolution to resolve failure on some machines, https://issues.apache.org/activemq/browse/AMQ-1855

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=812046&r1=812045&r2=812046&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
Mon Sep  7 09:12:34 2009
@@ -32,6 +32,8 @@
 import org.apache.activemq.util.Wait;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.api.Invocation;
@@ -50,25 +52,40 @@
 
     private static final Log LOG = LogFactory.getLog(DiscoveryNetworkReconnectTest.class);
     final int maxReconnects = 5;
-    BrokerService brokerA, brokerB;
-    Mockery context;
-    ManagementContext managementContext;
-    
     final String groupName = "GroupID-" + "DiscoveryNetworkReconnectTest";
     final String discoveryAddress = "multicast://default?group=" + groupName + "&initialReconnectDelay=1000";
     final Semaphore mbeanRegistered = new Semaphore(0);
     final Semaphore mbeanUnregistered = new Semaphore(0);
-
-    
-    private DiscoveryAgent agent;
+    BrokerService brokerA, brokerB;
+    Mockery context;
+    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;
+        }
+        
+        public boolean matches(Object arg0) {
+            ObjectName other = (ObjectName) arg0;
+            ObjectName mine = (ObjectName) name;
+            return other.getKeyProperty("Type").equals(mine.getKeyProperty("Type")) &&
+                other.getKeyProperty("NetworkConnectorName").equals(mine.getKeyProperty("NetworkConnectorName"));
+        }
+
+        public void describeTo(Description arg0) {
+            arg0.appendText(this.getClass().getName());
+        }       
+    }
+    
     @Before
     public void setUp() throws Exception {
         context = new JUnit4Mockery() {{
             setImposteriser(ClassImposteriser.INSTANCE);
         }};
-            
         brokerA = new BrokerService();
         brokerA.setBrokerName("BrokerA");
         configure(brokerA);
@@ -91,7 +108,7 @@
             allowing (managementContext).registerMBean(with(any(Object.class)), with(equal(
           
                     new ObjectName("Test:BrokerName=BrokerNC,Type=Topic,Destination=ActiveMQ.Advisory.Connection"))));
             
-            atLeast(maxReconnects - 1).of (managementContext).registerMBean(with(any(Object.class)),
with(equal(
+            atLeast(maxReconnects - 1).of (managementContext).registerMBean(with(any(Object.class)),
with(new NetworkBridgeObjectNameMatcher<ObjectName>(
                         new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkBridge,NetworkConnectorName=localhost,Name=localhost/127.0.0.1_"

                             + proxy.getUrl().getPort())))); will(new CustomAction("signal
register network mbean") {
                                 public Object invoke(Invocation invocation) throws Throwable
{
@@ -100,7 +117,7 @@
                                     return new ObjectInstance((ObjectName)invocation.getParameter(0),
"dscription");
                                 }
                             });
-            atLeast(maxReconnects - 1).of (managementContext).unregisterMBean(with(equal(
+            atLeast(maxReconnects - 1).of (managementContext).unregisterMBean(with(new NetworkBridgeObjectNameMatcher<ObjectName>(
                     new ObjectName("Test:BrokerName=BrokerNC,Type=NetworkBridge,NetworkConnectorName=localhost,Name=localhost/127.0.0.1_"

                             + proxy.getUrl().getPort())))); will(new CustomAction("signal
unregister network mbean") {
                                 public Object invoke(Invocation invocation) throws Throwable
{



Mime
View raw message