ZooKeeperManager { public InetSocketAddress getControllerLeader() throws Exception { String json = new String(zkClient.get().getData( "/" + this.clusterName + "/CONTROLLER/LEADER", false, new Stat())); JSONObject object = (JSONObject)new JSONParser( JSONParser.MODE_JSON_SIMPLE|JSONParser.ACCEPT_SIMPLE_QUOTE).parse(json); String[] leaderHostPort = ((String)object.get("id")).split("_"); String host = leaderHostPort[0]; int port = Integer.parseInt(leaderHostPort[1]); return new InetSocketAddress(host, port); } ZooKeeperManager(ZooKeeperClient zkClient, String clusterName); void createClusterPaths(); void registerWatchAllFileSets(); void lockFileSet(String fileSet,
                          FileSetInfo fileSetInfo,
                          CreateMode mode); void lockFileSet(String fileSet,
                          FileSetInfo fileSetInfo); void unlockFileSet(String fileSet); void setFileSetInfo(String fileSet,
                             FileSetInfo fileSetInfo); void deleteFileSetInfo(String fileSet); FileSetInfo getFileSetInfo(String fileSet); ViewInfo getViewInfo(String resource); void setViewInfo(ViewInfo viewInfo); void deleteViewInfo(String resource); FileSetInfo getFileSetInfoForced(String fileSet); FileSetInfo getLockedFileSetInfo(String fileSet); Map<String, Pair<FileSetInfo, FileSetInfo>> getCandidateHdfsDirMap(); InetSocketAddress getControllerLeader(); ClusterInfo getClusterInfo(); void setClusterInfo(ClusterInfo info); Map<String, FileSetInfo> getFileSetInfoMap(); List<String> getLockedFileSets(); List<String> getLiveInstances();  }
@Test public void testGetControllerLeader() throws Exception { String host = "somehost"; int port = 9090; String json = String.format("{\"id\": \"%s_%d\"}", host, port); when(zk.getData(eq("/" + CLUSTER_NAME + "/CONTROLLER/LEADER"), anyBoolean(), any(Stat.class))).thenReturn(json.getBytes()); InetSocketAddress address = zkManager.getControllerLeader(); assertEquals(host, address.getHostName()); assertEquals(port, address.getPort()); }