Search in sources :

Example 31 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class SuspendResume method test.

@Test
public void test() 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);
    CurrentImple current = OTSImpleManager.current();
    Control myControl = null;
    System.out.println("Beginning transaction.");
    try {
        current.begin();
        myControl = current.get_control();
        assertNotNull(myControl);
    } catch (Exception sysEx) {
        sysEx.printStackTrace(System.err);
        fail();
    }
    System.out.println("Committing transaction.");
    try {
        current.commit(true);
        current.resume(myControl);
    } catch (Exception e) {
        fail("commit error: " + e);
        e.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Test completed successfully.");
}
Also used : Control(org.omg.CosTransactions.Control) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 32 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class GridClient method test.

@Test
public void test() 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);
    TransactionFactory theOTS = null;
    Control myControl = null;
    grid gridVar = null;
    int h = -1, w = -1, v = -1;
    String gridReference = "/tmp/grid.ref";
    String serverName = "Grid";
    if (System.getProperty("os.name").startsWith("Windows")) {
        gridReference = "C:\\temp\\grid.ref";
    }
    Services serv = new Services(myORB);
    try {
        String[] params = new String[1];
        params[0] = Services.otsKind;
        org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params);
        params = null;
        theOTS = TransactionFactoryHelper.narrow(obj);
    } catch (Exception e) {
        fail("Unexpected bind exception: " + e);
    }
    System.out.println("Creating transaction.");
    try {
        myControl = theOTS.create(0);
    } catch (Exception e) {
        fail("Create call failed: " + e);
        e.printStackTrace();
    }
    try {
        gridVar = gridHelper.narrow(serv.getService(gridReference, null, Services.FILE));
    } catch (Exception e) {
        fail("Grid bind failed: " + e);
    }
    try {
        h = gridVar.height();
        w = gridVar.width();
    } catch (Exception e) {
        fail("Grid invocation failed: " + e);
    }
    System.out.println("height is " + h);
    System.out.println("width  is " + w);
    try {
        System.out.println("calling set");
        gridVar.set(2, 4, 123, myControl);
        System.out.println("calling get");
        v = gridVar.get(2, 4, myControl);
    } catch (Exception sysEx) {
        fail("Grid set/get failed: " + sysEx);
    }
    // no problem setting and getting the elememt:
    System.out.println("grid[2,4] is " + v);
    // sanity check: make sure we got the value 123 back:
    if (v != 123) {
        // oops - we didn't:
        fail("something went seriously wrong");
        try {
            myControl.get_terminator().rollback();
        } catch (Exception e) {
        }
    } else {
        System.out.println("Committing transaction.");
        try {
            Terminator handle = myControl.get_terminator();
            handle.commit(true);
        } catch (Exception sysEx) {
            fail("Transaction commit error: " + sysEx);
        }
    }
    try {
        OTSManager.destroyControl(myControl);
    } catch (Exception e) {
        fail("Caught destroy exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Test completed successfully.");
}
Also used : RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TestModule.grid(com.hp.mwtests.ts.jts.TestModule.grid) TransactionFactory(org.omg.CosTransactions.TransactionFactory) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 33 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class ExplicitInterClient method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    CurrentImple current = OTSImpleManager.current();
    Control theControl = null;
    String objectReference = args[0];
    SetGet SetGetVar = null;
    short h = 0;
    try {
        current.begin();
        current.begin();
        current.begin();
    } catch (Exception e) {
        TestUtility.fail("Caught exception during begin: " + e);
        e.printStackTrace(System.err);
    }
    try {
        Services serv = new Services(myORB);
        SetGetVar = SetGetHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(objectReference)));
    } catch (Exception ex) {
        TestUtility.fail("Failed to bind to setget server: " + ex);
        ex.printStackTrace(System.err);
    }
    try {
        theControl = current.get_control();
        SetGetVar.set((short) 2, theControl);
        // SetGetVar.set((short) 2, theControl);
        theControl = null;
        System.out.println("Set value.");
    } catch (Exception ex1) {
        TestUtility.fail("Unexpected system exception during set: " + ex1);
        ex1.printStackTrace(System.err);
    }
    try {
        System.out.println("committing first nested action");
        current.commit(true);
        // SetGetVar.set((short) 4, current.get_control());
        System.out.println("committing second nested action");
        current.commit(true);
    } catch (Exception sysEx) {
        TestUtility.fail("Caught unexpected exception during commit: " + sysEx);
        sysEx.printStackTrace(System.err);
    }
    try {
        theControl = current.get_control();
        h = SetGetVar.get(theControl);
        theControl = null;
        System.out.println("Got value.");
    } catch (Exception ex2) {
        TestUtility.fail("Unexpected system exception during get: " + ex2);
        ex2.printStackTrace(System.err);
    }
    try {
        current.commit(true);
        System.out.println("committed top-level action");
    } catch (Exception ep) {
        TestUtility.fail("Caught commit exception for top-level action: " + ep);
        ep.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Passed");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) SetGet(com.hp.mwtests.ts.jts.TestModule.SetGet) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 34 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class ServerNestedRestrictedUnitTest method test.

@Test
public void test() throws Exception {
    ControlImple cont = new ControlImple(null, null);
    Control theControl = cont.getControl();
    ArjunaTransactionImple tx = cont.getImplHandle();
    ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
    ServerRestrictedNestedAction act = new ServerRestrictedNestedAction(sc);
    assertTrue(act.deepestControl() != null);
    assertEquals(act.child(), null);
}
Also used : Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ServerRestrictedNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.restricted.ServerRestrictedNestedAction) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 35 with Control

use of org.omg.CosTransactions.Control in project narayana by jbosstm.

the class ServerNestedStrictUnitTest method testCommit.

@Test
public void testCommit() throws Exception {
    ControlImple cont = new ControlImple(null, null);
    Control theControl = cont.getControl();
    ArjunaTransactionImple tx = cont.getImplHandle();
    ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
    ServerStrictNestedAction act = new ServerStrictNestedAction(sc, true);
    assertFalse(act.interposeResource());
    act.commit_subtransaction(null);
}
Also used : Control(org.omg.CosTransactions.Control) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerControl(com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl) ServerStrictNestedAction(com.arjuna.ats.internal.jts.orbspecific.interposition.resources.strict.ServerStrictNestedAction) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Aggregations

Control (org.omg.CosTransactions.Control)103 Test (org.junit.Test)40 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)24 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)20 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)20 ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)18 TransactionFactory (org.omg.CosTransactions.TransactionFactory)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)14 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)13 Coordinator (org.omg.CosTransactions.Coordinator)13 SystemException (org.omg.CORBA.SystemException)11 IntHolder (org.omg.CORBA.IntHolder)10 Current (org.omg.CosTransactions.Current)9 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)6 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)6 Services (com.arjuna.orbportability.Services)6 PropagationContext (org.omg.CosTransactions.PropagationContext)6 ActionControl (com.arjuna.ArjunaOTS.ActionControl)5 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)5