HdfsUtils { @VisibleForTesting public static boolean isJobFolder(Path p, String regex) { return p != null && getLastComponent(p.toString()).matches(regex); } private  HdfsUtils(); static boolean pathExists(FileSystem fs, Path filePath); static String contentOfHdfsFile(FileSystem fs, Path filePath); static String getLastComponent(String path); @VisibleForTesting static boolean isJobFolder(Path p, String regex); static List<FileStatus> getDirectories(FileSystem fs, Path path); static Path getJobDirPath(FileSystem fs, Path curr, String applicationId); static List<Path> getJobDirs(FileSystem fs, Path curr, String regex); static void copySrcToDest(Path src, Path dst, Configuration conf);  }
@Test public void testIsJobFolderMatch() { Path filePath1 = new Path("/abc/def/application_1541469337545_0024"); Path filePath2 = new Path("/abc/def/job2"); String regex1 = "^application_.*"; String regex2 = "^job.*"; assertTrue(HdfsUtils.isJobFolder(filePath1, regex1)); assertTrue(HdfsUtils.isJobFolder(filePath2, regex2)); }
@Test public void testIsJobFolderNoMatch() { Path filePath1 = new Path(Constants.TONY_CORE_SRC + "test/job/application_1541469337545_0024"); Path filePath2 = new Path(Constants.TONY_CORE_SRC + "test/resources/application2/"); String regex1 = ".*job.*"; String regex2 = "application_.*"; assertFalse(HdfsUtils.isJobFolder(filePath1, regex1)); assertFalse(HdfsUtils.isJobFolder(filePath2, regex2)); }