Search in sources :

Example 6 with DemoDurableParticipant

use of com.arjuna.wstx.tests.common.DemoDurableParticipant 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)

Example 7 with DemoDurableParticipant

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

the class SuspendResumeParticipantsTest method testSuspendResumeParticipants.

@Test
public void testSuspendResumeParticipants() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();
    DemoDurableParticipant p1 = new DemoDurableParticipant();
    DemoDurableParticipant p2 = new DemoDurableParticipant();
    DemoDurableParticipant p3 = new DemoDurableParticipant();
    DemoDurableParticipant p4 = new DemoDurableParticipant();
    System.out.println("Starting first transaction.\n");
    ut.begin();
    try {
        tm.enlistForDurableTwoPhase(p1, p1.identifier());
        tm.enlistForDurableTwoPhase(p2, p2.identifier());
        tm.enlistForDurableTwoPhase(p3, p3.identifier());
        tm.enlistForDurableTwoPhase(p4, p4.identifier());
        TxContext ctx = tm.suspend();
        System.out.println("Suspended: " + ctx);
        ut.begin();
        System.out.println("\nStarted second transaction.");
        tm.resume(ctx);
        System.out.println("\nCommitting first transaction.\n");
    } catch (Exception eouter) {
        try {
            ut.rollback();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    ut.commit();
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Example 8 with DemoDurableParticipant

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

the class CommitRollbackInPrepareTest method testCommitRollbackInPrepare.

@Test
public void testCommitRollbackInPrepare() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    try {
        TransactionManager tm = TransactionManager.getTransactionManager();
        FailureParticipant p1 = new FailureParticipant(FailureParticipant.FAIL_IN_PREPARE, FailureParticipant.NONE);
        DemoDurableParticipant p2 = new DemoDurableParticipant();
        ut.begin();
        tm.enlistForDurableTwoPhase(p1, "failure");
        tm.enlistForDurableTwoPhase(p2, p2.identifier());
    } catch (Exception eouter) {
        try {
            ut.rollback();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    try {
        ut.commit();
        fail("expected TransactionRolledBackException");
    } catch (com.arjuna.wst.TransactionRolledBackException ex) {
    // we should arrive here
    }
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) FailureParticipant(com.arjuna.wstx.tests.common.FailureParticipant) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) Test(org.junit.Test)

Example 9 with DemoDurableParticipant

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

the class MultiParticipantsTest method testMultiParticipants.

@Test
public void testMultiParticipants() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();
    DemoDurableParticipant p1 = new DemoDurableParticipant();
    DemoDurableParticipant p2 = new DemoDurableParticipant();
    DemoDurableParticipant p3 = new DemoDurableParticipant();
    DemoDurableParticipant p4 = new DemoDurableParticipant();
    ut.begin();
    try {
        tm.enlistForDurableTwoPhase(p1, p1.identifier());
        tm.enlistForDurableTwoPhase(p2, p2.identifier());
        tm.enlistForDurableTwoPhase(p3, p3.identifier());
        tm.enlistForDurableTwoPhase(p4, p4.identifier());
    } catch (Exception eouter) {
        try {
            ut.rollback();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    ut.commit();
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) Test(org.junit.Test)

Example 10 with DemoDurableParticipant

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

the class SuspendResumeSingleParticipantTest method testSuspendResumeSingleParticipant.

@Test
public void testSuspendResumeSingleParticipant() throws Exception {
    UserTransaction ut = UserTransaction.getUserTransaction();
    TransactionManager tm = TransactionManager.getTransactionManager();
    DemoDurableParticipant p = new DemoDurableParticipant();
    try {
        ut.begin();
        tm.enlistForDurableTwoPhase(p, p.identifier());
        TxContext ctx = tm.suspend();
        System.out.println("Suspended: " + ctx);
        tm.resume(ctx);
        System.out.println("\nResumed\n");
    } catch (Exception eouter) {
        try {
            ut.rollback();
        } catch (Exception einner) {
        }
        throw eouter;
    }
    ut.commit();
}
Also used : UserTransaction(com.arjuna.mw.wst11.UserTransaction) TransactionManager(com.arjuna.mw.wst11.TransactionManager) DemoDurableParticipant(com.arjuna.wstx.tests.common.DemoDurableParticipant) TxContext(com.arjuna.mw.wst.TxContext) Test(org.junit.Test)

Aggregations

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