Search in sources :

Example 1 with DemoSubTranResource

use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource in project narayana by jbosstm.

the class NestedTester method test.

@Test
public void test() {
    boolean registerSubtran = false;
    boolean doAbort = false;
    DemoResource r = null;
    DemoSubTranResource sr = null;
    ORB myORB = null;
    RootOA myOA = null;
    try {
        myORB = ORB.getInstance("test");
        myOA = OA.getRootOA(myORB);
        myORB.initORB(new String[] {}, null);
        myOA.initOA();
        ORBManager.setORB(myORB);
        ORBManager.setPOA(myOA);
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        r = new DemoResource();
        sr = new DemoSubTranResource();
        current.begin();
        current.begin();
        current.begin();
        sr.registerResource(registerSubtran);
        r.registerResource();
        System.out.println("committing first nested transaction");
        current.commit(true);
        System.out.println("committing second nested transaction");
        current.commit(true);
        if (!doAbort) {
            System.out.println("committing top-level transaction");
            current.commit(true);
        } else {
            System.out.println("aborting top-level transaction");
            current.rollback();
        }
        System.out.println("Test completed successfully.");
        if ((!doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit)) {
        // assertSuccess();
        } else {
            if ((doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
            // assertSuccess();
            } else {
                if ((!doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceCommitOnePhase)) {
                // assertSuccess();
                } else {
                    if ((doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
                    // assertSuccess();
                    } else
                        fail();
                }
            }
        }
    } catch (UserException e) {
        fail("Caught UserException: " + e);
        e.printStackTrace(System.err);
    } catch (SystemException e) {
        fail("Caught SystemException: " + e);
        e.printStackTrace(System.err);
    }
    myOA.shutdownObject(r);
    myOA.shutdownObject(sr);
    myOA.destroy();
    myORB.shutdown();
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) SystemException(org.omg.CORBA.SystemException) DemoSubTranResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource) RootOA(com.arjuna.orbportability.RootOA) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 2 with DemoSubTranResource

use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource in project narayana by jbosstm.

the class AtomicTransactionUnitTest method testCommit.

@Test
public void testCommit() throws Exception {
    AtomicTransaction A = new AtomicTransaction();
    A.begin();
    assertTrue(A.get_txcontext() != null);
    A.registerResource(new DemoResource().getResource());
    AtomicTransaction B = new AtomicTransaction();
    B.begin();
    B.registerSubtranAware(new DemoSubTranResource().getReference());
    B.commit(true);
    A.commit(true);
    A = new AtomicTransaction();
    A.begin();
    A.rollbackOnly();
    try {
        A.commit(true);
        fail();
    } catch (final TRANSACTION_ROLLEDBACK ex) {
    }
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) AtomicTransaction(com.arjuna.ats.jts.extensions.AtomicTransaction) DemoSubTranResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) Test(org.junit.Test)

Aggregations

DemoResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource)2 DemoSubTranResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource)2 Test (org.junit.Test)2 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)1 ORB (com.arjuna.orbportability.ORB)1 RootOA (com.arjuna.orbportability.RootOA)1 SystemException (org.omg.CORBA.SystemException)1 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)1 UserException (org.omg.CORBA.UserException)1