Search in sources :

Example 1 with DemoResource

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

the class AsyncTest method test.

@Test
public void test() throws Exception {
    boolean errorp = false;
    boolean errorc = false;
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    try {
        Current current = OTSManager.get_current();
        DemoResource.printThread = true;
        current.begin();
        for (int j = 0; j < 100; j++) {
            if ((j == 10) && (errorp || errorc)) {
                boolean heuristicPrepare = errorp;
                heuristic h = new heuristic(heuristicPrepare);
                current.get_control().get_coordinator().register_resource(h.getReference());
                h = null;
            }
            DemoResource r = new DemoResource();
            r.registerResource();
            r = null;
        }
        System.out.println("committing top-level transaction");
        current.commit(false);
        System.out.println("Test completed.");
    } catch (org.omg.CORBA.TRANSACTION_ROLLEDBACK e) {
        System.out.println("Caught exception: " + e);
        assertTrue(errorp || errorc);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) RootOA(com.arjuna.orbportability.RootOA) com.hp.mwtests.ts.jts.orbspecific.resources.heuristic(com.hp.mwtests.ts.jts.orbspecific.resources.heuristic) Current(org.omg.CosTransactions.Current) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 2 with DemoResource

use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource 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 3 with DemoResource

use of com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource 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)

Example 4 with DemoResource

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

the class ResourceRecordUnitTest method test.

@Test
public void test() throws Exception {
    DemoResource res = new DemoResource();
    ResourceRecord rec = new ResourceRecord(false, res.getResource(), new Uid());
    PrintWriter writer = new PrintWriter(new ByteArrayOutputStream());
    rec.print(writer);
    assertTrue(rec.resourceHandle() != null);
    OutputObjectState os = new OutputObjectState();
    assertTrue(rec.save_state(os, ObjectType.ANDPERSISTENT));
    InputObjectState is = new InputObjectState(os);
    assertTrue(rec.restore_state(is, ObjectType.ANDPERSISTENT));
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceRecord(com.arjuna.ats.internal.jts.resources.ResourceRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with DemoResource

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

the class RecoveredTransactionReplayerUnitTest method testCommitted.

@Test
public void testCommitted() throws Exception {
    /*
         * Deliberately choose a Uid that doesn't represent a state
         * on disk.
         * 
         * Use un-threaded.
         */
    Uid dummyUid = new Uid();
    String dummyState = "/StateManager/DummyState";
    RecoveredTransactionReplayer replayer = new RecoveredTransactionReplayer(dummyUid, dummyState);
    DemoResource res = new DemoResource();
    assertTrue(RecoveredTransactionReplayer.isPresent(dummyUid) != null);
    replayer.swapResource(dummyUid, res.getResource());
    replayer.run();
    assertTrue(RecoveredTransactionReplayer.isPresent(dummyUid) == null);
}
Also used : DemoResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveredTransactionReplayer(com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer) Test(org.junit.Test)

Aggregations

DemoResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoResource)9 Test (org.junit.Test)9 AtomicTransaction (com.arjuna.ats.jts.extensions.AtomicTransaction)3 Uid (com.arjuna.ats.arjuna.common.Uid)2 JacOrbRCServiceInit (com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators.JacOrbRCServiceInit)2 JacOrbRecoveryInit (com.arjuna.ats.internal.jts.orbspecific.jacorb.recoverycoordinators.JacOrbRecoveryInit)2 RecoveryCreator (com.arjuna.ats.internal.jts.recovery.RecoveryCreator)2 GenericRecoveryCreator (com.arjuna.ats.internal.jts.recovery.recoverycoordinators.GenericRecoveryCreator)2 TopLevelTransaction (com.arjuna.ats.jts.extensions.TopLevelTransaction)2 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 DemoSubTranResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoSubTranResource)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)1 RecoveredTransactionReplayer (com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer)1 ResourceRecord (com.arjuna.ats.internal.jts.resources.ResourceRecord)1 com.hp.mwtests.ts.jts.orbspecific.resources.heuristic (com.hp.mwtests.ts.jts.orbspecific.resources.heuristic)1 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1