ZookeeperCoordinator implements Coordinator { @Override public Set<NodeId> getAvailableNodes(NodeType type) { Set<NodeId> result = Sets.newHashSet(); ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(type)); for (ZNode node : typeNode.children()) { if (node.hasChild(CoordinationUtil.AVAILABLE_NODE_NAME)) { result.add(NodeId.of(type, node.getShortPath())); } } return result; } ZookeeperCoordinator(ZNode rootNode, Executor executor, UrlClassLoaderHolder classLoaderHolder); @Override void registerNode(NodeContext nodeContext, Set<Worker> workers, final StatusChangeListener listener); @Override RemoteExecutor getExecutor(NodeId nodeId); @Override boolean canExecuteCommands(NodeId nodeId, Set<Qualifier<?>> qualifiers); @Override Set<NodeId> getAvailableNodes(NodeType type); @Override void waitForReady(); @Override void initialize(); @Override void waitForInitialization();  }
@Test public void nodeAvailability() throws Exception { ZNode availableNode = mockZnode(); when(availableNode.hasChild("available")).thenReturn(true); when(availableNode.getShortPath()).thenReturn("av"); ZNode notAvailableNode = mockZnode(); when(notAvailableNode.hasChild("available")).thenReturn(false); when(notAvailableNode.getShortPath()).thenReturn("nav"); List<ZNode> children = Lists.newLinkedList(); children.add(availableNode); children.add(availableNode); when(kernel.children()).thenReturn(children); Collection<NodeId> availableNodes = coordinator.getAvailableNodes(NodeType.KERNEL); assertTrue(availableNodes.contains(NodeId.kernelNode("av"))); assertFalse(availableNodes.contains(NodeId.kernelNode("nav"))); }
@Test public void nodeAvailabilityWhenNoNodeIsAvailable() throws Exception { List<ZNode> children = Lists.newLinkedList(); when(kernel.children()).thenReturn(children); Collection<NodeId> availableNodes = coordinator.getAvailableNodes(NodeType.KERNEL); assertTrue(availableNodes.isEmpty()); }