Search in sources :

Example 1 with GridClientTopologyListener

use of org.apache.ignite.internal.client.GridClientTopologyListener in project ignite by apache.

the class ClientAbstractMultiNodeSelfTest method testTopologyListener.

/**
 * @throws Exception If failed.
 */
public void testTopologyListener() throws Exception {
    final Collection<UUID> added = new ArrayList<>(1);
    final Collection<UUID> rmvd = new ArrayList<>(1);
    final CountDownLatch addedLatch = new CountDownLatch(1);
    final CountDownLatch rmvLatch = new CountDownLatch(1);
    assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size());
    GridClientTopologyListener lsnr = new GridClientTopologyListener() {

        @Override
        public void onNodeAdded(GridClientNode node) {
            added.add(node.nodeId());
            addedLatch.countDown();
        }

        @Override
        public void onNodeRemoved(GridClientNode node) {
            rmvd.add(node.nodeId());
            rmvLatch.countDown();
        }
    };
    client.addTopologyListener(lsnr);
    try {
        Ignite g = startGrid(NODES_CNT + 1);
        UUID id = g.cluster().localNode().id();
        assertTrue(addedLatch.await(2 * TOP_REFRESH_FREQ, MILLISECONDS));
        assertEquals(1, added.size());
        assertEquals(id, F.first(added));
        stopGrid(NODES_CNT + 1);
        assertTrue(rmvLatch.await(2 * TOP_REFRESH_FREQ, MILLISECONDS));
        assertEquals(1, rmvd.size());
        assertEquals(id, F.first(rmvd));
    } finally {
        client.removeTopologyListener(lsnr);
        stopGrid(NODES_CNT + 1);
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientTopologyListener(org.apache.ignite.internal.client.GridClientTopologyListener) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignite (org.apache.ignite.Ignite)1 GridClientNode (org.apache.ignite.internal.client.GridClientNode)1 GridClientTopologyListener (org.apache.ignite.internal.client.GridClientTopologyListener)1