Search in sources :

Example 16 with ServerORB

use of com.hp.mwtests.ts.jts.utils.ServerORB in project narayana by jbosstm.

the class TimeoutClient method main.

public static void main(String[] args) throws Exception {
    ORB myORB = null;
    RootOA myOA = null;
    try {
        ServerORB orb = new ServerORB();
        myORB = orb.getORB();
        myOA = orb.getOA();
        CurrentImple current = OTSImpleManager.current();
        Control theControl = null;
        String objectReference = args[0];
        SetGet SetGetVar = null;
        System.out.println("Setting transaction timeout to " + timeout * mfactor + " seconds.");
        current.set_timeout(timeout * mfactor);
        current.begin();
        current.begin();
        long startTime = System.currentTimeMillis();
        try {
            Services serv = new Services(myORB);
            SetGetVar = SetGetHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(objectReference)));
        } catch (Exception e) {
            TestUtility.fail("Bind to object failed: " + e);
            e.printStackTrace(System.err);
        }
        try {
            theControl = current.get_control();
            SetGetVar.set((short) 2, theControl);
            theControl = null;
            System.out.println("Set value.");
        } catch (Exception e) {
            TestUtility.fail("Call to set or get failed: " + e);
            e.printStackTrace(System.err);
        }
        try {
            long timeNow = System.currentTimeMillis();
            long setTime = (timeNow - startTime);
            long timeoutTime = (timeout * 1000 * mfactor);
            long sleepTime = timeoutTime - setTime;
            if (sleepTime > 0) {
                System.out.println("Now sleeping for " + sleepTime * mfactor + " milliseconds.");
                Thread.sleep(sleepTime * mfactor);
            }
        } catch (Exception e) {
        }
        System.out.println("\ncommitting nested action.");
        try {
            current.commit(true);
            TestUtility.fail("commit worked");
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.out.println("Caught TransactionRolledBack");
        } catch (INVALID_TRANSACTION e1) /* For JacORB */
        {
            System.out.println("Caught InvalidTransaction");
        }
        System.out.println("\ncommitting top-level action");
        try {
            current.commit(true);
            TestUtility.fail("commit worked");
        } catch (TRANSACTION_ROLLEDBACK e2) {
            System.out.println("Caught TransactionRolledBack");
        } catch (INVALID_TRANSACTION e3) {
            System.out.println("Caught InvalidTransaction");
        } catch (Exception e) {
            TestUtility.fail("Caught other exception: " + e);
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
        TestUtility.fail(e.toString());
    }
    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) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 17 with ServerORB

use of com.hp.mwtests.ts.jts.utils.ServerORB in project narayana by jbosstm.

the class TMTest method test.

@Test
public void test() throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    TransactionFactory theOTS = null;
    Control topLevelControl = null;
    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);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) Control(org.omg.CosTransactions.Control) TransactionFactory(org.omg.CosTransactions.TransactionFactory) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 18 with ServerORB

use of com.hp.mwtests.ts.jts.utils.ServerORB in project narayana by jbosstm.

the class TranGridServer method test.

@Test
public void test() throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String serverName = "TranGrid";
    String refFile = "/tmp/trangrid.ref";
    if (System.getProperty("os.name").startsWith("Windows")) {
        refFile = "C:\\temp\\trangrid.ref";
    }
    trangrid_i gridI = new trangrid_i((short) 100, (short) 100);
    Services serv = new Services(myORB);
    try {
        TestUtility.registerService(refFile, myORB.orb().object_to_string(gridI.getReference()));
        System.out.println("**TranGrid server started**");
        // assertReady();
        myOA.run();
    } catch (Exception e) {
        fail("TranGrid server caught exception: " + e);
    }
    myOA.shutdownObject(gridI);
    System.out.println("**TranGrid server exiting**");
}
Also used : com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i(com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) RootOA(com.arjuna.orbportability.RootOA) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 19 with ServerORB

use of com.hp.mwtests.ts.jts.utils.ServerORB 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 20 with ServerORB

use of com.hp.mwtests.ts.jts.utils.ServerORB 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)

Aggregations

ORB (com.arjuna.orbportability.ORB)20 RootOA (com.arjuna.orbportability.RootOA)20 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)20 Services (com.arjuna.orbportability.Services)16 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 Control (org.omg.CosTransactions.Control)6 IntHolder (org.omg.CORBA.IntHolder)5 Test (org.junit.Test)4 SetGet (com.hp.mwtests.ts.jts.TestModule.SetGet)2 com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i (com.hp.mwtests.ts.jts.orbspecific.resources.trangrid_i)2 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)2 ExplicitStack (com.hp.mwtests.ts.jts.TestModule.ExplicitStack)1 ExplicitStackPOATie (com.hp.mwtests.ts.jts.TestModule.ExplicitStackPOATie)1 HammerPOATie (com.hp.mwtests.ts.jts.TestModule.HammerPOATie)1 TranGrid (com.hp.mwtests.ts.jts.TestModule.TranGrid)1 TestModule.grid (com.hp.mwtests.ts.jts.TestModule.grid)1 TestModule.stack (com.hp.mwtests.ts.jts.TestModule.stack)1 TestModule.stackPOATie (com.hp.mwtests.ts.jts.TestModule.stackPOATie)1 DHThreadObject2 (com.hp.mwtests.ts.jts.orbspecific.resources.DHThreadObject2)1 DHThreadObject3b (com.hp.mwtests.ts.jts.orbspecific.resources.DHThreadObject3b)1