[Jboss-cvs] JBossAS SVN: r55972 - in trunk/ejb3: . src/resources/test/mdbtransactions src/resources/test/mdbtransactions/META-INF src/test/org/jboss/ejb3/test/mdbtransactions src/test/org/jboss/ejb3/test/mdbtransactions/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 15 14:49:26 EDT 2006


Author: bdecoste
Date: 2006-08-15 14:49:20 -0400 (Tue, 15 Aug 2006)
New Revision: 55972

Added:
   trunk/ejb3/src/resources/test/mdbtransactions/META-INF/ejb-jar.xml
   trunk/ejb3/src/resources/test/mdbtransactions/META-INF/jboss.xml
   trunk/ejb3/src/resources/test/mdbtransactions/META-INF/persistence.xml
   trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/Entity.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueBean21.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacade.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatus.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatusBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java
Modified:
   trunk/ejb3/build-test.xml
Log:
added test for MDB transaction handling

Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/build-test.xml	2006-08-15 18:49:20 UTC (rev 55972)
@@ -1895,6 +1895,39 @@
          </fileset>
       </jar>
    </target>
+   
+   <target name="mdbtransactions"
+      description="Builds all jar files."
+      depends="compile-classes">
+      
+      <mkdir dir="${build.lib}"/>
+      
+      <jar jarfile="${build.lib}/mdbtransactions-test.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/mdbtransactions/*.class"/>
+            <exclude name="org/jboss/ejb3/test/mdbtransactions/*21.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/mdbtransactions">
+            <include name="META-INF/persistence.xml"/>
+         </fileset>
+      </jar>
+      
+      <jar jarfile="${build.lib}/mdbtransactions21-test.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/mdbtransactions/*21.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/mdbtransactions">
+            <include name="META-INF/ejb-jar.xml"/>
+            <include name="META-INF/jboss.xml"/>
+         </fileset>
+      </jar>
+      
+      <copy todir="${build.lib}">
+         <fileset dir="${resources}/test/mdbtransactions">
+            <include name="*.xml"/>
+         </fileset>
+      </copy>
+   </target>
 
    <target name="longlived"
       description="Builds all jar files."
@@ -2531,7 +2564,7 @@
       </jar>
    </target>
    
-   <target name="jars" depends="unauthenticatedprincipal, clusteredservice, invoker, classloader, circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ejbthree440, ejbthree454, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, securitydomain, enventry, jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions, exception, dd/override, stateless, standalone-jar, dd/mdb, bank, dd, longlived, xmlcfg, hbm, pkg, regressionHHH275, entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob,cache,initial,timer,benchmark,entity,joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression, composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc, localcall, interceptors, interceptors2, clientinterceptor"/>
+   <target name="jars" depends="mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader, circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ejbthree440, ejbthree454, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, securitydomain, enventry, jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions, exception, dd/override, stateless, standalone-jar, dd/mdb, bank, dd, longlived, xmlcfg, hbm, pkg, regressionHHH275, entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob,cache,initial,timer,benchmark,entity,joininheritance, singletable, tableperclass, dependent, mdb, manytomany, regression, composite, composite2, entitycallback, relationships, ssl, ssladvanced, clusteredsession, strictpool, jacc, localcall, interceptors, interceptors2, clientinterceptor"/>
 
    <target name="test" depends="init" if="test"
       description="Execute all tests in the given test directory.">
@@ -3115,6 +3148,9 @@
          <param name="test" value="mdb"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="mdbtransactions"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="consumer"/>
       </antcall>
       <antcall target="test" inheritRefs="true">

Added: trunk/ejb3/src/resources/test/mdbtransactions/META-INF/ejb-jar.xml
===================================================================
--- trunk/ejb3/src/resources/test/mdbtransactions/META-INF/ejb-jar.xml	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/resources/test/mdbtransactions/META-INF/ejb-jar.xml	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+
+<!DOCTYPE ejb-jar PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+  "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+  <enterprise-beans>
+    <message-driven>
+	  <ejb-name>QueueBean21</ejb-name>
+	  <ejb-class>org.jboss.ejb3.test.mdbtransactions.QueueBean21</ejb-class>
+      <transaction-type>Container</transaction-type>
+      <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
+      <message-driven-destination>
+        <destination-type>javax.jms.Queue</destination-type>
+      </message-driven-destination>
+    </message-driven>
+  </enterprise-beans>
+  <assembly-descriptor>
+    <container-transaction>
+      <method>
+        <ejb-name>QueueBean21</ejb-name>
+          <method-name>onMessage</method-name>
+          <method-params>
+            <method-param>javax.jms.Message</method-param>
+          </method-params>
+        </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>  
+  </assembly-descriptor>
+</ejb-jar>

