Search in sources :

Example 61 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class TMClient 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 topLevelControl = null;
    Control nestedControl = null;
    String server = "/tmp/hammer1.ref";
    boolean slave = false;
    if (System.getProperty("os.name").startsWith("Windows")) {
        server = "C:\\temp\\hammer1.ref";
    }
    Services serv = new Services(myORB);
    int resolver = Services.getResolver();
    try {
        String[] params = new String[1];
        params[0] = Services.otsKind;
        org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params, resolver);
        params = null;
        theOTS = TransactionFactoryHelper.narrow(obj);
    } catch (Exception e) {
        fail("Unexpected bind exception: " + e);
        e.printStackTrace(System.err);
    }
    System.out.println("Creating transaction.");
    try {
        topLevelControl = theOTS.create(0);
    } catch (Exception e) {
        fail("Create call failed: " + e);
        e.printStackTrace(System.err);
    }
    System.out.println("Creating subtransaction.");
    try {
        nestedControl = topLevelControl.get_coordinator().create_subtransaction();
    } catch (Exception e) {
        System.err.println("Subtransaction create call failed: " + e);
        try {
            topLevelControl.get_terminator().rollback();
        } catch (Exception ex) {
        }
        e.printStackTrace(System.err);
        fail();
    }
    try {
        DistributedHammerWorker1.hammerObject_1 = HammerHelper.narrow(serv.getService(server, null, Services.FILE));
        if (!DistributedHammerWorker1.hammerObject_1.incr(1, nestedControl))
            System.out.println("Could not increment!");
        else
            System.out.println("incremented.");
        System.out.println("sleeping.");
        Thread.sleep(20000);
        nestedControl.get_terminator().rollback();
        if (!slave) {
            System.out.println("master sleeping again.");
            Thread.sleep(20000);
        }
        IntHolder value = new IntHolder(0);
        org.omg.CosTransactions.PropagationContext ctx = topLevelControl.get_coordinator().get_txcontext();
        assertTrue(DistributedHammerWorker1.hammerObject_1.get(value, topLevelControl));
        topLevelControl.get_terminator().rollback();
    } catch (Exception e) {
        fail("TMClient: " + e);
        e.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory) IntHolder(org.omg.CORBA.IntHolder) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 62 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class ExplicitArjunaClient 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();
    String refFile = args[0];
    int value = 1;
    Control cont = null;
    try {
        System.out.println("Starting initialising top-level transaction.");
        current.begin();
        System.out.println("Initialising transaction name: " + current.get_transaction_name());
    } catch (Exception e) {
        TestUtility.fail(e.toString());
    }
    // pointer the grid object that will be used.
    ExplicitStack stackVar = null;
    try {
        stackVar = ExplicitStackHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(refFile)));
    } catch (Exception e) {
        TestUtility.fail("Bind error: " + e);
    }
    try {
        System.out.println("pushing " + value + " onto stack");
        cont = current.get_control();
        stackVar.push(value, cont);
        System.out.println("\npushing " + (value + 1) + " onto stack");
        stackVar.push(value + 1, cont);
        cont = null;
    } catch (Exception e) {
        TestUtility.fail(e.toString());
    }
    try {
        current.commit(true);
        System.out.println("Committed top-level transaction");
        System.out.println("\nBeginning top-level transaction");
        current.begin();
        System.out.println("Top-level name: " + current.get_transaction_name());
        IntHolder val = new IntHolder(-1);
        cont = current.get_control();
        if (stackVar.pop(val, cont) == 0) {
            System.out.println("popped top of stack " + val.value);
            System.out.println("\nbeginning nested transaction");
            current.begin();
            System.out.println("nested name: " + current.get_transaction_name());
            cont = null;
            cont = current.get_control();
            stackVar.push(value + 2, cont);
            System.out.println("pushed " + (value + 2) + " onto stack. Aborting nested action.");
            // current will destroy this control!
            cont = null;
            current.rollback();
            cont = current.get_control();
            System.out.println("current transaction name: " + current.get_transaction_name());
            System.out.println("rolledback nested transaction");
            stackVar.pop(val, cont);
            System.out.println("\npopped top of stack is " + val.value);
            System.out.println("\nTrying to print stack contents - should fail.");
            stackVar.printStack();
            cont = null;
            current.commit(true);
            System.out.println("\nCommitted top-level transaction");
            if (current.get_transaction_name() == null)
                System.out.println("current transaction name: null");
            else
                System.out.println("Error - current transaction name: " + current.get_transaction_name());
            TestUtility.assertEquals(value, val.value);
        } else {
            System.out.println("Error getting stack value.");
            current.rollback();
            System.out.println("\nRolledback top-level transaction.");
        }
        try {
            System.out.println("\nPrinting stack contents (should be empty).");
            stackVar.printStack();
        } catch (Exception e) {
            TestUtility.fail("\nError - could not print.");
        }
    } catch (Exception e) {
        TestUtility.fail("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Passed");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Control(org.omg.CosTransactions.Control) IntHolder(org.omg.CORBA.IntHolder) RootOA(com.arjuna.orbportability.RootOA) ExplicitStack(com.hp.mwtests.ts.jts.TestModule.ExplicitStack) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 63 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class CurrentTest 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 myControl = null;
    String gridReference = args[0];
    // pointer the grid object that will be used.
    grid gridVar = null;
    int h = -1, w = -1, v = -1;
    System.out.println("Beginning transaction.");
    try {
        current.begin();
        myControl = current.get_control();
        TestUtility.assertTrue(myControl != null);
    } catch (Exception sysEx) {
        sysEx.printStackTrace(System.err);
        TestUtility.fail(sysEx.toString());
    }
    try {
        Services serv = new Services(myORB);
        gridVar = gridHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(gridReference)));
    } catch (Exception sysEx) {
        TestUtility.fail("failed to bind to grid: " + sysEx);
        sysEx.printStackTrace(System.err);
    }
    try {
        h = gridVar.height();
        w = gridVar.width();
    } catch (Exception sysEx) {
        TestUtility.fail("grid height/width failed: " + sysEx);
        sysEx.printStackTrace(System.err);
    }
    System.out.println("height is " + h);
    System.out.println("width  is " + w);
    try {
        gridVar.set(2, 4, 123, myControl);
        v = gridVar.get(2, 4, myControl);
    } catch (Exception sysEx) {
        TestUtility.fail("grid set/get failed: " + sysEx);
        sysEx.printStackTrace(System.err);
    }
    // no problem setting and getting the element:
    System.out.println("grid[2,4] is " + v);
    // sanity check: make sure we got the value 123 back:
    if (v != 123) {
        TestUtility.fail("something went seriously wrong");
        try {
            current.rollback();
        } catch (Exception e) {
            TestUtility.fail("rollback error: " + e);
            e.printStackTrace(System.err);
        }
    } else {
        System.out.println("Committing transaction.");
        try {
            current.commit(true);
        } catch (Exception e) {
            TestUtility.fail("commit error: " + e);
            e.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) TestModule.grid(com.hp.mwtests.ts.jts.TestModule.grid) 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 64 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class ORBPrePostShutdownTest method test.

@Test
public void test() throws Exception {
    ORB orb = ORB.getInstance("main_orb");
    RootOA oa = RootOA.getRootOA(orb);
    System.out.println("Initialising ORB and OA");
    orb.initORB(new String[] {}, null);
    oa.initOA();
    _currentState = NONE;
    orb.addPreShutdown(new TestPreShutdown("PreShutdown", this));
    orb.addPostShutdown(new TestPostShutdown("PostShutdown", this));
    System.out.println("Shutting down ORB and OA");
    oa.destroy();
    orb.shutdown();
    System.out.println("Final state: " + PrettyPrintState(_currentState));
    assertEquals(POSTSHUTDOWN, _currentState);
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 65 with RootOA

use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.

the class PropertyInitTest2 method test.

@Test
public void test() {
    int numberOfORBs = 1;
    int numberOfOAsPerORB = 3;
    Map<String, String> testProps = opPropertyManager.getOrbPortabilityEnvironmentBean().getOrbInitializationProperties();
    /**
     * Setup pre-initialisation classes for all ORBs and all OAs
     */
    for (int orbCount = 0; orbCount < numberOfORBs; orbCount++) {
        System.out.println("Registering pre-initialisation property '" + PreInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount) + "'");
        testProps.put(PreInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount, "preinitmyorb"), "com.hp.mwtests.orbportability.initialisation.preinit.PreInitialisation");
        for (int oaCount = 0; oaCount < numberOfOAsPerORB; oaCount++) {
            System.out.println("Registering pre-initialisation property '" + PreInitLoader.generateOAPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount, OA_INSTANCE_NAME + oaCount) + "'");
            System.out.println("Registering pre-initialisation property '" + PreInitLoader.generateOAPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount, OA_INSTANCE_NAME + oaCount, "mypoainit") + "'");
            testProps.put(PreInitLoader.generateOAPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount, OA_INSTANCE_NAME + oaCount), "com.hp.mwtests.orbportability.initialisation.preinit.PreInitialisation");
            testProps.put(PreInitLoader.generateOAPropertyName("com.arjuna.orbportability.orb", ORB_INSTANCE_NAME + orbCount, OA_INSTANCE_NAME + oaCount, "mypoainit"), "com.hp.mwtests.orbportability.initialisation.preinit.PreInitialisation2");
        }
    }
    opPropertyManager.getOrbPortabilityEnvironmentBean().setOrbInitializationProperties(testProps);
    try {
        long preInitExpectedValue = 0;
        long myPoaExceptedValue = 0;
        for (int orbCount = 0; orbCount < numberOfORBs; orbCount++) {
            String orbId = ORB_INSTANCE_NAME + orbCount;
            ORB orb = ORB.getInstance(orbId);
            System.out.println("Initialising ORB Instance '" + orbId + "'");
            orb.initORB(new String[] {}, null);
            RootOA rootOA = RootOA.getRootOA(orb);
            rootOA.initPOA(new String[] {});
            preInitExpectedValue++;
            assertEquals(preInitExpectedValue, PreInitialisation._count);
            for (int oaCount = 0; oaCount < numberOfOAsPerORB; oaCount++) {
                String oaId = OA_INSTANCE_NAME + oaCount;
                System.out.println("Initialising OA instance '" + oaId + "' for ORB Instance '" + orbId + "'");
                Policy[] p = new Policy[1];
                p[0] = rootOA.rootPoa().create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION);
                OA oa = rootOA.createPOA(oaId, p);
                preInitExpectedValue++;
                myPoaExceptedValue++;
            }
            assertEquals(myPoaExceptedValue, PreInitialisation2._count);
            assertEquals(preInitExpectedValue, PreInitialisation._count);
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("ERROR - " + e);
    }
    for (int orbCount = 0; orbCount < numberOfORBs; orbCount++) {
        try {
            String orbId = ORB_INSTANCE_NAME + orbCount;
            ORB orb = ORB.getInstance(orbId);
            RootOA oa = RootOA.getRootOA(orb);
            oa.destroy();
            orb.destroy();
        } catch (Exception e) {
            fail("ERROR - While destroying ORB instance '" + ORB_INSTANCE_NAME + orbCount + "' (" + e + ")");
            e.printStackTrace(System.err);
        }
    }
}
Also used : Policy(org.omg.CORBA.Policy) RootOA(com.arjuna.orbportability.RootOA) OA(com.arjuna.orbportability.OA) RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Aggregations

ORB (com.arjuna.orbportability.ORB)70 RootOA (com.arjuna.orbportability.RootOA)70 Test (org.junit.Test)49 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)20 Services (com.arjuna.orbportability.Services)18 Control (org.omg.CosTransactions.Control)18 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)9 SystemException (org.omg.CORBA.SystemException)7 IntHolder (org.omg.CORBA.IntHolder)6 UserException (org.omg.CORBA.UserException)5 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)4 Terminator (org.omg.CosTransactions.Terminator)4 AtomicObject (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicObject)3 Coordinator (org.omg.CosTransactions.Coordinator)3 Status (org.omg.CosTransactions.Status)3 TransactionFactory (org.omg.CosTransactions.TransactionFactory)3 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2 TestResource (com.hp.mwtests.ts.jta.jts.common.TestResource)2 XACreator (com.hp.mwtests.ts.jta.jts.common.XACreator)2 SetGet (com.hp.mwtests.ts.jts.TestModule.SetGet)2