Search in sources :

Example 11 with StatelessEJBLocator

use of org.jboss.ejb.client.StatelessEJBLocator in project wildfly by wildfly.

the class HTTPEJBClientXidTransactionTestCase method testServerSuspension.

/**
     * Calls for a preexistent transaction are allowed and calls for a non-preexistent transaction are not allowed
     * on server suspension.
     *
     * @throws Exception
     */
@Test
public void testServerSuspension() throws Exception {
    final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
    final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
    // begin a transaction, and make sure that the server now works normally
    txManager.begin();
    try {
        // invoke the bean
        cmtRemoteBean.mandatoryTxOp();
    } finally {
        // end the tx
        txManager.commit();
    }
    // begin the transaction
    txManager.begin();
    try {
        // invoke the bean
        cmtRemoteBean.mandatoryTxOp();
        ModelNode op = new ModelNode();
        op.get(OP).set("suspend");
        managementClient.getControllerClient().execute(op);
        txManager.commit();
    } catch (Exception e) {
        try {
            txManager.rollback();
        } catch (Exception exc) {
        }
        throw e;
    } finally {
        // resume server
        ModelNode op = new ModelNode();
        op.get(OP).set("resume");
        managementClient.getControllerClient().execute(op);
    }
    try {
        // begin a transaction
        txManager.begin();
        long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
        while (true) {
            try {
                // can invoke bean
                cmtRemoteBean.mandatoryTxOp();
                break;
            } catch (Exception e) {
                if (System.currentTimeMillis() > fin) {
                    throw e;
                }
            }
            Thread.sleep(300);
        }
        // suspend server
        ModelNode op = new ModelNode();
        op.get(OP).set("suspend");
        managementClient.getControllerClient().execute(op);
    // FIXME check with remoting team why this transaction is not recognized as active in EJBSuspendHandlerService
    // can continue invoking bean with current transaction
    //cmtRemoteBean.mandatoryTxOp();
    } catch (Exception e) {
        e.printStackTrace();
        // resume server
        ModelNode op = new ModelNode();
        op.get(OP).set("resume");
        managementClient.getControllerClient().execute(op);
        throw e;
    } finally {
        // rollback current transaction
        txManager.commit();
    }
    // still cannot begin a new transaction
    txManager.begin();
    try {
        cmtRemoteBean.mandatoryTxOp();
        Assert.fail("Exception expected, server is shutdown");
    } catch (Exception expected) {
    // expected
    } finally {
        txManager.rollback();
    }
    // resume server
    ModelNode op = new ModelNode();
    op.get(OP).set("resume");
    managementClient.getControllerClient().execute(op);
    try {
        // begin a transaction, and make sure that the server now works normally
        txManager.begin();
        long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
        while (true) {
            try {
                // can invoke bean
                cmtRemoteBean.mandatoryTxOp();
                break;
            } catch (Exception e) {
                if (System.currentTimeMillis() > fin) {
                    throw e;
                }
            }
            Thread.sleep(300);
        }
        // end the tx
        txManager.commit();
    } catch (Exception e) {
        txManager.rollback();
        throw e;
    }
}
Also used : StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) ModelNode(org.jboss.dmr.ModelNode) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 12 with StatelessEJBLocator

use of org.jboss.ejb.client.StatelessEJBLocator in project wildfly by wildfly.

the class SimpleApplicationClientTestCase method simpleAppClientTest.

/**
     * Tests a simple app client that calls an ejb with its command line parameters
     */
@Test
public void simpleAppClientTest() throws Exception {
    final StatelessEJBLocator<AppClientSingletonRemote> locator = new StatelessEJBLocator(AppClientSingletonRemote.class, APP_NAME, MODULE_NAME, AppClientStateSingleton.class.getSimpleName(), "");
    final AppClientSingletonRemote remote = EJBClient.createProxy(locator);
    remote.reset();
    final AppClientWrapper wrapper = new AppClientWrapper(archive, "--host=" + managementClient.getRemoteEjbURL(), "client-annotation.jar", "cmdLineParam");
    try {
        final String result = remote.awaitAppClientCall();
        assertTrue("App client call failed. App client output: " + wrapper.readAllUnformated(1000), result != null);
        assertEquals("cmdLineParam", result);
    } finally {
        wrapper.quit();
    }
}
Also used : AppClientWrapper(org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) Test(org.junit.Test)

Aggregations

StatelessEJBLocator (org.jboss.ejb.client.StatelessEJBLocator)12 Test (org.junit.Test)11 UserTransaction (javax.transaction.UserTransaction)5 AppClientWrapper (org.jboss.as.test.integration.ee.appclient.util.AppClientWrapper)3 ModelNode (org.jboss.dmr.ModelNode)3 URISyntaxException (java.net.URISyntaxException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 EJBException (javax.ejb.EJBException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 EJBHomeLocator (org.jboss.ejb.client.EJBHomeLocator)1 EntityEJBLocator (org.jboss.ejb.client.EntityEJBLocator)1 StatefulEJBLocator (org.jboss.ejb.client.StatefulEJBLocator)1