use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class JTSXARTest method injectCommitException.
void injectCommitException(String exceptionType) throws Exception {
XAFailureSpec fault = new XAFailureSpec("JTSXARTest", XAFailureMode.XAEXCEPTION, XAFailureType.XARES_COMMIT, exceptionType, 0);
XAException xae = XAFailureResource.getXAExceptionType(exceptionType);
int expectedXAE = xae == null ? HeuristicStatus.UNKNOWN_XA_ERROR_CODE : xae.errorCode;
TransactionManagerImple tm = new TransactionManagerImple();
Uid txUid;
TransactionImple txn;
// clean the thread that will create the transaction
ThreadActionData.purgeActions();
// begin a transaction
tm.begin();
txn = (TransactionImple) tm.getTransaction();
txUid = txn.get_uid();
// enlist two XA resources
tm.getTransaction().enlistResource(new XAFailureResource());
tm.getTransaction().enlistResource(new XAFailureResource(fault));
// commit the transaction and check for any expected exceptions
try {
tm.commit();
} catch (HeuristicRollbackException e) {
if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURRB, expectedXAE))
throw e;
} catch (RollbackException e) {
if (!XAFailureSpec.compatibleHeuristics(XAException.XA_RBROLLBACK, expectedXAE))
throw e;
} catch (HeuristicMixedException e) {
if (!XAFailureSpec.compatibleHeuristics(XAException.XA_HEURMIX, expectedXAE))
throw e;
} catch (SystemException e) {
if (!XAFailureSpec.compatibleHeuristics(XAException.XAER_RMFAIL, expectedXAE))
throw e;
}
// Validate that the correct MBeans were created to instrument the transaction and participants
// and validate they have the correct heuristic status
ObjStoreBrowser osb = createObjStoreBrowser(true);
UidWrapper w = osb.findUid(txUid);
assertNotNull(w);
Set<UidWrapper> wrappers = validateChildBeans(osb, w.getName(), 1, expectedXAE);
assertTrue(wrappers.size() > 0);
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class WorkUnitTest method testWorkManager.
@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);
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class WorkUnitTest method testWorkSynchronization.
@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);
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class SynchronizationUnitTest method test.
@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);
}
use of com.arjuna.ats.internal.jta.transaction.jts.TransactionImple in project narayana by jbosstm.
the class TransactionImpleUnitTest method testFailure.
@Test
public void testFailure() throws Exception {
ThreadActionData.purgeActions();
OTSImpleManager.current().contextManager().purgeActions();
TransactionImple tx = new TransactionImple();
assertFalse(tx.equals(null));
assertTrue(tx.equals(tx));
tx.enlistResource(new FailureXAResource(FailLocation.commit));
try {
tx.commit();
fail();
} catch (final HeuristicMixedException ex) {
}
assertEquals(tx.getStatus(), Status.STATUS_COMMITTED);
try {
tx.registerSynchronization(null);
fail();
} catch (final SystemException ex) {
}
try {
tx.commit();
fail();
} catch (final IllegalStateException ex) {
}
}
Aggregations