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;
}
}
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();
}
}
Aggregations