[jboss-cvs] JBossAS SVN: r91284 - in branches/JBPAPP_5_0/testsuite: src/main/org/jboss/test/ejb3 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 15 05:21:07 EDT 2009


Author: wolfc
Date: 2009-07-15 05:21:07 -0400 (Wed, 15 Jul 2009)
New Revision: 91284

Added:
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/AbstractReplierMDB.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/EJB3TestCase.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/TransactionMDB.java
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java
   branches/JBPAPP_5_0/testsuite/src/resources/ejb3/jbpapp2260/
   branches/JBPAPP_5_0/testsuite/src/resources/ejb3/jbpapp2260/jbpapp2260-destinations-service.xml
Removed:
   branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java
Modified:
   branches/JBPAPP_5_0/testsuite/imports/sections/ejb3.xml
Log:
JBPAPP-2260: unit test (merged from JBPAPP_4_2_0_GA_CP 91207, 91208)

Modified: branches/JBPAPP_5_0/testsuite/imports/sections/ejb3.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/imports/sections/ejb3.xml	2009-07-15 08:41:31 UTC (rev 91283)
+++ branches/JBPAPP_5_0/testsuite/imports/sections/ejb3.xml	2009-07-15 09:21:07 UTC (rev 91284)
@@ -49,6 +49,18 @@
       </jar>
    </target>
    
+   <target name="jbpapp2260" depends="compile">
+      <mkdir dir="${build.lib}" />
+      
+      <jar destfile="${build.lib}/jbpapp2260.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/ejb3/common/**" />
+            <include name="org/jboss/test/ejb3/jbpapp2260/**" />
+         </fileset>
+         <fileset dir="${source.resources}/ejb3/jbpapp2260" includes="**"/>
+      </jar>
+   </target>
+   
    <!-- This issue affected the ejb3 AS module -->
    <target name="ejbthree1597" depends="compile">
       <mkdir dir="${build.lib}"/>
@@ -112,7 +124,9 @@
       </copy>
    </target>
    
-   <target name="_jars-ejb3" depends="ejb3-servlet,jbas6161,jbas6239,ejbthree1597,jbas5713">
+   <target name="_jars-ejb3" depends="ejb3-servlet,jbas6161,jbas6239,ejbthree1597,jbas5713,
+      jbpapp2260
+      ">
       <mkdir dir="${build.lib}" />
 
       <!-- A jar with a simple ejb3 session -->

