[jboss-cvs] JBossAS SVN: r68294 - in branches/Branch_4_2/testsuite: src/main/org/jboss/test/jca/ejb and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 14 11:48:31 EST 2007


Author: adrian at jboss.org
Date: 2007-12-14 11:48:31 -0500 (Fri, 14 Dec 2007)
New Revision: 68294

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
   branches/Branch_4_2/testsuite/src/resources/jca/txactive/
   branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/
   branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml
   branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/jboss.xml
Modified:
   branches/Branch_4_2/testsuite/imports/sections/jca.xml
Log:
[JBAS-5083] - Add a test for trying to execute an update in a transaction that has rolled back due to a transaction timeout

Modified: branches/Branch_4_2/testsuite/imports/sections/jca.xml
===================================================================
--- branches/Branch_4_2/testsuite/imports/sections/jca.xml	2007-12-14 16:44:47 UTC (rev 68293)
+++ branches/Branch_4_2/testsuite/imports/sections/jca.xml	2007-12-14 16:48:31 UTC (rev 68294)
@@ -210,6 +210,18 @@
       	
       </jar>
       
+      <jar destfile="${build.lib}/jca-txactive-ejb.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/jca/interfaces/TransactionActive*"/>
+         </fileset>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/jca/ejb/TransactionActive*"/>
+         </fileset>
+         <fileset dir="${build.resources}/jca/txactive">
+            <include name="**/*.xml"/>
+         </fileset>
+      </jar>
+      
       <jar destfile="${build.lib}/jca-tests.jar">
          <fileset dir="${build.classes}">
             <patternset refid="common.test.client.classes"/>

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/ejb/TransactionActiveBean.java	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,231 @@
+/*
+  * 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.jca.ejb;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+/**
+ * TransactionActiveBean.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionActiveBean implements SessionBean  
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+   private SessionContext sessionCtx;
+   private static final Logger log = Logger.getLogger(TransactionActiveBean.class);
+
+   public void setupDatabase()
+   {
+      try
+      {
+         InitialContext ctx = new InitialContext();
+         DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+         Connection c = ds.getConnection();
+         try
+         {
+            Statement stmt = c.createStatement();
+            try
+            {
+               stmt.executeUpdate("create table JCA_TRANSACTION_ACTIVE (name varchar(100))");
+            }
+            catch (SQLException ignored)
+            {
+            }
+            stmt.executeUpdate("delete from JCA_TRANSACTION_ACTIVE");
+            stmt.executeUpdate("insert into JCA_TRANSACTION_ACTIVE values ('100')");
+         }
+         finally
+         {
+            c.close();
+         }
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Unexpected Error: ", e);
+      }
+   }
+
+   public void changeDatabase()
+   {
+      try
+      {
+         InitialContext ctx = new InitialContext();
+         UserTransaction ut = sessionCtx.getUserTransaction();
+         ut.setTransactionTimeout(5);
+         ut.begin();
+         try
+         {
+            DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+            Connection c = ds.getConnection();
+            try
+            {
+               Statement stmt = c.createStatement();
+               stmt.executeUpdate("insert into JCA_TRANSACTION_ACTIVE values ('101')");
+               try
+               {
+                  Thread.sleep(10000);
+               }
+               catch (InterruptedException ignored)
+               {
+               }
+               try
+               {
+                  stmt.executeUpdate("delete from JCA_TRANSACTION_ACTIVE where name='100'");
+               }
+               catch (SQLException expected)
+               {
+                  log.debug("Got expected exception: " + expected);
+               }
+            }
+            finally
+            {
+               try
+               {
+                  c.close();
+               }
+               catch (Exception ignored)
+               {
+               }
+            }
+         }
+         finally
+         {
+            try
+            {
+               ut.rollback();
+            }
+            catch (Exception ignored)
+            {
+            }
+         }
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Unexpected Error: ", e);
+      }
+   }
+
+   public void checkDatabase()
+   {
+      try
+      {
+         InitialContext ctx = new InitialContext();
+         UserTransaction ut = sessionCtx.getUserTransaction();
+         ut.begin();
+         try
+         {
+            DataSource ds = (DataSource) ctx.lookup("java:DefaultDS");
+            Connection c = ds.getConnection();
+            try
+            {
+               Statement stmt = c.createStatement();
+               ResultSet rs = stmt.executeQuery("select name from JCA_TRANSACTION_ACTIVE");
+               if (rs.next() == false)
+                  throw new RuntimeException("Expected a first row");
+               String value = rs.getString(1);
+               if ("100".equals(value) == false)
+                  throw new RuntimeException("Expected first row to be 100 got " + value);
+               if (rs.next())
+                  throw new RuntimeException("Expected only one row");
+            }
+            finally
+            {
+               try
+               {
+                  c.close();
+               }
+               catch (Exception ignored)
+               {
+               }
+            }
+         }
+         finally
+         {
+            try
+            {
+               ut.commit();
+            }
+            catch (Exception ignored)
+            {
+            }
+         }
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Unexpected Error: ", e);
+      }
+   }
+
+   public void ejbCreate() 
+   {
+   }
+
+   public void ejbActivate()
+   {
+    }
+
+   public void ejbPassivate()
+   {
+   }
+
+   public void ejbRemove()
+   {
+   }
+
+   public void setSessionContext(SessionContext ctx)
+   {
+      this.sessionCtx = ctx;
+   }
+
+   public void unsetSessionContext()
+   {
+      this.sessionCtx = null;
+   }
+
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveHome.java	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jca.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBHome;
+
+/**
+ * TransactionActiveHome.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TransactionActiveHome extends EJBHome
+{
+   TransactionActiveRemote create() throws CreateException, RemoteException;
+
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/interfaces/TransactionActiveRemote.java	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.jca.interfaces;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBObject;
+
+/**
+ * TransactionActiveRemote.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TransactionActiveRemote extends EJBObject
+{
+   void setupDatabase() throws RemoteException;
+   void changeDatabase() throws RemoteException;
+   void checkDatabase() throws RemoteException;
+}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/jca/test/TransactionActiveUnitTestCase.java	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.jca.test;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.jca.interfaces.TransactionActiveHome;
+import org.jboss.test.jca.interfaces.TransactionActiveRemote;
+
+/**
+ * TransactionActiveUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TransactionActiveUnitTestCase extends JBossTestCase
+{
+   public TransactionActiveUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(TransactionActiveUnitTestCase.class, "jca-txactive-ejb.jar");
+   }
+
+   public void testJDBCTransactionActive() throws Exception
+   {
+      TransactionActiveHome home = (TransactionActiveHome) getInitialContext().lookup("test/ejbs/TxActiveBean");
+      TransactionActiveRemote remote = home.create();
+      remote.setupDatabase();
+      remote.changeDatabase();
+      remote.checkDatabase();
+   }
+}

Added: branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/ejb-jar.xml	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,26 @@
+<?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>
+   <enterprise-beans>
+      <session>
+         <ejb-name>TxActiveBean</ejb-name>
+         <home>org.jboss.test.jca.interfaces.TransactionActiveHome</home>
+         <remote>org.jboss.test.jca.interfaces.TransactionActiveRemote</remote>
+         <ejb-class>org.jboss.test.jca.ejb.TransactionActiveBean</ejb-class>
+            <session-type>Stateless</session-type>
+            <transaction-type>Bean</transaction-type>
+      </session>
+   </enterprise-beans>
+   <assembly-descriptor>
+      <container-transaction>
+         <method>
+            <ejb-name>TxActiveBean</ejb-name>
+            <method-name>*</method-name>
+         </method>
+         <trans-attribute>Required</trans-attribute>
+      </container-transaction>
+   </assembly-descriptor>
+</ejb-jar>

Added: branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/jboss.xml	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/resources/jca/txactive/META-INF/jboss.xml	2007-12-14 16:48:31 UTC (rev 68294)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 3.2//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">
+
+<jboss>
+   <enterprise-beans>
+      <session>
+         <ejb-name>TxActiveBean</ejb-name>
+         <jndi-name>test/ejbs/TxActiveBean</jndi-name>
+      </session>
+   </enterprise-beans>
+
+</jboss>




More information about the jboss-cvs-commits mailing list