[jboss-cvs] JBoss Messaging SVN: r2391 - in projects/jms-integration: src/etc/deployments and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 21 18:17:10 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-02-21 18:17:09 -0500 (Wed, 21 Feb 2007)
New Revision: 2391

Added:
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/ejb-jar.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/jboss.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/ejb-jar.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/jboss.xml
   projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionDupsOkTestMessageDriven.java
   projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionTestMessageDriven.java
   projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionDupsOKTest.java
   projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionTest.java
Modified:
   projects/jms-integration/build.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20-durable/META-INF/ejb-jar.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20-selector/META-INF/ejb-jar.xml
   projects/jms-integration/src/etc/deployments/mdb-ejb20/META-INF/ejb-jar.xml
   projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/TestMessageDriven.java
   projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBDurableTest.java
Log:
Adding UserTransaction tests

Modified: projects/jms-integration/build.xml
===================================================================
--- projects/jms-integration/build.xml	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/build.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -190,6 +190,8 @@
    <property name="integration.test.mdb20" value="integration-mdb20.jar"/>
    <property name="integration.test.mdb20.selector" value="integration-mdb20-selector.jar"/>
    <property name="integration.test.mdb20.durable" value="integration-mdb20-durable.jar"/>
+   <property name="integration.test.mdb20.userTransaction" value="integration-mdb20-userTransaction.jar"/>
+   <property name="integration.test.mdb20.userTransactionDups" value="integration-mdb20-userTransactionDups.jar"/>
 
    <target name="integration-ejb20-jar" depends="compile">
       <mkdir dir="${build.tests.lib}"/>
@@ -211,7 +213,7 @@
       </jar>
    </target>
 
-   <target name="integration-ejb20-selector-durable" depends="compile">
+   <target name="integration-ejb20-durable" depends="compile">
       <mkdir dir="${build.tests.lib}"/>
       <jar jarfile="${build.tests.lib}/${integration.test.mdb20.durable}">
          <metainf dir="${tests.root}/src/etc/deployments/mdb-ejb20-durable/META-INF"/>
@@ -221,9 +223,29 @@
       </jar>
    </target>
 
-   <target name="tests-jar" depends="compile, integration-ejb20-jar, integration-ejb20-selector-jar, integration-ejb20-selector-durable"/>
+   <target name="integration-ejb20-userTransaction" depends="compile">
+      <mkdir dir="${build.tests.lib}"/>
+      <jar jarfile="${build.tests.lib}/${integration.test.mdb20.userTransaction}">
+         <metainf dir="${tests.root}/src/etc/deployments/mdb-ejb20-userTransaction/META-INF"/>
+         <fileset dir="${build.tests.classes}">
+            <include name="org/jboss/test/jms/integration/support/ejb20/**"/>
+         </fileset>
+      </jar>
+   </target>
 
+   <target name="integration-ejb20-userTransactionDups" depends="compile">
+      <mkdir dir="${build.tests.lib}"/>
+      <jar jarfile="${build.tests.lib}/${integration.test.mdb20.userTransactionDups}">
+         <metainf dir="${tests.root}/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF"/>
+         <fileset dir="${build.tests.classes}">
+            <include name="org/jboss/test/jms/integration/support/ejb20/**"/>
+         </fileset>
+      </jar>
+   </target>
 
+   <target name="tests-jar" depends="compile, integration-ejb20-jar, integration-ejb20-selector-jar, integration-ejb20-durable, integration-ejb20-userTransaction, integration-ejb20-userTransactionDups"/>
+
+
    <target name="integration-tests"
            depends="tests-jar, integration-ejb20-jar"
            description="Runs the clustering tests">

Modified: projects/jms-integration/src/etc/deployments/mdb-ejb20/META-INF/ejb-jar.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20/META-INF/ejb-jar.xml	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20/META-INF/ejb-jar.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
 
 <ejb-jar>
    <description>MBean Integration Tests</description>

Modified: projects/jms-integration/src/etc/deployments/mdb-ejb20-durable/META-INF/ejb-jar.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-durable/META-INF/ejb-jar.xml	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-durable/META-INF/ejb-jar.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
 
 <ejb-jar>
    <description>MBean Integration Tests</description>

