use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class TransactionalRemoteStatefulEJBFailoverTestCase method test.
@Test
public void test(@ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) ManagementClient client1, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) ManagementClient client2) throws Exception {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class);
Result<Integer> result = bean.increment();
// Bean should retain weak affinity for this node
String target = result.getNode();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
// Validate that multi-invocations function correctly within a tx
UserTransaction tx = EJBClient.getUserTransaction(target);
// TODO Currently requires environment to be configured with provider URLs.
// UserTransaction tx = directory.lookupUserTransaction();
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
tx.commit();
// Validate that second invocation fails if target node is undeployed in middle of tx
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
undeploy(this.findDeployment(target));
try {
result = bean.increment();
Assert.fail("Expected a NoSuchEJBException");
} catch (NoSuchEJBException e) {
// Expected
} finally {
tx.rollback();
// TODO remove workaround for WFLY-12128
undeploy(TWO_DEPLOYMENTS);
ServerReload.executeReloadAndWaitForCompletion(client1);
ServerReload.executeReloadAndWaitForCompletion(client2);
// Workaround the above yielding "DeploymentException: Cannot deploy StatefulFailoverTestCase.war: WFLYCTL0379: System boot is in process; execution of remote management operations is not currently available"
Thread.sleep(GRACE_TIME_TOPOLOGY_CHANGE);
}
}
}
use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class TransactionalRemoteStatelessTestCase method affinityNodeFailure.
/**
* This is a similar test to
* {@link TransactionalRemoteStatefulEJBFailoverTestCase#test(ManagementClient, ManagementClient)}
* but this test works with a stateless bean.
*/
@Test
public void affinityNodeFailure() throws Exception {
InitialContext initCtx = getInitialContext(InitialContextLookupType.REMOTE_HTTP, TESTSUITE_NODE0);
String targetNode = null;
UserTransaction txn = null;
try {
txn = getUserTransaction(initCtx);
txn.begin();
Incrementor bean = getStatelessRemoteBean(initCtx, StatelessTransactionBean.class);
Result<Integer> result = bean.increment();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
targetNode = result.getNode();
undeploy(this.findDeployment(targetNode));
try {
result = bean.increment();
Assert.fail("Expected a NoSuchEJBException as transaction affinity needs to be maintained");
} catch (NoSuchEJBException | AssertionError expected) {
// expected as the deployment was removed from the node
}
} finally {
if (txn != null)
txn.rollback();
initCtx.close();
}
}
use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class StatelessBean method remoteCall.
public int remoteCall() throws Exception {
++methodCount;
InitialContext jndiContext = getInitialContext();
log.trace("Calling Remote... " + jndiContext.getEnvironment());
StatelessRemote stateless = (StatelessRemote) jndiContext.lookup("ejb:/" + EjbOverHttpTestCase.ARCHIVE_NAME_SERVER + "//" + StatelessBean.class.getSimpleName() + "!" + StatelessRemote.class.getName());
try {
return stateless.method();
} catch (NoSuchEJBException e) {
return EjbOverHttpTestCase.NO_EJB_RETURN_CODE;
}
}
use of javax.ejb.NoSuchEJBException in project tomee by apache.
the class StatefulTimeoutTest method testZeroTimeout.
public void testZeroTimeout() throws Exception {
final InitialContext ctx = new InitialContext();
final MyLocalBean bean;
// cache is cleared ever 3 seconds and bean timeout is 0 seconds
bean = (MyLocalBean) ctx.lookup("BeanZeroLocal");
bean.doNothing(0);
// cache should be cleared by now and the bean should be removed
Thread.sleep(5 * 1000);
try {
bean.doNothing(0);
fail("Did not throw expected exception");
} catch (final NoSuchEJBException e) {
// that's what we expect
}
}
use of javax.ejb.NoSuchEJBException in project tomee by apache.
the class SingletonInstanceManager method getInstance.
public Instance getInstance(final ThreadContext callContext) throws OpenEJBException {
final BeanContext beanContext = callContext.getBeanContext();
final Data data = (Data) beanContext.getContainerData();
final AtomicReference<Future<Instance>> singleton = data.singleton;
try {
// Has the singleton been created yet?
// If there is a Future object in the AtomicReference, then
// it's either been created or is being created now.
Future<Instance> singletonFuture = singleton.get();
if (singletonFuture != null) {
return singletonFuture.get();
}
// The singleton has not been created nor is being created
// We will construct this FutureTask and compete with the
// other threads for the right to create the singleton
final FutureTask<Instance> task = new FutureTask<Instance>(new Callable<Instance>() {
public Instance call() throws Exception {
return createInstance(callContext, beanContext);
}
});
do {
// the singleton while the others wait.
if (singleton.compareAndSet(null, task)) {
task.run();
}
// If we didn't win the slot and no other FutureTask
// has been set by a different thread, than we need
// to try again.
} while ((singletonFuture = singleton.get()) == null);
// At this point we can safely return the singleton
return singletonFuture.get();
} catch (final InterruptedException e) {
Thread.interrupted();
throw new ApplicationException(new NoSuchEJBException("Singleton initialization interrupted").initCause(e));
} catch (final ExecutionException e) {
final Throwable throwable = e.getCause();
if (throwable instanceof ApplicationException) {
throw (ApplicationException) throwable;
}
throw new ApplicationException(new NoSuchEJBException("Singleton initialization failed").initCause(e.getCause()));
}
}
Aggregations