[jboss-cvs] JBoss Messaging SVN: r1747 - in branches/Branch_Client_Failover_Experiment: src/main/org/jboss/jms/client/container src/main/org/jboss/jms/client/state tests/src/org/jboss/test/messaging/jms tests/src/org/jboss/test/messaging/jms/clustering

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Dec 9 15:00:31 EST 2006


Author: timfox
Date: 2006-12-09 15:00:24 -0500 (Sat, 09 Dec 2006)
New Revision: 1747

Modified:
   branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java
   branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/HAAspect.java
   branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java
   branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
   branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
Log:
connection close now automatically closes exceptionlistener



Modified: branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java	2006-12-09 18:57:09 UTC (rev 1746)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java	2006-12-09 20:00:24 UTC (rev 1747)
@@ -24,11 +24,13 @@
 import javax.jms.ExceptionListener;
 import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
+
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.jms.client.JBossConnectionMetaData;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.jms.client.state.ConnectionState;
+import org.jboss.jms.delegate.ConnectionDelegate;
 import org.jboss.jms.message.MessageIdGeneratorFactory;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.logging.Logger;
@@ -184,6 +186,16 @@
    {
       Object ret = invocation.invokeNext();
       
+      //Remove any exception listener
+      ConnectionState currentState = getConnectionState(invocation);
+      
+      Client client = getConnectionState(invocation).getRemotingConnection().getInvokingClient();
+      
+      if (currentState.isListenerAdded())
+      {
+         client.removeConnectionListener(this);
+      }
+            
       ConnectionState state = getConnectionState(invocation);
       
       // Finished with the connection - we need to shutdown callback server

Modified: branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/HAAspect.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/HAAspect.java	2006-12-09 18:57:09 UTC (rev 1746)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/HAAspect.java	2006-12-09 20:00:24 UTC (rev 1747)
@@ -111,7 +111,7 @@
          
          return invocation.invokeNext();
       }
-   }
+   }   
    
    //TODO this is currently hardcoded as round-robin, this should be made pluggable
    private synchronized ClientConnectionFactoryDelegate getDelegateRoundRobin()
@@ -173,8 +173,10 @@
       
       ConnectionState state = (ConnectionState)((DelegateSupport)connDelegate).getState();
       
-      state.getRemotingConnection().getInvokingClient().addConnectionListener(new Listener(connDelegate));
+      ConnectionListener listener = new Listener(connDelegate);
       
+      state.getRemotingConnection().getInvokingClient().addConnectionListener(listener);
+      
       return connDelegate;   
    }
 

Modified: branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java	2006-12-09 18:57:09 UTC (rev 1746)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java	2006-12-09 20:00:24 UTC (rev 1747)
@@ -21,10 +21,10 @@
   */
 package org.jboss.jms.client.state;
 
-import EDU.oswego.cs.dl.util.concurrent.SyncSet;
-import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
 import java.util.HashSet;
+
 import javax.jms.ExceptionListener;
+
 import org.jboss.jms.client.delegate.DelegateSupport;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
 import org.jboss.jms.delegate.ConnectionDelegate;
@@ -32,7 +32,11 @@
 import org.jboss.jms.server.Version;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.logging.Logger;
+import org.jboss.remoting.ConnectionListener;
 
+import EDU.oswego.cs.dl.util.concurrent.SyncSet;
+import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+
 /**
  * 
  * State corresponding to a connection. This state is acessible inside aspects/interceptors.
@@ -79,9 +83,8 @@
 
     /** This property used to be delcared on ConnectionAspect */
    private boolean listenerAdded;
-
-
-
+   
+   
    public ConnectionState(int serverID, ConnectionDelegate delegate,
                           JMSRemotingConnection remotingConnection, Version versionToUse,
                           ResourceManager rm, MessageIdGenerator gen)
@@ -221,7 +224,7 @@
     public void setListenerAdded(boolean listenerAdded)
     {
         this.listenerAdded = listenerAdded;
-    }
+    }    
 
     /** Connection doesn't have a parent */
     public HierarchicalState getParent()

Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2006-12-09 18:57:09 UTC (rev 1746)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2006-12-09 20:00:24 UTC (rev 1747)
@@ -379,7 +379,30 @@
       conn.close();
 
    }
