[jboss-svn-commits] JBL Code SVN: r31958 - in labs/jbosstm/trunk: ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Mar 5 07:37:06 EST 2010


Author: mark.little at jboss.com
Date: 2010-03-05 07:37:04 -0500 (Fri, 05 Mar 2010)
New Revision: 31958

Added:
   labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionManagerImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/TestBase.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/SubordinateTxUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/TransactionImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/WorkUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/XATerminatorImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/TransactionImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/SynchronizationUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionManagerImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/XAResourceRecordUnitTest.java
Modified:
   labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporter.java
   labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporterImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/LocalCleanupSynchronization.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/orbspecific/XAResourceRecord.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionManagerImple.java
   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/TransactionImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/jca/TransactionImple.java
   labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java
   labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/jts/extensions/AtomicTransaction.java
Log:
https://jira.jboss.org/jira/browse/JBTM-715

Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporter.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporter.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporter.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -20,12 +20,10 @@
  */
 package com.arjuna.ats.internal.jta.transaction.arjunacore.jca;
 
-import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple;
 import com.arjuna.ats.arjuna.common.Uid;
 
 import javax.transaction.xa.Xid;
 import javax.transaction.xa.XAException;
-import javax.transaction.Transaction;
 
 /**
  * A TransactionImporter is used to manager the relationship with external SubordinateTransactions.

Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporterImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporterImple.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TransactionImporterImple.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -34,7 +34,6 @@
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.transaction.xa.*;
-import javax.transaction.Transaction;
 
 import com.arjuna.ats.arjuna.common.Uid;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple;

Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionManagerImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionManagerImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionManagerImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,58 @@
+/*
+ * 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.twophase;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+
+import static org.junit.Assert.*;
+
+
+public class TransactionManagerImpleUnitTest
+{
+    @Test
+    public void test () throws Exception
+    {
+        TransactionManagerImple tmi = new TransactionManagerImple();
+        
+        assertEquals(tmi.getTransaction(), null);
+        
+        assertEquals(tmi.getObjectInstance(null, null, null, null), tmi);
+        
+        tmi.setTransactionTimeout(10);
+        
+        assertEquals(tmi.getTimeout(), 10);
+    }
+}

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/LocalCleanupSynchronization.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/LocalCleanupSynchronization.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/LocalCleanupSynchronization.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -36,10 +36,6 @@
 
 import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
 
-import com.arjuna.ats.jta.utils.JTAHelper;
-
-import javax.transaction.xa.*;
-
 /**
  * This synchronization is responsible for removing the JTA transaction
  * from the internal table. We don't need one for the purely local JTA
@@ -63,6 +59,10 @@
 	return true;
     }
 
+    /**
+     * status is ActionStatus
+     */
+    
     public boolean afterCompletion (int status)
     {
 	_tx.shutdown();

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/orbspecific/XAResourceRecord.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/orbspecific/XAResourceRecord.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/resources/jts/orbspecific/XAResourceRecord.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -221,7 +221,7 @@
 		{
 			removeConnection();
 
-			return Vote.VoteReadOnly;
+			return Vote.VoteRollback;
 		}
 
 		if (_tranID == null)

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionManagerImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionManagerImple.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/TransactionManagerImple.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -34,9 +34,6 @@
 import com.arjuna.ats.internal.jta.utils.jtaxLogger;
 import org.omg.CosTransactions.*;
 
-import com.arjuna.ats.jta.logging.*;
-
-import com.arjuna.ats.jts.*;
 import com.arjuna.ats.jts.OTSManager;
 
 import com.arjuna.ats.internal.jts.ControlWrapper;

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-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/SubordinateAtomicTransaction.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -238,10 +238,17 @@
 
 	private ServerTransaction getTransaction ()
 	{
-		ServerControlWrapper scw = (ServerControlWrapper) super._theAction;
-		ServerControl sc = (ServerControl) scw.getImple();
-		
-		return (ServerTransaction) sc.getImplHandle();
+	    ServerControlWrapper scw = (ServerControlWrapper) super._theAction;
+
+	    if (scw != null)
+	    {
+	        ServerControl sc = (ServerControl) scw.getImple();
+
+	        if (sc != null)
+	            return (ServerTransaction) sc.getImplHandle();
+	    }
+
+	    return null;
 	}
 	
 	    /*

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/TransactionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/TransactionImple.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/TransactionImple.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -41,7 +41,6 @@
 import com.arjuna.ats.jta.exceptions.InactiveTransactionException;
 import com.arjuna.ats.jta.exceptions.InvalidTerminationStateException;
 import com.arjuna.ats.jta.exceptions.UnexpectedConditionException;
-import com.arjuna.ats.jta.logging.*;
 
 import java.lang.IllegalStateException;
 

Modified: labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/jca/TransactionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/jca/TransactionImple.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/classes/com/arjuna/ats/internal/jta/transaction/jts/subordinate/jca/TransactionImple.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -35,7 +35,6 @@
 import com.arjuna.common.util.logging.*;
 
 import com.arjuna.ats.arjuna.common.Uid;
-import com.arjuna.ats.jta.logging.*;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction;
 
 import javax.transaction.xa.Xid;

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/TestBase.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/TestBase.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/common/TestBase.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,69 @@
+/*
+ * 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.common;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.jts.ORBManager;
+import com.arjuna.orbportability.OA;
+import com.arjuna.orbportability.ORB;
+import com.arjuna.orbportability.RootOA;
+
+import static org.junit.Assert.*;
+
+public class TestBase
+{   
+    @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/jca/SubordinateTxUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/SubordinateTxUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/SubordinateTxUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,70 @@
+/*
+ * 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.jca;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.SubordinateAtomicTransaction;
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class SubordinateTxUnitTest extends TestBase
+{
+    @Test
+    public void testTransactionImple () throws Exception
+    {
+        TransactionImple tx = new TransactionImple(new Uid());
+        TransactionImple dummy = new TransactionImple(new Uid());
+        
+        tx.recordTransaction();
+        
+        assertFalse(tx.equals(dummy));
+        
+        assertTrue(tx.toString() != null);
+        
+        tx.recover();
+    }
+    
+    @Test
+    public void testAtomicTransaction () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        SubordinateAtomicTransaction saa1 = new SubordinateAtomicTransaction(new Uid());
+        SubordinateAtomicTransaction saa2 = new SubordinateAtomicTransaction(new Uid(), xid, 0);
+        
+        assertEquals(saa2.getXid(), xid);
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/TransactionImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/TransactionImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/TransactionImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,61 @@
+/*
+ * 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.jca;
+
+import org.junit.Test;
+
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class TransactionImpleUnitTest extends TestBase
+{   
+    @Test
+    public void test () throws Exception
+    {
+        TransactionImple tx = new TransactionImple(0);
+        
+        tx.recordTransaction();
+        
+        assertFalse(tx.equals(null));
+        assertTrue(tx.equals(tx));
+        assertFalse(tx.equals(new TransactionImple(0)));
+        
+        assertTrue(tx.toString() != null);
+        assertTrue(tx.baseXid() != null);
+        
+        tx.recover();
+        
+        assertTrue(tx.activated());  
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/WorkUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/WorkUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/WorkUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,116 @@
+/*
+ * 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.jca;
+
+import org.junit.Test;
+
+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.hp.mwtests.ts.jta.jts.common.TestBase;
+
+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 extends TestBase
+{
+    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);
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/XATerminatorImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/XATerminatorImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/jca/XATerminatorImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,211 @@
+/*
+ * 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.jca;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinationManager;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter;
+import com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class XATerminatorImpleUnitTest extends TestBase
+{
+    @Test
+    public void testPrepareCommit () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+        
+        assertTrue(xa.beforeCompletion(xid));
+        
+        assertEquals(xa.prepare(xid), XAResource.XA_RDONLY);
+        
+        try
+        {
+            xa.commit(xid, false);
+            
+            fail();
+        }
+        catch (final XAException ex)
+        {
+        }
+        
+        imp.importTransaction(xid);
+        
+        xa.commit(xid, false);
+    }
+    
+    @Test
+    public void testOnePhaseCommit () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+
+        xa.commit(xid, true);
+    }
+    
+    @Test
+    public void testPrepareAbort () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+        
+        assertEquals(xa.prepare(xid), XAResource.XA_RDONLY);
+        
+        try
+        {
+            xa.rollback(xid);
+        }
+        catch (final XAException ex)
+        {
+        }
+    }
+    
+    @Test
+    public void testAbort () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+
+        xa.rollback(xid);
+    }
+    
+    @Test
+    public void testForget () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+
+        xa.forget(xid);
+    }
+    
+    @Test
+    public void testRecover () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();
+        
+        imp.importTransaction(xid);
+        
+        XATerminatorImple xa = new XATerminatorImple();
+
+        xa.recover(XAResource.TMSTARTRSCAN);
+        
+        try
+        {
+            xa.recover(XAResource.TMSTARTRSCAN);
+            
+            fail();
+        }
+        catch (final Exception ex)
+        {
+        }
+        
+        xa.recover(XAResource.TMENDRSCAN);
+    }
+    
+    @Test
+    public void testNull () throws Exception
+    {
+        XidImple xid = new XidImple(new Uid());
+        TransactionImporter imp = SubordinationManager.getTransactionImporter();    
+        XATerminatorImple xa = new XATerminatorImple();
+
+        try
+        {
+            xa.prepare(xid);
+            
+            fail();
+        }
+        catch (final Exception ex)
+        {
+        }
+        
+        try
+        {
+            xa.commit(xid, false);
+            
+            fail();
+        }
+        catch (final Exception ex)
+        {
+        }
+        
+        try
+        {
+            xa.commit(xid, true);
+            
+            fail();
+        }
+        catch (final Exception ex)
+        {
+        }
+        
+        try
+        {
+            xa.rollback(xid);
+            
+            fail();
+        }
+        catch (final Exception ex)
+        {
+        }
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/TransactionImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/TransactionImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/subordinate/TransactionImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,113 @@
+/*
+ * 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 com.arjuna.ats.internal.jta.transaction.jts.AtomicTransaction;
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.SubordinateAtomicTransaction;
+import com.arjuna.ats.internal.jta.transaction.jts.subordinate.TransactionImple;
+import com.arjuna.ats.internal.jts.OTSImpleManager;
+import com.arjuna.ats.internal.jts.interposition.ServerControlWrapper;
+import com.arjuna.ats.jta.exceptions.InvalidTerminationStateException;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class TransactionImpleUnitTest extends TestBase
+{   
+    @Test
+    public void test () throws Exception
+    {
+        OTSImpleManager.current().begin();
+        
+        TransactionImple tx = new TransactionImple(new SubordinateAtomicTransaction(new ServerControlWrapper(OTSImpleManager.current().get_control())));
+        
+        assertFalse(tx.equals(null));
+        assertTrue(tx.equals(tx));
+        assertFalse(tx.equals(new TransactionImple(new AtomicTransaction())));
+        
+        try
+        {
+            tx.commit();
+            
+            fail();
+        }
+        catch (final InvalidTerminationStateException ex)
+        {
+        }
+        
+        try
+        {
+            tx.rollback();
+            
+            fail();
+        }
+        catch (final InvalidTerminationStateException ex)
+        {
+        }
+        
+        tx.doPrepare();
+        
+        try
+        {
+            tx.doCommit();
+            
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+        
+        try
+        {
+            tx.doRollback();
+            
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+        
+        try
+        {
+            tx.doOnePhaseCommit();
+            
+            fail();
+        }
+        catch (final Throwable ex)
+        {
+        }
+        
+        OTSImpleManager.current().rollback();
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/SynchronizationUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/SynchronizationUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/SynchronizationUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,58 @@
+/*
+ * 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 org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.internal.jta.resources.jts.LocalCleanupSynchronization;
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class SynchronizationUnitTest extends TestBase
+{
+    @Test
+    public void test () throws Exception
+    {
+        TransactionImple tx = new TransactionImple();
+        LocalCleanupSynchronization sync = new LocalCleanupSynchronization(tx);
+        
+        assertTrue(sync.beforeCompletion());
+        assertTrue(sync.afterCompletion(ActionStatus.COMMITTED));
+        
+        assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
+        assertTrue(sync.compareTo(new LocalCleanupSynchronization(null)) != 0);
+    }
+}

Modified: 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	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -45,6 +45,7 @@
 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.internal.jts.OTSImpleManager;
 import com.arjuna.ats.jta.TransactionManager;
 import com.arjuna.ats.jta.utils.JTAHelper;
 import com.arjuna.orbportability.OA;
@@ -53,6 +54,7 @@
 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 com.hp.mwtests.ts.jta.jts.common.Synchronization;
 
 import static org.junit.Assert.*;
 
@@ -70,6 +72,9 @@
         
         tx.delistResource(res, XAResource.TMSUSPEND);
         
+        assertTrue(tx.getResources() != null);      
+        assertTrue(tx.getTimeout() != -1);
+        
         tx.commit();
         
         assertTrue(TransactionImple.getTransactions() != null);
@@ -88,6 +93,28 @@
     }
     
     @Test
+    public void testSynchronization () throws Exception
+    {
+        TransactionImple tx = new TransactionImple();
+
+        tx.registerSynchronization(new Synchronization());
+        
+        assertTrue(tx.getSynchronizations().size() == 1);
+        
+        tx.setRollbackOnly();
+        
+        try
+        {
+            tx.registerSynchronization(new Synchronization());
+            
+            fail();
+        }
+        catch (final RollbackException ex)
+        {
+        }
+    }
+    
+    @Test
     public void testEnlist () throws Exception
     {
         ThreadActionData.purgeActions();
@@ -135,6 +162,19 @@
         catch (final IllegalStateException ex)
         {
         }
+        
+        OTSImpleManager.current().suspend();
+        
+        tx = new TransactionImple();
+        
+        DummyXA res = new DummyXA(false);
+        
+        tx.enlistResource(res);
+        
+        tx.delistResource(res, XAResource.TMSUSPEND);
+        tx.enlistResource(res);
+        
+        tx.commit();
     }
     
     @Test

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionManagerImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionManagerImpleUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/TransactionManagerImpleUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,77 @@
+/*
+ * 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 org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+
+public class TransactionManagerImpleUnitTest extends TestBase
+{
+    @Test
+    public void test () throws Exception
+    {
+        TransactionManagerImple tmi = new TransactionManagerImple();
+        
+        assertEquals(tmi.getTransaction(), null);
+        
+        assertEquals(tmi.getObjectInstance(null, null, null, null), tmi);
+        
+        tmi.setTransactionTimeout(10);
+        
+        assertEquals(tmi.getTimeout(), 10);
+    }
+    
+    @Test
+    public void testNested () throws Exception
+    {
+        TransactionManagerImple tmi = new TransactionManagerImple();
+        
+        tmi.begin();
+        
+        try
+        {
+            tmi.begin();
+        }
+        catch (final Throwable ex)
+        {
+        }
+        
+        tmi.rollback();
+    }
+}

Added: labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/XAResourceRecordUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/XAResourceRecordUnitTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTS/jtax/tests/classes/com/hp/mwtests/ts/jta/jts/twophase/XAResourceRecordUnitTest.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -0,0 +1,236 @@
+/*
+ * 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 org.junit.Test;
+import org.omg.CORBA.TRANSACTION_ROLLEDBACK;
+import org.omg.CORBA.UNKNOWN;
+import org.omg.CosTransactions.HeuristicHazard;
+import org.omg.CosTransactions.HeuristicMixed;
+import org.omg.CosTransactions.NotPrepared;
+import org.omg.CosTransactions.Vote;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.internal.jta.resources.jts.orbspecific.XAResourceRecord;
+import com.arjuna.ats.internal.jta.transaction.jts.TransactionImple;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection;
+import com.hp.mwtests.ts.jta.common.FailureXAResource;
+import com.hp.mwtests.ts.jta.common.TestResource;
+import com.hp.mwtests.ts.jta.jts.common.DummyXA;
+import com.hp.mwtests.ts.jta.jts.common.TestBase;
+
+import static org.junit.Assert.*;
+
+public class XAResourceRecordUnitTest extends TestBase
+{
+    @Test
+    public void test () throws Exception
+    {
+        XAResourceRecord xares = new XAResourceRecord();
+        DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
+        Object[] params = new Object[1];
+        
+        params[XAResourceRecord.XACONNECTION] = rc;
+        
+        xares = new XAResourceRecord(new TransactionImple(), new DummyXA(false), new XidImple(new Uid()), params);
+        
+        assertTrue(xares.type() != null);
+        
+        assertTrue(xares.toString() != null);
+    }
+    
+    @Test
+    public void testPackUnpack () throws Exception
+    {
+        XAResourceRecord xares;      
+        DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
+        Object[] params = new Object[1];
+        
+        params[XAResourceRecord.XACONNECTION] = rc;
+        
+        xares = new XAResourceRecord(new TransactionImple(), new DummyXA(false), new XidImple(new Uid()), params);
+        
+        OutputObjectState os = new OutputObjectState();
+        
+        assertTrue(xares.saveState(os));
+        
+        InputObjectState is = new InputObjectState(os);
+        
+        assertTrue(xares.restoreState(is));
+    }
+    
+    @Test
+    public void testReadonly () throws Exception
+    {
+        XAResourceRecord xares;
+        
+        DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
+        Object[] params = new Object[1];
+        
+        params[XAResourceRecord.XACONNECTION] = rc;
+        
+        xares = new XAResourceRecord(new TransactionImple(), new TestResource(true), new XidImple(new Uid()), params);
+        
+        try
+        {
+            xares.commit();
+            
+            fail();
+        }
+        catch (final NotPrepared ex)
+        {
+        }
+        
+        assertEquals(xares.prepare(), Vote.VoteReadOnly);
+    }
+    
+    @Test
+    public void testCommitFailure () throws Exception
+    {
+        FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.commit);
+        TransactionImple tx = new TransactionImple();
+        XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
+        
+        assertEquals(xares.prepare(), Vote.VoteCommit);
+        
+        try
+        {
+            xares.commit();
+            
+            fail();
+        }
+        catch (final HeuristicMixed ex)
+        {      
+        }
+        
+        xares.forget();
+    }
+    
+    @Test
+    public void testRollbackFailure () throws Exception
+    {
+        FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.rollback);
+        TransactionImple tx = new TransactionImple();
+        XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
+        
+        assertEquals(xares.prepare(), Vote.VoteCommit);
+        
+        try
+        {
+            xares.rollback();
+            
+            fail();
+        }
+        catch (final HeuristicHazard ex)
+        {      
+        }
+        
+        xares.forget();
+    }
+    
+    @Test
+    public void testValid2PC () throws Exception
+    {
+        TransactionImple tx = new TransactionImple();
+        DummyXA res = new DummyXA(false);
+        XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
+        
+        assertEquals(xares.prepare(), Vote.VoteCommit);
+        
+        xares.commit();
+    }
+    
+    @Test
+    public void testValid1PC () throws Exception
+    {
+        TransactionImple tx = new TransactionImple();
+        DummyXA res = new DummyXA(false);
+        XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
+        
+        xares.commit_one_phase();
+    }
+    
+    @Test
+    public void testInvalid () throws Exception
+    {
+        XAResourceRecord xares = new XAResourceRecord();
+        
+        assertEquals(xares.getXid(), null);
+        assertTrue(xares.uid() != null);
+        
+        try
+        {
+            xares.commit_one_phase();
+            
+            fail();
+        }
+        catch (final TRANSACTION_ROLLEDBACK ex)
+        {
+        }
+        
+        assertEquals(xares.prepare(), Vote.VoteRollback);
+        
+        xares.rollback();
+        xares.commit();
+    }
+    
+    @Test
+    public void testNested () throws Exception
+    {
+        XAResourceRecord xares = new XAResourceRecord();
+        
+        assertEquals(xares.prepare_subtransaction(), Vote.VoteRollback);
+        
+        try
+        {
+            xares.commit_subtransaction(null);
+            
+            fail();
+        }
+        catch (final UNKNOWN ex)
+        {       
+        }
+        
+        try
+        {
+            xares.rollback_subtransaction();
+            
+            fail();
+        }
+        catch (final UNKNOWN ex)
+        {       
+        }
+    }
+}

Modified: labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/jts/extensions/AtomicTransaction.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/jts/extensions/AtomicTransaction.java	2010-03-05 12:10:53 UTC (rev 31957)
+++ labs/jbosstm/trunk/ArjunaJTS/jts/classes/com/arjuna/ats/jts/extensions/AtomicTransaction.java	2010-03-05 12:37:04 UTC (rev 31958)
@@ -794,7 +794,10 @@
 
 	public Uid get_uid ()
 	{
+	    if (_theAction != null)
 		return _theAction.get_uid();
+	    else
+	        return Uid.nullUid();
 	}
 
 	/**



More information about the jboss-svn-commits mailing list