[jboss-cvs] JBoss Messaging SVN: r2152 - in trunk/tests: src/org/jboss/test/messaging/jms/clustering and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 2 17:44:55 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-02-02 17:44:55 -0500 (Fri, 02 Feb 2007)
New Revision: 2152

Modified:
   trunk/tests/etc/poison.xml
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
   trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-733, also http://jira.jboss.org/jira/browse/JBMESSAGING-808

This replicating failure on MultiThreadFailoverTest under a single thread scenario.

Modified: trunk/tests/etc/poison.xml
===================================================================
--- trunk/tests/etc/poison.xml	2007-02-02 17:26:56 UTC (rev 2151)
+++ trunk/tests/etc/poison.xml	2007-02-02 22:44:55 UTC (rev 2152)
@@ -10,4 +10,8 @@
       <interceptor-ref name="org.jboss.test.messaging.tools.aop.PoisonInterceptor"/>
    </bind>
 
+   <bind pointcut="execution(* org.jboss.jms.server.endpoint.advised.SessionAdvised->*(..))">
+      <interceptor-ref name="org.jboss.test.messaging.tools.aop.PoisonInterceptor"/>
+   </bind>
+
 </aop>
\ No newline at end of file

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java	2007-02-02 17:26:56 UTC (rev 2151)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java	2007-02-02 22:44:55 UTC (rev 2152)
@@ -1665,6 +1665,18 @@
       }
    }
 
+   // http://jira.jboss.org/jira/browse/JBMESSAGING-808
+   public void testFailureRightAfterACK() throws Exception
+   {
+      failureOnInvocation(PoisonInterceptor.FAIL_AFTER_ACKNOWLEDGE_DELIVERY);
+   }
+
+   // http://jira.jboss.org/jira/browse/JBMESSAGING-808
+   public void testFailureRightBeforeACK() throws Exception
+   {
+      failureOnInvocation(PoisonInterceptor.FAIL_BEFORE_ACKNOWLEDGE_DELIVERY);
+   }
+
    // Package protected ----------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------
@@ -1761,6 +1773,57 @@
       }
    }
 
+   // Used for both testFailureRightAfterACK and  testFailureRightBeforeACK
+   private void failureOnInvocation(int typeOfFailure) throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+         conn.close();
+
+         conn = cf.createConnection();
+
+         assertEquals(1, ((JBossConnection)conn).getServerID());
+
+         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
+         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
+         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
+            getDelegate()).getRemotingConnection();
+         rc.removeConnectionListener();
+
+         // poison the server
+         ServerManagement.poisonTheServer(1, typeOfFailure);
+
+         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         conn.start();
+
+         MessageProducer producer = session.createProducer(queue[0]);
+
+         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+         MessageConsumer consumer = session.createConsumer(queue[0]);
+
+         producer.send(session.createTextMessage("before-poison"));
+
+         TextMessage tm = (TextMessage)consumer.receive(5000);
+
+         assertNotNull(tm);
+
+         assertEquals("before-poison", tm.getText());
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
    // Inner classes --------------------------------------------------------------------------------
 
    private class SimpleFailoverListener implements FailoverListener

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-02 17:26:56 UTC (rev 2151)
+++ trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java	2007-02-02 22:44:55 UTC (rev 2152)
@@ -13,7 +13,10 @@
 import org.jboss.aop.joinpoint.Invocation;
 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.advised.ConnectionAdvised;
+import org.jboss.jms.server.endpoint.advised.SessionAdvised;
+import org.jboss.jms.server.ServerPeer;
 import org.jboss.jms.tx.TransactionRequest;
 import org.jboss.logging.Logger;
 import org.jboss.test.messaging.tools.jmx.rmi.RMITestServer;
@@ -34,8 +37,11 @@
    public static final int TYPE_CREATE_SESSION = 0;
    
    public static final int TYPE_2PC_COMMIT = 1;
-   
 
+   public static final int FAIL_AFTER_ACKNOWLEDGE_DELIVERY = 2;
+
+   public static final int FAIL_BEFORE_ACKNOWLEDGE_DELIVERY = 3;
+
    // Static ---------------------------------------------------------------------------------------
    
    private static int type;
@@ -60,8 +66,9 @@
    {
       MethodInvocation mi = (MethodInvocation)invocation;
       String methodName = mi.getMethod().getName();
+      Object target = mi.getTargetObject();
 
-      if ("createSessionDelegate".equals(methodName) && type == TYPE_CREATE_SESSION)
+      if (target instanceof ConnectionAdvised && "createSessionDelegate".equals(methodName) && type == TYPE_CREATE_SESSION)
       {
          // Used by the failover tests to kill server in the middle of an invocation.
 
@@ -69,7 +76,7 @@
          
          crash(invocation.getTargetObject());
       }
-      else if ("sendTransaction".equals(methodName))
+      else if (target instanceof ConnectionAdvised && "sendTransaction".equals(methodName))
       {
          TransactionRequest request = (TransactionRequest)mi.getArguments()[0];
          
@@ -83,6 +90,20 @@
             crash(invocation.getTargetObject());            
          }
       }
+      else if (target instanceof SessionAdvised && "acknowledgeDelivery".equals(methodName)
+                 && type == FAIL_AFTER_ACKNOWLEDGE_DELIVERY)
+      {
+         System.out.println("########################## Crashing on ack");
+         invocation.invokeNext();
+         // simulating failure right after invocation (before message is transmitted to client)
+         crash(invocation.getTargetObject());
+      }
+      else if (target instanceof SessionAdvised && "acknowledgeDelivery".equals(methodName)
+                 && type == FAIL_BEFORE_ACKNOWLEDGE_DELIVERY)
+      {
+         System.out.println("########################## Crashing on ack");
+         crash(invocation.getTargetObject());
+      }
 
       return invocation.invokeNext();
    }
@@ -95,15 +116,33 @@
    // Protected ------------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------
-   
+
+   private ServerPeer getServerPeer(Object obj) throws Exception
+   {
+      if (obj instanceof ConnectionAdvised)
+      {
+         ConnectionAdvised adv = (ConnectionAdvised) obj;
+         ServerConnectionEndpoint endpoint = (ServerConnectionEndpoint )adv.getEndpoint();
+         return endpoint.getServerPeer();
+      }
+      else if (obj instanceof SessionAdvised)
+      {
+         SessionAdvised adv = (SessionAdvised) obj;
+         ServerSessionEndpoint endpoint = (ServerSessionEndpoint)adv.getEndpoint();
+         return endpoint.getConnectionEndpoint().getServerPeer();
+      }
+      else
+      {
+         throw new IllegalStateException("PoisonInterceptor doesn't support " +
+            obj.getClass().getName() +
+            " yet! You will have to implement getServerPeer for this class");
+      }
+   }
+
    private void crash(Object target) throws Exception
    {
-      ConnectionAdvised advised = (ConnectionAdvised)target;
-      
-      ServerConnectionEndpoint endpoint = (ServerConnectionEndpoint)advised.getEndpoint();
-      
-      int serverId = endpoint.getServerPeer().getServerPeerID();
-            
+      int serverId = getServerPeer(target).getServerPeerID();
+
       //First unregister from the RMI registry
       Registry registry = LocateRegistry.getRegistry(RMITestServer.DEFAULT_REGISTRY_PORT);
 




More information about the jboss-cvs-commits mailing list