You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2009/03/04 23:40:00 UTC

svn commit: r750203 - in /qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test: client/failover/FailoverTest.java utils/FailoverBaseCase.java

Author: rajith
Date: Wed Mar  4 22:40:00 2009
New Revision: 750203

URL: http://svn.apache.org/viewvc?rev=750203&view=rev
Log:
This is related QPID-1640
This includes a the failover test run in a loop.

Modified:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java?rev=750203&r1=750202&r2=750203&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/client/failover/FailoverTest.java Wed Mar  4 22:40:00 2009
@@ -50,8 +50,8 @@
     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 @@
         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 @@
     {
         try
         {
-            connnection.close();
+            connection.close();
         }
         catch (Exception e)
         {
@@ -193,7 +193,7 @@
         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 @@
             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 @@
         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 @@
         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)
     {
     }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java?rev=750203&r1=750202&r2=750203&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java Wed Mar  4 22:40:00 2009
@@ -25,22 +25,29 @@
 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 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 @@
     
     protected void setFailingPort(int p)
     {
-        if (_broker.equals(VM))
-        {
-            FAILING_VM_PORT = p;
-        }
-        else
-        {
-            FAILING_PORT = p;
-        }
+        failingPort = p;
     }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org