qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject qpid-jms git commit: QPIDJMS-46: skip the discovery tests if multicast doesnt seem to be working
Date Tue, 12 May 2015 17:21:54 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master 125d72b2a -> c452cd63c


QPIDJMS-46: skip the discovery tests if multicast doesnt seem to be working


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/c452cd63
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/c452cd63
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/c452cd63

Branch: refs/heads/master
Commit: c452cd63c50ac4f9c7f6b9233debe689180fb375
Parents: 125d72b
Author: Robert Gemmell <robbie@apache.org>
Authored: Tue May 12 18:06:36 2015 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Tue May 12 18:06:36 2015 +0100

----------------------------------------------------------------------
 .../multicast/MulticastDiscoveryAgent.java      |  6 +-
 .../jms/discovery/JmsAmqpDiscoveryTest.java     | 79 +++++++++++++++++++-
 2 files changed, 81 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/c452cd63/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java
----------------------------------------------------------------------
diff --git a/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java
b/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java
index 9a67458..1c5e2c1 100644
--- a/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java
+++ b/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java
@@ -396,7 +396,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable
{
         this.parser = parser;
     }
 
-    private void trySetNetworkInterface(MulticastSocket mcastSock) throws SocketException
{
+    public static void trySetNetworkInterface(MulticastSocket mcastSock) throws SocketException
{
         List<NetworkInterface> interfaces = findNetworkInterface();
         SocketException lastError = null;
         boolean found = false;
@@ -404,7 +404,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable
{
         for (NetworkInterface networkInterface : interfaces) {
             try {
                 mcastSock.setNetworkInterface(networkInterface);
-                LOG.debug("Configured mcast socket {} to network interface {}", mcast, networkInterface);
+                LOG.debug("Configured mcast socket {} to network interface {}", mcastSock,
networkInterface);
                 found = true;
                 break;
             } catch (SocketException error) {
@@ -421,7 +421,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable
{
         }
     }
 
-    private List<NetworkInterface> findNetworkInterface() throws SocketException {
+    private static List<NetworkInterface> findNetworkInterface() throws SocketException
{
         Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
         List<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
         while (ifcs.hasMoreElements()) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/c452cd63/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsAmqpDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsAmqpDiscoveryTest.java
b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsAmqpDiscoveryTest.java
index 4d9bf5a..13f9c1d 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsAmqpDiscoveryTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsAmqpDiscoveryTest.java
@@ -18,8 +18,16 @@ package org.apache.qpid.jms.discovery;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.MulticastSocket;
+import java.net.SocketTimeoutException;
 import java.net.URI;
+import java.net.UnknownHostException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -31,8 +39,10 @@ import org.apache.qpid.jms.JmsConnectionFactory;
 import org.apache.qpid.jms.JmsConnectionListener;
 import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
 import org.apache.qpid.jms.provider.discovery.DiscoveryProviderFactory;
+import org.apache.qpid.jms.provider.discovery.multicast.MulticastDiscoveryAgent;
 import org.apache.qpid.jms.support.AmqpTestSupport;
 import org.apache.qpid.jms.support.Wait;
+import org.apache.qpid.proton.amqp.Binary;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -45,11 +55,67 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
 
     private static final Logger LOG = LoggerFactory.getLogger(JmsAmqpDiscoveryTest.class);
 
+    private static boolean multicastWorking = false;
+    static
+    {
+        String host = MulticastDiscoveryAgent.DEFAULT_HOST_IP;
+        int myPort = MulticastDiscoveryAgent.DEFAULT_PORT;
+        int timeToLive = 1;
+        int soTimeout = 500;
+        boolean success = false;
+        try {
+            InetAddress inetAddress = InetAddress.getByName(host);
+            InetSocketAddress sockAddress = new InetSocketAddress(inetAddress, myPort);
+
+            MulticastSocket mcastSend = new MulticastSocket(myPort);
+            mcastSend.setTimeToLive(timeToLive);
+            MulticastDiscoveryAgent.trySetNetworkInterface(mcastSend);
+            mcastSend.joinGroup(inetAddress);
+            mcastSend.setSoTimeout(soTimeout);
+
+            MulticastSocket mcastRcv = new MulticastSocket(myPort);
+            MulticastDiscoveryAgent.trySetNetworkInterface(mcastRcv);
+            mcastRcv.joinGroup(inetAddress);
+            mcastRcv.setSoTimeout(soTimeout);
+
+            byte[] bytesOut = "verifyingMulticast".getBytes("UTF-8");
+            DatagramPacket packetOut = new DatagramPacket(bytesOut, 0, bytesOut.length, sockAddress);
+
+                mcastSend.send(packetOut);
+
+            byte[] buf = new byte[1024];
+            DatagramPacket packetIn = new DatagramPacket(buf, 0, buf.length);
+
+            try {
+                mcastRcv.receive(packetIn);
+
+                if(packetIn.getLength() > 0) {
+                    LOG.info("Received packet with content, multicast seems to be working!");
+                    success = true;
+                } else {
+                    LOG.info("Received packet without content, lets assume multicast isnt
working!");
+                }
+            } catch (SocketTimeoutException e) {
+                LOG.info("Recieve timed out, assuming multicast isn't available");
+            }
+        } catch (UnknownHostException e) {
+            LOG.info("Caught exception testing for multicast functionality", e);
+        } catch (IOException e) {
+            LOG.info("Caught exception testing for multicast functionality", e);
+        }
+
+        multicastWorking = success;
+    }
+
     private CountDownLatch connected;
     private CountDownLatch interrupted;
     private CountDownLatch restored;
     private JmsConnection jmsConnection;
 
+    public void verifyMulticastIsWorking() {
+        assumeTrue("Multicast does not seem to be working, skip!", multicastWorking);
+    }
+
     @Override
     @Before
     public void setUp() throws Exception {
@@ -75,6 +141,9 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
 
     @Test(timeout=30000)
     public void testRunningBrokerIsDiscovered() throws Exception {
+        // Check assumptions
+        verifyMulticastIsWorking();
+
         connection = createConnection();
         connection.start();
 
@@ -89,6 +158,9 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
 
     @Test(timeout=30000)
     public void testConnectionFailsWhenBrokerGoesDown() throws Exception {
+        // Check assumptions
+        verifyMulticastIsWorking();
+
         connection = createConnection();
         connection.start();
 
@@ -108,6 +180,9 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
 
     @Test(timeout=30000)
     public void testConnectionRestoresAfterBrokerRestarted() throws Exception {
+        // Check assumptions
+        verifyMulticastIsWorking();
+
         connection = createConnection();
         connection.start();
 
@@ -127,6 +202,8 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
 
     @Test(timeout=30000)
     public void testDiscoversAndReconnectsToSecondaryBroker() throws Exception {
+        // Check assumptions
+        verifyMulticastIsWorking();
 
         connection = createConnection();
         connection.start();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message