use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class RemoteFailoverTestCase method testStatelessFailover.
private void testStatelessFailover(String properties, Class<? extends Incrementor> beanClass) 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 properties and ensure the EJB client context is reset
// to its original state at the end of the test
EJBClientContextSelector.setup(properties);
try (EJBDirectory context = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = context.lookupStateless(beanClass, Incrementor.class);
// Allow sufficient time for client to receive full topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
List<String> results = new ArrayList<>(COUNT);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.add(result.getNode());
Thread.sleep(INVOCATION_WAIT);
}
for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}
undeploy(DEPLOYMENT_1);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}
Assert.assertEquals(0, Collections.frequency(results, NODE_1));
Assert.assertEquals(COUNT, Collections.frequency(results, NODE_2));
deploy(DEPLOYMENT_1);
// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}
for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}
stop(CONTAINER_2);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}
Assert.assertEquals(COUNT, Collections.frequency(results, NODE_1));
Assert.assertEquals(0, Collections.frequency(results, NODE_2));
start(CONTAINER_2);
// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}
for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class GroupListenerTestCase method test.
@Test
public void test() throws Exception {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
ClusterTopologyRetriever bean = directory.lookupStateless(ClusterTopologyRetrieverBean.class, ClusterTopologyRetriever.class);
ClusterTopology topology = bean.getClusterTopology();
assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size());
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1));
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2));
stop(NODE_2);
Thread.sleep(VIEW_CHANGE_WAIT);
topology = bean.getClusterTopology();
assertEquals(topology.getCurrentMembers().toString(), 1, topology.getCurrentMembers().size());
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1));
assertEquals(topology.getPreviousMembers().toString(), 2, topology.getPreviousMembers().size());
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1));
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2));
start(NODE_2);
Thread.sleep(VIEW_CHANGE_WAIT);
topology = bean.getClusterTopology();
assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size());
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1));
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2));
if (topology.getTargetMember().equals(NODE_1)) {
assertEquals(topology.getPreviousMembers().toString(), 1, topology.getPreviousMembers().size());
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1));
} else {
// Since node 2 was just started, its previous membership will be empty
assertEquals(topology.getPreviousMembers().toString(), 0, topology.getPreviousMembers().size());
}
stop(NODE_1);
Thread.sleep(VIEW_CHANGE_WAIT);
topology = bean.getClusterTopology();
assertEquals(topology.getCurrentMembers().toString(), 1, topology.getCurrentMembers().size());
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2));
assertEquals(topology.getPreviousMembers().toString(), 2, topology.getPreviousMembers().size());
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_1));
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2));
start(NODE_1);
Thread.sleep(VIEW_CHANGE_WAIT);
topology = bean.getClusterTopology();
assertEquals(topology.getCurrentMembers().toString(), 2, topology.getCurrentMembers().size());
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_1));
assertTrue(topology.getCurrentMembers().toString(), topology.getCurrentMembers().contains(NODE_2));
if (topology.getTargetMember().equals(NODE_2)) {
assertEquals(topology.getPreviousMembers().toString(), 1, topology.getPreviousMembers().size());
assertTrue(topology.getPreviousMembers().toString(), topology.getPreviousMembers().contains(NODE_2));
} else {
// Since node 1 was just started, its previous membership will be empty
assertEquals(topology.getPreviousMembers().toString(), 0, topology.getPreviousMembers().size());
}
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class SuspendResumeRemoteEJB2TestCase 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.
*
* 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);
HeartbeatRemoteHome home = directory.lookupHome(SlowHeartbeatBean.class, HeartbeatRemoteHome.class);
HeartbeatRemote bean = home.create();
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");
}
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class SuspendResumeRemoteEJB2TestCase 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.
*
* 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)) {
HeartbeatRemoteHome home = directory.lookupHome(SlowHeartbeatBean.class, HeartbeatRemoteHome.class);
HeartbeatRemote bean = home.create();
ContinuousInvoker continuousInvoker = new ContinuousInvoker(bean);
Thread thread = new Thread(continuousInvoker);
LOGGER.info("Starting the invoker ...");
thread.start();
for (int i = 0; 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());
}
LOGGER.info("testSuspendResumeContinuous() - end");
}
use of org.jboss.as.test.clustering.ejb.EJBDirectory in project wildfly by wildfly.
the class TransactionalRemoteStatefulEJBFailoverTestCase method test.
@Test
public void test(@ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) ManagementClient client1, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) ManagementClient client2) throws Exception {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class);
Result<Integer> result = bean.increment();
// Bean should retain weak affinity for this node
String target = result.getNode();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
// Validate that multi-invocations function correctly within a tx
UserTransaction tx = EJBClient.getUserTransaction(target);
// TODO Currently requires environment to be configured with provider URLs.
// UserTransaction tx = directory.lookupUserTransaction();
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
tx.commit();
// Validate that second invocation fails if target node is undeployed in middle of tx
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
undeploy(this.findDeployment(target));
try {
result = bean.increment();
Assert.fail("Expected a NoSuchEJBException");
} catch (NoSuchEJBException e) {
// Expected
} finally {
tx.rollback();
// TODO remove workaround for WFLY-12128
undeploy(TWO_DEPLOYMENTS);
ServerReload.executeReloadAndWaitForCompletion(client1);
ServerReload.executeReloadAndWaitForCompletion(client2);
// Workaround the above yielding "DeploymentException: Cannot deploy StatefulFailoverTestCase.war: WFLYCTL0379: System boot is in process; execution of remote management operations is not currently available"
Thread.sleep(GRACE_TIME_TOPOLOGY_CHANGE);
}
}
}
Aggregations