Search in sources :

Example 1 with DemoArjunaResource

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

the class ArjunaNestingTest method run.

@Test
public void run() throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    myORB = ORB.getInstance("test");
    myOA = OA.getRootOA(myORB);
    myORB.initORB(new String[] {}, null);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    boolean doAbort = false;
    boolean registerSubtran = false;
    org.omg.CosTransactions.Current current = OTSManager.get_current();
    DemoArjunaResource sr = new DemoArjunaResource();
    try {
        current.begin();
        current.begin();
        current.begin();
    } catch (SystemException sysEx) {
        fail("Unexpected system exception:" + sysEx);
        sysEx.printStackTrace(System.err);
    } catch (UserException se) {
        fail("Unexpected user exception:" + se);
        se.printStackTrace(System.err);
    }
    try {
        sr.registerResource(registerSubtran);
    } catch (SystemException ex1) {
        fail("Unexpected system exception: " + ex1);
        ex1.printStackTrace(System.err);
    } catch (Exception e) {
        fail("call to registerSubtran failed: " + e);
        e.printStackTrace(System.err);
    }
    try {
        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();
        }
    } catch (Exception ex) {
        fail("Caught unexpected exception: " + ex);
        ex.printStackTrace(System.err);
    }
    myOA.shutdownObject(sr);
    myOA.destroy();
    myORB.shutdown();
}
Also used : DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) SystemException(org.omg.CORBA.SystemException) RootOA(com.arjuna.orbportability.RootOA) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Test(org.junit.Test)

Example 2 with DemoArjunaResource

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

the class ExtendedResourceUnitTest method test.

@Test
public void test() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    ArjunaTransactionImple tx = new ArjunaTransactionImple(null);
    ExtendedResourceRecord res1 = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), null, new Uid(), tx);
    ExtendedResourceRecord res2 = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), null, new Uid(), tx);
    assertTrue(res1.resourceHandle() != null);
    assertTrue(res1.value() != null);
    assertFalse(res1.propagateOnAbort());
    assertFalse(res1.propagateOnCommit());
    assertTrue(res1.order().notEquals(Uid.nullUid()));
    assertEquals(res1.typeIs(), 101);
    assertTrue(res1.order() != null);
    res1.setValue(null);
    res1.print(new PrintWriter(new ByteArrayOutputStream()));
    OutputObjectState os = new OutputObjectState();
    assertTrue(res1.save_state(os, ObjectType.ANDPERSISTENT));
    InputObjectState is = new InputObjectState(os);
    assertTrue(res1.restore_state(is, ObjectType.ANDPERSISTENT));
    assertFalse(res2.doSave());
    assertFalse(res1.shouldAdd(res2));
    assertFalse(res1.shouldAlter(res2));
    assertFalse(res1.shouldMerge(res2));
    assertFalse(res1.shouldReplace(res2));
    res1 = new ExtendedResourceRecord();
    assertTrue(res1.getRCUid().notEquals(res2.getRCUid()));
    res1.alter(res2);
    res1.merge(res2);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with DemoArjunaResource

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

the class ExtendedResourceUnitTest method testTopLevelCommit.

@Test
public void testTopLevelCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(res.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
    // no heuristic but we can still call method
    assertTrue(res.forgetHeuristic());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 4 with DemoArjunaResource

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

the class ExtendedResourceUnitTest method testNestedCommit.

@Test
public void testNestedCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    OTSImpleManager.current().begin();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(res.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
    OTSImpleManager.current().rollback();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 5 with DemoArjunaResource

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

the class ExtendedResourceUnitTest method testOnePhaseCommit.

@Test
public void testOnePhaseCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.topLevelOnePhaseCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Aggregations

DemoArjunaResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource)8 Test (org.junit.Test)8 Uid (com.arjuna.ats.arjuna.common.Uid)7 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)7 ExtendedResourceRecord (com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord)7 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 ORB (com.arjuna.orbportability.ORB)1 RootOA (com.arjuna.orbportability.RootOA)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 SystemException (org.omg.CORBA.SystemException)1 UserException (org.omg.CORBA.UserException)1