[hornetq-commits] JBoss hornetq SVN: r9111 - trunk/tests/src/org/hornetq/tests/integration/discovery.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Apr 14 08:09:00 EDT 2010


Author: timfox
Date: 2010-04-14 08:09:00 -0400 (Wed, 14 Apr 2010)
New Revision: 9111

Modified:
   trunk/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java
Log:
added test for local bind address

Modified: trunk/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java	2010-04-14 11:54:24 UTC (rev 9110)
+++ trunk/tests/src/org/hornetq/tests/integration/discovery/DiscoveryTest.java	2010-04-14 12:09:00 UTC (rev 9111)
@@ -14,6 +14,8 @@
 package org.hornetq.tests.integration.discovery;
 
 import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -116,7 +118,98 @@
       dg.stop();
 
    }
+   
+   public void testSimpleBroadcastSpecificNIC() throws Exception
+   {
+      final InetAddress groupAddress = InetAddress.getByName(DiscoveryTest.address1);
+      final int groupPort = 6745;
+      final int timeout = 500;
 
+      final String nodeID = RandomUtil.randomString();
+      
+      //We need to choose a real NIC on the local machine - note this will silently pass if the machine
+      //has no usable NIC!
+      
+      NetworkInterface ni = null;
+      Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
+      while (networkInterfaces.hasMoreElements())
+      {
+         NetworkInterface networkInterface = networkInterfaces.nextElement();
+         if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp() ||
+                  !networkInterface.supportsMulticast())
+         {
+            continue;
+         }
+         
+         ni = networkInterface;
+         
+         break;
+
+      }
+      
+      if (ni == null)
+      {
+         log.warn("Can't find NIC");
+         
+         return;
+      }
+      
+      InetAddress localAddress = ni.getInetAddresses().nextElement();
+      
+      log.info("Local address is " + localAddress);
+
+      BroadcastGroup bg = new BroadcastGroupImpl(nodeID,
+                                                 RandomUtil.randomString(),
+                                                 localAddress,
+                                                 6552,
+                                                 groupAddress,
+                                                 groupPort,
+                                                 true);
+
+      bg.start();
+
+      TransportConfiguration live1 = generateTC();
+
+      TransportConfiguration backup1 = generateTC();
+
+      Pair<TransportConfiguration, TransportConfiguration> connectorPair = new Pair<TransportConfiguration, TransportConfiguration>(live1,
+                                                                                                                                    backup1);
+
+      bg.addConnectorPair(connectorPair);
+
+      DiscoveryGroup dg = new DiscoveryGroupImpl(RandomUtil.randomString(),
+                                                 RandomUtil.randomString(),
+                                                 localAddress,
+                                                 groupAddress,
+                                                 groupPort,
+                                                 timeout);
+
+      dg.start();
+
+      bg.broadcastConnectors();
+
+      boolean ok = dg.waitForBroadcast(1000);
+
+      Assert.assertTrue(ok);
+
+      Map<String, DiscoveryEntry> entryMap = dg.getDiscoveryEntryMap();
+
+      Assert.assertNotNull(entryMap);
+
+      Assert.assertEquals(1, entryMap.size());
+
+      DiscoveryEntry entry = entryMap.get(nodeID);
+
+      Assert.assertNotNull(entry);
+
+      Assert.assertEquals(connectorPair, entry.getConnectorPair());
+
+      bg.stop();
+
+      dg.stop();
+
+   }
+
    public void testSimpleBroadcastWithStopStartDiscoveryGroup() throws Exception
    {
       final InetAddress groupAddress = InetAddress.getByName(DiscoveryTest.address1);



More information about the hornetq-commits mailing list