use of org.jboss.as.test.clustering.cluster.group.bean.ClusterTopology 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());
}
}
}
Aggregations