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");
}
}
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);
}
}
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");
}
}
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");
}
}
Aggregations