Modified: projects/jms-integration/src/etc/deployments/mdb-ejb20-selector/META-INF/ejb-jar.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-selector/META-INF/ejb-jar.xml	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-selector/META-INF/ejb-jar.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
 
 <ejb-jar>
    <description>MBean Integration Tests</description>

Added: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/ejb-jar.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/ejb-jar.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <description>MBean Integration Tests</description>
+   <display-name>QueueAdapter</display-name>
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>QueueAdapter</ejb-name>
+         <ejb-class>
+            org.jboss.test.jms.integration.support.ejb20.UserTransactionTestMessageDriven
+         </ejb-class>
+         <transaction-type>Bean</transaction-type>
+         <message-selector></message-selector>
+         <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
+         <message-driven-destination>
+            <destination-type>javax.jms.Queue</destination-type>
+            <subscription-durability>
+               NonDurable
+            </subscription-durability>
+         </message-driven-destination>
+         <resource-ref>
+            <description>A ConnectionFactory</description>
+            <res-ref-name>connectionFactory</res-ref-name>
+            <res-type>javax.jms.ConnectionFactory</res-type>
+            <res-auth>Container</res-auth>
+         </resource-ref>
+      </message-driven>
+   </enterprise-beans>
+   <assembly-descriptor>
+      <container-transaction>
+         <method>
+            <ejb-name>QueueAdapter</ejb-name>
+            <method-name>*</method-name>
+         </method>
+         <trans-attribute>Required</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+</ejb-jar>


Property changes on: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/ejb-jar.xml
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/jboss.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/jboss.xml	                        (rev 0)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/jboss.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>QueueAdapter</ejb-name>
+         <destination-jndi-name>queue/testQueue</destination-jndi-name>
+         <!-- I"m using singleton on this test to guarantee the order -->
+         <configuration-name>Singleton Message Driven Bean</configuration-name>
+         <resource-ref>
+            <res-ref-name>connectionFactory</res-ref-name>
+            <resource-name>connectionFactory</resource-name>
+         </resource-ref>
+      </message-driven>
+   </enterprise-beans>
+
+   <resource-managers>
+      <resource-manager>
+         <res-name>connectionFactory</res-name>
+         <res-jndi-name>java:/JmsXA</res-jndi-name>
+      </resource-manager>
+   </resource-managers>
+</jboss>
+


Property changes on: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransaction/META-INF/jboss.xml
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/ejb-jar.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/ejb-jar.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+   <description>MBean Integration Tests</description>
+   <display-name>QueueAdapter</display-name>
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>QueueAdapter</ejb-name>
+         <ejb-class>
+            org.jboss.test.jms.integration.support.ejb20.UserTransactionDupsOkTestMessageDriven
+         </ejb-class>
+         <transaction-type>Bean</transaction-type>
+         <message-selector></message-selector>
+         <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
+         <message-driven-destination>
+            <destination-type>javax.jms.Queue</destination-type>
+            <subscription-durability>
+               NonDurable
+            </subscription-durability>
+         </message-driven-destination>
+         <resource-ref>
+            <description>A ConnectionFactory</description>
+            <res-ref-name>connectionFactory</res-ref-name>
+            <res-type>javax.jms.ConnectionFactory</res-type>
+            <res-auth>Container</res-auth>
+         </resource-ref>
+      </message-driven>
+   </enterprise-beans>
+   <assembly-descriptor>
+      <container-transaction>
+         <method>
+            <ejb-name>QueueAdapter</ejb-name>
+            <method-name>*</method-name>
+         </method>
+         <trans-attribute>Required</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+</ejb-jar>


