[jboss-cvs] JBossAS SVN: r61798 - in branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 28 13:46:05 EDT 2007


Author: bdecoste
Date: 2007-03-28 13:46:04 -0400 (Wed, 28 Mar 2007)
New Revision: 61798

Added:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/ConcurrentQueueTestMDB.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/ConcurrentMDBUnitTestCase.java
Modified:
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java
Log:
test for customer support issue of mismatched MDB instances and jms adaptor sessions

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/ConcurrentQueueTestMDB.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/ConcurrentQueueTestMDB.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/ConcurrentQueueTestMDB.java	2007-03-28 17:46:04 UTC (rev 61798)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.mdb;
+
+import java.util.Random;
+
+import javax.ejb.ActivationConfigProperty;
+
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.jboss.annotation.ejb.PoolClass;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at MessageDriven(activationConfig =
+        {
+        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/concurrentmdbtest"),
+        @ActivationConfigProperty(propertyName="maxSession", propertyValue="5")
+        })
+ at PoolClass (value=org.jboss.ejb3.StrictMaxPool.class, maxSize=30, timeout=500)
+public class ConcurrentQueueTestMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(ConcurrentQueueTestMDB.class);
+   
+   private static Random random = new Random(1234);
+   
+   public void onMessage(Message message)
+   {
+      TextMessage txt = (TextMessage)message;
+      int test = random.nextInt(10);
+      try
+      {                 
+         System.out.println("--- ConcurrentQueueTestMDB onMessage " + TestStatusBean.concurrentQueueRan + " " + txt.getText() + " " + test);
+      
+         Thread.sleep(2000);         
+      }
+      catch (Exception e)
+      {
+      }
+      
+      if (test == 1)
+         throw new RuntimeException("Testing");
+      else
+         ++TestStatusBean.concurrentQueueRan;
+   }
+}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java	2007-03-28 17:35:23 UTC (rev 61797)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatus.java	2007-03-28 17:46:04 UTC (rev 61798)
@@ -36,6 +36,8 @@
 
    int queueFired();
    
+   int concurrentQueueFired();
+   
    int overrideQueueFired();
    
    int nondurableQueueFired();

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java	2007-03-28 17:35:23 UTC (rev 61797)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/TestStatusBean.java	2007-03-28 17:46:04 UTC (rev 61798)
@@ -40,6 +40,7 @@
    private static final Logger log = Logger.getLogger(TestStatusBean.class);
    
    public static int queueRan = 0;
+   public static int concurrentQueueRan = 0;
    public static int overrideQueueRan = 0;
    public static int defaultedQueueRan = 0;
    public static int overrideDefaultedQueueRan = 0;
@@ -59,6 +60,7 @@
    public void clear()
    {
       queueRan = 0;
+      concurrentQueueRan = 0;
       topicRan = 0;
       bmtQueueRan = 0;
       cmtQueueRan = 0;
@@ -80,6 +82,11 @@
       return queueRan;
    }
    
+   public int concurrentQueueFired()
+   {
+      return concurrentQueueRan;
+   }
+   
    public int overrideQueueFired()
    {
       return overrideQueueRan;

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/ConcurrentMDBUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/ConcurrentMDBUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/mdb/unit/ConcurrentMDBUnitTestCase.java	2007-03-28 17:46:04 UTC (rev 61798)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.mdb.unit;
+
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.InitialContextFactory;
+import org.jboss.ejb3.test.mdb.TestStatus;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class ConcurrentMDBUnitTestCase extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(ConcurrentMDBUnitTestCase.class);
+
+   public ConcurrentMDBUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+
+   public void testQueue() throws Exception
+   {
+      TestStatus status = (TestStatus) getInitialContext().lookup(
+            "TestStatusBean/remote");
+      clear(status);
+      QueueConnection cnn = null;
+      QueueSender sender = null;
+      QueueSession session = null;
+
+      Queue queue = (Queue) getInitialContext().lookup("queue/concurrentmdbtest");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      cnn = factory.createQueueConnection();
+      session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+      TextMessage msg ;
+      int numMessages = 100;
+      sender = session.createSender(queue);
+      for (int i = 1 ; i <= numMessages ; ++i)
+      {
+         msg = session.createTextMessage("Hello World " + i);
+         sender.send(msg);
+      }
+      
+      session.close();
+      cnn.close();
+
+      Thread.sleep(60 * 1000);
+      assertEquals(numMessages, status.concurrentQueueFired());
+   }
+
+   protected QueueConnectionFactory getQueueConnectionFactory()
+         throws Exception
+   {
+      try
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "ConnectionFactory");
+      } catch (NamingException e)
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "java:/ConnectionFactory");
+      }
+   }
+
+   protected void clear(TestStatus status)
+   {
+      status.clear();
+      assertEquals(0, status.bmtQueueRan());
+      assertEquals(0, status.defaultedQueueFired());
+      assertEquals(0, status.messageCount());
+      assertEquals(0, status.nondurableQueueFired());
+      assertEquals(0, status.overrideDefaultedQueueFired());
+      assertEquals(0, status.overrideQueueFired());
+      assertEquals(0, status.queueFired());
+      assertEquals(0, status.topicFired());
+      assertEquals(0, status.expirationQueueRan());
+      assertFalse(status.interceptedQueue());
+      assertFalse(status.interceptedTopic());
+      assertFalse(status.postConstruct());
+      assertFalse(status.preDestroy());
+   }
+   
+   protected InitialContext getInitialContext() throws Exception
+   {
+      return InitialContextFactory.getInitialContext();
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ConcurrentMDBUnitTestCase.class,
+            "mdbtest-service.xml, mdb-test.jar");
+   }
+
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list