use of org.jboss.as.test.clustering.twoclusters.bean.stateful.RemoteStatefulSB in project wildfly by wildfly.
the class RemoteEJBTwoClusterTestCase method testConcurrentFailoverOverWithTwoClusters.
/*
* Tests that EJBClient invocations on stateful session beans can still successfully be processed
* as long as one node in each cluster is available.
*/
public void testConcurrentFailoverOverWithTwoClusters(boolean useTransactions) 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 FORWARDER_CLIENT_PROPERTIES and ensure the EJB client context is reset
// to its original state at the end of the test
EJBClientContextSelector.setup(FORWARDER_CLIENT_PROPERTIES);
try {
// get the correct forwarder deployment on cluster A
RemoteStatefulSB bean = null;
if (useTransactions)
bean = txnBeanDirectory.lookupStateful(ForwardingStatefulSBImpl.class, RemoteStatefulSB.class);
else
bean = beanDirectory.lookupStateful(NonTxForwardingStatefulSBImpl.class, RemoteStatefulSB.class);
AtomicInteger count = new AtomicInteger();
// Allow sufficient time for client to receive full topology
logger.trace("Waiting for clusters to form:");
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
int newSerialValue = bean.getSerialAndIncrement();
int newCountValue = count.getAndIncrement();
logger.trace("First invocation: count = " + newCountValue + ", serial = " + newSerialValue);
//
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
CountDownLatch latch = new CountDownLatch(1);
ClientInvocationTask client = new ClientInvocationTask(bean, latch, count);
try {
// set up the client invocations
Future<?> future = executor.scheduleWithFixedDelay(client, 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
logger.trace("------ Shutdown clusterA-node0 -----");
// stop cluster A node 0
stop(CONTAINER_1);
// Let the server stay down for a while
Thread.sleep(SERVER_DOWN_TIME);
logger.trace("------ Startup clusterA-node0 -----");
start(CONTAINER_1);
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
logger.trace("----- Shutdown clusterA-node1 -----");
// stop cluster A node 1
stop(CONTAINER_2);
// Let the server stay down for a while
Thread.sleep(SERVER_DOWN_TIME);
logger.trace("------ Startup clusterA-node1 -----");
start(CONTAINER_2);
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
logger.trace("----- Shutdown clusterB-node0 -----");
// stop cluster B node 0
stop(CONTAINER_3);
// Let the server stay down for a while
Thread.sleep(SERVER_DOWN_TIME);
logger.trace("------ Startup clusterB-node0 -----");
start(CONTAINER_3);
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
logger.trace("----- Shutdown clusterB-node1 -----");
// stop cluster B node 1
stop(CONTAINER_4);
// Let the server stay down for a while
Thread.sleep(SERVER_DOWN_TIME);
logger.trace("------ Startup clusterB-node1 -----");
start(CONTAINER_4);
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
// cancel the executor and wait for it to complete
future.cancel(false);
try {
future.get();
} catch (CancellationException e) {
logger.trace("Could not cancel future: " + e.toString());
}
// test is completed, report results
double invocations = client.getInvocationCount();
double exceptions = client.getExceptionCount();
logger.trace("Total invocations = " + invocations + ", total exceptions = " + exceptions);
Assert.assertTrue("Too many exceptions! percentage = " + 100 * (exceptions / invocations), (exceptions / invocations) < EXCEPTION_PERCENTAGE);
} catch (Exception e) {
Assert.fail("Exception occurred on client: " + e.getMessage() + ", test did not complete successfully (inner)");
} finally {
logger.trace("Shutting down executor");
executor.shutdownNow();
}
} catch (Exception e) {
Assert.fail("Exception occurred on client: " + e.getMessage() + ", test did not complete successfully (outer)");
}
}
Aggregations