Property changes on: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/ejb-jar.xml
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/jboss.xml
===================================================================
--- projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/jboss.xml	                        (rev 0)
+++ projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/jboss.xml	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>QueueAdapter</ejb-name>
+         <destination-jndi-name>queue/testQueue</destination-jndi-name>
+         <!-- I"m using singleton on this test to guarantee the order -->
+         <configuration-name>Singleton Message Driven Bean</configuration-name>
+         <resource-ref>
+            <res-ref-name>connectionFactory</res-ref-name>
+            <resource-name>connectionFactory</resource-name>
+         </resource-ref>
+      </message-driven>
+   </enterprise-beans>
+
+   <resource-managers>
+      <resource-manager>
+         <res-name>connectionFactory</res-name>
+         <res-jndi-name>java:/JmsXA</res-jndi-name>
+      </resource-manager>
+   </resource-managers>
+</jboss>
+


Property changes on: projects/jms-integration/src/etc/deployments/mdb-ejb20-userTransactionDups/META-INF/jboss.xml
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Modified: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/TestMessageDriven.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/TestMessageDriven.java	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/TestMessageDriven.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -169,7 +169,7 @@
 
       } catch (Exception e)
       {
-         log.error(e);
+         log.error(e, e);
          messageDrivenContext.setRollbackOnly();
       }
    }

