private synchronized void updateAllNodes(AllNodes allNodes) { if (includeCoordinator) { currentCount = allNodes.getActiveNodes().size(); } else { currentCount = Sets.difference(allNodes.getActiveNodes(), allNodes.getActiveCoordinators()).size(); } if (currentCount >= executionMinCount) { ImmutableList<SettableFuture<?>> listeners = ImmutableList.copyOf(futures); futures.clear(); executor.submit(() -> listeners.forEach(listener -> listener.set(null))); } } }
private synchronized void updateAllNodes(AllNodes allNodes) { if (includeCoordinator) { currentCount = allNodes.getActiveNodes().size(); } else { currentCount = Sets.difference(allNodes.getActiveNodes(), allNodes.getActiveCoordinators()).size(); } if (currentCount >= executionMinCount) { ImmutableList<SettableFuture<?>> listeners = ImmutableList.copyOf(futures); futures.clear(); executor.submit(() -> listeners.forEach(listener -> listener.set(null))); } } }
@Test(timeOut = 60000) public void testNodeChangeListener() throws Exception { DiscoveryNodeManager manager = new DiscoveryNodeManager(selector, nodeInfo, new NoOpFailureDetector(), expectedVersion, testHttpClient, internalCommunicationConfig); try { manager.startPollingNodeStates(); BlockingQueue<AllNodes> notifications = new ArrayBlockingQueue<>(100); manager.addNodeChangeListener(notifications::add); AllNodes allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), activeNodes); assertEquals(allNodes.getInactiveNodes(), inactiveNodes); selector.announceNodes(ImmutableSet.of(currentNode), ImmutableSet.of(coordinator)); allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), ImmutableSet.of(currentNode, coordinator)); assertEquals(allNodes.getActiveCoordinators(), ImmutableSet.of(coordinator)); selector.announceNodes(activeNodes, inactiveNodes); allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), activeNodes); assertEquals(allNodes.getInactiveNodes(), inactiveNodes); } finally { manager.stop(); } }
@Test(timeOut = 60000) public void testNodeChangeListener() throws Exception { DiscoveryNodeManager manager = new DiscoveryNodeManager(selector, nodeInfo, new NoOpFailureDetector(), expectedVersion, testHttpClient, internalCommunicationConfig); try { manager.startPollingNodeStates(); BlockingQueue<AllNodes> notifications = new ArrayBlockingQueue<>(100); manager.addNodeChangeListener(notifications::add); AllNodes allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), activeNodes); assertEquals(allNodes.getInactiveNodes(), inactiveNodes); selector.announceNodes(ImmutableSet.of(currentNode), ImmutableSet.of(coordinator)); allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), ImmutableSet.of(currentNode, coordinator)); assertEquals(allNodes.getActiveCoordinators(), ImmutableSet.of(coordinator)); selector.announceNodes(activeNodes, inactiveNodes); allNodes = notifications.take(); assertEquals(allNodes.getActiveNodes(), activeNodes); assertEquals(allNodes.getInactiveNodes(), inactiveNodes); } finally { manager.stop(); } }