[jboss-cvs] JBoss Messaging SVN: r1795 - in trunk: src/main/org/jboss/jms/server/connectionfactory tests/src/org/jboss/test/messaging/jms/clustering

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 14 15:56:46 EST 2006


Author: timfox
Date: 2006-12-14 15:56:41 -0500 (Thu, 14 Dec 2006)
New Revision: 1795

Modified:
   trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
Log:
Now order cf array in server id order



Modified: trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2006-12-14 19:32:42 UTC (rev 1794)
+++ trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2006-12-14 20:56:41 UTC (rev 1795)
@@ -22,6 +22,10 @@
 package org.jboss.jms.server.connectionfactory;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -329,9 +333,11 @@
                throw new IllegalStateException("Cannot find cf with name " + uniqueName);
             }
             
+            List newDels = sortCFS(updatedReplicantMap.values());
+            
             ClientConnectionFactoryDelegate[] delArr = 
-               (ClientConnectionFactoryDelegate[])updatedReplicantMap.values().
-                  toArray(new ClientConnectionFactoryDelegate[updatedReplicantMap.size()]);
+               (ClientConnectionFactoryDelegate[])newDels.
+                  toArray(new ClientConnectionFactoryDelegate[newDels.size()]);
 
             del.setDelegates(delArr);
             
@@ -381,7 +387,7 @@
    {     
       FailoverMapper mapper = replicator.getFailoverMapper();
       failoverMap = mapper.generateMapping(nodeAddressMap.keySet());
-   }
+   }      
    
    /**
     * @param localDelegates - Map<Integer(nodeId) - ClientConnectionFactoryDelegate>
@@ -390,9 +396,23 @@
       throws Exception
    {
       if (trace) { log.trace(this + " updating failover delegates, map size " + localDelegates.size()); }
+      
+      //First sort the local delegates in order of server id
+      List localDels = sortCFS(localDelegates.values());
+      
+      Collections.sort(localDels,
+                       new Comparator()
+                       {
+                           public int compare(Object obj1, Object obj2)
+                           {
+                              ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)obj1;
+                              ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)obj2;
+                              return del1.getServerID() - del2.getServerID();
+                           } 
+                       });
 
       ClientConnectionFactoryDelegate[] delArr = 
-         (ClientConnectionFactoryDelegate[])localDelegates.values().
+         (ClientConnectionFactoryDelegate[])localDels.
             toArray(new ClientConnectionFactoryDelegate[localDelegates.size()]);
 
       // If the map is not cached - generate it now
@@ -418,20 +438,20 @@
 
       ClientConnectionFactoryDelegate mainDelegate = null;
       
-      for(Iterator i = localDelegates.values().iterator(); i.hasNext();)
+      for(Iterator i = localDels.iterator(); i.hasNext();)
       {
          ClientConnectionFactoryDelegate del = (ClientConnectionFactoryDelegate)i.next();
-            
-          if (del.getServerID() == this.serverPeer.getServerPeerID())
-          {
-             // sanity check
-             if (mainDelegate != null)
-             {
-                throw new IllegalStateException("There are two servers with serverID=" +
-                   this.serverPeer.getServerPeerID() + ", verify your clustering configuration");
-             }
-             mainDelegate = del;
-          }
+         
+         if (del.getServerID() == this.serverPeer.getServerPeerID())
+         {
+            // sanity check
+            if (mainDelegate != null)
+            {
+               throw new IllegalStateException("There are two servers with serverID=" +
+                        this.serverPeer.getServerPeerID() + ", verify your clustering configuration");
+            }
+            mainDelegate = del;
+         }
       }
             
       return new ClusteredClientConnectionFactoryDelegate(mainDelegate, delArr, failoverMap);
@@ -455,6 +475,27 @@
          }
       }
    }
+   
+   /*
+    * Sort the collection of delegates in order of server id
+    */
+   private List sortCFS(Collection delegates)
+   {
+      List localDels = new ArrayList(delegates);
+      
+      Collections.sort(localDels,
+                       new Comparator()
+                       {
+                           public int compare(Object obj1, Object obj2)
+                           {
+                              ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)obj1;
+                              ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)obj2;
+                              return del1.getServerID() - del2.getServerID();
+                           } 
+                       });
+      
+      return localDels;
+   }
 
    // Inner classes -------------------------------------------------
 }

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-14 19:32:42 UTC (rev 1794)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-14 20:56:41 UTC (rev 1795)
@@ -356,9 +356,9 @@
          
          log.info("cf2 serverid=" + cf2.getServerID());
          
