Search in sources :

Example 6 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)

Example 7 with EJBDirectory

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

the class RemoteFailoverTestCase method testStatelessFailover.

private void testStatelessFailover(String properties, Class<? extends Incrementor> beanClass) 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 properties and ensure the EJB client context is reset
    // to its original state at the end of the test
    EJBClientContextSelector.setup(properties);
    try (EJBDirectory context = new RemoteEJBDirectory(MODULE_NAME)) {
        Incrementor bean = context.lookupStateless(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);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) 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)

Example 8 with EJBDirectory

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

the class CommandDispatcherTestCase method test.

@Test
public void test() throws Exception {
    JBossEJBProperties properties = JBossEJBProperties.fromClassPath(CommandDispatcherTestCase.class.getClassLoader(), CLIENT_PROPERTIES);
    properties.runCallable(() -> {
        try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
            ClusterTopologyRetriever bean = directory.lookupStateless(ClusterTopologyRetrieverBean.class, ClusterTopologyRetriever.class);
            ClusterTopology topology = bean.getClusterTopology();
            assertEquals(1, topology.getNodes().size());
            assertTrue(topology.getNodes().toString(), topology.getNodes().contains(NODE_1));
            assertTrue(topology.getRemoteNodes().toString() + " should be empty", topology.getRemoteNodes().isEmpty());
        }
        return null;
    });
}
Also used : JBossEJBProperties(org.jboss.ejb.client.legacy.JBossEJBProperties) ClusterTopologyRetriever(org.jboss.as.test.clustering.cluster.dispatcher.bean.ClusterTopologyRetriever) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) ClusterTopology(org.jboss.as.test.clustering.cluster.dispatcher.bean.ClusterTopology) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Example 9 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 {
    JBossEJBProperties properties = JBossEJBProperties.fromClassPath(ServiceProviderRegistrationTestCase.class.getClassLoader(), CLIENT_PROPERTIES);
    properties.runCallable(() -> {
        try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
            ServiceProviderRetriever bean = directory.lookupStateless(ServiceProviderRetrieverBean.class, ServiceProviderRetriever.class);
            Collection<String> names = bean.getProviders();
            assertEquals(1, names.size());
            assertTrue(names.toString(), names.contains(NODE_1));
        }
        return null;
    });
}
Also used : JBossEJBProperties(org.jboss.ejb.client.legacy.JBossEJBProperties) 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 10 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 {
    JBossEJBProperties properties = JBossEJBProperties.fromClassPath(RegistryTestCase.class.getClassLoader(), CLIENT_PROPERTIES);
    properties.runCallable(() -> {
        try (EJBDirectory context = new RemoteEJBDirectory(MODULE_NAME)) {
            RegistryRetriever bean = context.lookupStateless(RegistryRetrieverBean.class, RegistryRetriever.class);
            Collection<String> names = bean.getNodes();
            assertEquals(1, names.size());
            assertTrue(names.toString(), names.contains(NODE_1));
        }
        return null;
    });
}
Also used : JBossEJBProperties(org.jboss.ejb.client.legacy.JBossEJBProperties) 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)

Aggregations

EJBDirectory (org.jboss.as.test.clustering.ejb.EJBDirectory)10 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)10 Test (org.junit.Test)8 Incrementor (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JBossEJBProperties (org.jboss.ejb.client.legacy.JBossEJBProperties)3 CancellationException (java.util.concurrent.CancellationException)2 InSequence (org.jboss.arquillian.junit.InSequence)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 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 EJBException (javax.ejb.EJBException)1 NamingException (javax.naming.NamingException)1