use of org.jboss.as.test.clustering.ejb.RemoteEJBDirectory in project wildfly by wildfly.
the class RegistryTestCase method test.
@Test
public void test() 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 context = new RemoteEJBDirectory(MODULE_NAME)) {
RegistryRetriever bean = context.lookupStateless(RegistryRetrieverBean.class, RegistryRetriever.class);
Collection<String> names = bean.getNodes();
assertEquals(2, names.size());
assertTrue(names.toString(), names.contains(NODE_1));
assertTrue(names.toString(), names.contains(NODE_2));
undeploy(DEPLOYMENT_1);
names = bean.getNodes();
assertEquals(1, names.size());
assertTrue(names.contains(NODE_2));
deploy(DEPLOYMENT_1);
names = bean.getNodes();
assertEquals(2, names.size());
assertTrue(names.contains(NODE_1));
assertTrue(names.contains(NODE_2));
stop(CONTAINER_2);
names = bean.getNodes();
assertEquals(1, names.size());
assertTrue(names.contains(NODE_1));
start(CONTAINER_2);
names = bean.getNodes();
assertEquals(2, names.size());
assertTrue(names.contains(NODE_1));
assertTrue(names.contains(NODE_2));
}
}
use of org.jboss.as.test.clustering.ejb.RemoteEJBDirectory in project wildfly by wildfly.
the class RemoteEJBTwoClusterTestCase method beforeTest.
/*
* In the test case framework:
* - containers are deployed by the framework before any test runs
* - containers are undeployed by the test case itself
* - deployments are deployed by the test case itself
* - deployments are undeployed by the test case itself
*/
@BeforeClass
public static void beforeTest() throws NamingException {
beanDirectory = new RemoteEJBDirectory(FORWARDER_MODULE_NAME);
txnBeanDirectory = new RemoteEJBDirectory(FORWARDER_WITH_TXN_MODULE_NAME);
}
use of org.jboss.as.test.clustering.ejb.RemoteEJBDirectory in project wildfly by wildfly.
the class RemoteFailoverTestCase method testStatefulFailover.
@InSequence(2)
@Test
public void testStatefulFailover() 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 context = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = context.lookupStateful(StatefulIncrementorBean.class, Incrementor.class);
Result<Integer> result = bean.increment();
String target = result.getNode();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain weak 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));
result = bean.increment();
// Bean should failover to other node
String failoverTarget = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertNotEquals(target, failoverTarget);
deploy(this.findDeployment(target));
// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
result = bean.increment();
String failbackTarget = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain weak affinity for this node
Assert.assertEquals(failoverTarget, failbackTarget);
result = bean.increment();
// Bean may have acquired new weak affinity
target = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain weak 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());
}
stop(this.findContainer(target));
result = bean.increment();
// Bean should failover to other node
failoverTarget = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertNotEquals(target, failoverTarget);
start(this.findContainer(target));
// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);
result = bean.increment();
failbackTarget = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain weak affinity for this node
Assert.assertEquals(failoverTarget, failbackTarget);
result = bean.increment();
// Bean may have acquired new weak affinity
target = result.getNode();
Assert.assertEquals(count++, result.getValue().intValue());
// Bean should retain weak 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());
}
}
}
use of org.jboss.as.test.clustering.ejb.RemoteEJBDirectory in project wildfly by wildfly.
the class RemoteFailoverTestCase method testClientException.
/**
* Test for WFLY-5788.
*/
@InSequence(5)
@Test
public void testClientException() 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 context = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = context.lookupStateful(InfinispanExceptionThrowingIncrementorBean.class, Incrementor.class);
bean.increment();
} catch (Exception ejbException) {
assertTrue("Expected exception wrapped in EJBException", ejbException instanceof EJBException);
assertNull("Cause of EJBException has not been removed", ejbException.getCause());
return;
}
fail("Expected EJBException but didn't catch it");
}
use of org.jboss.as.test.clustering.ejb.RemoteEJBDirectory 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);
}
}
}
Aggregations