ZooKeeperManager { public void setFileSetInfo(String fileSet, FileSetInfo fileSetInfo) throws Exception { String fileSetPath = getFileSetPath(fileSet); Stat stat = zkClient.get().exists(fileSetPath, false); if (stat == null) { try { zkClient.get().create( fileSetPath, fileSetInfo.toJson(), ZK_ACL_LIST, CreateMode.PERSISTENT); } catch (KeeperException e) { if (e instanceof KeeperException.NodeExistsException) { LOG.error("File set " + fileSet + " was created after we checked that it does not " + "exist. We are racing with another client."); } throw e; } } else { zkClient.get().setData(getFileSetPath(fileSet), fileSetInfo.toJson(), -1); } } 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 testSetNonExistingFileSetInfo() throws Exception { when(zk.exists(anyString(), anyBoolean())).thenReturn(null); when(zk.create(anyString(), any(byte[].class), anyListOf(ACL.class), any(CreateMode.class))) .thenReturn(""); zkManager.setFileSetInfo(FILE_SET, FILE_SET_INFO); verify(zk).exists(eq(FILE_SET_PATH), eq(false)); verify(zk).create(eq(FILE_SET_PATH), eq(FILE_SET_INFO.toJson()), anyListOf(ACL.class), any(CreateMode.class)); }
@Test public void testSetExistingFileSetInfo() throws Exception { when(zk.exists(anyString(), anyBoolean())).thenReturn(mock(Stat.class)); when(zk.setData(anyString(), any(byte[].class), anyInt())).thenReturn(mock(Stat.class)); zkManager.setFileSetInfo(FILE_SET, FILE_SET_INFO); verify(zk).exists(eq(FILE_SET_PATH), eq(false)); verify(zk).setData(eq(FILE_SET_PATH), eq(FILE_SET_INFO.toJson()), eq(-1)); }