Search in sources :

Example 1 with Heartbeat

use of org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat 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 2 with Heartbeat

use of org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat in project wildfly by wildfly.

the class ClientClusterNodeSelectorTestCase method test.

/**
 * Instructs the ClusterNodeSelector on which node to call before each request and that checks that the response
 * comes from that very node;
 */
@Test
public void test(@ArquillianResource() @OperateOnDeployment(DEPLOYMENT_1) URL baseURL1) throws Exception {
    EJBClientContext BKP = null;
    try {
        final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
        ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
        final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
        connBuilder.setDestination(URI.create(String.format("remote+%s", baseURL1)));
        ejbClientBuilder.addClientConnection(connBuilder.build());
        // ====================================================================================
        // set the custom ClusterNodeSelector
        // ====================================================================================
        ejbClientBuilder.setClusterNodeSelector(new CustomClusterNodeSelector());
        BKP = EJBClientContext.getContextManager().getThreadDefault();
        final EJBClientContext ejbCtx = ejbClientBuilder.build();
        EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
        InitialContext ctx = new InitialContext(props);
        String lookupName = "ejb:/" + MODULE_NAME + "/" + HeartbeatBean.class.getSimpleName() + "!" + Heartbeat.class.getName();
        Heartbeat bean = (Heartbeat) ctx.lookup(lookupName);
        // ====================================================================================
        // first call goes to connected node regardless of CustomClusterNodeSelector
        // ====================================================================================
        Result<Date> res = bean.pulse();
        Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
        // ====================================================================================
        // subsequent calls must be routed to the node selected by the CustomClusterNodeSelector
        // ====================================================================================
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_2);
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_4);
        callBeanOnNode(bean, NODE_1);
        callBeanOnNode(bean, NODE_3);
        ctx.close();
    } finally {
        EJBClientContext.getContextManager().setThreadDefault(BKP);
    }
}
Also used : WildFlyInitialContextFactory(org.wildfly.naming.client.WildFlyInitialContextFactory) EJBClientContext(org.jboss.ejb.client.EJBClientContext) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) Date(java.util.Date) EJBClientConnection(org.jboss.ejb.client.EJBClientConnection) HeartbeatBean(org.jboss.as.test.clustering.cluster.ejb.remote.bean.HeartbeatBean) Heartbeat(org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat) RemoteTransportProvider(org.jboss.ejb.protocol.remote.RemoteTransportProvider) Test(org.junit.Test)

Example 3 with Heartbeat

use of org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat in project wildfly by wildfly.

the class SuspendResumeRemoteEJBTestCase 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.
 * <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(1)
public void testSuspendResumeAfterProxyInit() throws Exception {
    LOGGER.info("testSuspendResumeAfterProxyInit() - start");
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        Heartbeat bean = directory.lookupStateless(HeartbeatBean.class, Heartbeat.class);
        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 : 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 4 with Heartbeat

use of org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat in project wildfly by wildfly.

the class SuspendResumeRemoteEJBTestCase method testSuspendResumeBeforeProxyInit.

/**
 * 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(2)
public void testSuspendResumeBeforeProxyInit() throws Exception {
    LOGGER.info("testSuspendResumeBeforeProxyInit() - start");
    try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
        suspendTheServer(NODE_1);
        Heartbeat bean = directory.lookupStateless(HeartbeatBean.class, Heartbeat.class);
        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("testSuspendResumeBeforeProxyInit() - 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)

Aggregations

Heartbeat (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Heartbeat)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 InSequence (org.jboss.arquillian.junit.InSequence)3 EJBDirectory (org.jboss.as.test.clustering.ejb.EJBDirectory)3 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)3 Date (java.util.Date)1 Properties (java.util.Properties)1 InitialContext (javax.naming.InitialContext)1 HeartbeatBean (org.jboss.as.test.clustering.cluster.ejb.remote.bean.HeartbeatBean)1 EJBClientConnection (org.jboss.ejb.client.EJBClientConnection)1 EJBClientContext (org.jboss.ejb.client.EJBClientContext)1 RemoteTransportProvider (org.jboss.ejb.protocol.remote.RemoteTransportProvider)1 WildFlyInitialContextFactory (org.wildfly.naming.client.WildFlyInitialContextFactory)1