InteractionProtocol { public NodeQueue publishNode(Node node, NodeMetaData nodeMetaData) { LOG.info("publishing node '" + node.getName() + "' ..."); final String nodePath = _zkConf.getZkPath(PathDef.NODES_LIVE, node.getName()); final String nodeMetadataPath = _zkConf.getZkPath(PathDef.NODES_METADATA, node.getName()); if (_zkClient.exists(nodeMetadataPath)) { _zkClient.writeData(nodeMetadataPath, nodeMetaData); } else { _zkClient.createPersistent(nodeMetadataPath, nodeMetaData); } String queuePath = _zkConf.getZkPath(PathDef.NODE_QUEUE, node.getName()); if (_zkClient.exists(queuePath)) { _zkClient.deleteRecursive(queuePath); } NodeQueue nodeQueue = new NodeQueue(_zkClient, queuePath); if (_zkClient.exists(nodePath)) { LOG.warn("Old node ephemeral '" + nodePath + "' detected, deleting it..."); _zkClient.delete(nodePath); } createEphemeral(node, nodePath, null); return nodeQueue; } InteractionProtocol(ZkClient zkClient, ZkConfiguration zkConfiguration); void registerComponent(ConnectedComponent connectedComponent); void unregisterComponent(ConnectedComponent component); void disconnect(); int getRegisteredComponentCount(); int getRegisteredListenerCount(); List<String> registerChildListener(ConnectedComponent component, PathDef pathDef, IAddRemoveListener listener); List<String> registerChildListener(ConnectedComponent component, PathDef pathDef, String childName,
          IAddRemoveListener listener); void unregisterChildListener(ConnectedComponent component, PathDef pathDef); void unregisterChildListener(ConnectedComponent component, PathDef pathDef, String childName); void registerDataListener(ConnectedComponent component, PathDef pathDef, String childName,
          IZkDataListener listener); void unregisterDataChanges(ConnectedComponent component, PathDef pathDef, String childName); void unregisterDataChanges(ConnectedComponent component, String dataPath); List<String> getKnownNodes(); List<String> getLiveNodes(); List<String> getIndices(); MasterMetaData getMasterMD(); NodeMetaData getNodeMD(String node); Collection<String> getNodeShards(String nodeName); int getShardReplication(String shard); long getShardAnnounceTime(String node, String shard); Map<String, List<String>> getShard2NodesMap(Collection<String> shardNames); List<String> getShardNodes(String shard); List<String> getShard2NodeShards(); ReplicationReport getReplicationReport(IndexMetaData indexMD); MasterQueue publishMaster(final Master master); NodeQueue publishNode(Node node, NodeMetaData nodeMetaData); void publishIndex(IndexMetaData indexMD); void unpublishIndex(String indexName); IndexMetaData getIndexMD(String index); void updateIndexMD(IndexMetaData indexMD); void publishShard(Node node, String shardName); void unpublishShard(Node node, String shard); void setMetric(String nodeName, MetricsRecord metricsRecord); MetricsRecord getMetric(String nodeName); void addMasterOperation(MasterOperation operation); OperationId addNodeOperation(String nodeName, NodeOperation nodeOperation); OperationResult getNodeOperationResult(OperationId operationId, boolean remove); boolean isNodeOperationQueued(OperationId operationId); void registerNodeOperationListener(ConnectedComponent component, OperationId operationId,
          IZkDataListener dataListener); boolean indexExists(String indexName); void showStructure(final boolean all); void explainStructure(); void setVersion(Version version); Version getVersion(); void setFlag(String name); boolean flagExists(String name); void removeFlag(String name); ZkConfiguration getZkConfiguration(); ZkClient getZkClient();  }
@Test(timeout = 7000) public void testPublishNode() throws Exception { Node node = Mocks.mockNode(); assertNull(_protocol.getNodeMD(node.getName())); NodeQueue queue = _protocol.publishNode(node, new NodeMetaData(node.getName())); assertNotNull(queue); assertNotNull(_protocol.getNodeMD(node.getName())); NodeOperation operation = mock(NodeOperation.class); OperationId operationId = _protocol.addNodeOperation(node.getName(), operation); assertEquals(1, queue.size()); assertNotNull(queue.peek()); assertEquals(node.getName(), operationId.getNodeName()); }