summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-04-14 14:38:35 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-04-14 14:38:35 +0000
commita2c4c70d6218a9ff70372d55c8528e48f033d542 (patch)
treec7290f522bc7de22a6750ed2cd69e2db8c913047
parent51f6e8c0f8f17ba00c5f78ddf3c368a1eaab7f09 (diff)
downloadqpid-python-a2c4c70d6218a9ff70372d55c8528e48f033d542.tar.gz
QPID-1778 : Add NoFailover FailoverMethod that blocks that still allows connection retry but only on the initial
merged from trunk r759097 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.5-fix@764795 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java5
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java2
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java6
-rw-r--r--qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java62
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java76
5 files changed, 146 insertions, 5 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
index 4186706ade..b366648663 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java
@@ -23,6 +23,7 @@ package org.apache.qpid.jms;
import org.apache.qpid.jms.failover.FailoverMethod;
import org.apache.qpid.jms.failover.FailoverRoundRobinServers;
import org.apache.qpid.jms.failover.FailoverSingleServer;
+import org.apache.qpid.jms.failover.NoFailover;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,6 +89,10 @@ public class FailoverPolicy
{
method = new FailoverRoundRobinServers(connectionDetails);
}
+ else if (failoverMethod.equals(FailoverMethod.NO_FAILOVER))
+ {
+ method = new NoFailover(connectionDetails);
+ }
else
{
try
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java
index d7ec46dea3..f6db72e885 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java
@@ -28,6 +28,8 @@ public interface FailoverMethod
public static final String SINGLE_BROKER = "singlebroker";
public static final String ROUND_ROBIN = "roundrobin";
public static final String RANDOM = "random";
+ public static final String NO_FAILOVER = "nofailover";
+
/**
* Reset the Failover to initial conditions
*/
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java
index 9fa006233b..0d5507e8f8 100644
--- a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java
@@ -36,10 +36,10 @@ public class FailoverSingleServer implements FailoverMethod
private BrokerDetails _brokerDetail;
/** The number of times to retry connecting to the sever */
- private int _retries;
+ protected int _retries;
/** The current number of attempts made to the server */
- private int _currentRetries;
+ protected int _currentRetries;
public FailoverSingleServer(ConnectionURL connectionDetails)
@@ -157,7 +157,7 @@ public class FailoverSingleServer implements FailoverMethod
public String toString()
{
- return "SingleServer:\n" +
+ return methodName()+":\n" +
"Max Retries:" + _retries +
"\nCurrent Retry:" + _currentRetries +
"\n" + _brokerDetail + "\n";
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java
new file mode 100644
index 0000000000..1231324397
--- /dev/null
+++ b/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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.failover;
+
+import org.apache.qpid.jms.BrokerDetails;
+import org.apache.qpid.jms.ConnectionURL;
+
+/**
+ * Extend the Single Server Model to gain retry functionality but once connected do not attempt to failover.
+ */
+public class NoFailover extends FailoverSingleServer
+{
+ private boolean _connected = false;
+
+ public NoFailover(BrokerDetails brokerDetail)
+ {
+ super(brokerDetail);
+ }
+
+ public NoFailover(ConnectionURL connectionDetails)
+ {
+ super(connectionDetails);
+ }
+
+ @Override
+ public void attainedConnection()
+ {
+ _connected=true;
+ _currentRetries = _retries;
+ }
+
+ @Override
+ public String methodName()
+ {
+ return "NoFailover";
+ }
+
+ @Override
+ public String toString()
+ {
+ return super.toString() + (_connected ? "Connection attained." : "Never connected.") + "\n";
+ }
+
+}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
index 14c7f26fad..cca4c47e6a 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java
@@ -28,8 +28,6 @@ import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
import org.apache.qpid.url.URLSyntaxException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@@ -151,4 +149,78 @@ public class FailoverMethodTest extends TestCase implements ExceptionListener
_failoverComplete.countDown();
}
}
+
+ public void testNoFailover() throws URLSyntaxException, AMQVMBrokerCreationException,
+ InterruptedException, JMSException
+ {
+ String connectionString = "amqp://guest:guest@/test?brokerlist='vm://:1?connectdelay='500',retries='3'',failover='nofailover'";
+
+ AMQConnectionURL url = new AMQConnectionURL(connectionString);
+
+ try
+ {
+ //Kill initial broker
+ TransportConnection.killAllVMBrokers();
+
+ //Create a thread to start the broker asynchronously
+ Thread brokerStart = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ //Wait before starting broker
+ // The wait should allow atleast 1 retries to fail before broker is ready
+ Thread.sleep(750);
+ TransportConnection.createVMBroker(1);
+ }
+ catch (Exception e)
+ {
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ });
+
+
+ brokerStart.start();
+ long start = System.currentTimeMillis();
+
+
+ //Start the connection so it will use the retries
+ AMQConnection connection = new AMQConnection(url, null);
+
+ long end = System.currentTimeMillis();
+
+ long duration = (end - start);
+
+ // Check that we actually had a delay had a delay in connection
+ assertTrue("Initial connection should be longer than 1 delay : 500 <:(" + duration + ")", duration > 500);
+
+
+ connection.setExceptionListener(this);
+
+ //Ensure we collect the brokerStart thread
+ brokerStart.join();
+
+ start = System.currentTimeMillis();
+
+ //Kill connection
+ TransportConnection.killAllVMBrokers();
+
+ _failoverComplete.await();
+
+ end = System.currentTimeMillis();
+
+ duration = (end - start);
+
+ // Notification of the connection failure should be very quick as we are denying the ability to failover.
+ assertTrue("Notification of the connection failure took was : 100 >:(" + duration + ")", duration < 100);
+ }
+ catch (AMQException e)
+ {
+ fail(e.getMessage());
+ }
+ }
+
}