[jboss-svn-commits] JBL Code SVN: r31914 - in labs/jbosstm/trunk: ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 3 10:25:02 EST 2010


Author: mark.little at jboss.com
Date: 2010-03-03 10:25:01 -0500 (Wed, 03 Mar 2010)
New Revision: 31914

Added:
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/basic/UtilsUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryModuleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceManagerUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/WorkUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/UserTransactionUnitTest.java
Modified:
   labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/jca/WorkUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceManagerImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/AtomicTransaction.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/TxWorkManager.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/WorkSynchronization.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/SubordinateAtomicTransaction.java
   labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/internal/jts/orbspecific/coordinator/ArjunaTransactionImple.java
Log:
https://jira.jboss.org/jira/browse/JBTM-715

Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/jca/WorkUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/jca/WorkUnitTest.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/jca/WorkUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -35,10 +35,15 @@
 
 import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TxWorkManager;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.WorkSynchronization;
+
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.Work;
 import javax.resource.spi.work.WorkCompletedException;
 import javax.resource.spi.work.WorkException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
 
 import static org.junit.Assert.*;
 
@@ -46,6 +51,10 @@
 {
     class DummyWork implements Work
     {       
+        public DummyWork ()
+        {
+        }
+        
         public void release ()
         {
         }
@@ -59,7 +68,7 @@
     public void testWorkManager () throws Exception
     {
         DummyWork work = new DummyWork();
-        TransactionImple tx = new TransactionImple(0);
+        Transaction tx = new TransactionImple(0);
         
         TxWorkManager.addWork(work, tx);
         
@@ -81,4 +90,26 @@
         
         assertEquals(TxWorkManager.getWork(tx), null);
     }
+    
+    @Test
+    public void testWorkSynchronization () throws Exception
+    {
+        Transaction tx = new TransactionImple(0);
+        Synchronization ws = new WorkSynchronization(tx);
+        DummyWork work = new DummyWork();
+        
+        TxWorkManager.addWork(work, tx);
+        
+        try
+        {
+            ws.beforeCompletion();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+        
+        ws.afterCompletion(Status.STATUS_COMMITTED);
+    }
 }

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceImple.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceImple.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -42,11 +42,8 @@
 
 import javax.transaction.xa.*;
 
-/*
- * Default visibility.
- */
 
-class XARecoveryResourceImple extends XAResourceRecord implements XARecoveryResource
+public class XARecoveryResourceImple extends XAResourceRecord implements XARecoveryResource
 {
 
     public XARecoveryResourceImple (Uid u)
@@ -69,7 +66,7 @@
     public int recoverable ()
     {
 	/*
-	 * If we haven't got an XID then we tried to load the
+	 * If we haven't got an XID then we probably tried to load the
 	 * state of an inflight transaction and that state had
 	 * just been deleted. So, no recovery to perform.
 	 */

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceManagerImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceManagerImple.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/recovery/jts/XARecoveryResourceManagerImple.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -35,7 +35,6 @@
 
 import com.arjuna.ats.arjuna.common.*;
 
-import java.util.*;
 import javax.transaction.xa.*;
 
 public class XARecoveryResourceManagerImple implements XARecoveryResourceManager

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/AtomicTransaction.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/AtomicTransaction.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/AtomicTransaction.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -36,8 +36,6 @@
 import com.arjuna.ats.internal.jts.orbspecific.ControlImple;
 import com.arjuna.ats.internal.jta.utils.jts.XidUtils;
 
-import com.arjuna.ats.jta.logging.*;
-
 import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
 
 import com.arjuna.common.util.logging.*;

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionImple.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionImple.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -245,7 +245,7 @@
 		}
 
 		if (_theTransaction != null)
-		{
+		{   
 			/*
 			 * Call end on any suspended resources. If this fails, then the
 			 * transaction will be rolled back.
@@ -253,6 +253,9 @@
 
 			try
 			{
+			    if ((getStatus() != Status.STATUS_ACTIVE) && (getStatus() != Status.STATUS_MARKED_ROLLBACK))
+		                        throw new NoTransaction();
+		             
 				if (!endSuspendedRMs())
 					_theTransaction.rollbackOnly();
 
@@ -334,26 +337,31 @@
 			jtaxLogger.logger.debug(DebugLevel.FUNCTIONS, VisibilityLevel.VIS_PUBLIC, com.arjuna.ats.jta.logging.FacilityCode.FAC_JTA, "TransactionImple.rollback");
 		}
 
+		boolean endSuspendedFailed = false;
+		
 		if (_theTransaction != null)
 		{
-			/*
-			 * Call end on any suspended resources. If this fails, then there's
-			 * not a lot else we can do because the transaction is about to roll
-			 * back anyway!
-			 */
-
-			boolean endSuspendedFailed = !endSuspendedRMs();
-
-			if (endSuspendedFailed)
+			try
 			{
-				if (jtaxLogger.loggerI18N.isWarnEnabled())
-				{
-					jtaxLogger.loggerI18N.warn("com.arjuna.ats.internal.jta.transaction.jts.endsuspendfailed1");
-				}
-			}
+		             if ((getStatus() != Status.STATUS_ACTIVE) && (getStatus() != Status.STATUS_MARKED_ROLLBACK))
+		                        throw new NoTransaction();
+		             
+		                 /*
+	                         * Call end on any suspended resources. If this fails, then there's
+	                         * not a lot else we can do because the transaction is about to roll
+	                         * back anyway!
+	                         */
+		             
+		              endSuspendedFailed = !endSuspendedRMs();
 
-			try
-			{
+	                        if (endSuspendedFailed)
+	                        {
+	                                if (jtaxLogger.loggerI18N.isWarnEnabled())
+	                                {
+	                                        jtaxLogger.loggerI18N.warn("com.arjuna.ats.internal.jta.transaction.jts.endsuspendfailed1");
+	                                }
+	                        }
+	                        
 				_theTransaction.abort();
 			}
 			catch (org.omg.CosTransactions.WrongTransaction e1)

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/TxWorkManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/TxWorkManager.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/TxWorkManager.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -40,8 +40,6 @@
 import javax.resource.spi.work.WorkException;
 import javax.transaction.Transaction;
 
-import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple;
-
 import com.arjuna.ats.internal.jta.utils.jtaxLogger;
 import com.arjuna.ats.jta.logging.*;
 

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/WorkSynchronization.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/WorkSynchronization.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/jca/WorkSynchronization.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -32,7 +32,6 @@
 package com.arjuna.ats.internal.jta.transaction.jts.jca;
 
 import com.arjuna.ats.internal.jta.transaction.jts.jca.TxWorkManager;
-import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple;
 
 import javax.transaction.Transaction;
 

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/SubordinateAtomicTransaction.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/SubordinateAtomicTransaction.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/SubordinateAtomicTransaction.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -28,8 +28,6 @@
 
 package com.arjuna.ats.internal.jta.transaction.jts.subordinate;
 
-import javax.transaction.Status;
-
 import org.omg.CORBA.SystemException;
 import org.omg.CORBA.UNKNOWN;
 import org.omg.CosTransactions.HeuristicHazard;

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/basic/UtilsUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/basic/UtilsUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/basic/UtilsUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,100 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2010,
+ * @author JBoss Inc.
+ */
+
+package com.hp.mwtests.ts.jta.jts.basic;
+
+import javax.transaction.Status;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.internal.jta.transaction.jts.AtomicTransaction;
+import com.arjuna.ats.internal.jta.utils.jts.StatusConverter;
+import com.arjuna.ats.internal.jta.utils.jts.XidUtils;
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.ats.internal.jts.OTSImpleManager;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+
+import org.omg.CosTransactions.*;
+
+import static org.junit.Assert.*;
+
+public class UtilsUnitTest
+{
+    @Test
+    public void testXidUtils () throws Exception
+    {
+        assertTrue(XidUtils.getXid(new Uid(), true) != null);
+        
+        OTSImpleManager.current().begin();
+        
+        AtomicTransaction tx = new AtomicTransaction(OTSImpleManager.current().getControlWrapper());
+        
+        assertTrue(XidUtils.getXid(tx.getControlWrapper().get_control(), false) != null);
+        
+        OTSImpleManager.current().commit(true);
+    }
+    
+    @Test
+    public void testStatusConverter () throws Exception
+    {
+        StatusConverter sc = new StatusConverter();
+        
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusActive), Status.STATUS_ACTIVE);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusCommitted), Status.STATUS_COMMITTED);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusCommitting), Status.STATUS_COMMITTING);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusMarkedRollback), Status.STATUS_MARKED_ROLLBACK);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusNoTransaction), Status.STATUS_NO_TRANSACTION);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusPrepared), Status.STATUS_PREPARED);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusPreparing), Status.STATUS_PREPARING);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusRolledBack), Status.STATUS_ROLLEDBACK);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusRollingBack), Status.STATUS_ROLLING_BACK);
+        assertEquals(StatusConverter.convert(org.omg.CosTransactions.Status.StatusUnknown), Status.STATUS_UNKNOWN);
+    }
+    
+    @Before
+    public void setUp () throws Exception
+    {
+        myORB = ORB.getInstance("test");
+        myOA = OA.getRootOA(myORB);
+
+        myORB.initORB(new String[] {}, null);
+        myOA.initOA();
+
+        ORBManager.setORB(myORB);
+        ORBManager.setPOA(myOA);
+    }
+    
+    @After
+    public void tearDown () throws Exception
+    {
+        myOA.destroy();
+        myORB.shutdown();
+    }
+    
+    private ORB myORB = null;
+    private RootOA myOA = null;
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/RecoveryXAResource.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,119 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryXAResource.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.common;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+import com.arjuna.ats.arjuna.common.Uid;
+
+import com.arjuna.ats.jta.xa.*;
+
+import javax.transaction.xa.*;
+
+public class RecoveryXAResource implements XAResource
+{
+    
+    public RecoveryXAResource ()
+    {
+	if (xids == null)
+	{
+	    xids = new Xid[2];
+
+	    AtomicAction a = new AtomicAction();
+	
+	    xids[0] = new XidImple(a);
+
+	    byte[] c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName();
+	
+	    byte[] b = new byte[1];
+	    
+	    b[0] = 'c';
+	
+	    com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(b);
+	
+	    xids[1] = new XidImple(new Uid());
+
+	    com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(c);
+	}
+    }
+	
+    public void commit (Xid xid, boolean onePhase) throws XAException
+    {
+	System.err.println("**commit "+xid);
+    }
+
+    public void end (Xid xid, int flags) throws XAException
+    {
+    }
+
+    public void forget (Xid xid) throws XAException
+    {
+    }
+    
+    public int getTransactionTimeout () throws XAException
+    {
+	return 0;
+    }
+    
+    public int prepare (Xid xid) throws XAException
+    {
+	return XAResource.XA_OK;
+    }
+
+    public Xid[] recover (int flag) throws XAException
+    {
+	System.err.println("**returning "+xids[0]+" and "+xids[1]);
+	
+	return xids;
+    }
+
+    public void rollback (Xid xid) throws XAException
+    {
+	System.err.println("**rollback "+xid);
+    }
+
+    public boolean setTransactionTimeout (int seconds) throws XAException
+    {
+	return true;
+    }
+
+    public void start (Xid xid, int flags) throws XAException
+    {
+    }
+
+    public boolean isSameRM (XAResource xares) throws XAException
+    {
+	return (xares == this);
+    }
+
+    private static Xid[] xids = null;
+    
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryModuleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryModuleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryModuleUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,111 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.  
+ *
+ * $Id: xidcheck.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.recovery;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.arjuna.coordinator.TwoPhaseOutcome;
+import com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule;
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction;
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.ats.jta.common.jtaPropertyManager;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+import com.hp.mwtests.ts.jta.common.RecoveryXAResource;
+
+import static org.junit.Assert.*;
+
+public class XARecoveryModuleUnitTest
+{
+    @Test
+    public void testNull ()
+    {
+        XARecoveryModule xarm = new XARecoveryModule();
+        
+        xarm.periodicWorkFirstPass();
+        xarm.periodicWorkSecondPass();
+    }
+    
+    @Test
+    public void testRecover () throws Exception
+    {
+        ArrayList<String> r = new ArrayList<String>();
+        TransactionImple tx = new TransactionImple();
+        
+        assertTrue(tx.enlistResource(new RecoveryXAResource()));
+        
+        SubordinateAtomicTransaction sat = new SubordinateAtomicTransaction(tx.get_uid(), tx.getTxId(), 0);
+        
+        assertEquals(sat.doPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
+        
+        r.add("com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
+
+        jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveryInstances(r);
+        
+        XARecoveryModule xarm = new XARecoveryModule();
+        
+        for (int i = 0; i < 11; i++)
+        {
+            xarm.periodicWorkFirstPass();
+            xarm.periodicWorkSecondPass();
+        }
+    }
+    
+    @Before
+    public void setUp () throws Exception
+    {
+        myORB = ORB.getInstance("test");
+        myOA = OA.getRootOA(myORB);
+
+        myORB.initORB(new String[] {}, null);
+        myOA.initOA();
+
+        ORBManager.setORB(myORB);
+        ORBManager.setPOA(myOA);
+    }
+    
+    @After
+    public void tearDown () throws Exception
+    {
+        myOA.destroy();
+        myORB.shutdown();
+    }
+    
+    private ORB myORB = null;
+    private RootOA myOA = null;
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceImpleUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,80 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.  
+ *
+ * $Id: xidcheck.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.recovery;
+
+import java.util.ArrayList;
+
+import javax.transaction.xa.XAException;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.recovery.jts.XARecoveryResourceImple;
+import com.arjuna.ats.jta.recovery.XARecoveryResource;
+import com.hp.mwtests.ts.jta.jts.common.DummyXA;
+
+import static org.junit.Assert.*;
+
+class DummyXARecoveryResource extends XARecoveryResourceImple
+{
+    public DummyXARecoveryResource ()
+    {
+        super(new Uid());
+    }
+    
+    public boolean notAProblem (XAException ex, boolean commit)
+    {
+        return super.notAProblem(ex, commit);
+    }
+}
+
+
+public class XARecoveryResourceImpleUnitTest
+{
+    @Test
+    public void test ()
+    {
+        XARecoveryResourceImple xares = new XARecoveryResourceImple(new Uid());
+        
+        assertEquals(xares.getXAResource(), null);
+        assertEquals(xares.recoverable(), XARecoveryResource.INFLIGHT_TRANSACTION);
+        
+        xares = new XARecoveryResourceImple(new Uid(), new DummyXA(false));
+        
+        assertEquals(xares.recover(), XARecoveryResource.FAILED_TO_RECOVER);
+        
+        DummyXARecoveryResource dummy = new DummyXARecoveryResource();
+        
+        assertTrue(dummy.notAProblem(new XAException(XAException.XAER_NOTA), true));
+        assertFalse(dummy.notAProblem(new XAException(XAException.XAER_DUPID), false));
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceManagerUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceManagerUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/recovery/XARecoveryResourceManagerUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,57 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.  
+ *
+ * $Id: xidcheck.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.recovery;
+
+import java.util.ArrayList;
+
+import javax.transaction.xa.XAException;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.recovery.jts.XARecoveryResourceManagerImple;
+import com.hp.mwtests.ts.jta.jts.common.DummyXA;
+
+import static org.junit.Assert.*;
+
+
+public class XARecoveryResourceManagerUnitTest
+{
+    @Test
+    public void test ()
+    {
+        XARecoveryResourceManagerImple man = new XARecoveryResourceManagerImple();
+        
+        assertTrue(man.getResource(new Uid()) != null);
+        assertTrue(man.getResource(new Uid(), new DummyXA(false)) != null);
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/WorkUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/WorkUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/WorkUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,144 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.  
+ *
+ * $Id: xidcheck.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.subordinate;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
+import com.arjuna.ats.internal.jta.transaction.jts.jca.TxWorkManager;
+import com.arjuna.ats.internal.jta.transaction.jts.jca.WorkSynchronization;
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkCompletedException;
+import javax.resource.spi.work.WorkException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+
+import static org.junit.Assert.*;
+
+public class WorkUnitTest
+{
+    class DummyWork implements Work
+    {       
+        public DummyWork ()
+        {
+        }
+        
+        public void release ()
+        {
+        }
+        
+        public void run ()
+        {
+        }
+    }
+    
+    @Test
+    public void testWorkManager () throws Exception
+    {
+        DummyWork work = new DummyWork();
+        Transaction tx = new TransactionImple();
+        
+        TxWorkManager.addWork(work, tx);
+        
+        try
+        {
+            TxWorkManager.addWork(new DummyWork(), tx);
+            
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+        
+        assertTrue(TxWorkManager.hasWork(tx));
+        
+        assertEquals(work, TxWorkManager.getWork(tx));       
+        
+        TxWorkManager.removeWork(work, tx);
+        
+        assertEquals(TxWorkManager.getWork(tx), null);
+    }
+    
+    @Test
+    public void testWorkSynchronization () throws Exception
+    {
+        Transaction tx = new TransactionImple();
+        Synchronization ws = new WorkSynchronization(tx);
+        DummyWork work = new DummyWork();
+        
+        TxWorkManager.addWork(work, tx);
+        
+        try
+        {
+            ws.beforeCompletion();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+        
+        ws.afterCompletion(Status.STATUS_COMMITTED);
+    }
+    
+    @Before
+    public void setUp () throws Exception
+    {
+        myORB = ORB.getInstance("test");
+        myOA = OA.getRootOA(myORB);
+
+        myORB.initORB(new String[] {}, null);
+        myOA.initOA();
+
+        ORBManager.setORB(myORB);
+        ORBManager.setPOA(myOA);
+    }
+    
+    @After
+    public void tearDown () throws Exception
+    {
+        myOA.destroy();
+        myORB.shutdown();
+    }
+    
+    private ORB myORB = null;
+    private RootOA myOA = null;
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,252 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2001, 2002,
+ *
+ * Hewlett-Packard Arjuna Labs,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: SimpleTest.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.twophase;
+
+import javax.naming.InitialContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.xa.XAResource;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.arjuna.thread.ThreadActionData;
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.ats.jta.TransactionManager;
+import com.arjuna.ats.jta.utils.JTAHelper;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+import com.hp.mwtests.ts.jta.common.FailureXAResource;
+import com.hp.mwtests.ts.jta.common.FailureXAResource.FailLocation;
+import com.hp.mwtests.ts.jta.jts.common.DummyXA;
+
+import static org.junit.Assert.*;
+
+
+public class TransactionImpleUnitTest
+{
+    @Test
+    public void test () throws Exception
+    {
+        TransactionImple tx = new TransactionImple();
+
+        DummyXA res = new DummyXA(false);
+        
+        tx.enlistResource(res);
+        
+        tx.delistResource(res, XAResource.TMSUSPEND);
+        
+        tx.commit();
+        
+        assertTrue(TransactionImple.getTransactions() != null);
+        
+        assertEquals(TransactionImple.getTransactions().size(), 0);
+        
+        try
+        {
+            tx = (TransactionImple) TransactionManager.transactionManager(new InitialContext());
+        
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testEnlist () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        TransactionImple tx = new TransactionImple();
+        
+        tx.setRollbackOnly();
+        
+        try
+        {
+            tx.enlistResource(null);
+            
+            fail();
+        }
+        catch (final SystemException ex)
+        {
+        }
+        
+        try
+        {
+            tx.enlistResource(new DummyXA(false));
+            
+            fail();
+        }
+        catch (final RollbackException ex)
+        {
+        }
+        
+        try
+        {
+            tx.commit();
+            
+            fail();
+        }
+        catch (final RollbackException ex)
+        {
+        }
+        
+        try
+        {
+            tx.enlistResource(new DummyXA(false));
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testDelist () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        TransactionImple tx = new TransactionImple();
+
+        try
+        {
+            tx.delistResource(null, XAResource.TMSUCCESS);
+            
+            fail();
+        }
+        catch (final SystemException ex)
+        {
+        }
+
+        DummyXA xares = new DummyXA(false);
+        
+        try
+        {
+            assertFalse(tx.delistResource(xares, XAResource.TMSUCCESS));
+        }
+        catch (final Throwable ex)
+        {
+            fail();
+        }
+
+        tx.enlistResource(xares);
+        
+        assertTrue(tx.delistResource(xares, XAResource.TMSUCCESS));
+        
+        tx.commit();
+        
+        try
+        {
+            tx.delistResource(xares, XAResource.TMSUCCESS);
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testFailure () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        TransactionImple tx = new TransactionImple();
+        
+        assertFalse(tx.equals(null));
+        assertTrue(tx.equals(tx));
+        
+        tx.enlistResource(new FailureXAResource(FailLocation.commit));
+        
+        try
+        {
+            tx.commit();
+            
+            fail();
+        }
+        catch (final HeuristicMixedException ex)
+        {
+        }
+        
+        assertEquals(tx.getStatus(), Status.STATUS_COMMITTED);
+        
+        try
+        {
+            tx.registerSynchronization(null);
+            
+            fail();
+        }
+        catch (final SystemException ex)
+        {
+        }
+        
+        try
+        {
+            tx.commit();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+    }
+    
+    @Before
+    public void setUp () throws Exception
+    {
+        myORB = ORB.getInstance("test");
+        myOA = OA.getRootOA(myORB);
+
+        myORB.initORB(new String[] {}, null);
+        myOA.initOA();
+
+        ORBManager.setORB(myORB);
+        ORBManager.setPOA(myOA);
+    }
+    
+    @After
+    public void tearDown () throws Exception
+    {
+        myOA.destroy();
+        myORB.shutdown();
+    }
+    
+    private ORB myORB = null;
+    private RootOA myOA = null;
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/UserTransactionUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/UserTransactionUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/UserTransactionUnitTest.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -0,0 +1,160 @@
+/*
+ * 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 in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2001, 2002,
+ *
+ * Hewlett-Packard Arjuna Labs,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: SimpleTest.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.jta.jts.twophase;
+
+import javax.naming.InitialContext;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.arjuna.thread.ThreadActionData;
+import com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple;
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.ats.jta.UserTransaction;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+
+import static org.junit.Assert.*;
+
+
+public class UserTransactionUnitTest
+{
+    @Test
+    public void test () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        UserTransactionImple ut = new UserTransactionImple();
+        
+        assertTrue(ut.getTimeout() >= 0);
+        assertTrue(ut.toString() != null);
+        
+        assertEquals(ut.getObjectInstance(null, null, null, null), ut);
+        
+        try
+        {
+            ut = (UserTransactionImple) UserTransaction.userTransaction(new InitialContext());
+        
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testRollbackOnly () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        UserTransactionImple ut = new UserTransactionImple();
+        
+        ut.begin();
+        
+        ut.setRollbackOnly();
+        
+        try
+        {
+            ut.commit();
+            
+            fail();
+        }
+        catch (final RollbackException ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testNull () throws Exception
+    {
+        ThreadActionData.purgeActions();
+        
+        UserTransactionImple ut = new UserTransactionImple();
+        
+        try
+        {
+            ut.commit();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+        
+        try
+        {
+            ut.rollback();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+        
+        try
+        {
+            ut.setRollbackOnly();
+            
+            fail();
+        }
+        catch (final IllegalStateException ex)
+        {
+        }
+    }
+    
+    @Before
+    public void setUp () throws Exception
+    {
+        myORB = ORB.getInstance("test");
+        myOA = OA.getRootOA(myORB);
+
+        myORB.initORB(new String[] {}, null);
+        myOA.initOA();
+
+        ORBManager.setORB(myORB);
+        ORBManager.setPOA(myOA);
+    }
+    
+    @After
+    public void tearDown () throws Exception
+    {
+        myOA.destroy();
+        myORB.shutdown();
+    }
+    
+    private ORB myORB = null;
+    private RootOA myOA = null;
+}

Modified: labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/internal/jts/orbspecific/coordinator/ArjunaTransactionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/internal/jts/orbspecific/coordinator/ArjunaTransactionImple.java	2010-03-03 15:18:31 UTC (rev 31913)
+++ labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/internal/jts/orbspecific/coordinator/ArjunaTransactionImple.java	2010-03-03 15:25:01 UTC (rev 31914)
@@ -308,6 +308,9 @@
 	 * example) then we do nothing - could throw TransactionRequired or
 	 * INVALID_TRANSACTION. However, if it was rolledback then we throw
 	 * TRANSACTION_ROLLEDBACK. Seems like an inconsistency.
+	 * 
+	 * OTS is vague as to what to do if the transaction has been terminated,
+	 * so we make a sensible choice.
 	 *
 	 * report_heuristics is ignored if we are a subtransaction.
 	 */



More information about the jboss-svn-commits mailing list