Search in sources :

Example 1 with ClusterTopology

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());
        }
    }
}
Also used : ClusterTopologyRetriever(org.jboss.as.test.clustering.cluster.group.bean.ClusterTopologyRetriever) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) ClusterTopology(org.jboss.as.test.clustering.cluster.group.bean.ClusterTopology) EJBDirectory(org.jboss.as.test.clustering.ejb.EJBDirectory) RemoteEJBDirectory(org.jboss.as.test.clustering.ejb.RemoteEJBDirectory) Test(org.junit.Test)

Aggregations

ClusterTopology (org.jboss.as.test.clustering.cluster.group.bean.ClusterTopology)1 ClusterTopologyRetriever (org.jboss.as.test.clustering.cluster.group.bean.ClusterTopologyRetriever)1 EJBDirectory (org.jboss.as.test.clustering.ejb.EJBDirectory)1 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)1 Test (org.junit.Test)1