Search in sources :

Example 1 with DemoVolatileParticipant

use of com.arjuna.wstx.tests.common.DemoVolatileParticipant in project narayana by jbosstm.

the class SubtransactionCommitRollbackInPrepareTest method testSubTransactionCommitRollbackInPrepare.

@Test
public void testSubTransactionCommitRollbackInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    try {
        ut.commit();
        fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException trbe) {
    // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Example 2 with DemoVolatileParticipant

use of com.arjuna.wstx.tests.common.DemoVolatileParticipant in project narayana by jbosstm.

the class SubtransactionRollbackTest method testSubTransactionRollback.

@Test
public void testSubTransactionRollback() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final DemoDurableParticipant p3 = new DemoDurableParticipant();
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, p3.identifier());
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    ut.rollback();
    assertTrue(p1.resolved() && !p1.passed());
    assertTrue(p2.resolved() && !p2.passed());
    assertTrue(p3.resolved() && !p3.passed());
    assertTrue(p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Example 3 with DemoVolatileParticipant

use of com.arjuna.wstx.tests.common.DemoVolatileParticipant in project narayana by jbosstm.

the class SubtransactionCommitTest method testSubTransactionCommit.

@Test
public void testSubTransactionCommit() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final DemoDurableParticipant p3 = new DemoDurableParticipant();
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, p3.identifier());
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    ut.commit();
    assertTrue(p1.prepared() && p1.resolved() && p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && p2.passed());
    assertTrue(p3.prepared() && p3.resolved() && p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Example 4 with DemoVolatileParticipant

use of com.arjuna.wstx.tests.common.DemoVolatileParticipant in project narayana by jbosstm.

the class SubtransactionCommitFailInPrepareTest method testSubTransactionCommitFailInPrepare.

@Test
public void testSubTransactionCommitFailInPrepare() throws Exception {
    final UserTransaction ut = UserTransactionFactory.userTransaction();
    final UserTransaction ust = UserTransactionFactory.userSubordinateTransaction();
    final TransactionManager tm = TransactionManager.getTransactionManager();
    final DemoDurableParticipant p1 = new DemoDurableParticipant();
    final DemoVolatileParticipant p2 = new DemoVolatileParticipant();
    final FailureParticipant p3 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.WRONG_STATE);
    final DemoVolatileParticipant p4 = new DemoVolatileParticipant();
    ut.begin();
    final TxContext tx = tm.suspend();
    tm.resume(tx);
    tm.enlistForDurableTwoPhase(p1, p1.identifier());
    tm.enlistForVolatileTwoPhase(p2, p2.identifier());
    ust.begin();
    final TxContext stx = tm.suspend();
    tm.resume(stx);
    tm.enlistForDurableTwoPhase(p3, "failure in prepare");
    tm.enlistForVolatileTwoPhase(p4, p4.identifier());
    tm.resume(tx);
    try {
        ut.commit();
        fail("expecting TransactionRolledBackException");
    } catch (TransactionRolledBackException wse) {
    // expect this
    }
    assertTrue(p1.prepared() && p1.resolved() && !p1.passed());
    assertTrue(p2.prepared() && p2.resolved() && !p2.passed());
    assertTrue(!p3.passed());
    assertTrue(p4.prepared() && p4.resolved() && !p4.passed());
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) DemoVolatileParticipant(com.arjuna.wstx.tests.common.DemoVolatileParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) TransactionRolledBackException(com.arjuna.wst.TransactionRolledBackException) Test(org.junit.Test)

Aggregations

TxContext (com.arjuna.mw.wst.TxContext)4 TransactionManager (com.arjuna.mw.wst11.TransactionManager)4 UserTransaction (com.arjuna.mw.wst11.UserTransaction)4 DemoDurableParticipant (com.arjuna.wstx.tests.common.DemoDurableParticipant)4 DemoVolatileParticipant (com.arjuna.wstx.tests.common.DemoVolatileParticipant)4 Test (org.junit.Test)4 TransactionRolledBackException (com.arjuna.wst.TransactionRolledBackException)2 FailureParticipant (com.arjuna.wstx.tests.common.FailureParticipant)2