Search in sources :

Example 16 with NoSuchEJBException

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);
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) NoSuchEJBException(javax.ejb.NoSuchEJBException) Incrementor(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) Test(org.junit.Test)

Example 17 with NoSuchEJBException

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();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) NoSuchEJBException(javax.ejb.NoSuchEJBException) Incrementor(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 18 with NoSuchEJBException

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;
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) InitialContext(javax.naming.InitialContext)

Example 19 with NoSuchEJBException

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
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) InitialContext(javax.naming.InitialContext)

Example 20 with NoSuchEJBException

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()));
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) SystemInstance(org.apache.openejb.loader.SystemInstance) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) NoSuchEJBException(javax.ejb.NoSuchEJBException) NamingException(javax.naming.NamingException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) BeanContext(org.apache.openejb.BeanContext) ApplicationException(org.apache.openejb.ApplicationException) FutureTask(java.util.concurrent.FutureTask) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NoSuchEJBException (javax.ejb.NoSuchEJBException)24 Test (org.junit.Test)9 InitialContext (javax.naming.InitialContext)8 EJBException (javax.ejb.EJBException)5 NamingException (javax.naming.NamingException)5 Incrementor (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor)4 EJBTransactionRolledbackException (javax.ejb.EJBTransactionRolledbackException)3 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)3 RollbackException (javax.transaction.RollbackException)3 UserTransaction (javax.transaction.UserTransaction)3 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RemoteException (java.rmi.RemoteException)2 Future (java.util.concurrent.Future)2 NoSuchEntityException (javax.ejb.NoSuchEntityException)2 Context (javax.naming.Context)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2 SystemException (javax.transaction.SystemException)2