[jboss-cvs] JBoss Messaging SVN: r2464 - in trunk: src/main/org/jboss/jms/client/delegate and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 27 04:00:28 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-02-27 04:00:28 -0500 (Tue, 27 Feb 2007)
New Revision: 2464

Added:
   trunk/tests/src/org/jboss/test/messaging/graveyard/ClusteredConnectionFactoryGraveyardTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteredConnectionFactoryTest.java
Modified:
   trunk/src/main/org/jboss/jms/client/container/ClusteringAspect.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
   trunk/tests/etc/poison.xml
   trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-898

Summary of changes:

Testsuite:
Added a testsuite on graveyard (a test that would kill server0... what would invalidate the test run)
Added ClusteredConnectionFactoryTest, and also added poisoning support for ConnectionFactory
   (Adding poisoning required to expose serverPeer on ServerConnectionFactoryEndpoint)

Implementation:
Protected the connection creation in a loop, and doing retries until a max is reached.
Testing connection/IO failures on getClientAOPConfig, retrying on any delegates. (notice that a failure on getClientAOPConfig is expected to be a rare event, as this is executed only once)

Modified: trunk/src/main/org/jboss/jms/client/container/ClusteringAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClusteringAspect.java	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/src/main/org/jboss/jms/client/container/ClusteringAspect.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -17,6 +17,7 @@
 import org.jboss.jms.client.FailoverCommandCenter;
 import org.jboss.jms.client.plugin.LoadBalancingPolicy;
 import org.jboss.jms.server.endpoint.CreateConnectionResult;
+import org.jboss.jms.util.MessagingNetworkFailureException;
 
 import javax.jms.JMSException;
 import java.util.Map;
@@ -36,6 +37,7 @@
  *
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  * @version <tt>$Revision$</tt>
  *
