Search in sources :

Example 1 with XATerminatorExtensions

use of com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions in project narayana by jbosstm.

the class SubordinateTestCase method testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync() 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.prepare(xid);
    } catch (XAException e) {
        assertEquals(XAException.XA_RBROLLBACK, e.errorCode);
    // expected - we tried to prepare a rollbackonly tx.
    }
    // no need to call rollback - the XA_RBROLLBACK code indicates its been done.
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 2 with XATerminatorExtensions

use of com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions in project narayana by jbosstm.

the class SubordinateTestCase method testTwoPhaseCommitSyncViaXATerminatorWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncViaXATerminatorWithSeparateSync() 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);
    assertEquals(XAResource.XA_RDONLY, xaTerminator.prepare(xid));
    // don't call commit for read only case
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 3 with XATerminatorExtensions

use of com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions 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());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) Test(org.junit.Test)

Example 4 with XATerminatorExtensions

use of com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions 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());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 5 with XATerminatorExtensions

use of com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions in project narayana by jbosstm.

the class SubordinateTestCase method testOnePhaseCommitSyncViaXATerminatorWithSeparateSync.

@Test
public void testOnePhaseCommitSyncViaXATerminatorWithSeparateSync() 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.commit(xid, true);
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Aggregations

Uid (com.arjuna.ats.arjuna.common.Uid)6 XATerminatorExtensions (com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions)6 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)6 XidImple (com.arjuna.ats.jta.xa.XidImple)6 XATerminator (javax.resource.spi.XATerminator)6 Transaction (javax.transaction.Transaction)6 Xid (javax.transaction.xa.Xid)6 Test (org.junit.Test)6 XAException (javax.transaction.xa.XAException)2 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple)1