Added: trunk/ejb3/src/resources/test/mdbtransactions/META-INF/jboss.xml
===================================================================
--- trunk/ejb3/src/resources/test/mdbtransactions/META-INF/jboss.xml	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/resources/test/mdbtransactions/META-INF/jboss.xml	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE jboss PUBLIC
+      "-//JBoss//DTD JBOSS 3.2//EN"
+      "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
+<jboss>
+   <!--invoker-proxy-bindings>
+      <invoker-proxy-binding>
+         <name>my-message-driven-bean</name>
+         <invoker-mbean>default</invoker-mbean>
+         <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
+         <proxy-factory-config>
+            <JMSProviderAdapterJNDI>DefaultJMSProvider</JMSProviderAdapterJNDI>
+            <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
+            <MaximumSize>15</MaximumSize>
+            <MaxMessages>1</MaxMessages>
+            <MDBConfig>
+               <ReconnectIntervalSec>10</ReconnectIntervalSec>
+               <DLQConfig>
+                  <DestinationQueue>queue/DLQ</DestinationQueue>
+                  <MaxTimesRedelivered>10</MaxTimesRedelivered>
+                  <TimeToLive>0</TimeToLive>
+               </DLQConfig>
+            </MDBConfig>
+         </proxy-factory-config>
+      </invoker-proxy-binding>
+   </invoker-proxy-bindings-->
+
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>QueueBean21</ejb-name>
+         <destination-jndi-name>queue/mdb21test</destination-jndi-name>
+      </message-driven>
+   </enterprise-beans>
+</jboss>

Added: trunk/ejb3/src/resources/test/mdbtransactions/META-INF/persistence.xml
===================================================================
--- trunk/ejb3/src/resources/test/mdbtransactions/META-INF/persistence.xml	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/resources/test/mdbtransactions/META-INF/persistence.xml	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+   <persistence-unit name="tempdb">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+      </properties>
+   </persistence-unit>
+</persistence>

