[jboss-cvs] JBoss Messaging SVN: r2159 - in trunk/tests/src/org/jboss/test/messaging: tools/aop and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 2 20:47:40 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-02-02 20:47:40 -0500 (Fri, 02 Feb 2007)
New Revision: 2159

Modified:
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/MultiThreadFailoverTest.java
   trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-809 - Adding testcase

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/MultiThreadFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/MultiThreadFailoverTest.java	2007-02-03 01:32:40 UTC (rev 2158)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/MultiThreadFailoverTest.java	2007-02-03 01:47:40 UTC (rev 2159)
@@ -33,10 +33,12 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.remoting.JMSRemotingConnection;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.logging.Logger;
 import org.jboss.test.messaging.jms.clustering.base.ClusteringTestBase;
 import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.aop.PoisonInterceptor;
 
 /**
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
@@ -128,6 +130,108 @@
       conn.close();
    }
 
+
+   // Crash the Server when you have two clients in receive and send simultaneously
+   public void testFailureOnSendReceiveSynchronized() throws Throwable
+   {
+      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, PoisonInterceptor.FAIL_SYNCHRONIZED_SEND_RECEIVE);
+
+         conn.start();
+
+         final Session sessionProducer  = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         final MessageProducer producer = sessionProducer.createProducer(queue[0]);
+
+         final Session sessionConsumer  = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         final MessageConsumer consumer = sessionConsumer.createConsumer(queue[0]);
+
+         final ArrayList failures = new ArrayList();
+
+         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+         
+         Thread t1 = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  producer.send(sessionProducer.createTextMessage("before-poison"));
+               }
+               catch (Throwable e)
+               {
+                  failures.add(e);
+               }
+            }
+         };
+
+         Thread t2 = new Thread()
+         {
+            public void run()
+            {
+               try
+               {
+                  log.info("### Waiting message");
+                  TextMessage text = (TextMessage)consumer.receive();
+                  assertNotNull(text);
+                  assertEquals("before-poison", text.getText());
+
+                  Object obj = consumer.receive(5000);
+                  if (obj != null)
+                  {
+                     log.info("!!!!!! it was not null", new Exception());
+                  }
+                  assertNull(obj);
+               }
+               catch (Throwable e)
+               {
+                  fail("Thread consumer failed");
+               }
+            }
+         };
+
+         t2.start();
+         Thread.sleep(500);
+         t1.start();
+
+         t1.join();
+         t2.join();
+
+         if (!failures.isEmpty())
+         {
+            throw (Throwable)failures.iterator().next();
+         }
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+
+   }
+
    /**
     * This test will open several Consumers at the same Connection and it will kill the server,
     * expecting failover to happen inside the Valve
@@ -349,7 +453,7 @@
             int counter = 0;
             while (true)
             {
-               Message message = consumer.receive(50000);
+               Message message = consumer.receive(5000);
                if (message == null && shouldStop)
                {
                   break;

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-03 01:32:40 UTC (rev 2158)
+++ trunk/tests/src/org/jboss/test/messaging/tools/aop/PoisonInterceptor.java	2007-02-03 01:47:40 UTC (rev 2159)
@@ -46,9 +46,13 @@
 
    public static final int FAIL_BEFORE_SEND = 5;
 
+   public static final int FAIL_SYNCHRONIZED_SEND_RECEIVE = 6;
+
    // Static ---------------------------------------------------------------------------------------
    
    private static int type;
+
+   private static Object sync = new Object();
    
    public static void setType(int type)
    {
@@ -79,7 +83,7 @@
 
          log.info("##### Crashing on createSessionDelegate!!");
          
-         crash(invocation.getTargetObject());
+         crash(target);
       }
       else if (target instanceof ConnectionAdvised && "sendTransaction".equals(methodName))
       {
@@ -92,7 +96,7 @@
             
             log.info("##### Crashing on 2PC commit!!");
             
-            crash(invocation.getTargetObject());            
+            crash(target);
          }
       }
       else if (target instanceof SessionAdvised && "acknowledgeDelivery".equals(methodName)
@@ -103,7 +107,7 @@
          log.info("##### Crashing after acknowledgeDelivery call!!!");
 
          // simulating failure right after invocation (before message is transmitted to client)
-         crash(invocation.getTargetObject());
+         crash(target);
       }
       else if (target instanceof SessionAdvised && "acknowledgeDelivery".equals(methodName)
                  && type == FAIL_BEFORE_ACKNOWLEDGE_DELIVERY)
@@ -111,7 +115,7 @@
 
          log.info("##### Crashing before acknowledgeDelivery call!!!");
 
-         crash(invocation.getTargetObject());
+         crash(target);
       }
       else if (target instanceof SessionAdvised && "send".equals(methodName)
                  && type == FAIL_AFTER_SEND)
@@ -120,15 +124,47 @@
 
          log.info("##### Crashing after send!!!");
 
-         crash(invocation.getTargetObject());
+         // On this case I really want to screw things up! I want the client to receive the message
+         // not only after the send was executed.
+
+         Thread.sleep(5000);
+
+         crash(target);
       }
       else if (target instanceof SessionAdvised && "send".equals(methodName)
                  && type == FAIL_BEFORE_SEND)
       {
-         log.info("##### Crashing before send!!!");
+         log.info("##### Crashing before send!!!", new Exception());
 
-         crash(invocation.getTargetObject());
+         crash(target);
       }
+      else if (type == FAIL_SYNCHRONIZED_SEND_RECEIVE)
+      {
+         if (target instanceof SessionAdvised && "send".equals(methodName))
+         {
+            invocation.invokeNext();
+            synchronized (sync)
+            {
+               log.info("#### Will wait till an acknowledge comes to fail at the same time",
+                  new Exception());
+               sync.wait();
+            }
+            crash(target);
+         }
+         else if (target instanceof SessionAdvised && "acknowledgeDelivery".equals(methodName))
+         {
+            invocation.invokeNext();
+            log.info("#### Notifying sender thread to crash the server, as ack was completed",
+               new Exception());
+            synchronized (sync)
+            {
+               sync.notifyAll();
+            }
+            // lets sleep until the server is killed
+            log.info("Waiting the synchronized send to kill this invocation.");
+            Thread.sleep(60000);
+         }
+      }
 
       return invocation.invokeNext();
    }




More information about the jboss-cvs-commits mailing list