use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class RemoteFailoverTestCase method testConcurrentFailover.
public void testConcurrentFailover(Lifecycle lifecycle) 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 directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(SlowToDestroyStatefulIncrementorBean.class, Incrementor.class);
AtomicInteger count = new AtomicInteger();
// Allow sufficient time for client to receive full topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
String target = bean.increment().getNode();
count.incrementAndGet();
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
CountDownLatch latch = new CountDownLatch(1);
Future<?> future = executor.scheduleWithFixedDelay(new IncrementTask(bean, count, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();
lifecycle.stop(target);
future.cancel(false);
try {
future.get();
} catch (CancellationException e) {
// Ignore
}
lifecycle.start(target);
latch = new CountDownLatch(1);
future = executor.scheduleWithFixedDelay(new LookupTask(directory, SlowToDestroyStatefulIncrementorBean.class, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();
lifecycle.stop(target);
future.cancel(false);
try {
future.get();
} catch (CancellationException e) {
// Ignore
}
lifecycle.start(target);
} finally {
executor.shutdownNow();
}
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class ClientExceptionRemoteEJBTestCase method test.
@Test
public void test() throws Exception {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(InfinispanExceptionThrowingIncrementorBean.class, Incrementor.class);
bean.increment();
fail("Expected EJBException but didn't catch it");
} catch (EJBException e) {
assertNull("Cause of EJBException has not been removed", e.getCause());
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class PassivationDisabledRemoteStatefulEjbFailoverTestCase method test.
@Test
public void test() throws Exception {
try (EJBDirectory directory = this.directoryProvider.get()) {
Incrementor bean = directory.lookupStateful(PassivationDisabledStatefulIncrementorBean.class, Incrementor.class);
Result<Integer> result = bean.increment();
String target = result.getNode();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain strong affinity for this node
for (int i = 0; i < COUNT; ++i) {
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(String.valueOf(i), target, result.getNode());
}
undeploy(this.findDeployment(target));
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
try {
result = bean.increment();
// Bean should fail to failover to other node
Assert.fail(result.getNode());
} catch (NoSuchEJBException e) {
// Failover should fail
}
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory 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.ejb.EJBDirectory in project wildfly by wildfly.
the class AbstractRemoteEJBForwardingTestCase method test.
/**
* Tests that Jakarta Enterprise Beans Client invocations on stateful session beans can still successfully be processed
* as long as one node in each cluster is available.
*/
@Test
public void test() throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try (EJBDirectory directory = directorySupplier.get()) {
// get the correct forwarder deployment on cluster A
RemoteStatefulSB bean = directory.lookupStateful(implementationClass, RemoteStatefulSB.class);
// Allow sufficient time for client to receive full topology
logger.debug("Waiting for clusters to form.");
Thread.sleep(FAILURE_FREE_TIME);
int newSerialValue = bean.getSerialAndIncrement();
logger.debugf("First invocation: serial = %d", newSerialValue);
ClientInvocationTask client = new ClientInvocationTask(bean, newSerialValue);
// set up the client invocations
executor.scheduleWithFixedDelay(client, 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
// a few seconds of non-failure behaviour
Thread.sleep(FAILURE_FREE_TIME);
client.assertNoExceptions("at the beginning of the test");
logger.debugf("------ Shutdown clusterA-node0 -----");
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_1);
Thread.sleep(SERVER_DOWN_TIME);
client.assertNoExceptions("after clusterA-node0 was shut down");
logger.debug("------ Startup clusterA-node0 -----");
start(NODE_1);
Thread.sleep(FAILURE_FREE_TIME);
client.assertNoExceptions("after clusterA-node0 was brought up");
logger.debug("----- Shutdown clusterA-node1 -----");
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_2);
Thread.sleep(SERVER_DOWN_TIME);
logger.debug("------ Startup clusterA-node1 -----");
start(NODE_2);
Thread.sleep(FAILURE_FREE_TIME);
client.assertNoExceptions("after clusterA-node1 was brought back up");
logger.debug("----- Shutdown clusterB-node0 -----");
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_3);
Thread.sleep(SERVER_DOWN_TIME);
client.assertNoExceptions("after clusterB-node0 was shut down");
logger.debug("------ Startup clusterB-node0 -----");
start(NODE_3);
Thread.sleep(FAILURE_FREE_TIME);
client.assertNoExceptions("after clusterB-node0 was brought back up");
logger.debug("----- Shutdown clusterB-node1 -----");
stop(GRACEFUL_SHUTDOWN_TIMEOUT, NODE_4);
Thread.sleep(SERVER_DOWN_TIME);
logger.debug("------ Startup clusterB-node1 -----");
start(NODE_4);
Thread.sleep(FAILURE_FREE_TIME);
// final assert
client.assertNoExceptions("after clusterB-node1 was brought back up");
} finally {
executor.shutdownNow();
}
}
Aggregations