Search in sources :

Example 1 with EJBDirectory

use of org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory in project eap-additional-testsuite by jboss-set.

the class RemoteStatefulEJBFailoverTestCase method test.

@Test
public void test() throws Exception {
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class);
        Result<Integer> result = bean.increment();
        String target = result.getNode();
        int count = 1;
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain weak affinity for this node
        for (int i = 0; i < COUNT; ++i) {
            result = bean.increment();
            Assert.assertEquals(count++, result.getValue().intValue());
            Assert.assertEquals(String.valueOf(i), target, result.getNode());
        }
        undeploy(this.findDeployment(target));
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        result = bean.increment();
        // Bean should failover to other node
        String failoverTarget = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        Assert.assertNotEquals(target, failoverTarget);
        deploy(this.findDeployment(target));
        // Allow sufficient time for client to receive new topology
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        result = bean.increment();
        String failbackTarget = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain weak affinity for this node
        Assert.assertEquals(failoverTarget, failbackTarget);
        result = bean.increment();
        // Bean may have acquired new weak affinity
        target = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain weak affinity for this node
        for (int i = 0; i < COUNT; ++i) {
            result = bean.increment();
            Assert.assertEquals(count++, result.getValue().intValue());
            Assert.assertEquals(String.valueOf(i), target, result.getNode());
        }
        stop(this.findContainer(target));
        result = bean.increment();
        // Bean should failover to other node
        failoverTarget = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        Assert.assertNotEquals(target, failoverTarget);
        start(this.findContainer(target));
        // Allow sufficient time for client to receive new topology
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        result = bean.increment();
        failbackTarget = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain weak affinity for this node
        Assert.assertEquals(failoverTarget, failbackTarget);
        result = bean.increment();
        // Bean may have acquired new weak affinity
        target = result.getNode();
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain weak affinity for this node
        for (int i = 0; i < COUNT; ++i) {
            result = bean.increment();
            Assert.assertEquals(count++, result.getValue().intValue());
            Assert.assertEquals(String.valueOf(i), target, result.getNode());
        }
    }
}
Also used : Incrementor(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory) Test(org.junit.Test)

Example 2 with EJBDirectory

use of org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory in project eap-additional-testsuite by jboss-set.

the class TransactionalRemoteStatefulEJBFailoverTestCase method test.

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

Example 3 with EJBDirectory

use of org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory in project eap-additional-testsuite by jboss-set.

the class ClientExceptionRemoteEJBTestCase method test.

@Test
public void test() throws Exception {
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = directory.lookupStateful(InfinispanExceptionThrowingIncrementorBean.class, Incrementor.class);
        bean.increment();
        fail("Expected EJBException but didn't catch it");
    } catch (EJBException e) {
        assertNull("Cause of EJBException has not been removed", e.getCause());
    }
}
Also used : Incrementor(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) EJBException(javax.ejb.EJBException) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory) Test(org.junit.Test)

Example 4 with EJBDirectory

use of org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory in project eap-additional-testsuite by jboss-set.

the class AbstractRemoteStatelessEJBFailoverTestCase method test.

@Test
public void test() throws Exception {
    this.configurator.apply(() -> {
        try (EJBDirectory directory = new RemoteEJBDirectory(this.module)) {
            Incrementor bean = directory.lookupStateless(this.beanClass, Incrementor.class);
            // Allow sufficient time for client to receive full topology
            Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
            List<String> results = new ArrayList<>(COUNT);
            for (int i = 0; i < COUNT; ++i) {
                Result<Integer> result = bean.increment();
                results.add(result.getNode());
                Thread.sleep(INVOCATION_WAIT);
            }
            for (String node : NODES) {
                int frequency = Collections.frequency(results, node);
                assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
            }
            undeploy(DEPLOYMENT_1);
            for (int i = 0; i < COUNT; ++i) {
                Result<Integer> result = bean.increment();
                results.set(i, result.getNode());
                Thread.sleep(INVOCATION_WAIT);
            }
            Assert.assertEquals(0, Collections.frequency(results, NODE_1));
            Assert.assertEquals(COUNT, Collections.frequency(results, NODE_2));
            deploy(DEPLOYMENT_1);
            // Allow sufficient time for client to receive new topology
            Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
            for (int i = 0; i < COUNT; ++i) {
                Result<Integer> result = bean.increment();
                results.set(i, result.getNode());
                Thread.sleep(INVOCATION_WAIT);
            }
            for (String node : NODES) {
                int frequency = Collections.frequency(results, node);
                assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
            }
            stop(CONTAINER_2);
            for (int i = 0; i < COUNT; ++i) {
                Result<Integer> result = bean.increment();
                results.set(i, result.getNode());
                Thread.sleep(INVOCATION_WAIT);
            }
            Assert.assertEquals(COUNT, Collections.frequency(results, NODE_1));
            Assert.assertEquals(0, Collections.frequency(results, NODE_2));
            start(CONTAINER_2);
            // Allow sufficient time for client to receive new topology
            Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
            for (int i = 0; i < COUNT; ++i) {
                Result<Integer> result = bean.increment();
                results.set(i, result.getNode());
                Thread.sleep(INVOCATION_WAIT);
            }
            for (String node : NODES) {
                int frequency = Collections.frequency(results, node);
                assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
            }
        }
        return null;
    });
}
Also used : ArrayList(java.util.ArrayList) Incrementor(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory) Test(org.junit.Test)

Example 5 with EJBDirectory

use of org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory in project eap-additional-testsuite by jboss-set.

the class RemoteStatefulEJBConcurrentFailoverTestCase method test.

public void test(Lifecycle lifecycle) throws Exception {
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = directory.lookupStateful(SlowToDestroyStatefulIncrementorBean.class, Incrementor.class);
        AtomicInteger count = new AtomicInteger();
        // Allow sufficient time for client to receive full topology
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        String target = bean.increment().getNode();
        count.incrementAndGet();
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        try {
            CountDownLatch latch = new CountDownLatch(1);
            Future<?> future = executor.scheduleWithFixedDelay(new IncrementTask(bean, count, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
            latch.await();
            lifecycle.stop(target);
            future.cancel(false);
            try {
                future.get();
            } catch (CancellationException e) {
            // Ignore
            }
            lifecycle.start(target);
            latch = new CountDownLatch(1);
            future = executor.scheduleWithFixedDelay(new LookupTask(directory, SlowToDestroyStatefulIncrementorBean.class, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
            latch.await();
            lifecycle.stop(target);
            future.cancel(false);
            try {
                future.get();
            } catch (CancellationException e) {
            // Ignore
            }
            lifecycle.start(target);
        } finally {
            executor.shutdownNow();
        }
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CancellationException(java.util.concurrent.CancellationException) Incrementor(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) CountDownLatch(java.util.concurrent.CountDownLatch) RemoteEJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory)

Aggregations

EJBDirectory (org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.EJBDirectory)5 RemoteEJBDirectory (org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.RemoteEJBDirectory)5 Incrementor (org.jboss.additional.testsuite.jdkall.present.clustering.cluster.ejb.remote.bean.Incrementor)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 CancellationException (java.util.concurrent.CancellationException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EJBException (javax.ejb.EJBException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 UserTransaction (javax.transaction.UserTransaction)1