Added: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionDupsOkTestMessageDriven.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionDupsOkTestMessageDriven.java	                        (rev 0)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionDupsOkTestMessageDriven.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,194 @@
+/*
+   * 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.jms.integration.support.ejb20;
+
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.EJBException;
+import javax.jms.MessageListener;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import javax.jms.Destination;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.UserTransaction;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class UserTransactionDupsOkTestMessageDriven implements MessageDrivenBean, MessageListener
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   private static Logger log = Logger.getLogger(UserTransactionDupsOkTestMessageDriven.class);
+
+   static String CONNECTION_FACTORY = "java:comp/env/connectionFactory";
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   MessageDrivenContext messageDrivenContext;
+   Context ctx;
+   ConnectionFactory cf;
+   Connection conn;
+   UserTransaction userTransaction;
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) throws EJBException
+   {
+      this.messageDrivenContext = messageDrivenContext;
+   }
+
+   public void ejbCreate() throws EJBException
+   {
+      try
+      {
+         ctx = new InitialContext();
+         cf = (ConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
+         conn = cf.createConnection();
+         conn.start();
+         userTransaction = (UserTransaction) ctx.lookup("UserTransaction");
+      }
+      catch (NamingException e)
+      {
+          throw new EJBException(e);
+      }
+      catch (JMSException e)
+      {
+         throw new EJBException(e);
+      }
+
+   }
+
+   public void ejbRemove() throws EJBException
+   {
+      try
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+      catch (JMSException e)
+      {
+         throw new EJBException (e);
+      }
+   }
+
+   public void onMessage(Message message)
+   {
+      TextMessage txtMessage = null;
+      try
+      {
+         userTransaction.begin();
+
+         if (message instanceof TextMessage)
+         {
+            txtMessage = (TextMessage)message;
+            System.out.println("Received message " + txtMessage.getText());
+         }
+         else
+         {
+            System.out.println("Received message " + message);
+         }
+         Destination replyTo = message.getJMSReplyTo();
+         Session session = null;
+         try
+         {
+            session = conn.createSession(true, Session.SESSION_TRANSACTED);
+            MessageProducer producer = session.createProducer(replyTo);
+
+            TextMessage reply = null;
+
+            if (txtMessage != null)
+            {
+               reply = session.createTextMessage("reply to message " + txtMessage.getText());
+            }
+            else
+            {
+               reply = session.createTextMessage("reply to message " + message);
+            }
+
+            reply.setStringProperty("toStringOnMessage", message.toString());
+
+            producer.send(reply);
+
+
+            boolean commit = message.getBooleanProperty("commit");
+            if (commit)
+            {
+               userTransaction.commit();
+               message.acknowledge();
+            }
+            else
+            {
+               userTransaction.rollback();
+            }
+
+         }
+         finally
+         {
+           if (session!=null)
+           {
+              session.close();
+           }
+         }
+
+         // I'm not doing anything with this connections... this is just to validate
+         // if there isn't any problem on creating connections (such as classLoading isolations)
+         ConnectionFactory localCF = (ConnectionFactory)ctx.lookup("/ConnectionFactory");
+         Connection conn = localCF.createConnection();
+         conn.close();
+
+      } catch (Exception e)
+      {
+         log.error(e, e);
+         //messageDrivenContext.setRollbackOnly();
+      }
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionDupsOkTestMessageDriven.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionTestMessageDriven.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionTestMessageDriven.java	                        (rev 0)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionTestMessageDriven.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,193 @@
+/*
+   * 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.jms.integration.support.ejb20;
+
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.EJBException;
+import javax.jms.MessageListener;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+import javax.jms.Destination;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.UserTransaction;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class UserTransactionTestMessageDriven implements MessageDrivenBean, MessageListener
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   private static Logger log = Logger.getLogger(UserTransactionTestMessageDriven.class);
+
+   static String CONNECTION_FACTORY = "java:comp/env/connectionFactory";
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   MessageDrivenContext messageDrivenContext;
+   Context ctx;
+   ConnectionFactory cf;
+   Connection conn;
+   UserTransaction userTransaction;
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) throws EJBException
+   {
+      this.messageDrivenContext = messageDrivenContext;
+   }
+
+   public void ejbCreate() throws EJBException
+   {
+      try
+      {
+         ctx = new InitialContext();
+         cf = (ConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
+         conn = cf.createConnection();
+         conn.start();
+         userTransaction = (UserTransaction) ctx.lookup("UserTransaction");
+      }
+      catch (NamingException e)
+      {
+          throw new EJBException(e);
+      }
+      catch (JMSException e)
+      {
+         throw new EJBException(e);
+      }
+
+   }
+
+   public void ejbRemove() throws EJBException
+   {
+      try
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+      catch (JMSException e)
+      {
+         throw new EJBException (e);
+      }
+   }
+
+   public void onMessage(Message message)
+   {
+      TextMessage txtMessage = null;
+      try
+      {
+         userTransaction.begin();
+
+         if (message instanceof TextMessage)
+         {
+            txtMessage = (TextMessage)message;
+            System.out.println("Received message " + txtMessage.getText());
+         }
+         else
+         {
+            System.out.println("Received message " + message);
+         }
+         Destination replyTo = message.getJMSReplyTo();
+         Session session = null;
+         try
+         {
+            session = conn.createSession(true, Session.SESSION_TRANSACTED);
+            MessageProducer producer = session.createProducer(replyTo);
+
+            TextMessage reply = null;
+
+            if (txtMessage != null)
+            {
+               reply = session.createTextMessage("reply to message " + txtMessage.getText());
+            }
+            else
+            {
+               reply = session.createTextMessage("reply to message " + message);
+            }
+
+            reply.setStringProperty("toStringOnMessage", message.toString());
+
+            producer.send(reply);
+
+
+            boolean commit = message.getBooleanProperty("commit");
+            if (commit)
+            {
+               userTransaction.commit();
+            }
+            else
+            {
+               userTransaction.rollback();
+            }
+
+         }
+         finally
+         {
+           if (session!=null)
+           {
+              session.close();
+           }
+         }
+
+         // I'm not doing anything with this connections... this is just to validate
+         // if there isn't any problem on creating connections (such as classLoading isolations)
+         ConnectionFactory localCF = (ConnectionFactory)ctx.lookup("/ConnectionFactory");
+         Connection conn = localCF.createConnection();
+         conn.close();
+
+      } catch (Exception e)
+      {
+         log.error(e, e);
+         //messageDrivenContext.setRollbackOnly();
+      }
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: projects/jms-integration/src/main/org/jboss/test/jms/integration/support/ejb20/UserTransactionTestMessageDriven.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Modified: projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBDurableTest.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBDurableTest.java	2007-02-21 20:36:52 UTC (rev 2390)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBDurableTest.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -39,8 +39,6 @@
 public class SimpleMDBDurableTest extends MDBTestBase
 {
 
-   Random random = new Random();
-
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------

Added: projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionDupsOKTest.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionDupsOKTest.java	                        (rev 0)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionDupsOKTest.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,112 @@
+/*
+   * 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.jms.integration.tests;
+
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.jms.MessageConsumer;
+import javax.jms.TextMessage;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *          $Id$
+ */
+public class SimpleMDBUserTransactionDupsOKTest extends MDBTestBase
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public SimpleMDBUserTransactionDupsOKTest(String name)
+   {
+      super(name);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void testSimpleMDB() throws Exception
+   {
+      Connection conn = cf.createConnection();
+      conn.start();
+      Session sess = null;
+
+      try
+      {
+         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer producer = sess.createProducer(queueDestination);
+         MessageConsumer consumer = sess.createConsumer(responseDestination);
+         TextMessage message = sess.createTextMessage("Message " + random.nextLong());
+         message.setBooleanProperty("commit",true);
+         message.setJMSReplyTo(responseDestination);
+         producer.send(message);
+
+         TextMessage messageResponse = (TextMessage)consumer.receive(10000);
+         assertNotNull(messageResponse);
+         System.out.println("Received message " + messageResponse.getText());
+         assertEquals(message.toString(), messageResponse.getStringProperty("toStringOnMessage"));
+
+
+         message = sess.createTextMessage("Message " + random.nextLong());
+         message.setBooleanProperty("commit",false);
+         message.setJMSReplyTo(responseDestination);
+         producer.send(message);
+
+         messageResponse = (TextMessage)consumer.receive(10000);
+         assertNull(messageResponse);
+      }
+      finally
+      {
+         if (conn!=null)
+         {
+            conn.close();
+         }
+      }
+
+   }
+
+
+
+   public static Test suite() throws Exception
+   {
+      // This is from JBoss testsuite framework.. it will deploy the MDB before running the test
+     return getDeploySetup(SimpleMDBUserTransactionDupsOKTest.class,
+        "integration-mdb20-userTransactionDups.jar");
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionDupsOKTest.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionTest.java
===================================================================
--- projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionTest.java	                        (rev 0)
+++ projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionTest.java	2007-02-21 23:17:09 UTC (rev 2391)
@@ -0,0 +1,112 @@
+/*
+   * 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.jms.integration.tests;
+
+import junit.framework.Test;
+import javax.jms.Connection;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.jms.MessageConsumer;
+import javax.jms.TextMessage;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *          $Id$
+ */
+public class SimpleMDBUserTransactionTest extends MDBTestBase
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public SimpleMDBUserTransactionTest(String name)
+   {
+      super(name);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void testSimpleMDB() throws Exception
+   {
+      Connection conn = cf.createConnection();
+      conn.start();
+      Session sess = null;
+
+      try
+      {
+         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer producer = sess.createProducer(queueDestination);
+         MessageConsumer consumer = sess.createConsumer(responseDestination);
+         TextMessage message = sess.createTextMessage("Message " + random.nextLong());
+         message.setBooleanProperty("commit",true);
+         message.setJMSReplyTo(responseDestination);
+         producer.send(message);
+
+         TextMessage messageResponse = (TextMessage)consumer.receive(10000);
+         assertNotNull(messageResponse);
+         System.out.println("Received message " + messageResponse.getText());
+         assertEquals(message.toString(), messageResponse.getStringProperty("toStringOnMessage"));
+
+
+         message = sess.createTextMessage("Message " + random.nextLong());
+         message.setBooleanProperty("commit",false);
+         message.setJMSReplyTo(responseDestination);
+         producer.send(message);
+
+         messageResponse = (TextMessage)consumer.receive(10000);
+         assertNull(messageResponse);
+      }
+      finally
+      {
+         if (conn!=null)
+         {
+            conn.close();
+         }
+      }
+
+   }
+
+
+
+   public static Test suite() throws Exception
+   {
+      // This is from JBoss testsuite framework.. it will deploy the MDB before running the test
+     return getDeploySetup(SimpleMDBUserTransactionTest.class,
+        "integration-mdb20-userTransaction.jar");
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}


Property changes on: projects/jms-integration/src/main/org/jboss/test/jms/integration/tests/SimpleMDBUserTransactionTest.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision




More information about the jboss-cvs-commits mailing list