summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorRajith Muditha Attapattu <rajith@apache.org>2009-03-04 22:40:00 +0000
committerRajith Muditha Attapattu <rajith@apache.org>2009-03-04 22:40:00 +0000
commit4fb58c0ae58ad53644482249b96efbcb26c11264 (patch)
tree31b203d776f7f9489cb359dacfd9eb6733eada39 /java
parentfd6337ce1b4658da62bb3e1dfe067f9d78457bb6 (diff)
downloadqpid-python-4fb58c0ae58ad53644482249b96efbcb26c11264.tar.gz
This is related QPID-1640
This includes a the failover test run in a loop. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@750203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java73
-rw-r--r--java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java36
2 files changed, 80 insertions, 29 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java b/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
index 4c4ef0320c..b7ae911a49 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
@@ -50,8 +50,8 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
private static final String QUEUE = "queue";
private static final int DEFAULT_NUM_MESSAGES = 10;
private static final int DEFAULT_SEED = 20080921;
- private int numMessages = 0;
- private Connection connnection;
+ protected int numMessages = 0;
+ protected Connection connection;
private Session producerSession;
private Queue queue;
private MessageProducer producer;
@@ -74,20 +74,20 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
seed = Integer.getInteger("profile.failoverRandomSeed",DEFAULT_SEED);
rand = new Random(seed);
- connnection = getConnection();
- ((AMQConnection) connnection).setConnectionListener(this);
- connnection.start();
+ connection = getConnection();
+ ((AMQConnection) connection).setConnectionListener(this);
+ connection.start();
failoverComplete = new CountDownLatch(1);
}
- private void init(boolean transacted, int mode) throws JMSException, NamingException
+ protected void init(boolean transacted, int mode) throws JMSException, NamingException
{
queue = (Queue) getInitialContext().lookup(QUEUE);
- consumerSession = connnection.createSession(transacted, mode);
+ consumerSession = connection.createSession(transacted, mode);
consumer = consumerSession.createConsumer(queue);
- producerSession = connnection.createSession(transacted, mode);
+ producerSession = connection.createSession(transacted, mode);
producer = producerSession.createProducer(queue);
}
@@ -96,7 +96,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
{
try
{
- connnection.close();
+ connection.close();
}
catch (Exception e)
{
@@ -193,7 +193,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
runP2PFailover(totalMessages,consumeAll, produceAll , transacted);
}
- private void runP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException
+ protected void runP2PFailover(int totalMessages, boolean consumeAll, boolean produceAll , boolean transacted) throws JMSException, NamingException
{
Message msg = null;
int toProduce = totalMessages;
@@ -281,7 +281,7 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
failure = e;
}
assertNotNull("Exception should be thrown", failure);
- }
+ }
/**
* The client used to have a fixed timeout of 4 minutes after which failover would no longer work.
@@ -302,12 +302,12 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
details.setProperty(BrokerDetails.OPTIONS_RETRY, String.valueOf(RETRIES));
details.setProperty(BrokerDetails.OPTIONS_CONNECT_DELAY, String.valueOf(DELAY));
- connnection = new AMQConnection(connectionURL, null);
+ connection = new AMQConnection(connectionURL, null);
- ((AMQConnection) connnection).setConnectionListener(this);
+ ((AMQConnection) connection).setConnectionListener(this);
//Start the connection
- connnection.start();
+ connection.start();
long FAILOVER_DELAY = (RETRIES * DELAY);
@@ -321,6 +321,51 @@ public class FailoverTest extends FailoverBaseCase implements ConnectionListener
assertTrue("Failover did not take long enough", System.nanoTime() > failTime);
}
+
+ /**
+ * The idea is to run a failover test in a loop by failing over
+ * to the other broker each time.
+ */
+ public void testFailoverInALoop() throws Exception
+ {
+ if (!CLUSTERED)
+ {
+ return;
+ }
+
+ int iterations = Integer.getInteger("profile.failoverIterations",0);
+ boolean b = true;
+ int failingPort = getFailingPort();
+ init(false, Session.AUTO_ACKNOWLEDGE);
+ for (int i=0; i < iterations; i++)
+ {
+ _logger.debug("===================================================================");
+ _logger.debug("Failover In a loop : iteration number " + i);
+ _logger.debug("===================================================================");
+
+ runP2PFailover(numMessages, false,false, false);
+ startBroker(failingPort);
+ if (b)
+ {
+ failingPort = getFailingPort()-1;
+ b = false;
+ }
+ else
+ {
+ failingPort = getFailingPort()+1;
+ b = true;
+ }
+ setFailingPort(failingPort);
+ }
+ //To prevent any failover logic being initiaed when we shutdown the brokers.
+ connection.close();
+
+ // Shutdown the brokers
+ stopBroker(getFailingPort());
+ stopBroker(b?getFailingPort()+1 : getFailingPort()-1);
+
+ }
+
public void bytesSent(long count)
{
}
diff --git a/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java b/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java
index 159bc04502..b185ec60a2 100644
--- a/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java
+++ b/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java
@@ -25,22 +25,29 @@ import javax.jms.Connection;
public class FailoverBaseCase extends QpidTestCase
{
- protected int FAILING_VM_PORT = 2;
- protected int FAILING_PORT = 5673;
+ public static int FAILING_VM_PORT = 2;
+ public static int FAILING_PORT = 5673;
+ protected int failingPort;
+
private boolean failedOver = false;
- protected int getFailingPort()
+ public FailoverBaseCase()
{
if (_broker.equals(VM))
{
- return FAILING_VM_PORT;
+ failingPort = FAILING_VM_PORT;
}
else
{
- return FAILING_PORT;
+ failingPort = FAILING_PORT;
}
}
+
+ protected int getFailingPort()
+ {
+ return failingPort;
+ }
protected void setUp() throws java.lang.Exception
{
@@ -64,10 +71,16 @@ public class FailoverBaseCase extends QpidTestCase
public void tearDown() throws Exception
{
- if (!failedOver)
+ int port;
+ if (_broker.equals(VM))
{
- stopBroker(getFailingPort());
+ port = FAILING_VM_PORT;
}
+ else
+ {
+ port = FAILING_PORT;
+ }
+ stopBroker(port);
super.tearDown();
}
@@ -90,13 +103,6 @@ public class FailoverBaseCase extends QpidTestCase
protected void setFailingPort(int p)
{
- if (_broker.equals(VM))
- {
- FAILING_VM_PORT = p;
- }
- else
- {
- FAILING_PORT = p;
- }
+ failingPort = p;
}
}