diff options
Diffstat (limited to 'java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java')
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java | 123 |
1 files changed, 53 insertions, 70 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java b/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java index 470fcefae3..ec222ff03d 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java +++ b/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java @@ -20,40 +20,58 @@ */ 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 junit.framework.TestCase; -import org.apache.qpid.AMQConnectionClosedException; import org.apache.qpid.AMQDisconnectedException; 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.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.url.URLSyntaxException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionListener +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import java.util.concurrent.CountDownLatch; + +public class FailoverMethodTest extends InternalBrokerBaseCase implements ExceptionListener { private CountDownLatch _failoverComplete = new CountDownLatch(1); protected static final Logger _logger = LoggerFactory.getLogger(FailoverMethodTest.class); + @Override + public void createBroker() throws Exception + { + super.createBroker(); + TransportConnection.createVMBroker(ApplicationRegistry.DEFAULT_INSTANCE); + } + @Override + public void stopBroker() + { + TransportConnection.killVMBroker(ApplicationRegistry.DEFAULT_INSTANCE); + super.stopBroker(); + } /** * Test that the round robin method has the correct delays. - * The first connection will work but the localhost connection should fail but the duration it takes + * The first connection to vm://:1 will work but the localhost connection should fail but the duration it takes * to report the failure is what is being tested. * + * @throws URLSyntaxException + * @throws InterruptedException + * @throws JMSException */ - public void testFailoverRoundRobinDelay() throws Exception + public void testFailoverRoundRobinDelay() throws URLSyntaxException, InterruptedException, JMSException { - //note: The first broker has no connect delay and the default 1 retry + //note: The VM 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() + + "'vm://:" + ApplicationRegistry.DEFAULT_INSTANCE + ";tcp://localhost:5670?connectdelay='2000',retries='3''"; AMQConnectionURL url = new AMQConnectionURL(connectionString); @@ -61,15 +79,13 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL try { long start = System.currentTimeMillis(); - AMQConnection connection = new AMQConnection(url); + AMQConnection connection = new AMQConnection(url, null); connection.setExceptionListener(this); stopBroker(); - _failoverComplete.await(30, TimeUnit.SECONDS); - assertEquals("failoverLatch was not decremented in given timeframe", - 0, _failoverComplete.getCount()); + _failoverComplete.await(); long end = System.currentTimeMillis(); @@ -96,24 +112,23 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL } } - public void testFailoverSingleDelay() throws Exception + public void testFailoverSingleDelay() throws URLSyntaxException, AMQVMBrokerCreationException, + InterruptedException, JMSException { - String connectionString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:" + getPort() + "?connectdelay='2000',retries='3''"; + String connectionString = "amqp://guest:guest@/test?brokerlist='vm://:1?connectdelay='2000',retries='3''"; AMQConnectionURL url = new AMQConnectionURL(connectionString); try { long start = System.currentTimeMillis(); - AMQConnection connection = new AMQConnection(url); + AMQConnection connection = new AMQConnection(url, null); connection.setExceptionListener(this); stopBroker(); - _failoverComplete.await(30, TimeUnit.SECONDS); - assertEquals("failoverLatch was not decremented in given timeframe", - 0, _failoverComplete.getCount()); + _failoverComplete.await(); long end = System.currentTimeMillis(); @@ -129,8 +144,8 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL assertTrue("Failover took less than 6 seconds", duration > 6000); // Ensure we don't have delays before initial connection and reconnection. - // We allow 3 second for initial connection and failover logic on top of 6s of sleep. - assertTrue("Failover took more than 9 seconds:(" + duration + ")", duration < 9000); + // We allow 1 second for initial connection and failover logic on top of 6s of sleep. + assertTrue("Failover took more than 7 seconds:(" + duration + ")", duration < 7000); } catch (AMQException e) { @@ -140,15 +155,11 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL public void onException(JMSException e) { - if (e.getLinkedException() instanceof AMQDisconnectedException || e.getLinkedException() instanceof AMQConnectionClosedException) + if (e.getLinkedException() instanceof AMQDisconnectedException) { _logger.debug("Received AMQDisconnectedException"); _failoverComplete.countDown(); } - else - { - _logger.error("Unexpected underlying exception", e.getLinkedException()); - } } /** @@ -157,37 +168,28 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL * * Test validates that there is a connection delay as required on initial * connection. + * + * @throws URLSyntaxException + * @throws AMQVMBrokerCreationException + * @throws InterruptedException + * @throws JMSException */ - public void testNoFailover() throws Exception + public void testNoFailover() throws URLSyntaxException, AMQVMBrokerCreationException, + InterruptedException, JMSException { - if (!isInternalBroker()) - { - // QPID-3359 - // These tests always used to be inVM tests, then QPID-2815, with removal of ivVM, - // converted the test to use QpidBrokerTestCase. However, since then we notice this - // test fails on slower CI boxes. It turns out the test design is *extremely* - // sensitive the length of time the broker takes to start up. - // - // Making the test a same-VM test to temporarily avoid the issue. In long term, test - // needs redesigned to avoid the issue. - return; - } - int CONNECT_DELAY = 2000; - String connectionString = "amqp://guest:guest@/test?brokerlist='tcp://localhost:" + getPort() + "?connectdelay='" + CONNECT_DELAY + "'," + + String connectionString = "amqp://guest:guest@/test?brokerlist='vm://:1?connectdelay='" + CONNECT_DELAY + "'," + "retries='3'',failover='nofailover'"; - AMQConnectionURL url = new AMQConnectionURL(connectionString); - Thread brokerStart = null; try { //Kill initial broker stopBroker(); //Create a thread to start the broker asynchronously - brokerStart = new Thread(new Runnable() + Thread brokerStart = new Thread(new Runnable() { public void run() { @@ -196,7 +198,7 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL //Wait before starting broker // The wait should allow atleast 1 retries to fail before broker is ready Thread.sleep(750); - startBroker(); + createBroker(); } catch (Exception e) { @@ -210,8 +212,9 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL brokerStart.start(); long start = System.currentTimeMillis(); + //Start the connection so it will use the retries - AMQConnection connection = new AMQConnection(url); + AMQConnection connection = new AMQConnection(url, null); long end = System.currentTimeMillis(); @@ -225,16 +228,13 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL //Ensure we collect the brokerStart thread brokerStart.join(); - brokerStart = null; start = System.currentTimeMillis(); //Kill connection stopBroker(); - _failoverComplete.await(30, TimeUnit.SECONDS); - assertEquals("failoverLatch was not decremented in given timeframe", - 0, _failoverComplete.getCount()); + _failoverComplete.await(); end = System.currentTimeMillis(); @@ -249,23 +249,6 @@ public class FailoverMethodTest extends QpidBrokerTestCase implements ExceptionL { fail(e.getMessage()); } - finally - { - // Guard against the case where the broker took too long to start - // and the initial connection failed to be formed. - if (brokerStart != null) - { - brokerStart.join(); - } - } - } - - public void stopBroker(int port) throws Exception - { - if (isBrokerPresent(port)) - { - super.stopBroker(port); - } } } |