Search in sources :

Example 11 with EJBDirectory

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

the class SuspendResumeRemoteEJB2TestCase method testSuspendResumeAfterProxyInit.

/**
 * This test checks that suspending and then resuming the server during invocation results in correct behaviour
 * in the case that the proxy is created before the server is suspended.
 *
 * The test assertion is checked after each invocation result, and verifies that no invocation is sent to a suspended node.
 *
 * @throws Exception
 */
@Test
@InSequence(1)
public void testSuspendResumeAfterProxyInit() throws Exception {
    LOGGER.info("testSuspendResumeAfterProxyInit() - start");
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        HeartbeatRemoteHome home = directory.lookupHome(SlowHeartbeatBean.class, HeartbeatRemoteHome.class);
        HeartbeatRemote bean = home.create();
        for (int i = 1; i < INVOCATION_LOOP_TIMES; i++) {
            performInvocation(bean);
        }
        suspendTheServer(NODE_1);
        for (int i = 1; i < INVOCATION_LOOP_TIMES; i++) {
            performInvocation(bean);
        }
        resumeTheServer(NODE_1);
        for (int i = 1; i < INVOCATION_LOOP_TIMES; i++) {
            performInvocation(bean);
        }
    } catch (Exception e) {
        LOGGER.info("Caught exception! e = " + e.getMessage());
        Assert.fail("Test failed with exception: e = " + e.getMessage());
    } finally {
        LOGGER.info("testSuspendResumeAfterProxyInit() - end");
    }
}
Also used : HeartbeatRemote(org.jboss.as.test.clustering.cluster.ejb2.remote.bean.HeartbeatRemote) 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) HeartbeatRemoteHome(org.jboss.as.test.clustering.cluster.ejb2.remote.bean.HeartbeatRemoteHome) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 12 with EJBDirectory

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

the class RegistryTestCase method test.

@Test
public void test() throws Exception {
    try (EJBDirectory context = new RemoteEJBDirectory(MODULE_NAME)) {
        RegistryRetriever bean = context.lookupStateless(RegistryRetrieverBean.class, RegistryRetriever.class);
        Collection<String> names = bean.getNodes();
        assertEquals(2, names.size());
        assertTrue(names.toString(), names.contains(NODE_1));
        assertTrue(names.toString(), names.contains(NODE_2));
        undeploy(DEPLOYMENT_1);
        names = bean.getNodes();
        assertEquals(1, names.size());
        assertTrue(names.contains(NODE_2));
        deploy(DEPLOYMENT_1);
        names = bean.getNodes();
        assertEquals(2, names.size());
        assertTrue(names.contains(NODE_1));
        assertTrue(names.contains(NODE_2));
        stop(NODE_2);
        names = bean.getNodes();
        assertEquals(1, names.size());
        assertTrue(names.contains(NODE_1));
        start(NODE_2);
        names = bean.getNodes();
        assertEquals(2, names.size());
        assertTrue(names.contains(NODE_1));
        assertTrue(names.contains(NODE_2));
    }
}
Also used : RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) RegistryRetriever(org.jboss.as.test.clustering.cluster.registry.bean.RegistryRetriever) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Example 13 with EJBDirectory

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

the class ServiceProviderRegistrationTestCase method test.

@Test
public void test() throws Exception {
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        ServiceProviderRetriever bean = directory.lookupStateless(ServiceProviderRetrieverBean.class, ServiceProviderRetriever.class);
        Collection<String> names = bean.getProviders();
        assertEquals(2, names.size());
        assertTrue(names.toString(), names.contains(NODE_1));
        assertTrue(names.toString(), names.contains(NODE_2));
        undeploy(DEPLOYMENT_1);
        names = bean.getProviders();
        assertEquals(1, names.size());
        assertTrue(names.contains(NODE_2));
        deploy(DEPLOYMENT_1);
        names = bean.getProviders();
        assertEquals(2, names.size());
        assertTrue(names.contains(NODE_1));
        assertTrue(names.contains(NODE_2));
        stop(NODE_2);
        names = bean.getProviders();
        assertEquals(1, names.size());
        assertTrue(names.contains(NODE_1));
        start(NODE_2);
        names = bean.getProviders();
        assertEquals(2, names.size());
        assertTrue(names.contains(NODE_1));
        assertTrue(names.contains(NODE_2));
    }
}
Also used : ServiceProviderRetriever(org.jboss.as.test.clustering.cluster.provider.bean.ServiceProviderRetriever) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Example 14 with EJBDirectory

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

the class RemoteFailoverTestCase method testStatefulFailover.

@InSequence(2)
@Test
public void testStatefulFailover() 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 context = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = context.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));
        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 : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) InSequence(org.jboss.arquillian.junit.InSequence) Test(org.junit.Test)

Example 15 with EJBDirectory

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

the class RemoteFailoverTestCase method testClientException.

/**
     * Test for WFLY-5788.
     */
@InSequence(5)
@Test
public void testClientException() 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 context = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = context.lookupStateful(InfinispanExceptionThrowingIncrementorBean.class, Incrementor.class);
        bean.increment();
    } catch (Exception ejbException) {
        assertTrue("Expected exception wrapped in EJBException", ejbException instanceof EJBException);
        assertNull("Cause of EJBException has not been removed", ejbException.getCause());
        return;
    }
    fail("Expected EJBException but didn't catch it");
}
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) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) NamingException(javax.naming.NamingException) CancellationException(java.util.concurrent.CancellationException) EJBException(javax.ejb.EJBException) InSequence(org.jboss.arquillian.junit.InSequence) 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