diff options
Diffstat (limited to 'qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java')
-rw-r--r-- | qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java | 55 |
1 files changed, 25 insertions, 30 deletions
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 470fcefae3..babe2d207d 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 @@ -20,11 +20,8 @@ */ package org.apache.qpid.server.failover; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import javax.jms.ExceptionListener; -import javax.jms.JMSException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.qpid.AMQConnectionClosedException; import org.apache.qpid.AMQDisconnectedException; @@ -32,15 +29,17 @@ import org.apache.qpid.AMQException; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.test.utils.QpidBrokerTestCase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionListener { + private static final Logger LOGGER = LoggerFactory.getLogger(FailoverMethodTest.class); private CountDownLatch _failoverComplete = new CountDownLatch(1); - protected static final Logger _logger = LoggerFactory.getLogger(FailoverMethodTest.class); - - + private final int _freePortWithNoBroker = findFreePort(); /** * Test that the round robin method has the correct delays. @@ -53,8 +52,8 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL //note: The first broker has no connect delay and the default 1 retry // while the tcp:localhost broker has 3 retries with a 2s connect delay String connectionString = "amqp://guest:guest@/test?brokerlist=" + - "'tcp://:" + getPort() + - ";tcp://localhost:5670?connectdelay='2000',retries='3''"; + "'tcp://localhost:" + getPort() + + ";tcp://localhost:" + _freePortWithNoBroker + "?connectdelay='2000',retries='3''"; AMQConnectionURL url = new AMQConnectionURL(connectionString); @@ -65,7 +64,9 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL connection.setExceptionListener(this); + LOGGER.debug("Stopping broker"); stopBroker(); + LOGGER.debug("Stopped broker"); _failoverComplete.await(30, TimeUnit.SECONDS); assertEquals("failoverLatch was not decremented in given timeframe", @@ -109,7 +110,9 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL connection.setExceptionListener(this); + LOGGER.debug("Stopping broker"); stopBroker(); + LOGGER.debug("Stopped broker"); _failoverComplete.await(30, TimeUnit.SECONDS); assertEquals("failoverLatch was not decremented in given timeframe", @@ -138,18 +141,6 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL } } - public void onException(JMSException e) - { - if (e.getLinkedException() instanceof AMQDisconnectedException || e.getLinkedException() instanceof AMQConnectionClosedException) - { - _logger.debug("Received AMQDisconnectedException"); - _failoverComplete.countDown(); - } - else - { - _logger.error("Unexpected underlying exception", e.getLinkedException()); - } - } /** * Test that setting 'nofailover' as the failover policy does not result in @@ -200,13 +191,11 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL } catch (Exception e) { - System.err.println(e.getMessage()); - e.printStackTrace(); + LOGGER.error("Exception whilst starting broker", e); } } }); - brokerStart.start(); long start = System.currentTimeMillis(); @@ -260,11 +249,17 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL } } - public void stopBroker(int port) throws Exception + @Override + public void onException(JMSException e) { - if (isBrokerPresent(port)) + if (e.getLinkedException() instanceof AMQDisconnectedException || e.getLinkedException() instanceof AMQConnectionClosedException) + { + LOGGER.debug("Received AMQDisconnectedException"); + _failoverComplete.countDown(); + } + else { - super.stopBroker(port); + LOGGER.error("Unexpected underlying exception", e.getLinkedException()); } } |