HistoryFileUtils { public static String generateFileName(JobMetadata metadata) { StringBuilder sb = new StringBuilder(); sb.append(metadata.getId()); sb.append("-"); sb.append(metadata.getStarted()); sb.append("-"); if (metadata.getCompleted() != -1L) { sb.append(metadata.getCompleted()); sb.append("-"); } sb.append(metadata.getUser()); if (!metadata.getStatus().isEmpty()) { sb.append("-"); sb.append(metadata.getStatus()); sb.append("." + Constants.HISTFILE_SUFFIX); return sb.toString(); } sb.append("." + Constants.HISTFILE_SUFFIX); sb.append("." + Constants.INPROGRESS); return sb.toString(); } private  HistoryFileUtils(); static String generateFileName(JobMetadata metadata);  }
@Test public void testGenerateFileNameInProgressJob() { String appId = "app123"; long started = 1L; String user = "user"; JobMetadata metadata = new JobMetadata.Builder() .setId(appId) .setStarted(started) .setUser(user) .setConf(new YarnConfiguration()) .build(); String expectedName = "app123-1-user." + Constants.HISTFILE_SUFFIX + "." + Constants.INPROGRESS; assertEquals(HistoryFileUtils.generateFileName(metadata), expectedName); }
@Test public void testGenerateFileNameFinishedJob() { String appId = "app123"; long started = 1L; long completed = 2L; String user = "user"; JobMetadata metadata = new JobMetadata.Builder() .setId(appId) .setStarted(started) .setCompleted(completed) .setUser(user) .setStatus(Constants.SUCCEEDED) .setConf(new YarnConfiguration()) .build(); String expectedName = "app123-1-2-user-SUCCEEDED." + Constants.HISTFILE_SUFFIX; assertEquals(HistoryFileUtils.generateFileName(metadata), expectedName); }