ZookeeperCoordinator implements Coordinator { @Override public boolean canExecuteCommands(NodeId nodeId, Set<Qualifier<?>> qualifiers) { ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(nodeId.getType())); String identifier = nodeId.getIdentifier(); if (!typeNode.hasChild(identifier)) { throw new CoordinatorException("Node with id " + nodeId + " is not found"); } ZNode node = typeNode.child(identifier); if (!node.hasChild(CoordinationUtil.AVAILABLE_NODE_NAME)) { return false; } for (Qualifier<?> qualifier : qualifiers) { if (!node.hasChild(nodeNameOf(qualifier))) { return false; } } return true; } 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 canExecuteCommandsWhen() throws Exception { ZNode node = mockZnode(); ZNode firstCommandNode = mockZnode(); ZNode secondCommandNode = mockZnode(); NodeId id = NodeId.kernelNode("identifier"); when(kernel.child(id.getIdentifier())).thenReturn(node); when(kernel.hasChild(id.getIdentifier())).thenReturn(true); when(node.hasChild("available")).thenReturn(true); when(node.child(TestCommandOne.class.getName())).thenReturn(firstCommandNode); when(node.hasChild(TestCommandOne.class.getName())).thenReturn(true); when(node.child(TestCommandTwo.class.getName())).thenReturn(secondCommandNode); when(node.hasChild(TestCommandTwo.class.getName())).thenReturn(true); Set<Qualifier<?>> qualifiers = Sets.newHashSet(); qualifiers.add(Qualifier.of(TestCommandOne.class)); qualifiers.add(Qualifier.of(TestCommandTwo.class)); assertTrue(coordinator.canExecuteCommands(id, qualifiers)); }