[jboss-svn-commits] JBL Code SVN: r31865 - in labs/jbosstm/trunk/ArjunaJTA/jta: classes/com/arjuna/ats/internal/jta/resources/arjunacore and 9 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Feb 27 19:15:44 EST 2010
Author: mark.little at jboss.com
Date: 2010-02-27 19:15:42 -0500 (Sat, 27 Feb 2010)
New Revision: 31865
Added:
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/ExceptionsUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/FailureXAResource.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/SampleOnePhaseResource.java
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/recovery/RecoveryXidsUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionImpleUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/XAResourceRecordUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/OnePhaseUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/SynchronizationUnitTest.java
Modified:
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAOnePhaseResource.java
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecord.java
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TxWorkManager.java
labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/jta/exceptions/NotImplementedException.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/UtilsUnitTest.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/DummyXA.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/TestResource.java
labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryResourceUnitTest.java
Log:
https://jira.jboss.org/jira/browse/JBTM-712
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/recovery/arjunacore/RecoveryXids.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -31,14 +31,8 @@
package com.arjuna.ats.internal.jta.recovery.arjunacore;
-import com.arjuna.ats.jta.recovery.*;
-
import com.arjuna.ats.jta.utils.XAHelper;
-import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord;
-
-import com.arjuna.ats.arjuna.common.*;
-
import java.util.*;
import javax.transaction.xa.*;
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAOnePhaseResource.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAOnePhaseResource.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAOnePhaseResource.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -130,7 +130,7 @@
return TwoPhaseOutcome.HEURISTIC_HAZARD;
case XAException.XA_HEURCOM:
doForget = true;
- break;
+ return TwoPhaseOutcome.FINISH_OK;
case XAException.XA_HEURRB:
doForget = true;
return TwoPhaseOutcome.ONE_PHASE_ERROR;
@@ -207,8 +207,18 @@
jtaLogger.loggerI18N.warn("com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource.rollbackexception",
new Object[] {xid, xae.getMessage()}, xae);
}
- return TwoPhaseOutcome.FINISH_ERROR ;
}
+ catch (final Throwable ex)
+ {
+ if (jtaLogger.logger.isDebugEnabled())
+ {
+ jtaLogger.logger.debug(DebugLevel.ERROR_MESSAGES,
+ VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_JTA,
+ "XAOnePhaseResource.rollback(" + xid + ") " + ex.getMessage());
+ }
+ }
+
+ return TwoPhaseOutcome.FINISH_ERROR ;
}
/**
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecord.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecord.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/resources/arjunacore/XAResourceRecord.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -228,26 +228,19 @@
"XAResourceRecord.topLevelPrepare for " + _tranID);
}
- if (!_valid || (_theXAResource == null))
+ if (!_valid || (_theXAResource == null) || (_tranID == null))
{
- removeConnection();
+ if (jtaLogger.loggerI18N.isWarnEnabled())
+ {
+ jtaLogger.loggerI18N
+ .warn(
+ "com.arjuna.ats.internal.jta.resources.arjunacore.preparenulltx",
+ new Object[]
+ { "XAResourceRecord.prepare" });
+ }
- return TwoPhaseOutcome.PREPARE_READONLY;
- }
+ removeConnection();
- if (_tranID == null)
- {
- if (jtaLogger.loggerI18N.isWarnEnabled())
- {
- jtaLogger.loggerI18N
- .warn(
- "com.arjuna.ats.internal.jta.resources.arjunacore.preparenulltx",
- new Object[]
- { "XAResourceRecord.prepare" });
- }
-
- removeConnection();
-
return TwoPhaseOutcome.PREPARE_NOTOK;
}
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/TransactionImple.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -550,7 +550,7 @@
throw new RollbackException(
"TransactionImple.enlistResource - "
+ jtaLogger.loggerI18N
- .getString("com.arjuna.ats.internal.jta.transaction.arjunacore.nullres"));
+ .getString("com.arjuna.ats.internal.jta.transaction.arjunacore.invalidstate"));
case javax.transaction.Status.STATUS_ACTIVE:
break;
default:
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TxWorkManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TxWorkManager.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/internal/jta/transaction/arjunacore/jca/TxWorkManager.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -72,6 +72,13 @@
{
workers = _transactions.get(tx);
+ /*
+ * TODO
+ *
+ * Is this really correct? We only get to add one unit of work per
+ * transaction?! If so why use a stack datastructure?
+ */
+
if (workers == null)
{
workers = new Stack<Work>();
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/jta/exceptions/NotImplementedException.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/jta/exceptions/NotImplementedException.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/classes/com/arjuna/ats/jta/exceptions/NotImplementedException.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -51,7 +51,7 @@
* call to {@link #initCause}.
*/
public NotImplementedException() {
- super(); //To change body of overridden methods use File | Settings | File Templates.
+ super();
}
/**
@@ -63,7 +63,7 @@
* later retrieval by the {@link #getMessage()} method.
*/
public NotImplementedException(String message) {
- super(message); //To change body of overridden methods use File | Settings | File Templates.
+ super(message);
}
/**
@@ -81,7 +81,7 @@
* @since 1.4
*/
public NotImplementedException(String message, Throwable cause) {
- super(message, cause); //To change body of overridden methods use File | Settings | File Templates.
+ super(message, cause);
}
/**
@@ -99,7 +99,7 @@
* @since 1.4
*/
public NotImplementedException(Throwable cause) {
- super(cause); //To change body of overridden methods use File | Settings | File Templates.
+ super(cause);
}
}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/ExceptionsUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/ExceptionsUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/ExceptionsUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,59 @@
+/*
+ * 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.basic;
+
+import org.junit.Test;
+
+import com.arjuna.ats.jta.exceptions.InactiveTransactionException;
+import com.arjuna.ats.jta.exceptions.NotImplementedException;
+import com.arjuna.ats.jta.exceptions.RollbackException;
+import com.arjuna.ats.jta.exceptions.UnexpectedConditionException;
+
+import static org.junit.Assert.*;
+
+public class ExceptionsUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ InactiveTransactionException ex = new InactiveTransactionException();
+
+ ex = new InactiveTransactionException("foobar");
+
+ NotImplementedException exp = new NotImplementedException();
+
+ exp = new NotImplementedException("foobar");
+ exp = new NotImplementedException("foobar", new NullPointerException());
+ exp = new NotImplementedException(new NullPointerException());
+
+ RollbackException exp2 = new RollbackException();
+
+ exp2 = new RollbackException("foobar");
+ exp2 = new RollbackException("foobar", new NullPointerException());
+ exp2 = new RollbackException(new NullPointerException());
+
+ UnexpectedConditionException ex2 = new UnexpectedConditionException();
+
+ ex2 = new UnexpectedConditionException("foobar");
+ }
+
+}
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/UtilsUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/UtilsUnitTest.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/UtilsUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -21,11 +21,14 @@
package com.hp.mwtests.ts.jta.basic;
+import javax.transaction.Status;
import javax.transaction.xa.XAException;
import org.junit.Test;
import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.internal.jta.utils.arjunacore.StatusConverter;
import com.arjuna.ats.jta.utils.JTAHelper;
import com.arjuna.ats.jta.utils.XAHelper;
import com.arjuna.ats.jta.xa.XidImple;
@@ -49,6 +52,28 @@
}
@Test
+ public void testStatusConverter () throws Exception
+ {
+ assertEquals(StatusConverter.convert(ActionStatus.ABORT_ONLY), Status.STATUS_MARKED_ROLLBACK);
+ assertEquals(StatusConverter.convert(ActionStatus.ABORTED), Status.STATUS_ROLLEDBACK);
+ assertEquals(StatusConverter.convert(ActionStatus.ABORTING), Status.STATUS_ROLLING_BACK);
+ assertEquals(StatusConverter.convert(ActionStatus.CLEANUP), Status.STATUS_UNKNOWN);
+ assertEquals(StatusConverter.convert(ActionStatus.COMMITTED), Status.STATUS_COMMITTED);
+ assertEquals(StatusConverter.convert(ActionStatus.COMMITTING), Status.STATUS_COMMITTING);
+ assertEquals(StatusConverter.convert(ActionStatus.CREATED), Status.STATUS_UNKNOWN);
+ assertEquals(StatusConverter.convert(ActionStatus.DISABLED), Status.STATUS_UNKNOWN);
+ assertEquals(StatusConverter.convert(ActionStatus.H_COMMIT), Status.STATUS_COMMITTED);
+ assertEquals(StatusConverter.convert(ActionStatus.H_HAZARD), Status.STATUS_COMMITTED);
+ assertEquals(StatusConverter.convert(ActionStatus.H_MIXED), Status.STATUS_COMMITTED);
+ assertEquals(StatusConverter.convert(ActionStatus.H_ROLLBACK), Status.STATUS_ROLLEDBACK);
+ assertEquals(StatusConverter.convert(ActionStatus.INVALID), Status.STATUS_UNKNOWN);
+ assertEquals(StatusConverter.convert(ActionStatus.NO_ACTION), Status.STATUS_NO_TRANSACTION);
+ assertEquals(StatusConverter.convert(ActionStatus.PREPARED), Status.STATUS_PREPARED);
+ assertEquals(StatusConverter.convert(ActionStatus.PREPARING), Status.STATUS_PREPARING);
+ assertEquals(StatusConverter.convert(ActionStatus.RUNNING), Status.STATUS_ACTIVE);
+ }
+
+ @Test
public void testXAHelper () throws Exception
{
assertTrue(XAHelper.printXAErrorCode(null) != null);
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/DummyXA.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/DummyXA.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/DummyXA.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -44,6 +44,7 @@
public class DummyXA implements XAResource, Serializable
{
+ private static final long serialVersionUID = -2285367224867593569L;
public DummyXA (boolean print)
{
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/FailureXAResource.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/FailureXAResource.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/FailureXAResource.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package com.hp.mwtests.ts.jta.common;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+public class FailureXAResource implements XAResource
+{
+ public enum FailLocation { none, prepare, commit, rollback };
+
+ public FailureXAResource ()
+ {
+ this(FailLocation.none);
+ }
+
+ public FailureXAResource (FailLocation loc)
+ {
+ _locale = loc;
+ }
+
+ public void commit(Xid id, boolean onePhase) throws XAException
+ {
+ if (_locale == FailLocation.commit)
+ throw new XAException(XAException.XA_HEURMIX);
+ }
+
+ public void end(Xid xid, int flags) throws XAException
+ {
+ }
+
+ public void forget(Xid xid) throws XAException
+ {
+ }
+
+ public int getTransactionTimeout() throws XAException
+ {
+ return 0;
+ }
+
+ public boolean isSameRM(XAResource xares) throws XAException
+ {
+ return false;
+ }
+
+ public int prepare(Xid xid) throws XAException
+ {
+ if (_locale == FailLocation.prepare)
+ throw new XAException(XAException.XAER_INVAL);
+
+ return XA_OK;
+ }
+
+ public Xid[] recover(int flag) throws XAException
+ {
+ return null;
+ }
+
+ public void rollback(Xid xid) throws XAException
+ {
+ if (_locale == FailLocation.rollback)
+ throw new XAException(XAException.XA_HEURHAZ);
+ }
+
+ public boolean setTransactionTimeout(int seconds) throws XAException
+ {
+ return true;
+ }
+
+ public void start(Xid xid, int flags) throws XAException
+ {
+ }
+
+ private FailLocation _locale;
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/SampleOnePhaseResource.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/SampleOnePhaseResource.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/SampleOnePhaseResource.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package com.hp.mwtests.ts.jta.common;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.Xid;
+
+public class SampleOnePhaseResource extends TestResource
+{
+ public enum ErrorType { none, heurcom, heurrb };
+
+ public SampleOnePhaseResource ()
+ {
+ this(ErrorType.none);
+ }
+
+ public SampleOnePhaseResource (ErrorType type)
+ {
+ _heuristic = type;
+ }
+
+ public boolean onePhaseCalled ()
+ {
+ return _onePhase;
+ }
+
+ public boolean forgetCalled ()
+ {
+ return _forgot;
+ }
+
+ public void commit (Xid id, boolean onePhase) throws XAException
+ {
+ System.out.println("XA_COMMIT[" + id + "]");
+
+ _onePhase = onePhase;
+
+ if (_heuristic == ErrorType.heurcom)
+ throw new XAException(XAException.XA_HEURCOM);
+ else
+ {
+ if (_heuristic == ErrorType.heurrb)
+ throw new XAException(XAException.XA_HEURRB);
+ }
+ }
+
+ public void forget (Xid xid) throws XAException
+ {
+ System.out.println("XA_FORGET[" + xid + "]");
+
+ _forgot = true;
+ }
+
+ private boolean _onePhase = false;
+ private ErrorType _heuristic = ErrorType.none;
+ private boolean _forgot = false;
+}
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/TestResource.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/TestResource.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/common/TestResource.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -27,8 +27,7 @@
public class TestResource implements XAResource
{
-
- public void commit (Xid id, boolean onePhase) throws XAException
+ public void commit (Xid id, boolean onePhase) throws XAException
{
System.out.println("XA_COMMIT[" + id + "]");
}
Added: 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 (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/jca/WorkUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,84 @@
+/*
+ * 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.jca;
+
+import org.junit.Test;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TxWorkManager;
+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 static org.junit.Assert.*;
+
+public class WorkUnitTest
+{
+ class DummyWork implements Work
+ {
+ public void release ()
+ {
+ }
+
+ public void run ()
+ {
+ }
+ }
+
+ @Test
+ public void testWorkManager () throws Exception
+ {
+ DummyWork work = new DummyWork();
+ TransactionImple tx = new TransactionImple(0);
+
+ 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);
+ }
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryXidsUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryXidsUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/RecoveryXidsUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -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.recovery;
+import javax.transaction.xa.Xid;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.common.DummyXA;
+import com.hp.mwtests.ts.jta.common.TestResource;
+
+import static org.junit.Assert.*;
+
+
+public class RecoveryXidsUnitTest
+{
+ @Test
+ public void test()
+ {
+ TestResource tr = new TestResource();
+ RecoveryXids rxids = new RecoveryXids(tr);
+ Xid[] xids = new XidImple[2];
+
+ xids[0] = new XidImple(new Uid());
+ xids[1] = new XidImple(new Uid());
+
+ RecoveryXids dup1 = new RecoveryXids(new DummyXA(false));
+ RecoveryXids dup2 = new RecoveryXids(tr);
+
+ assertFalse(rxids.equals(dup1));
+ assertTrue(rxids.equals(dup2));
+
+ rxids.nextScan(xids);
+
+ xids[1] = new XidImple(new Uid());
+
+ rxids.nextScan(xids);
+
+ Object[] trans = rxids.toRecover();
+
+ assertEquals(trans.length, 2);
+ assertEquals(trans[0], xids[0]);
+
+ assertTrue(rxids.contains(xids[0]));
+
+ assertFalse(rxids.updateIfEquivalentRM(new TestResource(), null));
+ assertTrue(rxids.updateIfEquivalentRM(new TestResource(), xids));
+ }
+}
Modified: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryResourceUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryResourceUnitTest.java 2010-02-27 19:09:56 UTC (rev 31864)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryResourceUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -31,13 +31,31 @@
package com.hp.mwtests.ts.jta.recovery;
+import javax.transaction.xa.XAException;
+
import org.junit.Test;
import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceImple;
import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceManagerImple;
+import com.arjuna.ats.jta.recovery.XARecoveryResource;
+import com.hp.mwtests.ts.jta.common.DummyXA;
import static org.junit.Assert.*;
+class DummyImple extends XARecoveryResourceImple
+{
+ public DummyImple ()
+ {
+ super(new Uid());
+ }
+
+ public boolean notAProblem (XAException ex, boolean commit)
+ {
+ return super.notAProblem(ex, commit);
+ }
+}
+
public class XARecoveryResourceUnitTest
{
@Test
@@ -49,4 +67,27 @@
assertTrue(xarr.getResource(new Uid(), null) != null);
assertTrue(xarr.type() != null);
}
+
+ @Test
+ public void testRecoveryResource ()
+ {
+ XARecoveryResourceImple res = new XARecoveryResourceImple(new Uid());
+
+ assertEquals(res.getXAResource(), null);
+ assertEquals(res.recoverable(), XARecoveryResource.INCOMPLETE_STATE);
+
+ res = new XARecoveryResourceImple(new Uid(), new DummyXA(false));
+
+ assertEquals(res.recoverable(), XARecoveryResource.RECOVERY_REQUIRED);
+ assertEquals(res.recover(), XARecoveryResource.WAITING_FOR_RECOVERY);
+ }
+
+ @Test
+ public void testNotAProblem ()
+ {
+ DummyImple impl = new DummyImple();
+
+ assertTrue(impl.notAProblem(new XAException(XAException.XAER_NOTA), true));
+ assertFalse(impl.notAProblem(new XAException(XAException.XA_HEURHAZ), true));
+ }
}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionImpleUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionImpleUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/TransactionImpleUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,229 @@
+/*
+ * 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 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 com.arjuna.ats.internal.arjuna.thread.ThreadActionData;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+import com.arjuna.ats.jta.utils.JTAHelper;
+import com.hp.mwtests.ts.jta.common.DummyXA;
+import com.hp.mwtests.ts.jta.common.FailureXAResource;
+import com.hp.mwtests.ts.jta.common.FailureXAResource.FailLocation;
+
+import static org.junit.Assert.*;
+
+class TxImpleOverride extends TransactionImple
+{
+ public static void put (TransactionImple tx)
+ {
+ TransactionImple.putTransaction(tx);
+ }
+
+ public static void remove (TransactionImple tx)
+ {
+ TransactionImple.removeTransaction(tx);
+ }
+}
+
+public class TransactionImpleUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ TransactionImple tx = new TransactionImple(0);
+
+ TxImpleOverride.put(tx);
+
+ assertEquals(tx, TransactionImple.getTransaction(tx.get_uid()));
+
+ DummyXA res = new DummyXA(false);
+
+ tx.enlistResource(res);
+
+ tx.delistResource(res, XAResource.TMSUSPEND);
+
+ tx.commit();
+
+ TxImpleOverride.remove(tx);
+
+ assertTrue(TransactionImple.getTransactions() != null);
+
+ assertEquals(TransactionImple.getTransaction(tx.get_uid()), null);
+ }
+
+ @Test
+ public void testEnlist () throws Exception
+ {
+ ThreadActionData.purgeActions();
+
+ TransactionImple tx = new TransactionImple(0);
+
+ 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(0);
+
+ 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(0);
+
+ 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)
+ {
+ }
+ }
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/XAResourceRecordUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/XAResourceRecordUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/twophase/XAResourceRecordUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,125 @@
+/*
+ * 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 com.arjuna.ats.arjuna.coordinator.TwoPhaseOutcome;
+import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+import com.hp.mwtests.ts.jta.common.DummyXA;
+import com.hp.mwtests.ts.jta.common.FailureXAResource;
+
+import static org.junit.Assert.*;
+
+public class XAResourceRecordUnitTest
+{
+ @Test
+ public void test () throws Exception
+ {
+ XAResourceRecord xares = new XAResourceRecord();
+ Object obj = new Object();
+
+ xares.setValue(obj);
+
+ assertTrue(xares.value() != obj);
+ }
+
+ @Test
+ public void testCommitFailure () throws Exception
+ {
+ FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.commit);
+ TransactionImple tx = new TransactionImple(0);
+ XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
+
+ assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
+ assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.HEURISTIC_MIXED);
+ assertTrue(xares.forgetHeuristic());
+ }
+
+ @Test
+ public void testRollbackFailure () throws Exception
+ {
+ FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.rollback);
+ TransactionImple tx = new TransactionImple(0);
+ XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
+
+ assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
+ assertEquals(xares.topLevelAbort(), TwoPhaseOutcome.HEURISTIC_HAZARD);
+ assertTrue(xares.forgetHeuristic());
+ }
+
+ @Test
+ public void testValid2PC () throws Exception
+ {
+ TransactionImple tx = new TransactionImple(0);
+ DummyXA res = new DummyXA(false);
+ XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
+
+ assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
+ assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
+ }
+
+ @Test
+ public void testValid1PC () throws Exception
+ {
+ TransactionImple tx = new TransactionImple(0);
+ DummyXA res = new DummyXA(false);
+ XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
+
+ assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.FINISH_OK);
+ }
+
+ @Test
+ public void testInvalid () throws Exception
+ {
+ XAResourceRecord xares = new XAResourceRecord();
+
+ assertEquals(xares.getXid(), null);
+ assertEquals(xares.value(), null);
+ assertEquals(xares.topLevelOnePhaseCommit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
+ assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
+ assertEquals(xares.topLevelAbort(), TwoPhaseOutcome.FINISH_ERROR);
+ assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.FINISH_ERROR);
+ }
+
+ @Test
+ public void testNested () throws Exception
+ {
+ XAResourceRecord xares = new XAResourceRecord();
+
+ assertEquals(xares.nestedOnePhaseCommit(), TwoPhaseOutcome.FINISH_ERROR);
+ assertEquals(xares.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
+ assertEquals(xares.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
+ assertEquals(xares.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
+ }
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/OnePhaseUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/OnePhaseUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/OnePhaseUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,128 @@
+/*
+ * 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.xa;
+
+import java.io.IOException;
+import java.io.NotSerializableException;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.TwoPhaseOutcome;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.common.DummyXA;
+import com.hp.mwtests.ts.jta.common.SampleOnePhaseResource;
+import com.hp.mwtests.ts.jta.common.SampleOnePhaseResource.ErrorType;
+
+import static org.junit.Assert.*;
+
+public class OnePhaseUnitTest
+{
+ @Test
+ public void testInvalid ()
+ {
+ XAOnePhaseResource xares = new XAOnePhaseResource();
+
+ assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
+ assertEquals(xares.rollback(), TwoPhaseOutcome.FINISH_ERROR);
+ }
+
+ @Test
+ public void testCommit ()
+ {
+ SampleOnePhaseResource res = new SampleOnePhaseResource();
+ XidImple xid = new XidImple(new Uid());
+ XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
+
+ assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
+ assertTrue(res.onePhaseCalled());
+ }
+
+ @Test
+ public void testCommitHeuristic ()
+ {
+ SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurcom);
+ XidImple xid = new XidImple(new Uid());
+ XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
+
+ assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK);
+ assertTrue(res.forgetCalled());
+ }
+
+ @Test
+ public void testRollbackHeuristic ()
+ {
+ SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurrb);
+ XidImple xid = new XidImple(new Uid());
+ XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
+
+ assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR);
+ assertTrue(res.forgetCalled());
+ }
+
+ @Test
+ public void testPackUnpackError () throws Exception
+ {
+ SampleOnePhaseResource res = new SampleOnePhaseResource();
+ XidImple xid = new XidImple(new Uid());
+ XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
+ OutputObjectState os = new OutputObjectState();
+
+ try
+ {
+ xares.pack(os);
+
+ fail();
+ }
+ catch (final IOException ex)
+ {
+ }
+ }
+
+ @Test
+ public void testPackUnpack () throws Exception
+ {
+ DummyXA res = new DummyXA(false);
+ XidImple xid = new XidImple(new Uid());
+ XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null);
+ OutputObjectState os = new OutputObjectState();
+
+ xares.pack(os);
+
+ InputObjectState is = new InputObjectState(os);
+
+ xares.unpack(is);
+ }
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/SynchronizationUnitTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/SynchronizationUnitTest.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/xa/SynchronizationUnitTest.java 2010-02-28 00:15:42 UTC (rev 31865)
@@ -0,0 +1,75 @@
+/*
+ * 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.xa;
+
+import javax.transaction.Status;
+
+import org.junit.Test;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple;
+import com.arjuna.ats.internal.jta.utils.XAUtils;
+import com.arjuna.ats.jta.xa.XidImple;
+import com.hp.mwtests.ts.jta.common.DummyXA;
+import com.hp.mwtests.ts.jta.common.Synchronization;
+
+import static org.junit.Assert.*;
+
+public class SynchronizationUnitTest
+{
+ @Test
+ public void testInvalid()
+ {
+ SynchronizationImple sync = new SynchronizationImple(null);
+
+ assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
+
+ assertFalse(sync.beforeCompletion());
+ assertFalse(sync.afterCompletion(Status.STATUS_COMMITTED));
+ }
+
+ @Test
+ public void testValid()
+ {
+ SynchronizationImple sync = new SynchronizationImple(new Synchronization());
+
+ assertTrue(sync.get_uid().notEquals(Uid.nullUid()));
+
+ assertTrue(sync.beforeCompletion());
+ assertTrue(sync.afterCompletion(Status.STATUS_COMMITTED));
+
+ SynchronizationImple comp = new SynchronizationImple(new Synchronization());
+
+ assertTrue(comp.compareTo(sync) != 0);
+ assertTrue(sync.toString() != null);
+ }
+}
More information about the jboss-svn-commits
mailing list