use of org.jboss.as.test.clustering.cluster.ejb2.stateful.failover.bean.shared.CounterRemoteHome in project wildfly by wildfly.
the class RemoteEJBClientStatefulFailoverTestBase method failoverFromRemoteClient.
/**
* Implementation of defined abstract tests above.
*/
protected void failoverFromRemoteClient(boolean undeployOnly) throws Exception {
CounterRemoteHome home = directory.lookupHome(CounterBean.class, CounterRemoteHome.class);
CounterRemote remoteCounter = home.create();
Assert.assertNotNull(remoteCounter);
final CounterSingletonRemote destructionCounter = singletonDirectory.lookupSingleton(CounterSingleton.class, CounterSingletonRemote.class);
destructionCounter.resetDestroyCount();
// invoke on the bean a few times
final int NUM_TIMES = 25;
for (int i = 0; i < NUM_TIMES; i++) {
final CounterResult result = remoteCounter.increment();
log.trace("Counter incremented to " + result.getCount() + " on node " + result.getNodeName());
}
final CounterResult result = remoteCounter.getCount();
Assert.assertNotNull("Result from remote stateful counter was null", result);
Assert.assertEquals("Unexpected count from remote counter", NUM_TIMES, result.getCount());
Assert.assertEquals("Nothing should have been destroyed yet", 0, destructionCounter.getDestroyCount());
// shutdown the node on which the previous invocation happened
final int totalCountBeforeShuttingDownANode = result.getCount();
final String previousInvocationNodeName = result.getNodeName();
// the value is configured in arquillian.xml of the project
if (previousInvocationNodeName.equals(NODE_1)) {
if (undeployOnly) {
deployer.undeploy(DEPLOYMENT_1);
deployer.undeploy(DEPLOYMENT_HELPER_1);
} else {
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_1);
}
} else {
if (undeployOnly) {
deployer.undeploy(DEPLOYMENT_2);
deployer.undeploy(DEPLOYMENT_HELPER_2);
} else {
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_2);
}
}
// invoke again
CounterResult resultAfterShuttingDownANode = remoteCounter.increment();
Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", totalCountBeforeShuttingDownANode + 1, resultAfterShuttingDownANode.getCount());
Assert.assertFalse("Result was received from an unexpected node, after shutting down a node", previousInvocationNodeName.equals(resultAfterShuttingDownANode.getNodeName()));
// repeat invocations
final int countBeforeDecrementing = resultAfterShuttingDownANode.getCount();
final String aliveNode = resultAfterShuttingDownANode.getNodeName();
for (int i = NUM_TIMES; i > 0; i--) {
resultAfterShuttingDownANode = remoteCounter.decrement();
Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, resultAfterShuttingDownANode.getNodeName());
log.trace("Counter decremented to " + resultAfterShuttingDownANode.getCount() + " on node " + resultAfterShuttingDownANode.getNodeName());
}
final CounterResult finalResult = remoteCounter.getCount();
Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", finalResult);
final int finalCount = finalResult.getCount();
final String finalNodeName = finalResult.getNodeName();
Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, finalNodeName);
Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", countBeforeDecrementing - NUM_TIMES, finalCount);
Assert.assertEquals("Nothing should have been destroyed yet", 0, destructionCounter.getDestroyCount());
remoteCounter.remove();
Assert.assertEquals("SFSB was not destroyed", 1, destructionCounter.getDestroyCount());
}
Aggregations