You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/06/25 17:13:40 UTC
qpid-jms git commit: QPIDJMS-76: do the multicast assumption check
before trying to start the broker,
avoids hitting cases where doing so actually fails
Repository: qpid-jms
Updated Branches:
refs/heads/master e6dfc7419 -> e0a49ba17
QPIDJMS-76: do the multicast assumption check before trying to start the broker, avoids hitting cases where doing so actually fails
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e0a49ba1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e0a49ba1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e0a49ba1
Branch: refs/heads/master
Commit: e0a49ba179df5fe21aaf6cb222f3bab1434661de
Parents: e6dfc74
Author: Robert Gemmell <ro...@apache.org>
Authored: Thu Jun 25 16:03:50 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Thu Jun 25 16:03:50 2015 +0100
----------------------------------------------------------------------
.../jms/discovery/JmsAmqpDiscoveryTest.java | 81 ++------------
.../jms/discovery/JmsDiscoveryProviderTest.java | 17 ++-
.../qpid/jms/support/MulticastTestSupport.java | 105 +++++++++++++++++++
3 files changed, 130 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e0a49ba1/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 70f0ca7..96ba0a4 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
@@ -20,14 +20,7 @@ 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;
@@ -39,8 +32,9 @@ 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.MulticastTestSupport;
+import org.apache.qpid.jms.support.MulticastTestSupport.MulticastSupportResult;
import org.apache.qpid.jms.support.Wait;
import org.junit.Before;
import org.junit.Test;
@@ -59,54 +53,9 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
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;
- networkInterface = mcastRcv.getNetworkInterface().getName();
- } 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;
+ MulticastSupportResult msr = MulticastTestSupport.checkMulticastWorking();
+ multicastWorking = msr.isMulticastWorking();
+ networkInterface = msr.getNetworkInterface();
}
private CountDownLatch connected;
@@ -114,13 +63,13 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
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 {
+ // Check assumptions *before* trying to start
+ // the broker, which may fail otherwise
+ assumeTrue("Multicast does not seem to be working, skip!", multicastWorking);
+
super.setUp();
connected = new CountDownLatch(1);
@@ -143,9 +92,6 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
@Test(timeout=30000)
public void testRunningBrokerIsDiscovered() throws Exception {
- // Check assumptions
- verifyMulticastIsWorking();
-
connection = createConnection();
connection.start();
@@ -160,9 +106,6 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
@Test(timeout=30000)
public void testConnectionFailsWhenBrokerGoesDown() throws Exception {
- // Check assumptions
- verifyMulticastIsWorking();
-
connection = createConnection();
connection.start();
@@ -182,9 +125,6 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
@Test(timeout=30000)
public void testConnectionRestoresAfterBrokerRestarted() throws Exception {
- // Check assumptions
- verifyMulticastIsWorking();
-
connection = createConnection();
connection.start();
@@ -204,9 +144,6 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti
@Test(timeout=30000)
public void testDiscoversAndReconnectsToSecondaryBroker() throws Exception {
- // Check assumptions
- verifyMulticastIsWorking();
-
connection = createConnection();
connection.start();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e0a49ba1/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsDiscoveryProviderTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsDiscoveryProviderTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsDiscoveryProviderTest.java
index b620451..2d299e0 100644
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsDiscoveryProviderTest.java
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/discovery/JmsDiscoveryProviderTest.java
@@ -18,6 +18,7 @@ package org.apache.qpid.jms.discovery;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
import java.io.IOException;
import java.net.URI;
@@ -27,6 +28,8 @@ import org.apache.activemq.broker.TransportConnector;
import org.apache.qpid.jms.provider.DefaultProviderListener;
import org.apache.qpid.jms.provider.Provider;
import org.apache.qpid.jms.provider.discovery.DiscoveryProviderFactory;
+import org.apache.qpid.jms.support.MulticastTestSupport;
+import org.apache.qpid.jms.support.MulticastTestSupport.MulticastSupportResult;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -42,12 +45,24 @@ public class JmsDiscoveryProviderTest {
protected static final Logger LOG = LoggerFactory.getLogger(JmsDiscoveryProviderTest.class);
+ private static boolean multicastWorking = false;
+
+ static
+ {
+ MulticastSupportResult msr = MulticastTestSupport.checkMulticastWorking();
+ multicastWorking = msr.isMulticastWorking();
+ }
+
@Rule public TestName name = new TestName();
private BrokerService broker;
@Before
public void setup() throws Exception {
+ // Check assumptions *before* trying to start
+ // the broker, which may fail otherwise
+ assumeTrue("Multicast does not seem to be working, skip!", multicastWorking);
+
broker = createBroker();
try {
broker.start();
@@ -71,7 +86,7 @@ public class JmsDiscoveryProviderTest {
}
@Test(timeout=30000)
- public void testCreateDiscvoeryProvider() throws Exception {
+ public void testCreateDiscoveryProvider() throws Exception {
URI discoveryUri = new URI("discovery:multicast://default");
Provider provider = DiscoveryProviderFactory.create(discoveryUri);
assertNotNull(provider);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e0a49ba1/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/support/MulticastTestSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/support/MulticastTestSupport.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/support/MulticastTestSupport.java
new file mode 100644
index 0000000..6b2b4af
--- /dev/null
+++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/support/MulticastTestSupport.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms.support;
+
+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.UnknownHostException;
+
+import org.apache.qpid.jms.provider.discovery.multicast.MulticastDiscoveryAgent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MulticastTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MulticastTestSupport.class);
+
+ public static MulticastSupportResult checkMulticastWorking() {
+ String host = MulticastDiscoveryAgent.DEFAULT_HOST_IP;
+ int myPort = MulticastDiscoveryAgent.DEFAULT_PORT;
+ int timeToLive = 1;
+ int soTimeout = 500;
+ boolean success = false;
+ String networkInterface = null;
+
+ 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;
+ networkInterface = mcastRcv.getNetworkInterface().getName();
+ } 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);
+ }
+
+ return new MulticastSupportResult(success, networkInterface);
+ }
+
+ public static class MulticastSupportResult {
+ private boolean multicastWorking;
+ private String networkInterface;
+
+ public MulticastSupportResult(boolean multicastWorking, String networkInterface) {
+ this.multicastWorking = multicastWorking;
+ this.networkInterface = networkInterface;
+ }
+
+ public boolean isMulticastWorking() {
+ return multicastWorking;
+ }
+
+ public String getNetworkInterface() {
+ return networkInterface;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org