Copied: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/AbstractReplierMDB.java (from rev 91282, branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/AbstractReplierMDB.java)
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/AbstractReplierMDB.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/AbstractReplierMDB.java	2009-07-15 09:21:07 UTC (rev 91284)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.common;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Sets up a MDB which can reply to messages via sendReply.
+ * 
+ * Make sure that postConstruct are preDestroy are properly executed when overridden.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractReplierMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(AbstractReplierMDB.class);
+   
+   @Resource(mappedName="java:/ConnectionFactory")
+   private QueueConnectionFactory factory;
+   
+   private QueueConnection connection;
+   private QueueSession session;
+   private QueueSender sender;
+   
+   /**
+    * Send an object message to the specified destination.
+    * 
+    * @param destination
+    * @param obj
+    * @throws JMSException
+    */
+   protected void sendReply(Destination destination, Serializable obj) throws JMSException
+   {
+      Message message = session.createObjectMessage(obj);
+      sender.send(destination, message);
+   }
+   
+   @PostConstruct
+   public void postConstruct()
+   {
+      try
+      {
+         connection = factory.createQueueConnection();
+         session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         sender = session.createSender(null);
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   @PreDestroy
+   public void preDestroy()
+   {
+      try
+      {
+         if(sender != null)
+            sender.close();
+         if(session != null)
+            session.close();
+         if(connection != null)
+            connection.close();
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}


Property changes on: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/AbstractReplierMDB.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/EJB3TestCase.java (from rev 91282, branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/EJB3TestCase.java)
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/EJB3TestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/EJB3TestCase.java	2009-07-15 09:21:07 UTC (rev 91284)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.ejb3.common;
+
+import javax.jms.QueueConnectionFactory;
+import javax.naming.NamingException;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class EJB3TestCase extends JBossTestCase
+{
+   protected EJB3TestCase(String name)
+   {
+      super(name);
+   }
+
+   protected QueueConnectionFactory getQueueConnectionFactory() throws Exception
+   {
+      try
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      }
+      catch (NamingException e)
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");
+      }
+   }
+
+   protected <T> T lookup(String name, Class<T> expectedType) throws Exception
+   {
+      return expectedType.cast(getInitialContext().lookup(name));
+   }
+   
+   /**
+    * Make sure the deployment is successful.
+    * @throws Exception
+    */
+   public final void testServerFound() throws Exception
+   {
+      // we don't want this done in suite, because then the individual
+      // failure count for this test would go down. (1 failure instead of many)
+      serverFound();
+   }
+}


Property changes on: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/common/EJB3TestCase.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/TransactionMDB.java (from rev 91207, branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/TransactionMDB.java)
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/TransactionMDB.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/TransactionMDB.java	2009-07-15 09:21:07 UTC (rev 91284)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.jbpapp2260;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.ejb3.common.AbstractReplierMDB;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/jbpapp2260"),
+      @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1"),
+      @ActivationConfigProperty(propertyName = "dLQMaxResent", propertyValue = "1"),
+      @ActivationConfigProperty(propertyName = "maxMessages", propertyValue = "50") })
+public class TransactionMDB extends AbstractReplierMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(TransactionMDB.class);
+   
+   // this goes against spec, normally you would use BMT and UserTransaction
+   @Resource(mappedName="java:/TransactionManager")
+   private TransactionManager tm;
+   
+   private ConcurrentHashMap<String, AtomicInteger> stats = new ConcurrentHashMap<String, AtomicInteger>();
+   
+   public void onMessage(Message message)
+   {
+      try
+      {
+         log.info(Thread.currentThread() + " " + this + " " + tm.getTransaction());
+         // The original plan was to get the tx in a rollback state and then
+         // observe the next message failing. This has a drawback that communicating
+         // back to the test case is a bit awkward.
+//         if(message instanceof TextMessage)
+//         {
+//            String cmd = ((TextMessage) message).getText();
+//            if(cmd.equals("abort"))
+//            {
+//               log.info("setting tx to rollback only");
+//               tm.setRollbackOnly();
+//            }
+//            else if(cmd.equals("RuntimeException"))
+//            {
+//               log.info("throwing a RuntimeException");
+//               throw new RuntimeException("throw it");
+//            }
+//         }
+         // So instead let's keep track of the transactions.
+         String key = tm.getTransaction().toString();
+         if(stats.get(key) == null)
+            stats.put(key, new AtomicInteger());
+         stats.get(key).incrementAndGet();
+         // a minimal sleep to make sure we build up some backlog
+         sleep(10, MILLISECONDS);
+         sendReply(message.getJMSReplyTo(), stats);
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   private void sleep(int duration, TimeUnit unit)
+   {
+      long millis = MILLISECONDS.convert(duration, unit);
+      try
+      {
+         Thread.sleep(millis);
+      }
+      catch(InterruptedException e)
+      {
+         // ignore
+      }
+   }
+}


Property changes on: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/TransactionMDB.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit (from rev 91207, branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit)


Property changes on: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit
___________________________________________________________________
Name: svn:mergeinfo
   + 

Deleted: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java	2009-07-14 13:01:24 UTC (rev 91207)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java	2009-07-15 09:21:07 UTC (rev 91284)
@@ -1,235 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.jbpapp2260.unit;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueReceiver;
-import javax.jms.QueueSender;
-import javax.jms.QueueSession;
-import javax.jms.TemporaryQueue;
-import javax.jms.TextMessage;
-import javax.management.ObjectName;
-import javax.transaction.Status;
-
-import junit.framework.Test;
-
-import org.jboss.ejb3.test.common.EJB3TestCase;
-import org.jboss.ejb3.test.jbpapp2260.StressQueueRemote;
-import org.jboss.logging.Logger;
-
-/**
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class MessageInflowTransactionUnitTestCase extends EJB3TestCase
-{
-   private static final Logger log = Logger.getLogger(MessageInflowTransactionUnitTestCase.class);
-   
-   private static final String QUEUE_NAME = "jbpapp2260";
-   
-   public MessageInflowTransactionUnitTestCase(String name)
-   {
-      super(name);
-   }
-
-   public Object sendMessage(String queueName, String text) throws Exception
-   {
-      return sendMessage(queueName, text, 1);
-   }
-   
-   public Object sendMessage(String queueName, String text, int redeliveryLimit) throws Exception
-   {
-      Queue queue = lookup("queue/" + queueName, Queue.class);
-      QueueConnectionFactory factory = getQueueConnectionFactory();
-      QueueConnection conn = factory.createQueueConnection();
-      try
-      {
-         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-         TemporaryQueue replyQueue = session.createTemporaryQueue();
-         QueueReceiver receiver = session.createReceiver(replyQueue);
-         QueueSender sender = session.createSender(queue);
-         conn.start();
-         try
-         {
-            TextMessage msg = session.createTextMessage(text);
-            msg.setJMSReplyTo(replyQueue);
-            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
-            msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", redeliveryLimit);
-      
-            sender.send(msg);
-            
-            Message reply = receiver.receive(5000);
-            assertNotNull(reply);
-            
-            Serializable obj = ((ObjectMessage) reply).getObject();
-            if(obj instanceof Exception)
-               throw (Exception) obj;
-            else
-               return obj;
-         }
-         finally
-         {
-            conn.stop();
-            sender.close();
-            receiver.close();
-            session.close();
-         }
-      }
-      finally
-      {
-         conn.close();
-      }
-   }
-   
-   public void _testBreak() throws Exception
-   {
-      Object result = sendMessage(QUEUE_NAME, "abort");
-      System.out.println("testBreak: result = " + result);
-   }
-   
-   public void testDefault() throws Exception
-   {
-      Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
-      int base = result.size();
-      result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
-      assertEquals(base + 1, result.size());
-      result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
-      assertEquals(base + 2, result.size());
-   }
-   
-   public void _testDefault2() throws Exception
-   {
-      StressQueueRemote bean = lookup("StressQueueBean/remote", StressQueueRemote.class);
-      
-      bean.fireMessages(100);
-   }
-   
-   public void _testRuntimeException() throws Exception
-   {
-      ObjectName name = new ObjectName("jboss.j2ee:jar=jbpapp2260.jar,name=TransactionMDB,service=EJB3");
-      getServer().invoke(name, "startDelivery", null, null);
-      try
-      {
-         Object result = sendMessage(QUEUE_NAME, "RuntimeException", 2);
-         assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
-//         result = sendMessage(QUEUE_NAME, "RuntimeException");
-//         assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
-//         result = sendMessage(QUEUE_NAME, "RuntimeException");
-//         assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
-      }
-      finally
-      {
-         getServer().invoke(name, "stopDelivery", null, null);
-      }
-   }
-   
-   public void testStress() throws Exception
-   {
-      Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
-      int base = result.size();
-      
-      Queue queue = lookup("queue/" + QUEUE_NAME, Queue.class);
-      QueueConnectionFactory factory = getQueueConnectionFactory();
-      QueueConnection conn = factory.createQueueConnection();
-      try
-      {
-         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-         TemporaryQueue replyQueue = session.createTemporaryQueue();
-         QueueReceiver receiver = session.createReceiver(replyQueue);
-         QueueSender sender = session.createSender(queue);
-         conn.start();
-         try
-         {
-            log.info("Firing messages...");
-            
-            for(int i = 0; i < 100; i++)
-            {
-               TextMessage msg = session.createTextMessage("message #" + i);
-               msg.setJMSReplyTo(replyQueue);
-               msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
-               msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
-         
-               sender.send(msg);
-            }
-            
-            log.info("Waiting for replies...");
-            
-            for(int i = 0; i < 100; i++)
-            {
-               Message reply = receiver.receive(5000);
-               assertNotNull(reply);
-               
-               Serializable obj = ((ObjectMessage) reply).getObject();
-               if(obj instanceof Exception)
-                  throw (Exception) obj;
-               
-               result = (Map<String, AtomicInteger>) obj;
-               assertEquals("Message was not delivered in unique transaction", base + 1 + i, result.size());
-            }
-            
-            log.info("Done");
-         }
-         finally
-         {
-            conn.stop();
-            sender.close();
-            receiver.close();
-            session.close();
-         }
-      }
-      finally
-      {
-         conn.close();
-      }
-   }
-   
-   public void _testStress2() throws Exception
-   {
-      StressQueueRemote bean = lookup("StressQueueBean/remote", StressQueueRemote.class);
-      
-      ObjectName name = new ObjectName("jboss.j2ee:jar=jbpapp2260.jar,name=TransactionMDB,service=EJB3");
-      getServer().invoke(name, "startDelivery", null, null);
-      
-      try
-      {
-         bean.fireMessages(100);
-      }
-      finally
-      {
-         getServer().invoke(name, "stopDelivery", null, null);
-      }   
-   }
-   
-   public static Test suite() throws Exception
-   {
-      return getDeploySetup(MessageInflowTransactionUnitTestCase.class, "jbpapp2260.jar");
-   }
-}

Copied: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java (from rev 91208, branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java)
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/ejb3/jbpapp2260/unit/MessageInflowTransactionUnitTestCase.java	2009-07-15 09:21:07 UTC (rev 91284)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.jbpapp2260.unit;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+
+import junit.framework.Test;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.ejb3.common.EJB3TestCase;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MessageInflowTransactionUnitTestCase extends EJB3TestCase
+{
+   private static final Logger log = Logger.getLogger(MessageInflowTransactionUnitTestCase.class);
+   
+   private static final String QUEUE_NAME = "jbpapp2260";
+   
+   public MessageInflowTransactionUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public Object sendMessage(String queueName, String text) throws Exception
+   {
+      return sendMessage(queueName, text, 1);
+   }
+   
+   public Object sendMessage(String queueName, String text, int redeliveryLimit) throws Exception
+   {
+      Queue queue = lookup("queue/" + queueName, Queue.class);
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      QueueConnection conn = factory.createQueueConnection();
+      try
+      {
+         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         QueueSender sender = session.createSender(queue);
+         conn.start();
+         try
+         {
+            TextMessage msg = session.createTextMessage(text);
+            msg.setJMSReplyTo(replyQueue);
+            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+            msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", redeliveryLimit);
+      
+            sender.send(msg);
+            
+            Message reply = receiver.receive(5000);
+            assertNotNull(reply);
+            
+            Serializable obj = ((ObjectMessage) reply).getObject();
+            if(obj instanceof Exception)
+               throw (Exception) obj;
+            else
+               return obj;
+         }
+         finally
+         {
+            conn.stop();
+            sender.close();
+            receiver.close();
+            session.close();
+         }
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+   
+   public void testDefault() throws Exception
+   {
+      Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+      int base = result.size();
+      result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+      assertEquals(base + 1, result.size());
+      result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+      assertEquals(base + 2, result.size());
+   }
+   
+   public void testStress() throws Exception
+   {
+      Map<String, AtomicInteger> result = (Map<String, AtomicInteger>) sendMessage(QUEUE_NAME, "testDefault");
+      int base = result.size();
+      
+      Queue queue = lookup("queue/" + QUEUE_NAME, Queue.class);
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      QueueConnection conn = factory.createQueueConnection();
+      try
+      {
+         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         QueueSender sender = session.createSender(queue);
+         conn.start();
+         try
+         {
+            log.info("Firing messages...");
+            
+            for(int i = 0; i < 100; i++)
+            {
+               TextMessage msg = session.createTextMessage("message #" + i);
+               msg.setJMSReplyTo(replyQueue);
+               msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+               msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
+         
+               sender.send(msg);
+            }
+            
+            log.info("Waiting for replies...");
+            
+            for(int i = 0; i < 100; i++)
+            {
+               Message reply = receiver.receive(5000);
+               assertNotNull(reply);
+               
+               Serializable obj = ((ObjectMessage) reply).getObject();
+               if(obj instanceof Exception)
+                  throw (Exception) obj;
+               
+               result = (Map<String, AtomicInteger>) obj;
+               assertEquals("Message was not delivered in unique transaction", base + 1 + i, result.size());
+            }
+            
+            log.info("Done");
+         }
+         finally
+         {
+            conn.stop();
+            sender.close();
+            receiver.close();
+            session.close();
+         }
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(MessageInflowTransactionUnitTestCase.class, "jbpapp2260.jar");
+   }
+}

Added: branches/JBPAPP_5_0/testsuite/src/resources/ejb3/jbpapp2260/jbpapp2260-destinations-service.xml
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/resources/ejb3/jbpapp2260/jbpapp2260-destinations-service.xml	                        (rev 0)
+++ branches/JBPAPP_5_0/testsuite/src/resources/ejb3/jbpapp2260/jbpapp2260-destinations-service.xml	2009-07-15 09:21:07 UTC (rev 91284)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+  <mbean code="org.jboss.mq.server.jmx.Queue"
+    name="jboss.mq.destination:service=Queue,name=jbpapp2260">
+    <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+  </mbean>
+</server>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list