[jboss-cvs] JBoss Messaging SVN: r1848 - in trunk/tests: . src/org/jboss/test/messaging/jms/clustering src/org/jboss/test/messaging/jms/clustering/base

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 22 11:26:53 EST 2006


Author: clebert.suconic at jboss.com
Date: 2006-12-22 11:26:50 -0500 (Fri, 22 Dec 2006)
New Revision: 1848

Modified:
   trunk/tests/build.xml
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-696 - Adding testcase

Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml	2006-12-22 10:23:27 UTC (rev 1847)
+++ trunk/tests/build.xml	2006-12-22 16:26:50 UTC (rev 1848)
@@ -69,6 +69,7 @@
 
    <!-- Clustering tests -->
    <property name="clustering.tests.database" value="mysql"/>
+   <property name ="test-mask" value="*Test"/>
 
    <!--
         Default remoting configuration (must be overrided by tasks that need it set otherwise).
@@ -816,7 +817,7 @@
             <formatter classname="org.jboss.test.messaging.tools.ant.JUnitTestSuiteListener"/>
 
             <fileset dir="${build.tests.classes}">
-               <include name="**/jms/clustering/*Test.class"/>
+               <include name="**/jms/clustering/${test-mask}.class"/>
             </fileset>
          </batchtest>
       </junit>

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-22 10:23:27 UTC (rev 1847)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-22 16:26:50 UTC (rev 1848)
@@ -94,6 +94,60 @@
       conn.close();
    }
 
+   /**
+    * This test was created as per http://jira.jboss.org/jira/browse/JBMESSAGING-696.
+    */
+   public void testCloseOnFailover() throws Exception
+   {
+      JBossConnectionFactory factory = (JBossConnectionFactory) ic[0].lookup("/ConnectionFactory");
+
+      Connection conn1 = factory.createConnection();
+      Connection conn2 = factory.createConnection();
+      Connection conn3 = factory.createConnection();
+
+      Connection[] conn = new Connection[]{conn1, conn2, conn3};
+
+      log.info("Connection delegate information after creation");
+      for (int i = 0; i < conn.length; i++)
+      {
+         log.info("conn" + i + ".serverid=" + getServerId(conn[i]) + " conn" + i + ".ObjectID=" + getObjectId(conn[i])
+            + " locatorURL=" + getLocatorURL(conn[i]));
+      }
+
+      log.info("Killing server 1 and waiting 30 seconds for failover to kick in on client (from Lease)");
+      ServerManagement.kill(1);
+      Thread.sleep(30000);
+
+      log.info("Connection delegate information after failover");
+      for (int i = 0; i < conn.length; i++)
+      {
+         log.info("conn" + i + ".serverid=" + getServerId(conn[i]) + " conn" + i + ".ObjectID=" + getObjectId(conn[i])
+            + " locatorURL=" + getLocatorURL(conn[i]));
+      }
+
+      ConnectionState state2 = getConnectionState(conn2);
+      ConnectionState state3 = getConnectionState(conn3);
+
+      assertNotSame(state2.getRemotingConnection(), state3.getRemotingConnection());
+      assertNotSame(state2.getRemotingConnection().getInvokingClient(), state3.getRemotingConnection().getInvokingClient());
+
+
+
+      conn1.close();
+      assertNotNull(state2.getRemotingConnection());
+      assertNotNull(state2.getRemotingConnection().getInvokingClient().getInvoker());
+      assertTrue(state2.getRemotingConnection().getInvokingClient().getInvoker().isConnected());
+      conn2.close();
+
+      log.info("Closing connection 3 now");
+
+      assertNotNull(state3.getRemotingConnection());
+      assertNotNull(state3.getRemotingConnection().getInvokingClient().getInvoker());
+      assertTrue(state3.getRemotingConnection().getInvokingClient().getInvoker().isConnected());
+      // When I created the testcase this was failing, throwing exceptions. This was basically why I created this testcase
+      conn3.close();
+   }
+
    /*
     * Test that connections created using a clustered connection factory are created round robin on
     * different servers

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java	2006-12-22 10:23:27 UTC (rev 1847)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java	2006-12-22 16:26:50 UTC (rev 1848)
@@ -130,6 +130,50 @@
       super.tearDown();
    }
 
+   protected String getLocatorURL(Connection conn)
+   {
+      return getConnectionState(conn).getRemotingConnection().getInvokingClient().getInvoker().getLocator().getLocatorURI();
+   }
+
+   protected int getServerId(Connection conn)
+   {
+      return getConnectionState(conn).getServerID();
+   }
+
+   protected int getObjectId(Connection conn)
+   {
+      return ((DelegateSupport) ((JBossConnection) conn).
+         getDelegate()).getID();
+   }
+
+   protected ConnectionState getConnectionState(Connection conn)
+   {
+      return (ConnectionState) (((DelegateSupport) ((JBossConnection) conn).
+         getDelegate()).getState());
+   }
+
+   protected Connection createConnectionOnServer(ConnectionFactory factory, int serverId) throws Exception
+   {
+      int count=0;
+
+      while (true)
+      {
+         if (count++>10)
+            return null;
+
+         Connection connection = factory.createConnection();
+
+         if (getServerId(connection) == serverId)
+         {
+            return connection;
+         }
+         else
+         {
+            connection.close();
+         }
+      }
+   }
+
    // lookup for the connection with the right serverID
    // I'm using this method to find the proper serverId so I won't relay on loadBalancing policies on testcases
    protected Connection getConnection(Connection[] conn, int serverId) throws Exception




More information about the jboss-cvs-commits mailing list