summaryrefslogtreecommitdiff
path: root/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java')
-rw-r--r--java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java51
1 files changed, 35 insertions, 16 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java b/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
index 4b766864b4..4f8a6ee54a 100644
--- a/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/client/failover/FailoverBehaviourTest.java
@@ -25,11 +25,12 @@ import org.apache.qpid.client.AMQSession;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.jms.FailoverPolicy;
import org.apache.qpid.test.utils.FailoverBaseCase;
+import org.apache.qpid.url.URLSyntaxException;
import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
@@ -929,18 +930,22 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
return queue;
}
- private AMQConnection createConnectionWithFailover() throws NamingException, JMSException
+ private AMQConnection createConnectionWithFailover() throws NamingException, JMSException, URLSyntaxException
{
- AMQConnection connection;
- AMQConnectionFactory connectionFactory = (AMQConnectionFactory)getConnectionFactory("default");
- ConnectionURL connectionURL = connectionFactory.getConnectionURL();
- connectionURL.setOption(ConnectionURL.OPTIONS_FAILOVER, "singlebroker");
- connectionURL.setOption(ConnectionURL.OPTIONS_FAILOVER_CYCLE, "2");
- BrokerDetails details = connectionURL.getBrokerDetails(0);
- details.setProperty(BrokerDetails.OPTIONS_RETRY, "200");
- details.setProperty(BrokerDetails.OPTIONS_CONNECT_DELAY, "1000");
+ BrokerDetails origBrokerDetails = ((AMQConnectionFactory) getConnectionFactory("default")).getConnectionURL().getBrokerDetails(0);
- connection = (AMQConnection)connectionFactory.createConnection("admin", "admin");
+ String retries = "200";
+ String connectdelay = "1000";
+ String cycleCount = "2";
+
+ String newUrlFormat="amqp://username:password@clientid/test?brokerlist=" +
+ "'tcp://%s:%s?retries='%s'&connectdelay='%s''&failover='singlebroker?cyclecount='%s''";
+
+ String newUrl = String.format(newUrlFormat, origBrokerDetails.getHost(), origBrokerDetails.getPort(),
+ retries, connectdelay, cycleCount);
+
+ ConnectionFactory connectionFactory = new AMQConnectionFactory(newUrl);
+ AMQConnection connection = (AMQConnection) connectionFactory.createConnection("admin", "admin");
connection.setConnectionListener(this);
return connection;
}
@@ -1313,7 +1318,7 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
* @param acknowledgeMode session acknowledge mode
* @throws JMSException
*/
- private void sessionCloseWhileFailoverImpl(int acknowledgeMode) throws JMSException
+ private void sessionCloseWhileFailoverImpl(int acknowledgeMode) throws Exception
{
initDelayedFailover(acknowledgeMode);
@@ -1324,9 +1329,14 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
failBroker(getFailingPort());
+ // wait until failover is started
+ _failoverStarted.await(5, TimeUnit.SECONDS);
+
// test whether session#close blocks while failover is in progress
_consumerSession.close();
+ assertTrue("Failover has not completed yet but session was closed", _failoverComplete.await(5, TimeUnit.SECONDS));
+
assertFailoverException();
}
@@ -1360,10 +1370,8 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
* @param acknowledgeMode session acknowledge mode
* @throws JMSException
*/
- private void browserCloseWhileFailoverImpl(int acknowledgeMode) throws JMSException
+ private void browserCloseWhileFailoverImpl(int acknowledgeMode) throws Exception
{
- setDelayedFailoverPolicy();
-
QueueBrowser browser = prepareQueueBrowser(acknowledgeMode);
@SuppressWarnings("unchecked")
@@ -1373,8 +1381,13 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
failBroker(getFailingPort());
+ // wait until failover is started
+ _failoverStarted.await(5, TimeUnit.SECONDS);
+
browser.close();
+ assertTrue("Failover has not completed yet but browser was closed", _failoverComplete.await(5, TimeUnit.SECONDS));
+
assertFailoverException();
}
@@ -1402,5 +1415,11 @@ public class FailoverBehaviourTest extends FailoverBaseCase implements Connectio
((AMQConnection) _connection).setFailoverPolicy(failoverPolicy);
return failoverPolicy;
}
-
+
+ @Override
+ public void failBroker(int port)
+ {
+ killBroker(port);
+ }
+
}