QPIDJMS-46: ensure the connection attempt fails when the attempts are exhausted, if discovery results in no target URIs
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/123990d4 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/123990d4 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/123990d4 Branch: refs/heads/master Commit: 123990d4dae65716bb5b200fed460ad223c8811c Parents: 0a7e148 Author: Robert Gemmell <[email protected]> Authored: Tue May 12 13:36:02 2015 +0100 Committer: Robert Gemmell <[email protected]> Committed: Tue May 12 13:36:02 2015 +0100 ---------------------------------------------------------------------- .../jms/provider/failover/FailoverProvider.java | 8 +++++- .../jms/discovery/JmsAmqpDiscoveryTest.java | 26 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/123990d4/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java index 924192e..6abfd49 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java @@ -634,12 +634,18 @@ public class FailoverProvider extends DefaultProviderListener implements Provide provider.close(); } catch (Throwable ex) {} } + } else { + LOG.debug("No target URI available to connect to"); } if (reconnectLimit != UNLIMITED && reconnectAttempts >= reconnectLimit) { LOG.error("Failed to connect after: " + reconnectAttempts + " attempt(s)"); failed.set(true); - failureCause = IOExceptionSupport.create(failure); + if(failure == null) { + failureCause = new IOException("Failed to connect after: " + reconnectAttempts + " attempt(s)"); + } else { + failureCause = IOExceptionSupport.create(failure); + } if (listener != null) { listener.onConnectionFailure(failureCause); }; http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/123990d4/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 ce6e468..4d9bf5a 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 @@ -17,12 +17,14 @@ package org.apache.qpid.jms.discovery; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.net.URI; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.jms.Connection; +import javax.jms.JMSException; import org.apache.qpid.jms.JmsConnection; import org.apache.qpid.jms.JmsConnectionFactory; @@ -58,6 +60,19 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti restored = new CountDownLatch(1); } + @Test(timeout=10000) + public void testFailureToDiscoverLeadsToConnectionFailure() throws Exception { + // We are using a different group to ensure failure, + // but shut down the broker anyway. + stopPrimaryBroker(); + try { + createFailingConnection(); + fail("Should have failed to connect"); + } catch (JMSException jmse) { + // expected + } + } + @Test(timeout=30000) public void testRunningBrokerIsDiscovered() throws Exception { connection = createConnection(); @@ -136,6 +151,17 @@ public class JmsAmqpDiscoveryTest extends AmqpTestSupport implements JmsConnecti return true; } + protected Connection createFailingConnection() throws JMSException { + String discoveryPrefix = DiscoveryProviderFactory.DISCOVERY_OPTION_PREFIX; + JmsConnectionFactory factory = new JmsConnectionFactory( + "discovery:(multicast://default?group=altGroup)?" + discoveryPrefix + "startupMaxReconnectAttempts=10" + "&" + discoveryPrefix +"maxReconnectDelay=100"); + connection = factory.createConnection(); + jmsConnection = (JmsConnection) connection; + jmsConnection.addConnectionListener(this); + jmsConnection.start(); + return connection; + } + protected Connection createConnection() throws Exception { String discoveryPrefix = DiscoveryProviderFactory.DISCOVERY_OPTION_PREFIX; JmsConnectionFactory factory = new JmsConnectionFactory( --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
