use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTestCase method testOnePhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync.
@Test
public void testOnePhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync() throws Exception {
final Xid xid = new XidImple(new Uid());
final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
final TestSynchronization sync = new TestSynchronization();
t.registerSynchronization(sync);
t.setRollbackOnly();
final XATerminator xaTerminator = SubordinationManager.getXATerminator();
final XATerminatorExtensions xaTerminatorExtensions = (XATerminatorExtensions) xaTerminator;
xaTerminatorExtensions.beforeCompletion(xid);
try {
xaTerminator.commit(xid, true);
((TransactionImple) t).doOnePhaseCommit();
fail("did not get expected rollback exception");
} catch (XAException e) {
assertEquals("javax.transaction.RollbackException", e.getCause().getClass().getName());
assertEquals(XAException.XA_RBROLLBACK, e.errorCode);
// expected - we tried to commit a rollbackonly tx.
}
assertTrue(sync.isBeforeCompletionDone());
assertTrue(sync.isAfterCompletionDone());
assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, t.getStatus());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTestCase method testRollbackSyncViaXATerminatorWithSeparateSync.
@Test
public void testRollbackSyncViaXATerminatorWithSeparateSync() throws Exception {
final Xid xid = new XidImple(new Uid());
final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
final TestSynchronization sync = new TestSynchronization();
t.registerSynchronization(sync);
final XATerminator xaTerminator = SubordinationManager.getXATerminator();
final XATerminatorExtensions xaTerminatorExtensions = (XATerminatorExtensions) xaTerminator;
xaTerminatorExtensions.beforeCompletion(xid);
xaTerminator.rollback(xid);
assertTrue(sync.isBeforeCompletionDone());
assertTrue(sync.isAfterCompletionDone());
assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, t.getStatus());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTestCase method testFailOnCommitOnePhase.
@Test
public void testFailOnCommitOnePhase() throws Exception {
final Xid xid = new XidImple(new Uid());
final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
final TestXAResource xaResource = new TestXAResource();
// provoke commit into failing with TwoPhaseOutcome.FINISH_ERROR
// warning: this is sensitive to the impl exception handling in
// XAResourceRecord.topLevelCommit
// should cause an exception!
xaResource.setCommitException(new XAException(XAException.XA_HEURRB));
t.enlistResource(xaResource);
final XATerminator xaTerminator = SubordinationManager.getXATerminator();
try {
xaTerminator.commit(xid, true);
} catch (final XAException ex) {
return;
}
assertTrue("commit should throw an exception and not get to here", false);
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTestCase method testOnePhaseCommitSyncWithRollbackOnlyViaXATerminator.
@Test
public void testOnePhaseCommitSyncWithRollbackOnlyViaXATerminator() throws Exception {
final Xid xid = new XidImple(new Uid());
final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
final TestSynchronization sync = new TestSynchronization();
t.registerSynchronization(sync);
t.setRollbackOnly();
final XATerminator xaTerminator = SubordinationManager.getXATerminator();
try {
xaTerminator.commit(xid, true);
((TransactionImple) t).doOnePhaseCommit();
fail("did not get expected rollback exception");
} catch (XAException e) {
assertEquals("javax.transaction.RollbackException", e.getCause().getClass().getName());
assertEquals(XAException.XA_RBROLLBACK, e.errorCode);
// expected - we tried to commit a rollbackonly tx.
}
assertFalse(sync.isBeforeCompletionDone());
assertTrue(sync.isAfterCompletionDone());
assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, t.getStatus());
}
use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.
the class SubordinateTxUnitTest method testSAADeferred.
@Test
public void testSAADeferred() throws Exception {
SubordinateAtomicAction saa = new SubordinateAtomicAction();
saa.add(new XAResourceRecord(null, new XAResource() {
@Override
public void commit(Xid xid, boolean b) throws XAException {
}
@Override
public void end(Xid xid, int i) throws XAException {
}
@Override
public void forget(Xid xid) throws XAException {
}
@Override
public int getTransactionTimeout() throws XAException {
return 0;
}
@Override
public boolean isSameRM(XAResource xaResource) throws XAException {
return false;
}
@Override
public int prepare(Xid xid) throws XAException {
XAException xae = new XAException(XAException.XAER_INVAL);
xae.initCause(new Throwable("test message"));
throw xae;
}
@Override
public Xid[] recover(int i) throws XAException {
return new Xid[0];
}
@Override
public void rollback(Xid xid) throws XAException {
}
@Override
public boolean setTransactionTimeout(int i) throws XAException {
return false;
}
@Override
public void start(Xid xid, int i) throws XAException {
}
}, new XidImple(new Xid() {
@Override
public int getFormatId() {
return 0;
}
@Override
public byte[] getGlobalTransactionId() {
return new byte[0];
}
@Override
public byte[] getBranchQualifier() {
return new byte[0];
}
}), null));
saa.doPrepare();
List<Throwable> deferredThrowables = saa.getDeferredThrowables();
assertEquals("test message", deferredThrowables.get(0).getCause().getMessage());
}
Aggregations