-         assertEquals(2, cf1.getServerID());
+         assertEquals(0, cf1.getServerID());
          
-         assertEquals(0, cf2.getServerID());
+         assertEquals(2, cf2.getServerID());
          
          
          assertEquals(2, failoverMap.size());
@@ -401,11 +401,11 @@
          
          log.info("cf3 serverid=" + cf3.getServerID());
          
-         assertEquals(2, cf1.getServerID());
+         assertEquals(0, cf1.getServerID());
          
-         assertEquals(0, cf2.getServerID());
+         assertEquals(1, cf2.getServerID());
          
-         assertEquals(1, cf3.getServerID());
+         assertEquals(2, cf3.getServerID());
          
          
          assertEquals(3, failoverMap.size());
@@ -468,16 +468,12 @@
             
       try
       {      
-         conn = factory.createConnection(); //connection on server 2
-         
-         conn.close();
-         
          conn = factory.createConnection(); //connection on server 0
          
          conn.close();
          
-         conn = factory.createConnection(); // connection on server 1
-         
+         conn = factory.createConnection(); //connection on server 1
+                          
          JBossConnection jbc = (JBossConnection)conn;
          
          ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
@@ -567,369 +563,369 @@
    }
    
    
-   public void testFailoverWithUnackedMessagesClientAcknowledge() throws Exception
-   {
-      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
-      ClusteredClientConnectionFactoryDelegate delegate =
-         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-
-      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
-      assertEquals(3, nodeIDView.size());
-      
-      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-      
-      ClientConnectionFactoryDelegate cf1 = delegates[0];
-      
-      ClientConnectionFactoryDelegate cf2 = delegates[1];
-      
-      ClientConnectionFactoryDelegate cf3 = delegates[2];
-      
-      int server0Id = cf1.getServerID();
-      
-      int server1Id = cf2.getServerID();
-      
-      int server2Id = cf3.getServerID();
-      
-      log.info("server 0 id: " + server0Id);
-      
-      log.info("server 1 id: " + server1Id);
-      
-      log.info("server 2 id: " + server2Id);
-                  
-      Map failoverMap = delegate.getFailoverMap();
-      
-      log.info(failoverMap.get(new Integer(server0Id)));
-      log.info(failoverMap.get(new Integer(server1Id)));
-      log.info(failoverMap.get(new Integer(server2Id)));
-      
-      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
-      
-      // server 1 should failover onto server 2
-      
-      assertEquals(server2Id, server1FailoverId);
-      
-      Connection conn = null;
-      
-      boolean killed = false;
-      
-      try
-      {      
-         conn = factory.createConnection(); //connection on server 1
-         
-         conn.close();
-         
-         conn = factory.createConnection(); //connection on server 2
-         
-         JBossConnection jbc = (JBossConnection)conn;
-         
-         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
-         
-         ConnectionState state = (ConnectionState)del.getState();
-         
-         int initialServerID = state.getServerID();
-         
-         assertEquals(2, initialServerID);
-                           
-         Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-         
-         MessageProducer prod = sess.createProducer(queue[1]);
-         
-         MessageConsumer cons = sess.createConsumer(queue[1]);
-         
-         final int NUM_MESSAGES = 100;
-         
-         for (int i = 0; i < NUM_MESSAGES; i++)
-         {
-            TextMessage tm = sess.createTextMessage("message:" + i);
-            
-            prod.send(tm);
-         }
-         
-         conn.start();
-         
-         //Now consume half of the messages but don't ack them these will end up in 
-         //client side toAck list
-         
-         for (int i = 0; i < NUM_MESSAGES / 2; i++)
-         {
-            TextMessage tm = (TextMessage)cons.receive(500);
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         //So now, messages should be in queue[1] on server 1
-         //So we now kill server 1
-         //Which should cause transparent failover of connection conn onto server 1
-         
-         log.info("************ KILLING (CRASHING) SERVER 1");
-         
-         ServerManagement.kill(1);
-         
-         killed = true;
-         
-         log.info("killed server, now waiting");
-         
-         Thread.sleep(10000);
-         
-         log.info("done wait");
-         
-         state = (ConnectionState)del.getState();
-         
-         int finalServerID = state.getServerID();
-         
-         log.info("final server id= " + finalServerID);
-         
-         //server id should now be 2
-         
-         assertEquals(2, finalServerID);
-         
-         conn.start();
-         
-         //Now should be able to consume the rest of the messages
-         
-         log.info("here1");
-         
-         TextMessage tm = null;
-         
-         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
-         {
-            tm = (TextMessage)cons.receive(500);
-                                    
-            log.info("message is " + tm.getText());
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         log.info("here2");
-         
-         //Now should be able to acknowledge them
-         
-         tm.acknowledge();
-         
-         //Now check there are no more messages there
-         sess.close();
-         
-         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         cons = sess.createConsumer(queue[1]);
-         
-         Message m = cons.receive(500);
-         
-         assertNull(m);
-         
-         log.info("got to end of test");
-      }
-      finally
-      {         
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-            }
-         }
-         
-         // Resurrect dead server
-         if (killed)
-         {
-            ServerManagement.spawn(1);
-         }
-      }
-      
-   }
+//   public void testFailoverWithUnackedMessagesClientAcknowledge() throws Exception
+//   {
+//      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
+//      
+//      ClusteredClientConnectionFactoryDelegate delegate =
+//         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+//
+//      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
+//      assertEquals(3, nodeIDView.size());
+//      
+//      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+//      
+//      ClientConnectionFactoryDelegate cf1 = delegates[0];
+//      
+//      ClientConnectionFactoryDelegate cf2 = delegates[1];
+//      
+//      ClientConnectionFactoryDelegate cf3 = delegates[2];
+//      
+//      int server0Id = cf1.getServerID();
+//      
+//      int server1Id = cf2.getServerID();
+//      
+//      int server2Id = cf3.getServerID();
+//      
+//      log.info("server 0 id: " + server0Id);
+//      
+//      log.info("server 1 id: " + server1Id);
+//      
+//      log.info("server 2 id: " + server2Id);
+//                  
+//      Map failoverMap = delegate.getFailoverMap();
+//      
+//      log.info(failoverMap.get(new Integer(server0Id)));
+//      log.info(failoverMap.get(new Integer(server1Id)));
+//      log.info(failoverMap.get(new Integer(server2Id)));
+//      
+//      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
+//      
+//      // server 1 should failover onto server 2
+//      
+//      assertEquals(server2Id, server1FailoverId);
+//      
+//      Connection conn = null;
+//      
+//      boolean killed = false;
+//      
+//      try
+//      {      
+//         conn = factory.createConnection(); //connection on server 1
+//         
+//         conn.close();
+//         
+//         conn = factory.createConnection(); //connection on server 2
+//         
+//         JBossConnection jbc = (JBossConnection)conn;
+//         
+//         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
+//         
+//         ConnectionState state = (ConnectionState)del.getState();
+//         
+//         int initialServerID = state.getServerID();
+//         
+//         assertEquals(2, initialServerID);
+//                           
+//         Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+//         
+//         MessageProducer prod = sess.createProducer(queue[1]);
+//         
+//         MessageConsumer cons = sess.createConsumer(queue[1]);
+//         
+//         final int NUM_MESSAGES = 100;
+//         
+//         for (int i = 0; i < NUM_MESSAGES; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("message:" + i);
+//            
+//            prod.send(tm);
+//         }
+//         
+//         conn.start();
+//         
+//         //Now consume half of the messages but don't ack them these will end up in 
+//         //client side toAck list
+//         
+//         for (int i = 0; i < NUM_MESSAGES / 2; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons.receive(500);
+//            
+//            assertNotNull(tm);
+//            
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//         
+//         //So now, messages should be in queue[1] on server 1
+//         //So we now kill server 1
+//         //Which should cause transparent failover of connection conn onto server 1
+//         
+//         log.info("************ KILLING (CRASHING) SERVER 1");
+//         
+//         ServerManagement.kill(1);
+//         
+//         killed = true;
+//         
+//         log.info("killed server, now waiting");
+//         
+//         Thread.sleep(10000);
+//         
+//         log.info("done wait");
+//         
+//         state = (ConnectionState)del.getState();
+//         
+//         int finalServerID = state.getServerID();
+//         
+//         log.info("final server id= " + finalServerID);
+//         
+//         //server id should now be 2
+//         
+//         assertEquals(2, finalServerID);
+//         
+//         conn.start();
+//         
+//         //Now should be able to consume the rest of the messages
+//         
+//         log.info("here1");
+//         
+//         TextMessage tm = null;
+//         
+//         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
+//         {
+//            tm = (TextMessage)cons.receive(500);
+//                                    
+//            log.info("message is " + tm.getText());
+//            
+//            assertNotNull(tm);
+//            
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//         
+//         log.info("here2");
+//         
+//         //Now should be able to acknowledge them
+//         
+//         tm.acknowledge();
+//         
+//         //Now check there are no more messages there
+//         sess.close();
+//         
+//         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         
+//         cons = sess.createConsumer(queue[1]);
+//         
+//         Message m = cons.receive(500);
+//         
+//         assertNull(m);
+//         
+//         log.info("got to end of test");
+//      }
+//      finally
+//      {         
+//         if (conn != null)
+//         {
+//            try
+//            {
+//               conn.close();
+//            }
+//            catch (Exception e)
+//            {
+//               e.printStackTrace();
+//            }
+//         }
+//         
+//         // Resurrect dead server
+//         if (killed)
+//         {
+//            ServerManagement.spawn(1);
+//         }
+//      }
+//      
+//   }
+//   
+//   public void testFailoverWithUnackedMessagesTransactional() throws Exception
+//   {
+//      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
+//      
+//      ClusteredClientConnectionFactoryDelegate delegate =
+//         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+//
+//      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
+//      assertEquals(3, nodeIDView.size());
+//      
+//      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+//      
+//      ClientConnectionFactoryDelegate cf1 = delegates[0];
+//      
+//      ClientConnectionFactoryDelegate cf2 = delegates[1];
+//      
+//      ClientConnectionFactoryDelegate cf3 = delegates[2];
+//      
+//      int server0Id = cf1.getServerID();
+//      
+//      int server1Id = cf2.getServerID();
+//      
+//      int server2Id = cf3.getServerID();
+//      
+//      log.info("server 0 id: " + server0Id);
+//      
+//      log.info("server 1 id: " + server1Id);
+//      
+//      log.info("server 2 id: " + server2Id);
+//                  
+//      Map failoverMap = delegate.getFailoverMap();
+//      
+//      log.info(failoverMap.get(new Integer(server0Id)));
+//      log.info(failoverMap.get(new Integer(server1Id)));
+//      log.info(failoverMap.get(new Integer(server2Id)));
+//      
+//      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
+//      
+//      // server 1 should failover onto server 2
+//      
+//      assertEquals(server2Id, server1FailoverId);
+//      
+//      Connection conn = null;
+//      
+//      boolean killed = false;
+//      
+//      try
+//      {      
+//         //Get a connection on server 1
+//         conn = factory.createConnection(); //connection on server 0
+//         
+//         conn.close();
+//         
+//         conn = factory.createConnection(); //connection on server 1
+//         
+//         JBossConnection jbc = (JBossConnection)conn;
+//         
+//         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
+//         
+//         ConnectionState state = (ConnectionState)del.getState();
+//         
+//         int initialServerID = state.getServerID();
+//         
+//         assertEquals(1, initialServerID);
+//                           
+//         Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+//         
+//         MessageProducer prod = sess.createProducer(queue[1]);
+//         
+//         MessageConsumer cons = sess.createConsumer(queue[1]);
+//         
+//         final int NUM_MESSAGES = 100;
+//         
+//         for (int i = 0; i < NUM_MESSAGES; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("message:" + i);
+//            
+//            prod.send(tm);
+//         }
+//         
+//         sess.commit();
+//         
+//         conn.start();
+//         
+//         //Now consume half of the messages but don't commit them these will end up in 
+//         //client side resource manager
+//         
+//         for (int i = 0; i < NUM_MESSAGES / 2; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons.receive(500);
+//            
+//            assertNotNull(tm);
+//            
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//         
+//         //So now, messages should be in queue[1] on server 1
+//         //So we now kill server 1
+//         //Which should cause transparent failover of connection conn onto server 1
+//         
+//         log.info("************ KILLING (CRASHING) SERVER 1");
+//         
+//         ServerManagement.kill(1);
+//         
+//         killed = true;
+//
+//         log.info("killed server, now waiting");
+//         
+//         Thread.sleep(5000);
+//         
+//         log.info("done wait");
+//         
+//         state = (ConnectionState)del.getState();
+//         
+//         int finalServerID = state.getServerID();
+//         
+//         log.info("final server id= " + finalServerID);
+//         
+//         //server id should now be 2
+//         
+//         assertEquals(2, finalServerID);
+//         
+//         conn.start();
+//         
+//         //Now should be able to consume the rest of the messages
+//         
+//         log.info("here1");
+//         
+//         TextMessage tm = null;
+//         
+//         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
+//         {
+//            tm = (TextMessage)cons.receive(500);
+//                                    
+//            log.info("message is " + tm.getText());
+//            
+//            assertNotNull(tm);
+//            
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//         
+//         log.info("here2");
+//         
+//         //Now should be able to commit them
+//         
+//         sess.commit();
+//         
+//         //Now check there are no more messages there
+//         sess.close();
+//         
+//         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         
+//         cons = sess.createConsumer(queue[1]);
+//         
+//         Message m = cons.receive(500);
+//         
+//         assertNull(m);
+//         
+//         log.info("got to end of test");
+//      }
+//      finally
+//      {         
+//         if (conn != null)
+//         {
+//            try
+//            {
+//               conn.close();
+//            }
+//            catch (Exception e)
+//            {
+//               e.printStackTrace();
+//            }
+//         }
+//         
+//         if (killed)
+//         {
+//            ServerManagement.spawn(1);
+//         }
+//      }
+//      
+//   }
    
