TerrapinAdmin { public static FileSetInfo lockFileSet(ZooKeeperManager zkManager, String fileSet, CreateMode mode) throws Exception { FileSetInfo fileSetInfo = zkManager.getFileSetInfo(fileSet); if (fileSetInfo == null) { throw new IllegalArgumentException("no such file set or it is invalid"); } zkManager.lockFileSet(fileSet, fileSetInfo, mode); return zkManager.getFileSetInfo(fileSet); } TerrapinAdmin(PropertiesConfiguration configuration); void setNamenode(String[] args); void setDfsReplication(String[] args); void checkClusterHealth(String[] args); void rollbackFileSet(String[] args); void deleteFileSet(String[] args); static FileSetInfo lockFileSet(ZooKeeperManager zkManager,
                                        String fileSet,
                                        CreateMode mode); static FileSetInfo lockFileSet(ZooKeeperManager zkManager, String fileSet); static void unlockFileSet(ZooKeeperManager zkManager, String fileSet); static void rollbackFileSet(ZooKeeperManager zkManager, String fileSet,
                                     FileSetInfo fileSetInfo, int versionIndex); static void deleteFileSet(ZooKeeperManager zkManager, String fileSet); static void main(String[] args);  }
@Test public void testLockFileSet() throws Exception { ZooKeeperManager mockZKManager = mock(ZooKeeperManager.class); FileSetInfo fileSetInfo = new FileSetInfo(); String fileSet = "test_fileset"; when(mockZKManager.getFileSetInfo(eq(fileSet))).thenReturn(fileSetInfo); doNothing().when(mockZKManager).lockFileSet(anyString(), any(FileSetInfo.class), eq(CreateMode.EPHEMERAL)); TerrapinAdmin.lockFileSet(mockZKManager, fileSet); verify(mockZKManager, times(1)).lockFileSet(eq(fileSet), eq(fileSetInfo), eq(CreateMode.EPHEMERAL)); }
@Test(expected = IllegalArgumentException.class) public void testLockNonExistingFileSet() throws Exception { ZooKeeperManager mockZKManager = mock(ZooKeeperManager.class); String fileSet = "test_fileset"; when(mockZKManager.getFileSetInfo(eq(fileSet))).thenReturn(null); TerrapinAdmin.lockFileSet(mockZKManager, fileSet); }