@@ -97,103 +99,115 @@
 
       while (attemptCount < MAX_RECONNECT_HOP_COUNT)
       {
-         int failedNodeIDToServer = -1;
+         // since an exceptiong might be captured during an attempt,
+         // this has to be the first operation
+         attemptCount++;
+         try
+         {
+            int failedNodeIDToServer = -1;
 
-         if (delegate == null)
-         {
-            if (failedNodeID != null && failedNodeID.intValue() >= 0)
+            if (delegate == null)
             {
-               delegate = getFailoverDelegateForNode(failedNodeID);
-               failedNodeIDToServer = failedNodeID.intValue();
+               if (failedNodeID != null && failedNodeID.intValue() >= 0)
+               {
+                  delegate = getFailoverDelegateForNode(failedNodeID);
+                  failedNodeIDToServer = failedNodeID.intValue();
+               }
+               else
+               {
+                  LoadBalancingPolicy loadBalancingPolicy = clusteredDelegate.getLoadBalancingPolicy();
+                  delegate = (ClientConnectionFactoryDelegate)loadBalancingPolicy.getNext();
+               }
             }
-            else
+
+            log.debug(this + " has chosen " + delegate + " as target, " +
+               (attemptCount == 0 ? "first connection attempt" : attemptCount + " connection attempts"));
+
+            CreateConnectionResult res = delegate.
+               createConnectionDelegate(username, password, failedNodeIDToServer);
+            ClientConnectionDelegate cd = (ClientConnectionDelegate)res.getDelegate();
+
+            if (cd != null)
             {
-               LoadBalancingPolicy loadBalancingPolicy = clusteredDelegate.getLoadBalancingPolicy();
-               delegate = (ClientConnectionFactoryDelegate)loadBalancingPolicy.getNext();
-            }
-         }
+               // valid connection
 
-         log.debug(this + " has chosen " + delegate + " as target, " +
-            (attemptCount == 0 ? "first connection attempt" : attemptCount + " connection attempts"));
+               log.debug(this + " got local connection delegate " + cd);
 
-         CreateConnectionResult res = delegate.
-            createConnectionDelegate(username, password, failedNodeIDToServer);
-         ClientConnectionDelegate cd = (ClientConnectionDelegate)res.getDelegate();
+               ConnectionState state = (ConnectionState)((DelegateSupport)cd).getState();
 
-         if (cd != null)
-         {
-            // valid connection
+               state.initializeFailoverCommandCenter();
 
-            log.debug(this + " got local connection delegate " + cd);
+               FailoverCommandCenter fcc = state.getFailoverCommandCenter();
 
-            ConnectionState state = (ConnectionState)((DelegateSupport)cd).getState();
+               // add a connection listener to detect failure; the consolidated remoting connection
+               // listener must be already in place and configured
+               state.getRemotingConnection().getConnectionListener().
+                  addDelegateListener(new ConnectionFailureListener(fcc, state.getRemotingConnection()));
 
-            state.initializeFailoverCommandCenter();
+               log.debug(this + " installed failure listener on " + cd);
 
-            FailoverCommandCenter fcc = state.getFailoverCommandCenter();
+               // also cache the username and the password into state, useful in case
+               // FailoverCommandCenter needs to create a new connection instead of a failed on
+               state.setUsername(username);
+               state.setPassword(password);
 
-            // add a connection listener to detect failure; the consolidated remoting connection
-            // listener must be already in place and configured
-            state.getRemotingConnection().getConnectionListener().
-               addDelegateListener(new ConnectionFailureListener(fcc, state.getRemotingConnection()));
+               // also add a reference to the clustered ConnectionFactory delegate, useful in case
+               // FailoverCommandCenter needs to create a new connection instead of a failed on
+               state.setClusteredConnectionFactoryDeleage(clusteredDelegate);
 
-            log.debug(this + " installed failure listener on " + cd);
+               return new CreateConnectionResult(cd);
+            }
+            else
+            {
+               // we did not get a valid connection to the node we've just tried
 
-            // also cache the username and the password into state, useful in case
-            // FailoverCommandCenter needs to create a new connection instead of a failed on
-            state.setUsername(username);
-            state.setPassword(password);
+               int actualServerID = res.getActualFailoverNodeID();
 
-            // also add a reference to the clustered ConnectionFactory delegate, useful in case
-            // FailoverCommandCenter needs to create a new connection instead of a failed on
-            state.setClusteredConnectionFactoryDeleage(clusteredDelegate);
+               if (actualServerID == -1)
+               {
+                  // No failover attempt was detected on the server side; this might happen if the
+                  // client side network fails temporarily so the client connection breaks but the
+                  // server cluster is still up and running - in this case we don't perform failover.
 
-            return new CreateConnectionResult(cd);
-         }
-         else
-         {
-            // we did not get a valid connection to the node we've just tried
+                  // In this case we should try back on the original server
 
-            int actualServerID = res.getActualFailoverNodeID();
+                  log.warn("Client attempted failover, but no failover attempt " +
+                           "has been detected on the server side. We will now try again on the original server " +
+                           "in case there was a temporary glitch on the client--server network");
 
-            if (actualServerID == -1)
-            {
-               // No failover attempt was detected on the server side; this might happen if the
-               // client side network fails temporarily so the client connection breaks but the
-               // server cluster is still up and running - in this case we don't perform failover.
+                  delegate = getDelegateForNode(failedNodeID.intValue());
 
-               // In this case we should try back on the original server
+                  //Pause a little to avoid hammering the same node in quick succession
 
-               log.warn("Client attempted failover, but no failover attempt " +
-                        "has been detected on the server side. We will now try again on the original server " +
-                        "in case there was a temporary glitch on the client--server network");
-               
-               delegate = getDelegateForNode(failedNodeID.intValue());
-               
-               //Pause a little to avoid hammering the same node in quick succession
-               
-               //Currently hardcoded
-               Thread.sleep(2000);
+                  //Currently hardcoded
+                  Thread.sleep(2000);
+               }
+               else
+               {
+                  // Server side failover has occurred / is occurring but trying to go to the 'default'
+                  // failover node did not succeed. Retry with the node suggested by the cluster.
+
+                  delegate = getDelegateForNode(actualServerID);
+               }
+
+               if (delegate == null)
+               {
+                  // the delegate corresponding to the actualServerID not found among the cached
+                  // delegates. TODO Could this ever happen? Should we send back the cf, or update it
+                  // instead of just the id??
+                  throw new JMSException("Cannot find a cached connection factory delegate for " +
+                     "node " + actualServerID);
+               }
+
             }
-            else
-            {   
-               // Server side failover has occurred / is occurring but trying to go to the 'default'
-               // failover node did not succeed. Retry with the node suggested by the cluster.
-   
-               delegate = getDelegateForNode(actualServerID);                  
-            }
-            
-            if (delegate == null)
-            {
-               // the delegate corresponding to the actualServerID not found among the cached
-               // delegates. TODO Could this ever happen? Should we send back the cf, or update it
-               // instead of just the id??
-               throw new JMSException("Cannot find a cached connection factory delegate for " +
-                  "node " + actualServerID);
-            }
-            
-            attemptCount++;
          }
+         catch (MessagingNetworkFailureException e)
+         {
+            delegate = null;
+            log.warn("Exception captured on createConnection... hopping a new connection", e);
+            //Currently hardcoded
+            Thread.sleep(2000);
+         }
       }
 
       throw new JMSException("Maximum number of failover attempts exceeded. " +

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -27,6 +27,7 @@
 import org.jboss.jms.server.endpoint.CreateConnectionResult;
 import org.jboss.jms.delegate.ConnectionFactoryDelegate;
 import org.jboss.jms.client.plugin.LoadBalancingPolicy;
+import org.jboss.jms.util.MessagingNetworkFailureException;
 import org.jboss.messaging.core.plugin.IDBlock;
 import org.jboss.logging.Logger;
 
@@ -81,16 +82,28 @@
 
    // ConnectionFactoryDelegate implementation -----------------------------------------------------
 
-   public byte[] getClientAOPStack() throws JMSException
+   public synchronized byte[] getClientAOPStack() throws JMSException
    {
       // Use one of the non-clustered ConnectionFactory delegates to retrieve the client AOP stack
       // from one of the nodes.
 
-      ConnectionFactoryDelegate aopStackProvider = delegates[0];
+      for (int server = 0; server < delegates.length; server++)
+      {
+         try
+         {
+            ConnectionFactoryDelegate aopStackProvider = delegates[server];
 
-      log.debug("getting AOP stack from " + aopStackProvider);
-      
-      return aopStackProvider.getClientAOPStack();
+            log.debug("getting AOP stack from " + aopStackProvider);
+
+            return aopStackProvider.getClientAOPStack();
+         }
+         catch (MessagingNetworkFailureException e)
+         {
+            log.warn("Server" + 0 + " was broken, loading AOP from next delegate", e);
+         }
+      }
+
+      throw new MessagingNetworkFailureException("Failed to download and/or install client side AOP stack");
    }
 
    /**

Modified: trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -37,6 +37,7 @@
 import org.jboss.messaging.util.Streamable;
 import org.jboss.remoting.CannotConnectException;
 import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionFailedException;
 
 /**
  * Base class for all client-side delegate classes.
@@ -202,16 +203,21 @@
    
    public JMSException handleThrowable(Throwable t)
    {
+      // ConnectionFailedException could happen during ConnectionFactory.createConnection
+      // IOException could happen during an interrupted exception.
+      // CannotConnectionException could happen during a communication error between a
+      //    connected remoting client and the server (what means.. any new invocation)
       if (t instanceof JMSException)
       {
          return (JMSException)t;
       }
-      else if ((t instanceof CannotConnectException) || (t instanceof IOException))
+      else if ((t instanceof CannotConnectException) || (t instanceof IOException) ||
+         (t instanceof ConnectionFailedException))
       {
          log.warn("Captured Exception:" + t, t);
          return new MessagingNetworkFailureException((Exception)t);
       }
-      else         
+      else
       {
          log.error("Failed", t);
          return new MessagingJMSException("Failed to invoke", t);

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -287,6 +287,11 @@
       return jndiBindings;
    }
 
+   public ServerPeer getServerPeer()
+   {
+      return serverPeer;
+   }
+
    /**
     * Sends a cluster view update message to its associated ClusteredConnectionFactories.
     *

Modified: trunk/tests/etc/poison.xml
===================================================================
--- trunk/tests/etc/poison.xml	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/tests/etc/poison.xml	2007-02-27 09:00:28 UTC (rev 2464)
@@ -14,4 +14,8 @@
       <interceptor-ref name="org.jboss.test.messaging.tools.aop.PoisonInterceptor"/>
    </bind>
 
+   <bind pointcut="execution(* org.jboss.jms.server.endpoint.advised.ConnectionFactoryAdvised->*(..))">
+      <interceptor-ref name="org.jboss.test.messaging.tools.aop.PoisonInterceptor"/>
+   </bind>
+
 </aop>
\ No newline at end of file

Added: trunk/tests/src/org/jboss/test/messaging/graveyard/ClusteredConnectionFactoryGraveyardTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/graveyard/ClusteredConnectionFactoryGraveyardTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/graveyard/ClusteredConnectionFactoryGraveyardTest.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -0,0 +1,154 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+
+package org.jboss.test.messaging.graveyard;
+
+import org.jboss.test.messaging.jms.clustering.base.ClusteringTestBase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.ClientAOPStackLoader;
+import javax.jms.Connection;
+import java.lang.reflect.Field;
+
+/**
+ * There are tests that should be on ClusteredConnectionFActoryTest that will need to kill server0
+ * to validate AOP configs.
+ *
+ * However it's not allowed to kill these servers under our regular scenario.
+ *
+ * So.. I'm adding these tests here to the graveyard, so we could run them manually
+ * until we figure out how to resurrect them.. what means.. how to avoid/allow killing server0 
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *          $Id$
+ */
+public class ClusteredConnectionFactoryGraveyardTest extends ClusteringTestBase
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public ClusteredConnectionFactoryGraveyardTest(String name)
+   {
+      super(name);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void testGetAOPBroken() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+
+         resetAOP();
+
+         ServerManagement.killAndWait(2);
+         ServerManagement.killAndWait(1);
+         ServerManagement.killAndWait(0);
+
+         try
+         {
+            conn = cf.createConnection();
+            fail ("This should try an exception as every server is down");
+         }
+         catch (RuntimeException e)
+         {
+            log.error(e.toString(), e);
+         }
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   public void testGetAOPBounce() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+
+         resetAOP();
+
+         ServerManagement.killAndWait(0);
+         ServerManagement.poisonTheServer(1, PoisonInterceptor.CF_GET_CLIENT_AOP_STACK);
+
+         conn = cf.createConnection();
+         assertEquals(2, ((JBossConnection)conn).getServerID());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      nodeCount = 3;
+      super.setUp();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+
+   private void resetAOP()
+      throws NoSuchFieldException, IllegalAccessException
+   {
+
+      // Using reflection to cleanup AOP status and force to load AOP again
+      Field field = ClientAOPStackLoader.class.getDeclaredField("instance");
+      field.setAccessible(true);
+      log.info("Reseting AOP");
+      field.set(null,null);
+   }
+
+
+   
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: trunk/tests/src/org/jboss/test/messaging/graveyard/ClusteredConnectionFactoryGraveyardTest.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteredConnectionFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteredConnectionFactoryTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteredConnectionFactoryTest.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -0,0 +1,183 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005, JBoss Inc., and individual contributors as indicated
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+
+package org.jboss.test.messaging.jms.clustering;
+
+import javax.jms.Connection;
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.ClientAOPStackLoader;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
+import org.jboss.test.messaging.jms.clustering.base.ClusteringTestBase;
+import java.lang.reflect.Field;
+
+/**
+ * TODO: Is it possible to move tests I added on ClusteredConnectionFactoryGraveyardTest?
+ * TODO:      These tests are kiilling server 0, as AOP is loaded starting from server 0.
+ * TODO:      and I wanted to validate crashing scenarios
+ * TODO: It's possible to run them manually but not as part of the entire testsuite.
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *          $Id$
+ */
+public class ClusteredConnectionFactoryTest extends ClusteringTestBase
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public ClusteredConnectionFactoryTest(String name)
+   {
+      super(name);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void testCreateConnectionOnBrokenServer() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+         conn.close();
+         conn = null;
+
+         ServerManagement.killAndWait(1);
+         conn = cf.createConnection();
+
+         assertEquals(2,((JBossConnection)conn).getServerID());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   public void testPoisonCFs() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+
+         // Poison each server with a different pointcut crash
+         ServerManagement.poisonTheServer(1, PoisonInterceptor.CF_GET_ID_BLOCK);
+
+         conn = cf.createConnection();
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+         conn.close();
+         conn = null;
+
+         // this should break on server1
+         conn = cf.createConnection();
+
+         assertEquals(2, ((JBossConnection)conn).getServerID());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   public void testCreateConnectionTwoServersBroken() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+         conn.close();
+
+         ServerManagement.killAndWait(1);
+         ServerManagement.killAndWait(2);
+         conn = cf.createConnection();
+
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   public void testFailureOnGetBlockId() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+         conn.close();
+
+         ServerManagement.killAndWait(1);
+         ServerManagement.killAndWait(2);
+         conn = cf.createConnection();
+
+         assertEquals(0, ((JBossConnection)conn).getServerID());
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      nodeCount = 3;
+      super.setUp();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteredConnectionFactoryTest.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Modified: trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java	2007-02-27 05:51:42 UTC (rev 2463)
+++ trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java	2007-02-27 09:00:28 UTC (rev 2464)
@@ -14,8 +14,10 @@
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.jms.server.endpoint.ServerConnectionEndpoint;
 import org.jboss.jms.server.endpoint.ServerSessionEndpoint;
+import org.jboss.jms.server.endpoint.ServerConnectionFactoryEndpoint;
 import org.jboss.jms.server.endpoint.advised.ConnectionAdvised;
 import org.jboss.jms.server.endpoint.advised.SessionAdvised;
+import org.jboss.jms.server.endpoint.advised.ConnectionFactoryAdvised;
 import org.jboss.jms.server.ServerPeer;
 import org.jboss.jms.tx.TransactionRequest;
 import org.jboss.logging.Logger;
@@ -34,6 +36,8 @@
 
    private static final Logger log = Logger.getLogger(PoisonInterceptor.class);
    
+   public static final int NULL = -1;
+
    public static final int TYPE_CREATE_SESSION = 0;
    
    public static final int TYPE_2PC_COMMIT = 1;
@@ -52,9 +56,12 @@
    
    public static final int LONG_SEND = 8;
 
+   public static final int CF_GET_ID_BLOCK = 9;
+
+   public static final int CF_GET_CLIENT_AOP_STACK = 10;
    // Static ---------------------------------------------------------------------------------------
    
-   private static int type;
+   private static int type = NULL;
 
    private static Object sync = new Object();
    
@@ -76,10 +83,18 @@
 
    public Object invoke(Invocation invocation) throws Throwable
    {
+
+      if (type==NULL)
+      {
+         return invocation.invokeNext();
+      }
+      
       MethodInvocation mi = (MethodInvocation)invocation;
       String methodName = mi.getMethod().getName();
       Object target = mi.getTargetObject();
 
+      log.info("Invoke target=" + target.getClass().getName() + " method = " + methodName);
+
       if (target instanceof ConnectionAdvised && "createSessionDelegate".equals(methodName)
              && type == TYPE_CREATE_SESSION)
       {
@@ -185,6 +200,12 @@
             invocation.invokeNext();
          }
       }
+      else if (target instanceof ConnectionFactoryAdvised &&
+               (type == CF_GET_ID_BLOCK && "getIdBlock".equals(methodName) ||
+                type == CF_GET_CLIENT_AOP_STACK && "getClientAOPStack".equals(methodName)))
+      {
+         crash(target);
+      }
 
       return invocation.invokeNext();
    }
@@ -212,6 +233,12 @@
          ServerSessionEndpoint endpoint = (ServerSessionEndpoint)adv.getEndpoint();
          return endpoint.getConnectionEndpoint().getServerPeer();
       }
+      else if (obj instanceof ConnectionFactoryAdvised)
+      {
+         ConnectionFactoryAdvised adv = (ConnectionFactoryAdvised) obj;
+         ServerConnectionFactoryEndpoint endpoint = (ServerConnectionFactoryEndpoint)adv.getEndpoint();
+         return endpoint.getServerPeer();
+      }
       else
       {
          throw new IllegalStateException("PoisonInterceptor doesn't support " +
@@ -222,26 +249,36 @@
 
    private void crash(Object target) throws Exception
    {
-      int serverId = getServerPeer(target).getServerPeerID();
+      try
+      {
+         int serverId = getServerPeer(target).getServerPeerID();
 
-      //First unregister from the RMI registry
-      Registry registry = LocateRegistry.getRegistry(RMITestServer.DEFAULT_REGISTRY_PORT);
+         //First unregister from the RMI registry
+         Registry registry = LocateRegistry.getRegistry(RMITestServer.DEFAULT_REGISTRY_PORT);
 
-      String name = RMITestServer.RMI_SERVER_PREFIX + serverId;
-      registry.unbind(name);
-      log.info("unregistered " + name + " from registry");
+         String name = RMITestServer.RMI_SERVER_PREFIX + serverId;
+         registry.unbind(name);
+         log.info("unregistered " + name + " from registry");
 
-      name = RMITestServer.NAMING_SERVER_PREFIX + serverId;
-      registry.unbind(name);
-      log.info("unregistered " + name + " from registry");
-      
-      log.info("#####"); 
-      log.info("#####");
-      log.info("##### Halting the server!");
-      log.info("#####");
-      log.info("#####");
+         name = RMITestServer.NAMING_SERVER_PREFIX + serverId;
+         registry.unbind(name);
+         log.info("unregistered " + name + " from registry");
 
-      Runtime.getRuntime().halt(1);
+         log.info("#####");
+         log.info("#####");
+         log.info("##### Halting the server!");
+         log.info("#####");
+         log.info("#####");
+      }
+      finally
+      {
+         // this finally is for the the case where server0 was killed and unbind throws an exception
+         // It shouldn't happen in our regular testsuite but it could happen on eventual
+         // temporary tests not meant to commit.
+         //
+         // For example I needed to kill server0 to test AOPLoader while I couldn't commit the test
+         Runtime.getRuntime().halt(1);
+      }
    }
 
    // Inner classes --------------------------------------------------------------------------------




More information about the jboss-cvs-commits mailing list