-   public void testFailoverWithUnackedMessagesTransactional() throws Exception
-   {
-      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
-      ClusteredClientConnectionFactoryDelegate delegate =
-         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-
-      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
-      assertEquals(3, nodeIDView.size());
-      
-      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-      
-      ClientConnectionFactoryDelegate cf1 = delegates[0];
-      
-      ClientConnectionFactoryDelegate cf2 = delegates[1];
-      
-      ClientConnectionFactoryDelegate cf3 = delegates[2];
-      
-      int server0Id = cf1.getServerID();
-      
-      int server1Id = cf2.getServerID();
-      
-      int server2Id = cf3.getServerID();
-      
-      log.info("server 0 id: " + server0Id);
-      
-      log.info("server 1 id: " + server1Id);
-      
-      log.info("server 2 id: " + server2Id);
-                  
-      Map failoverMap = delegate.getFailoverMap();
-      
-      log.info(failoverMap.get(new Integer(server0Id)));
-      log.info(failoverMap.get(new Integer(server1Id)));
-      log.info(failoverMap.get(new Integer(server2Id)));
-      
-      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
-      
-      // server 1 should failover onto server 2
-      
-      assertEquals(server2Id, server1FailoverId);
-      
-      Connection conn = null;
-      
-      boolean killed = false;
-      
-      try
-      {      
-         //Get a connection on server 1
-         conn = factory.createConnection(); //connection on server 0
-         
-         conn.close();
-         
-         conn = factory.createConnection(); //connection on server 1
-         
-         JBossConnection jbc = (JBossConnection)conn;
-         
-         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
-         
-         ConnectionState state = (ConnectionState)del.getState();
-         
-         int initialServerID = state.getServerID();
-         
-         assertEquals(1, initialServerID);
-                           
-         Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
-         
-         MessageProducer prod = sess.createProducer(queue[1]);
-         
-         MessageConsumer cons = sess.createConsumer(queue[1]);
-         
-         final int NUM_MESSAGES = 100;
-         
-         for (int i = 0; i < NUM_MESSAGES; i++)
-         {
-            TextMessage tm = sess.createTextMessage("message:" + i);
-            
-            prod.send(tm);
-         }
-         
-         sess.commit();
-         
-         conn.start();
-         
-         //Now consume half of the messages but don't commit them these will end up in 
-         //client side resource manager
-         
-         for (int i = 0; i < NUM_MESSAGES / 2; i++)
-         {
-            TextMessage tm = (TextMessage)cons.receive(500);
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         //So now, messages should be in queue[1] on server 1
-         //So we now kill server 1
-         //Which should cause transparent failover of connection conn onto server 1
-         
-         log.info("************ KILLING (CRASHING) SERVER 1");
-         
-         ServerManagement.kill(1);
-         
-         killed = true;
-
-         log.info("killed server, now waiting");
-         
-         Thread.sleep(5000);
-         
-         log.info("done wait");
-         
-         state = (ConnectionState)del.getState();
-         
-         int finalServerID = state.getServerID();
-         
-         log.info("final server id= " + finalServerID);
-         
-         //server id should now be 2
-         
-         assertEquals(2, finalServerID);
-         
-         conn.start();
-         
-         //Now should be able to consume the rest of the messages
-         
-         log.info("here1");
-         
-         TextMessage tm = null;
-         
-         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
-         {
-            tm = (TextMessage)cons.receive(500);
-                                    
-            log.info("message is " + tm.getText());
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         log.info("here2");
-         
-         //Now should be able to commit them
-         
-         sess.commit();
-         
-         //Now check there are no more messages there
-         sess.close();
-         
-         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         cons = sess.createConsumer(queue[1]);
-         
-         Message m = cons.receive(500);
-         
-         assertNull(m);
-         
-         log.info("got to end of test");
-      }
-      finally
-      {         
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-            }
-         }
-         
-         if (killed)
-         {
-            ServerManagement.spawn(1);
-         }
-      }
-      
-   }
    
-   
 // public void testConnectionFactoryConnect() throws Exception
 // {
 // try




More information about the jboss-cvs-commits mailing list