Search in sources :

Example 1 with EJBDirectory

use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.

the class RemoteFailoverTestCase method testConcurrentFailover.

public void testConcurrentFailover(Lifecycle lifecycle) throws Exception {
    // TODO Elytron: Once support for legacy EJB properties has been added back, actually set the EJB properties
    // that should be used for this test using CLIENT_PROPERTIES and ensure the EJB client context is reset
    // to its original state at the end of the test
    EJBClientContextSelector.setup(CLIENT_PROPERTIES);
    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.as.test.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) CountDownLatch(java.util.concurrent.CountDownLatch) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory)

Example 2 with EJBDirectory

use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.

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.as.test.clustering.cluster.ejb.remote.bean.Incrementor) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBException(javax.ejb.EJBException) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Example 3 with EJBDirectory

use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.

the class PassivationDisabledRemoteStatefulEjbFailoverTestCase method test.

@Test
public void test() throws Exception {
    try (EJBDirectory directory = this.directoryProvider.get()) {
        Incrementor bean = directory.lookupStateful(PassivationDisabledStatefulIncrementorBean.class, Incrementor.class);
        Result<Integer> result = bean.increment();
        String target = result.getNode();
        int count = 1;
        Assert.assertEquals(count++, result.getValue().intValue());
        // Bean should retain strong 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);
        try {
            result = bean.increment();
            // Bean should fail to failover to other node
            Assert.fail(result.getNode());
        } catch (NoSuchEJBException e) {
        // Failover should fail
        }
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) Incrementor(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Example 4 with EJBDirectory

use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.

the class SuspendResumeRemoteEJBTestCase method testSuspendResumeContinuous.

/**
 * This test checks that suspending and then resuming the server during invocation results in correct behaviour
 * in the case that the proxy is created after the server is suspended.
 * <p>
 * The test assertion is checked after each invocation result, and verifies that no invocation is sent to a suspended node.
 *
 * @throws Exception
 */
@Test
@InSequence(3)
public void testSuspendResumeContinuous() throws Exception {
    LOGGER.info("testSuspendResumeContinuous() - start");
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        Heartbeat bean = directory.lookupStateless(HeartbeatBean.class, Heartbeat.class);
        ContinuousInvoker continuousInvoker = new ContinuousInvoker(bean);
        Thread thread = new Thread(continuousInvoker);
        LOGGER.info("Starting the invoker ...");
        thread.start();
        for (int i = 1; i < SUSPEND_RESUME_LOOP_TIMES; i++) {
            // suspend and then resume each server in turn while invocations happen
            sleep(SUSPEND_RESUME_DURATION_MSECS);
            suspendTheServer(NODE_1);
            sleep(SUSPEND_RESUME_DURATION_MSECS);
            resumeTheServer(NODE_1);
            // suspend and then resume each server in turn while invocations happen
            sleep(SUSPEND_RESUME_DURATION_MSECS);
            suspendTheServer(NODE_2);
            sleep(SUSPEND_RESUME_DURATION_MSECS);
            resumeTheServer(NODE_2);
        }
        continuousInvoker.stopInvoking();
    } catch (Exception e) {
        LOGGER.info("Caught exception! e = " + e.getMessage());
        Assert.fail("Test failed with exception: e = " + e.getMessage());
    } finally {
        LOGGER.info("testSuspendResumeContinuous() - end");
    }
}
Also used : Heartbeat(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) IOException(java.io.IOException) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 5 with EJBDirectory

use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.

the class AbstractRemoteEJBForwardingTestCase method test.

/**
 * Tests that Jakarta Enterprise Beans Client invocations on stateful session beans can still successfully be processed
 * as long as one node in each cluster is available.
 */
@Test
public void test() throws Exception {
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    try (EJBDirectory directory = directorySupplier.get()) {
        // get the correct forwarder deployment on cluster A
        RemoteStatefulSB bean = directory.lookupStateful(implementationClass, RemoteStatefulSB.class);
        // Allow sufficient time for client to receive full topology
        logger.debug("Waiting for clusters to form.");
        Thread.sleep(FAILURE_FREE_TIME);
        int newSerialValue = bean.getSerialAndIncrement();
        logger.debugf("First invocation: serial = %d", newSerialValue);
        ClientInvocationTask client = new ClientInvocationTask(bean, newSerialValue);
        // set up the client invocations
        executor.scheduleWithFixedDelay(client, 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
        // a few seconds of non-failure behaviour
        Thread.sleep(FAILURE_FREE_TIME);
        client.assertNoExceptions("at the beginning of the test");
        logger.debugf("------ Shutdown clusterA-node0 -----");
        stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_1);
        Thread.sleep(SERVER_DOWN_TIME);
        client.assertNoExceptions("after clusterA-node0 was shut down");
        logger.debug("------ Startup clusterA-node0 -----");
        start(NODE_1);
        Thread.sleep(FAILURE_FREE_TIME);
        client.assertNoExceptions("after clusterA-node0 was brought up");
        logger.debug("----- Shutdown clusterA-node1 -----");
        stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_2);
        Thread.sleep(SERVER_DOWN_TIME);
        logger.debug("------ Startup clusterA-node1 -----");
        start(NODE_2);
        Thread.sleep(FAILURE_FREE_TIME);
        client.assertNoExceptions("after clusterA-node1 was brought back up");
        logger.debug("----- Shutdown clusterB-node0 -----");
        stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_3);
        Thread.sleep(SERVER_DOWN_TIME);
        client.assertNoExceptions("after clusterB-node0 was shut down");
        logger.debug("------ Startup clusterB-node0 -----");
        start(NODE_3);
        Thread.sleep(FAILURE_FREE_TIME);
        client.assertNoExceptions("after clusterB-node0 was brought back up");
        logger.debug("----- Shutdown clusterB-node1 -----");
        stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_4);
        Thread.sleep(SERVER_DOWN_TIME);
        logger.debug("------ Startup clusterB-node1 -----");
        start(NODE_4);
        Thread.sleep(FAILURE_FREE_TIME);
        // final assert
        client.assertNoExceptions("after clusterB-node1 was brought back up");
    } finally {
        executor.shutdownNow();
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RemoteStatefulSB(org.jboss.as.test.clustering.cluster.ejb.forwarding.bean.stateful.RemoteStatefulSB) NamingEJBDirectory(org.jboss.as.test.clustering.ejb.NamingEJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) Test(org.junit.Test)

Aggregations

EJBDirectory (org.jboss.as.test.clustering.ejb.EJBDirectory)24 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)23 Test (org.junit.Test)20 Incrementor (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor)10 InSequence (org.jboss.arquillian.junit.InSequence)8 IOException (java.io.IOException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CancellationException (java.util.concurrent.CancellationException)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Heartbeat (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat)3 HeartbeatRemote (org.jboss.as.test.clustering.cluster.ejb2.remote.bean.HeartbeatRemote)3 HeartbeatRemoteHome (org.jboss.as.test.clustering.cluster.ejb2.remote.bean.HeartbeatRemoteHome)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 EJBException (javax.ejb.EJBException)2 NoSuchEJBException (javax.ejb.NoSuchEJBException)2 ClusterTopology (org.jboss.as.test.clustering.cluster.dispatcher.bean.ClusterTopology)2 ClusterTopologyRetriever (org.jboss.as.test.clustering.cluster.dispatcher.bean.ClusterTopologyRetriever)2 ServiceProviderRetriever (org.jboss.as.test.clustering.cluster.provider.bean.ServiceProviderRetriever)2 RegistryRetriever (org.jboss.as.test.clustering.cluster.registry.bean.RegistryRetriever)2 ArrayList (java.util.ArrayList)1