You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2017/10/17 18:45:47 UTC

qpid-jms git commit: QPIDJMS-342 Ensure that the global connect timeout gets honored

Repository: qpid-jms
Updated Branches:
  refs/heads/master 31488bc0f -> 95070f162


QPIDJMS-342 Ensure that the global connect timeout gets honored

Better handle the jms.connectTimeout having been reached so that the
connection error triggers in a timely manner and the failover transport
gets notified correctly. 

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

Branch: refs/heads/master
Commit: 95070f162e2b85b7f598c660b16bc77934638aa9
Parents: 31488bc
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Oct 17 14:45:26 2017 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Oct 17 14:45:26 2017 -0400

----------------------------------------------------------------------
 .../qpid/jms/provider/ProviderFuture.java       | 10 ++-
 .../qpid/jms/provider/amqp/AmqpProvider.java    |  4 +-
 .../FailoverSocketLevelAcceptFailures.java      | 78 ++++++++++++++++++++
 3 files changed, 89 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/95070f16/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/ProviderFuture.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/ProviderFuture.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/ProviderFuture.java
index 4235496..61168d4 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/ProviderFuture.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/ProviderFuture.java
@@ -75,16 +75,22 @@ public class ProviderFuture implements AsyncResult {
      * @param unit
      *        The unit to use for this wait period.
      *
+     * @return true if the operation succeeded and false if the waiting time elapsed while
+     * 	       waiting for the operation to complete.
+     *
      * @throws IOException if an error occurs while waiting for the response.
      */
-    public void sync(long amount, TimeUnit unit) throws IOException {
+    public boolean sync(long amount, TimeUnit unit) throws IOException {
+        boolean result = false;
         try {
-            latch.await(amount, unit);
+            result = latch.await(amount, unit);
         } catch (InterruptedException e) {
             Thread.interrupted();
             throw IOExceptionSupport.create(e);
         }
         failOnError();
+
+        return result;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/95070f16/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
index 88deb58..f5c9e56 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpProvider.java
@@ -218,7 +218,9 @@ public class AmqpProvider implements Provider, TransportListener , AmqpResourceP
         });
 
         if (connectionInfo.getConnectTimeout() != JmsConnectionInfo.INFINITE) {
-            connectRequest.sync(connectionInfo.getConnectTimeout(), TimeUnit.MILLISECONDS);
+            if (!connectRequest.sync(connectionInfo.getConnectTimeout(), TimeUnit.MILLISECONDS)) {
+                throw new IOException("Timed out while waiting to connect");
+            }
         } else {
             connectRequest.sync();
         }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/95070f16/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverSocketLevelAcceptFailures.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverSocketLevelAcceptFailures.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverSocketLevelAcceptFailures.java
new file mode 100644
index 0000000..69b480b
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverSocketLevelAcceptFailures.java
@@ -0,0 +1,78 @@
+/*
+ * 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.provider.failover;
+
+import static org.junit.Assert.fail;
+
+import java.net.ServerSocket;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.net.ServerSocketFactory;
+
+import org.apache.qpid.jms.JmsConnectionFactory;
+import org.apache.qpid.jms.test.QpidJmsTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests failover reconnect behavior when the remote side is not accepting socket connections
+ * in a normal manner.
+ */
+public class FailoverSocketLevelAcceptFailures extends QpidJmsTestCase {
+
+    private static final Logger LOG = LoggerFactory.getLogger(FailoverSocketLevelAcceptFailures.class);
+
+    private ServerSocket server;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        server = ServerSocketFactory.getDefault().createServerSocket(0);
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        try {
+            server.close();
+            server = null;
+        } catch (Exception ignored) {
+        }
+
+        super.tearDown();
+    }
+
+    @Test(timeout = 40000)
+    public void testFailoverHandlesRedirection() throws Exception {
+        final String remoteURI = "failover:(amqp://localhost:" + server.getLocalPort() +
+            ")?jms.connectTimeout=666&failover.maxReconnectAttempts=1&failover.startupMaxReconnectAttempts=1";
+
+        try {
+            ConnectionFactory cf = new JmsConnectionFactory(remoteURI);
+            Connection connection = cf.createConnection();
+            connection.start();
+            fail("Should throw error once the connection starts");
+        } catch (Exception ex) {
+            LOG.info("Error on connect:", ex);
+        }
+    }
+}


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