Added: trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml
===================================================================
--- trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/resources/test/mdbtransactions/mdbtransactionstest-service.xml	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+   <mbean code="org.jboss.mq.server.jmx.Queue"
+      name="jboss.mq.destination:service=Queue,name=queuetest">
+      <attribute name="JNDIName">queue/mdbtest</attribute>
+      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+   </mbean>
+   <mbean code="org.jboss.mq.server.jmx.Queue"
+      name="jboss.mq.destination:service=Queue,name=rollbackqueuetest">
+      <attribute name="JNDIName">queue/rollbackmdbtest</attribute>
+      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+   </mbean>
+   <mbean code="org.jboss.mq.server.jmx.Queue"
+      name="jboss.mq.destination:service=Queue,name=queue21test">
+      <attribute name="JNDIName">queue/mdb21test</attribute>
+      <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+   </mbean>
+</server>

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/Entity.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/Entity.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/Entity.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,58 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at javax.persistence.Entity
+ at Table(name = "ENTITY")
+public class Entity implements java.io.Serializable
+{
+   private Long id;
+   private String name;
+
+   @Id
+   //@GeneratedValue(strategy= GenerationType.IDENTITY)
+   public Long getId()
+   {
+      return id;
+   }
+
+   public void setId(Long id)
+   {
+      this.id = id;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueBean21.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueBean21.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueBean21.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,58 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.EJBException;
+
+import javax.jms.MessageListener;
+import javax.jms.Message;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class QueueBean21 implements MessageDrivenBean, MessageListener
+{
+   private static final Logger log = Logger.getLogger(QueueBean21.class);
+   
+    private MessageDrivenContext ctx = null;
+    
+    public void onMessage(Message message)
+    {
+       log.info("***** onMessage " + message);
+    }
+    
+    public void setMessageDrivenContext(MessageDrivenContext ctx)
+       throws EJBException
+    {
+       this.ctx = ctx;
+    }
+    
+    public void ejbCreate(){}
+
+    public void ejbRemove(){}
+} 
+
+

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/QueueTestMDB.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,64 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+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/mdbtest")
+        })
+public class QueueTestMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(QueueTestMDB.class);
+   
+   private @PersistenceContext EntityManager manager;
+   @EJB StatelessFacade stateless;
+   
+   public void onMessage(Message recvMsg)
+   {    
+      try
+      {
+         ObjectMessage message = (ObjectMessage)recvMsg;
+         Entity entity = (Entity)message.getObject(); 
+         stateless.persist(entity);
+         ++TestStatusBean.messageCount;
+      }
+      catch (Throwable t)
+      {
+         TestStatusBean.caughtRollback = true;
+      }
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/RollbackQueueTestMDB.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,63 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+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/rollbackmdbtest")
+        })
+public class RollbackQueueTestMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(QueueTestMDB.class);
+   
+   private @PersistenceContext EntityManager manager;
+   @EJB StatelessFacade stateless;
+   
+   public void onMessage(Message recvMsg)
+   {    
+      try
+      {
+         ObjectMessage message = (ObjectMessage)recvMsg;
+         Entity entity = (Entity)message.getObject();
+         manager.remove(entity);
+      }
+      catch (Throwable t)
+      {
+          t.printStackTrace();
+      }
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacade.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacade.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacade.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,32 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface StatelessFacade
+{
+   void clear(Entity entity);
+   
+   void persist(Entity entity);
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/StatelessFacadeBean.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,73 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless(name="Stateless")
+ at Remote(StatelessFacade.class)
+ at RemoteBinding(jndiBinding = "StatelessFacade")
+public class StatelessFacadeBean implements StatelessFacade
+{
+   private static final Logger log = Logger.getLogger(StatelessFacadeBean.class);
+   
+   private @PersistenceContext EntityManager manager;
+   
+   @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+   public void clear(Entity entity)
+   {
+      try
+      {
+         entity = manager.find(Entity.class, entity.getId());
+         if (entity != null)
+            manager.remove(entity);
+      }
+      catch (Throwable t)
+      {
+         t.printStackTrace();
+      }
+   }
+   
+   @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+   public void persist(Entity entity)
+   {
+      try
+      {
+         manager.persist(entity);
+      }
+      catch (Throwable t)
+      {
+         t.printStackTrace();
+      }
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatus.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatus.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatus.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,34 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface TestStatus
+{
+   boolean caughtRollback();
+   
+   int messageCount();
+   
+   void clear();
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatusBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatusBean.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/TestStatusBean.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,56 @@
+/*
+  * 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.ejb3.test.mdbtransactions;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at Remote(TestStatus.class)
+public class TestStatusBean implements TestStatus
+{
+   private static final Logger log = Logger.getLogger(TestStatusBean.class);
+   
+   public static boolean caughtRollback = false;
+   public static int messageCount = 0;
+
+   public boolean caughtRollback()
+   {
+      return caughtRollback;
+   }
+   
+   public int messageCount()
+   {
+      return messageCount;
+   }
+   
+   public void clear()
+   {
+      caughtRollback = false;
+      messageCount = 0;
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java	2006-08-15 18:49:16 UTC (rev 55971)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtransactions/unit/MDBUnitTestCase.java	2006-08-15 18:49:20 UTC (rev 55972)
@@ -0,0 +1,159 @@
+/*
+ * 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.ejb3.test.mdbtransactions.unit;
+
+import javax.jms.Message;
+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.ObjectMessage;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.ejb3.InitialContextFactory;
+import org.jboss.ejb3.test.mdbtransactions.Entity;
+import org.jboss.ejb3.test.mdbtransactions.StatelessFacade;
+import org.jboss.ejb3.test.mdbtransactions.TestStatus;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class MDBUnitTestCase extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(MDBUnitTestCase.class);
+
+   static boolean deployed = false;
+
+   static int test = 0;
+
+   public MDBUnitTestCase(String name)
+   {
+
+      super(name);
+
+   }
+
+   public void testMdbTransactions() throws Exception
+   {
+      TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
+      status.clear();
+      
+      sendMessages("queue/mdbtest", 2);
+      
+      Thread.sleep(5000);
+      
+      assertEquals(1, status.messageCount());
+      assertTrue(status.caughtRollback());
+   }
+   
+   protected void sendMessages(String queueName, int numMessages) throws Exception
+   {
+      QueueConnection connection = null;
+      QueueSender sender = null;
+      QueueSession session = null;
+
+      Queue queue = (Queue) getInitialContext().lookup(
+            queueName);
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      connection = factory.createQueueConnection();
+      connection.start();
+      session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+      
+      QueueReceiver receiver = session.createReceiver(queue);
+      Message message = receiver.receiveNoWait();
+      while (message != null)
+         message = receiver.receiveNoWait();
+
+      Entity entity = new Entity();
+      entity.setName("test-entity");
+      entity.setId(1234L);
+      
+      StatelessFacade stateless = (StatelessFacade)getInitialContext().lookup("StatelessFacade");
+      stateless.clear(entity);
+      
+      ObjectMessage msg = session.createObjectMessage(entity);
+
+      sender = session.createSender(queue);
+      
+      for (int i = 0 ; i < numMessages ; ++i)
+         sender.send(msg);
+ 
+      session.close();
+      connection.close();
+   }
+   
+   public void testRollback() throws Exception
+   {
+      TestStatus status = (TestStatus)getInitialContext().lookup("TestStatusBean/remote");
+      status.clear();
+      
+      sendMessages("queue/rollbackmdbtest", 1);
+      
+      Thread.sleep(5000);
+      
+      Queue queue = (Queue) getInitialContext().lookup("queue/DLQ");
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      QueueConnection connection = factory.createQueueConnection();
+      connection.start();
+      QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+      QueueReceiver receiver = session.createReceiver(queue);
+      Message message = receiver.receiveNoWait();
+      assertNotNull(message);
+      
+      session.close();
+      connection.close();
+   }
+   
+   protected QueueConnectionFactory getQueueConnectionFactory()
+      throws Exception
+   {
+      try
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "ConnectionFactory");
+      } catch (NamingException e)
+      {
+         return (QueueConnectionFactory) getInitialContext().lookup(
+               "java:/ConnectionFactory");
+      }
+   }
+   
+   protected InitialContext getInitialContext() throws Exception
+   {
+      return InitialContextFactory.getInitialContext();
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(MDBUnitTestCase.class,
+            "mdbtransactionstest-service.xml, mdbtransactions-test.jar");
+   }
+
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list