-
+   
+   /*
+    * See http://jira.jboss.com/jira/browse/JBMESSAGING-635
+    * 
+    * This needs to be run remotely to see the exception
+    */
+   public void testConnectionListenerBug() throws Exception
+   {
+      for (int i = 0; i < 500; i++)
+      {
+         Connection conn = cf.createConnection();
+         
+         MyExceptionListener listener = new MyExceptionListener();
+         
+         conn.setExceptionListener(listener);
+         
+         conn.close();        
+         
+         //The problem with this test is I would need to capture the output and search
+         //for NullPointerException!!!
+                  
+      } 
+   }
+   
    // TODO - Decide if valid and uncomment or get rid of it!
 
 //   Commented out for now, since how can i make the server fail from a test?   

Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-09 18:57:09 UTC (rev 1746)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-09 20:00:24 UTC (rev 1747)
@@ -74,349 +74,349 @@
     * Test that connections created using a clustered connection factory are created round robin on
     * different servers
     */
-//   public void testRoundRobinConnectionCreation() throws Exception
-//   {
-//      JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
-//      
-//      ClusteredClientConnectionFactoryDelegate delegate =
-//         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//      
-//      log.info ("number of delegates = " + delegate.getDelegates().length);
-//      log.info ("number of servers = " + ServerManagement.getServer(0).getNumberOfNodesOnCluster());
-//      
-//      assertEquals(3, delegate.getDelegates().length);
-//      
-//      ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//      
-//      ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-//      
-//      ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-//      
-//      assertEquals(0, cf1.getServerId());
-//      
-//      assertEquals(1, cf2.getServerId());
-//      
-//      assertEquals(2, cf3.getServerId());
-//      
-//      assertEquals(3, ServerManagement.getServer(0).getNumberOfNodesOnCluster());
-//      
-//      Connection conn1 = null;
-//      
-//      Connection conn2 = null;
-//      
-//      Connection conn3 = null;
-//      
-//      Connection conn4 = null;
-//      
-//      Connection conn5 = null;
-//      
-//      try
-//      {         
-//         conn1 = factory.createConnection();
-//         
-//         conn2 = factory.createConnection();
-//         
-//         conn3 = factory.createConnection();
-//         
-//         conn4 = factory.createConnection();
-//         
-//         conn5 = factory.createConnection();
-//         
-//         ConnectionState state1 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn1).getDelegate()).getState());
-//         
-//         ConnectionState state2 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn2).getDelegate()).getState());
-//         
-//         ConnectionState state3 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn3).getDelegate()).getState());
-//         
-//         ConnectionState state4 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn4).getDelegate()).getState());
-//         
-//         ConnectionState state5 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn5).getDelegate()).getState());
-//         
-//         int serverID1 = state1.getServerID();
-//         
-//         int serverID2 = state2.getServerID();
-//         
-//         int serverID3 = state3.getServerID();
-//         
-//         int serverID4 = state4.getServerID();
-//         
-//         int serverID5 = state5.getServerID();
-//         
-//         log.info("server id 1: " + serverID1);
-//         
-//         log.info("server id 2: " + serverID2);
-//         
-//         log.info("server id 3: " + serverID3);
-//         
-//         log.info("server id 4: " + serverID4);
-//         
-//         log.info("server id 5: " + serverID5);
-//         
-//         assertEquals(0, serverID1);
-//         
-//         assertEquals(1, serverID2);
-//         
-//         assertEquals(2, serverID3);
-//         
-//         assertEquals(0, serverID4);
-//         
-//         assertEquals(1, serverID5);
-//      }
-//      finally
-//      {
-//         if (conn1 != null)
-//         {
-//            conn1.close();
-//         }
-//         
-//         if (conn2 != null)
-//         {
-//            conn2.close();
-//         }
-//         
-//         if (conn3 != null)
-//         {
-//            conn3.close();
-//         }
-//         
-//         if (conn4 != null)
-//         {
-//            conn4.close();
-//         }
-//         
-//         if (conn5 != null)
-//         {
-//            conn5.close();
-//         }
-//      }
-//      
-//   }
-// 
-//   /*
-//    * Test that the failover mapping is created correctly and updated properly when nodes leave
-//    * or join
-//    */
-//   public void testDefaultFailoverMap() throws Exception
-//   {     
-//      {
-//         JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
-//         
-//         ClusteredClientConnectionFactoryDelegate delegate =
-//            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//         
-//         assertEquals(3, ServerManagement.getServer(0).getNumberOfNodesOnCluster());
-//         
-//         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-//         
-//         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//         
-//         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-//         
-//         ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-//         
-//         //The order here depends on the order the servers were started in
-//         
-//         //If any servers get stopped and then started then the order will change
-//    
-//         log.info("cf1 serverid=" + cf1.getServerId());
-//         
-//         log.info("cf2 serverid=" + cf2.getServerId());
-//         
-//         log.info("cf3 serverid=" + cf3.getServerId());
-//         
-//         
-//         assertEquals(0, cf1.getServerId());
-//         
-//         assertEquals(1, cf2.getServerId());
-//         
-//         assertEquals(2, cf3.getServerId());
-//         
-//         Map failoverMap = delegate.getFailoverMap();
-//         
-//         assertEquals(3, delegates.length);
-//         
-//         assertEquals(3, failoverMap.size());
-//         
-//         // Default failover policy just chooses the node to the right
-//         
-//         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
-//         
-//         assertEquals(cf3.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
-//         
-//         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf3.getServerId()))).intValue());
-//      }
-//      
-//      //Now cleanly stop one of the servers
-//      
-//      
-//      log.info("************** STOPPING SERVER 0");
-//      ServerManagement.stop(0, true);
-//      
-//      log.info("server stopped");
-//      
-//      assertEquals(2, ServerManagement.getServer(1).getNumberOfNodesOnCluster());
-//      
-//      {         
-//         //Lookup another connection factory
-//         
-//         JBossConnectionFactory factory =  (JBossConnectionFactory )ic1.lookup("/ConnectionFactory");
-//         
-//         log.info("Got connection factory");
-//         
-//         ClusteredClientConnectionFactoryDelegate delegate =
-//            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//         
-//         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-//         
-//         Map failoverMap = delegate.getFailoverMap();
-//         
-//         log.info("Got failover map");
-//         
-//         assertEquals(2, delegates.length);
-//         
-//         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//         
-//         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-//         
-//         //Order here depends on order servers were started in
-//         
-//         log.info("cf1 serverid=" + cf1.getServerId());
-//         
-//         log.info("cf2 serverid=" + cf2.getServerId());
-//         
-//         assertEquals(1, cf1.getServerId());
-//         
-//         assertEquals(2, cf2.getServerId());
-//         
-//         
-//         assertEquals(2, failoverMap.size());
-//         
-//         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
-//         
-//         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
-//      }
-//      
-//      //Cleanly stop another server
-//      
-//      log.info("Server 1 is started: " + ServerManagement.getServer(1).isServerPeerStarted());
-//      
-//      ServerManagement.stop(1, true);
-//      
-//      assertEquals(1, ServerManagement.getServer(2).getNumberOfNodesOnCluster());
-//      
-//      {         
-//         //Lookup another connection factory
-//         
-//         JBossConnectionFactory factory =  (JBossConnectionFactory )ic2.lookup("/ConnectionFactory");
-//         
-//         ClusteredClientConnectionFactoryDelegate delegate =
-//            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//         
-//         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-//         
-//         Map failoverMap = delegate.getFailoverMap();
-//         
-//         assertEquals(1, delegates.length);
-//         
-//         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//         
-//         assertEquals(2, cf1.getServerId());
-//         
-//         
-//         assertEquals(1, failoverMap.size());
-//         
-//         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
-//      }
-//            
-//      //Restart server 0
-//      
-//      ServerManagement.start("all", 0);
-//      
-//      {
-//         JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
-//         
-//         log.info("Got connection factory");
-//         
-//         ClusteredClientConnectionFactoryDelegate delegate =
-//            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//         
-//         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-//         
-//         Map failoverMap = delegate.getFailoverMap();
-//         
-//         log.info("Got failover map");
-//         
-//         assertEquals(2, delegates.length);
-//         
-//         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//         
-//         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-//         
-//         log.info("cf1 serverid=" + cf1.getServerId());
-//         
-//         log.info("cf2 serverid=" + cf2.getServerId());
-//         
-//         assertEquals(2, cf1.getServerId());
-//         
-//         assertEquals(0, cf2.getServerId());
-//         
-//         
-//         assertEquals(2, failoverMap.size());
-//         
-//         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
-//         
-//         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
-//      }
-//      
-//      
-//      //Restart server 1
-//      
-//      ServerManagement.start("all", 1);
-//      
-//      {
-//         JBossConnectionFactory factory =  (JBossConnectionFactory )ic1.lookup("/ConnectionFactory");
-//         
-//         log.info("Got connection factory");
-//         
-//         ClusteredClientConnectionFactoryDelegate delegate =
-//            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-//         
-//         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-//         
-//         Map failoverMap = delegate.getFailoverMap();
-//         
-//         log.info("Got failover map");
-//         
-//         assertEquals(3, delegates.length);
-//         
-//         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-//         
-//         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-//         
-//         ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-//         
-//         log.info("cf1 serverid=" + cf1.getServerId());
-//         
-//         log.info("cf2 serverid=" + cf2.getServerId());
-//         
-//         log.info("cf3 serverid=" + cf3.getServerId());
-//         
-//         assertEquals(2, cf1.getServerId());
-//         
-//         assertEquals(0, cf2.getServerId());
-//         
-//         assertEquals(1, cf3.getServerId());
-//         
-//         
-//         assertEquals(3, failoverMap.size());
-//         
-//         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
-//         
-//         assertEquals(cf3.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
-//         
-//         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf3.getServerId()))).intValue());
-//      }            
-//   }
+   public void testRoundRobinConnectionCreation() throws Exception
+   {
+      JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
+      
+      ClusteredClientConnectionFactoryDelegate delegate =
+         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+      
+      log.info ("number of delegates = " + delegate.getDelegates().length);
+      log.info ("number of servers = " + ServerManagement.getServer(0).getNumberOfNodesOnCluster());
+      
+      assertEquals(3, delegate.getDelegates().length);
+      
+      ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+      
+      ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
+      
+      ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
+      
+      assertEquals(0, cf1.getServerId());
+      
+      assertEquals(1, cf2.getServerId());
+      
+      assertEquals(2, cf3.getServerId());
+      
+      assertEquals(3, ServerManagement.getServer(0).getNumberOfNodesOnCluster());
+      
+      Connection conn1 = null;
+      
+      Connection conn2 = null;
+      
+      Connection conn3 = null;
+      
+      Connection conn4 = null;
+      
+      Connection conn5 = null;
+      
+      try
+      {         
+         conn1 = factory.createConnection();
+         
+         conn2 = factory.createConnection();
+         
+         conn3 = factory.createConnection();
+         
+         conn4 = factory.createConnection();
+         
+         conn5 = factory.createConnection();
+         
+         ConnectionState state1 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn1).getDelegate()).getState());
+         
+         ConnectionState state2 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn2).getDelegate()).getState());
+         
+         ConnectionState state3 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn3).getDelegate()).getState());
+         
+         ConnectionState state4 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn4).getDelegate()).getState());
+         
+         ConnectionState state5 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn5).getDelegate()).getState());
+         
+         int serverID1 = state1.getServerID();
+         
+         int serverID2 = state2.getServerID();
+         
+         int serverID3 = state3.getServerID();
+         
+         int serverID4 = state4.getServerID();
+         
+         int serverID5 = state5.getServerID();
+         
+         log.info("server id 1: " + serverID1);
+         
+         log.info("server id 2: " + serverID2);
+         
+         log.info("server id 3: " + serverID3);
+         
+         log.info("server id 4: " + serverID4);
+         
+         log.info("server id 5: " + serverID5);
+         
+         assertEquals(0, serverID1);
+         
+         assertEquals(1, serverID2);
+         
+         assertEquals(2, serverID3);
+         
+         assertEquals(0, serverID4);
+         
+         assertEquals(1, serverID5);
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+         
+         if (conn4 != null)
+         {
+            conn4.close();
+         }
+         
+         if (conn5 != null)
+         {
+            conn5.close();
+         }
+      }
+      
+   }
+ 
+   /*
+    * Test that the failover mapping is created correctly and updated properly when nodes leave
+    * or join
+    */
+   public void testDefaultFailoverMap() throws Exception
+   {     
+      {
+         JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
+         
+         ClusteredClientConnectionFactoryDelegate delegate =
+            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+         
+         assertEquals(3, ServerManagement.getServer(0).getNumberOfNodesOnCluster());
+         
+         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+         
+         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+         
+         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
+         
+         ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
+         
+         //The order here depends on the order the servers were started in
+         
+         //If any servers get stopped and then started then the order will change
+    
+         log.info("cf1 serverid=" + cf1.getServerId());
+         
+         log.info("cf2 serverid=" + cf2.getServerId());
+         
+         log.info("cf3 serverid=" + cf3.getServerId());
+         
+         
+         assertEquals(0, cf1.getServerId());
+         
+         assertEquals(1, cf2.getServerId());
+         
+         assertEquals(2, cf3.getServerId());
+         
+         Map failoverMap = delegate.getFailoverMap();
+         
+         assertEquals(3, delegates.length);
+         
+         assertEquals(3, failoverMap.size());
+         
+         // Default failover policy just chooses the node to the right
+         
+         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
+         
+         assertEquals(cf3.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
+         
+         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf3.getServerId()))).intValue());
+      }
+      
+      //Now cleanly stop one of the servers
+      
+      
+      log.info("************** STOPPING SERVER 0");
+      ServerManagement.stop(0, true);
+      
+      log.info("server stopped");
+      
+      assertEquals(2, ServerManagement.getServer(1).getNumberOfNodesOnCluster());
+      
+      {         
+         //Lookup another connection factory
+         
+         JBossConnectionFactory factory =  (JBossConnectionFactory )ic1.lookup("/ConnectionFactory");
+         
+         log.info("Got connection factory");
+         
+         ClusteredClientConnectionFactoryDelegate delegate =
+            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+         
+         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+         
+         Map failoverMap = delegate.getFailoverMap();
+         
+         log.info("Got failover map");
+         
+         assertEquals(2, delegates.length);
+         
+         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+         
+         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
+         
+         //Order here depends on order servers were started in
+         
+         log.info("cf1 serverid=" + cf1.getServerId());
+         
+         log.info("cf2 serverid=" + cf2.getServerId());
+         
+         assertEquals(1, cf1.getServerId());
+         
+         assertEquals(2, cf2.getServerId());
+         
+         
+         assertEquals(2, failoverMap.size());
+         
+         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
+         
+         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
+      }
+      
+      //Cleanly stop another server
+      
+      log.info("Server 1 is started: " + ServerManagement.getServer(1).isServerPeerStarted());
+      
+      ServerManagement.stop(1, true);
+      
+      assertEquals(1, ServerManagement.getServer(2).getNumberOfNodesOnCluster());
+      
+      {         
+         //Lookup another connection factory
+         
+         JBossConnectionFactory factory =  (JBossConnectionFactory )ic2.lookup("/ConnectionFactory");
+         
+         ClusteredClientConnectionFactoryDelegate delegate =
+            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+         
+         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+         
+         Map failoverMap = delegate.getFailoverMap();
+         
+         assertEquals(1, delegates.length);
+         
+         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+         
+         assertEquals(2, cf1.getServerId());
+         
+         
+         assertEquals(1, failoverMap.size());
+         
+         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
+      }
+            
+      //Restart server 0
+      
+      ServerManagement.start("all", 0);
+      
+      {
+         JBossConnectionFactory factory =  (JBossConnectionFactory )ic0.lookup("/ConnectionFactory");
+         
+         log.info("Got connection factory");
+         
+         ClusteredClientConnectionFactoryDelegate delegate =
+            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+         
+         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+         
+         Map failoverMap = delegate.getFailoverMap();
+         
+         log.info("Got failover map");
+         
+         assertEquals(2, delegates.length);
+         
+         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+         
+         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
+         
+         log.info("cf1 serverid=" + cf1.getServerId());
+         
+         log.info("cf2 serverid=" + cf2.getServerId());
+         
+         assertEquals(2, cf1.getServerId());
+         
+         assertEquals(0, cf2.getServerId());
+         
+         
+         assertEquals(2, failoverMap.size());
+         
+         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
+         
+         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
+      }
+      
+      
+      //Restart server 1
+      
+      ServerManagement.start("all", 1);
+      
+      {
+         JBossConnectionFactory factory =  (JBossConnectionFactory )ic1.lookup("/ConnectionFactory");
+         
+         log.info("Got connection factory");
+         
+         ClusteredClientConnectionFactoryDelegate delegate =
+            (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+         
+         ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+         
+         Map failoverMap = delegate.getFailoverMap();
+         
+         log.info("Got failover map");
+         
+         assertEquals(3, delegates.length);
+         
+         ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
+         
+         ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
+         
+         ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
+         
+         log.info("cf1 serverid=" + cf1.getServerId());
+         
+         log.info("cf2 serverid=" + cf2.getServerId());
+         
+         log.info("cf3 serverid=" + cf3.getServerId());
+         
+         assertEquals(2, cf1.getServerId());
+         
+         assertEquals(0, cf2.getServerId());
+         
+         assertEquals(1, cf3.getServerId());
+         
+         
+         assertEquals(3, failoverMap.size());
+         
+         assertEquals(cf2.getServerId(), ((Integer)failoverMap.get(new Integer(cf1.getServerId()))).intValue());
+         
+         assertEquals(cf3.getServerId(), ((Integer)failoverMap.get(new Integer(cf2.getServerId()))).intValue());
+         
+         assertEquals(cf1.getServerId(), ((Integer)failoverMap.get(new Integer(cf3.getServerId()))).intValue());
+      }            
+   }
    
    public void testSimpleFailover() throws Exception
    {
@@ -489,7 +489,7 @@
          
          log.info("killed server, now waiting");
          
-         Thread.sleep(3000);
+         Thread.sleep(300000);
          
          log.info("done wait");
          




More information about the jboss-cvs-commits mailing list