Search in sources :

Example 36 with ORB

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

the class GridTest method test.

@Test
public void test() {
    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);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        Control myControl;
        grid_i localGrid = new grid_i(100, 100);
        int h, w, v;
        myControl = theOTS.create(0);
        assertNotNull(myControl);
        h = localGrid.height();
        w = localGrid.width();
        localGrid.set(2, 4, 123, myControl);
        v = localGrid.get(2, 4, myControl);
        // no problem setting and getting the elememt:
        System.out.println("grid[2,4] is " + v);
        assertEquals(123, v);
        Terminator handle = myControl.get_terminator();
        try {
            if (handle != null) {
                handle.commit(false);
            } else
                System.err.println("Error - no transaction terminator!");
        } catch (Exception ex) {
            System.out.println("Test error! Caught: " + ex);
        }
        ORBManager.getPOA().shutdownObject(theOTS);
        ORBManager.getPOA().shutdownObject(localGrid);
    } catch (UserException e) {
        fail("Caught UserException: " + e);
        e.printStackTrace();
    } catch (SystemException e) {
        fail("Caught SystemException: " + e);
        e.printStackTrace();
    }
    System.out.println("\nWill now try different thread terminating transaction.\n");
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        System.out.println("Starting new transaction.");
        current.begin();
        Control tc = current.get_control();
        if (tc != null) {
            System.out.println("Creating new thread.");
            TransactionalThread tranThread = new TransactionalThread(tc);
            System.out.println("Waiting for thread to terminate transaction.\n");
            tranThread.start();
            while (!tranThread.finished()) Thread.yield();
            System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
            try {
                current.rollback();
                fail("Error - managed to rollback transaction!");
            } catch (NoTransaction e1) {
                System.out.println("Correct termination - caught: " + e1);
            } catch (INVALID_TRANSACTION e2) {
                System.out.println("Correct termination - caught: " + e2);
            } catch (Exception e3) {
                fail("Wrong termination - caught unexpected exception: " + e3);
                e3.printStackTrace();
            }
            System.out.println("Test completed successfully.");
        } else
            System.err.println("Error - null transaction control!");
    } catch (Exception e) {
        System.out.println("Caught unexpected exception: " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : TransactionalThread(com.hp.mwtests.ts.jts.resources.TransactionalThread) NoTransaction(org.omg.CosTransactions.NoTransaction) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) com.hp.mwtests.ts.jts.orbspecific.resources.grid_i(com.hp.mwtests.ts.jts.orbspecific.resources.grid_i) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 37 with ORB

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

the class ExplicitStackServer method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String refFile = args[0];
    ExplicitStackPOATie theObject = new ExplicitStackPOATie(new ExplicitStackImple());
    myOA.objectIsReady(theObject);
    Services serv = new Services(myORB);
    try {
        TestUtility.registerService(refFile, myORB.orb().object_to_string(myOA.corbaReference(theObject)));
        System.out.println("Ready");
        myOA.run();
    } catch (Exception e) {
        e.printStackTrace();
    }
    myOA.shutdownObject(theObject);
    System.out.println("**ExplicitStackServer exiting**");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ExplicitStackImple(com.hp.mwtests.ts.jts.orbspecific.resources.ExplicitStackImple) Services(com.arjuna.orbportability.Services) RootOA(com.arjuna.orbportability.RootOA) ExplicitStackPOATie(com.hp.mwtests.ts.jts.TestModule.ExplicitStackPOATie) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 38 with ORB

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

the class HammerServer method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String refFile = args[0];
    HammerPOATie theObject = new HammerPOATie(new HammerObject());
    myOA.objectIsReady(theObject);
    Services serv = new Services(myORB);
    try {
        TestUtility.registerService(refFile, myORB.orb().object_to_string(HammerHelper.narrow(myOA.corbaReference(theObject))));
        System.out.println("\nIOR file: " + refFile);
        System.out.println("Ready");
        // assertReady();
        myOA.run();
    } catch (Exception e) {
        // fail("HammerServer caught exception: "+e);
        e.printStackTrace(System.err);
    }
    myOA.shutdownObject(theObject);
    System.out.println("**HammerServer exiting**");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) RootOA(com.arjuna.orbportability.RootOA) HammerPOATie(com.hp.mwtests.ts.jts.TestModule.HammerPOATie) HammerObject(com.hp.mwtests.ts.jts.orbspecific.resources.HammerObject) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB)

Example 39 with ORB

use of com.arjuna.orbportability.ORB 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 40 with ORB

use of com.arjuna.orbportability.ORB 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)

Aggregations

ORB (com.arjuna.orbportability.ORB)93 RootOA (com.arjuna.orbportability.RootOA)71 Test (org.junit.Test)57 OA (com.arjuna.orbportability.OA)20 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)20 Control (org.omg.CosTransactions.Control)20 Services (com.arjuna.orbportability.Services)19 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)9 PerfTestInterface (org.jboss.jbossts.qa.performance.PerfTestInterface)7 SystemException (org.omg.CORBA.SystemException)7 IntHolder (org.omg.CORBA.IntHolder)6 Coordinator (org.omg.CosTransactions.Coordinator)6 UserException (org.omg.CORBA.UserException)5 Properties (java.util.Properties)4 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)4 Terminator (org.omg.CosTransactions.Terminator)4 AtomicObject (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicObject)3 Status (org.omg.CosTransactions.Status)3 TransactionFactory (org.omg.CosTransactions.TransactionFactory)3 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2