CommandUtil { public static File createWorkDir(long executionId) { File path = new File(taskRootDir, Long.toString(executionId)); if (!path.exists()) { path.mkdirs(); } String dirs[] = path.list(); long lastCmdId = 0; if (dirs != null) { for (String dir : dirs) { long cmdId = Long.parseLong(dir); if (lastCmdId < cmdId) { lastCmdId = cmdId; } } } Long nextCmdId = lastCmdId + 1; path = new File(path, nextCmdId.toString()); path.mkdir(); return path; }  static File createWorkDir(long executionId);  }
@Test public void testCreateWorkDir() throws IOException { long executionId = 1L; long lastCmdId = 0L; CommandUtil.createWorkDir(executionId); File path = new File(CommandUtil.taskRootDir, Long.toString(executionId)); assertTrue(path.exists()); File childPath = new File(path, Long.toString(++lastCmdId)); assertTrue(childPath.exists()); CommandUtil.createWorkDir(executionId); childPath = new File(path, Long.toString(++lastCmdId)); assertTrue(childPath.exists()); delete(CommandUtil.taskRootDir.getAbsolutePath()); }