FileNameIndexUtils { public static String getDoneFileName(JobIndexInfo indexInfo) throws IOException { return getDoneFileName(indexInfo, JHAdminConfig.DEFAULT_MR_HS_JOBNAME_LIMIT); }  static String getDoneFileName(JobIndexInfo indexInfo); static String getDoneFileName(JobIndexInfo indexInfo,
      int jobNameLimit); static JobIndexInfo getIndexInfo(String jhFileName); static String encodeJobHistoryFileName(String logFileName); static String decodeJobHistoryFileName(String logFileName);  }
@Test public void testUserNamePercentEncoding() throws IOException { JobIndexInfo info = new JobIndexInfo(); JobID oldJobId = JobID.forName(JOB_ID); JobId jobId = TypeConverter.toYarn(oldJobId); info.setJobId(jobId); info.setSubmitTime(Long.parseLong(SUBMIT_TIME)); info.setUser(USER_NAME_WITH_DELIMITER); info.setJobName(JOB_NAME); info.setFinishTime(Long.parseLong(FINISH_TIME)); info.setNumMaps(Integer.parseInt(NUM_MAPS)); info.setNumReduces(Integer.parseInt(NUM_REDUCES)); info.setJobStatus(JOB_STATUS); info.setQueueName(QUEUE_NAME); info.setJobStartTime(Long.parseLong(JOB_START_TIME)); String jobHistoryFile = FileNameIndexUtils.getDoneFileName(info); Assert.assertTrue("User name not encoded correctly into job history file", jobHistoryFile.contains(USER_NAME_WITH_DELIMITER_ESCAPE)); }
@Test public void testJobNameWithMultibyteChars() throws IOException { JobIndexInfo info = new JobIndexInfo(); JobID oldJobId = JobID.forName(JOB_ID); JobId jobId = TypeConverter.toYarn(oldJobId); info.setJobId(jobId); info.setSubmitTime(Long.parseLong(SUBMIT_TIME)); info.setUser(USER_NAME); StringBuilder sb = new StringBuilder(); info.setFinishTime(Long.parseLong(FINISH_TIME)); info.setNumMaps(Integer.parseInt(NUM_MAPS)); info.setNumReduces(Integer.parseInt(NUM_REDUCES)); info.setJobStatus(JOB_STATUS); info.setQueueName(QUEUE_NAME); info.setJobStartTime(Long.parseLong(JOB_START_TIME)); for (int i = 0; i < 100; i++) { sb.append('%'); } String longJobName = sb.toString(); info.setJobName(longJobName); String jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, 50); Assert.assertTrue(jobHistoryFile.length() <= 255); String trimedJobName = jobHistoryFile.split( FileNameIndexUtils.DELIMITER)[3]; Assert.assertEquals(48, trimedJobName.getBytes(UTF_8).length); byte[] trimedJobNameInByte = trimedJobName.getBytes(UTF_8); String reEncodedTrimedJobName = new String(trimedJobNameInByte, UTF_8); Assert.assertArrayEquals(trimedJobNameInByte, reEncodedTrimedJobName.getBytes(UTF_8)); sb.setLength(0); for (int i = 0; i < 100; i++) { sb.append('\u03A9'); } longJobName = sb.toString(); info.setJobName(longJobName); jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, 27); Assert.assertTrue(jobHistoryFile.length() <= 255); trimedJobName = jobHistoryFile.split( FileNameIndexUtils.DELIMITER)[3]; Assert.assertEquals(24, trimedJobName.getBytes(UTF_8).length); trimedJobNameInByte = trimedJobName.getBytes(UTF_8); reEncodedTrimedJobName = new String(trimedJobNameInByte, UTF_8); Assert.assertArrayEquals(trimedJobNameInByte, reEncodedTrimedJobName.getBytes(UTF_8)); sb.setLength(0); for (int i = 0; i < 100; i++) { sb.append('\u2192'); } longJobName = sb.toString(); info.setJobName(longJobName); jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, 40); Assert.assertTrue(jobHistoryFile.length() <= 255); trimedJobName = jobHistoryFile.split( FileNameIndexUtils.DELIMITER)[3]; Assert.assertEquals(36, trimedJobName.getBytes(UTF_8).length); trimedJobNameInByte = trimedJobName.getBytes(UTF_8); reEncodedTrimedJobName = new String(trimedJobNameInByte, UTF_8); Assert.assertArrayEquals(trimedJobNameInByte, reEncodedTrimedJobName.getBytes(UTF_8)); sb.setLength(0); for (int i = 0; i < 100; i++) { sb.append("\uD867\uDE3D"); } longJobName = sb.toString(); info.setJobName(longJobName); jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, 49); Assert.assertTrue(jobHistoryFile.length() <= 255); trimedJobName = jobHistoryFile.split( FileNameIndexUtils.DELIMITER)[3]; Assert.assertEquals(48, trimedJobName.getBytes(UTF_8).length); trimedJobNameInByte = trimedJobName.getBytes(UTF_8); reEncodedTrimedJobName = new String(trimedJobNameInByte, UTF_8); Assert.assertArrayEquals(trimedJobNameInByte, reEncodedTrimedJobName.getBytes(UTF_8)); sb.setLength(0); sb.append('\u732B') .append("[") .append('\u03BB') .append('/') .append('A') .append("\ud867\ude49") .append('\u72AC'); longJobName = sb.toString(); info.setJobName(longJobName); jobHistoryFile = FileNameIndexUtils.getDoneFileName(info, 23); Assert.assertTrue(jobHistoryFile.length() <= 255); trimedJobName = jobHistoryFile.split( FileNameIndexUtils.DELIMITER)[3]; Assert.assertEquals(22, trimedJobName.getBytes(UTF_8).length); trimedJobNameInByte = trimedJobName.getBytes(UTF_8); reEncodedTrimedJobName = new String(trimedJobNameInByte, UTF_8); Assert.assertArrayEquals(trimedJobNameInByte, reEncodedTrimedJobName.getBytes(UTF_8)); }
@Test public void testJobNamePercentEncoding() throws IOException { JobIndexInfo info = new JobIndexInfo(); JobID oldJobId = JobID.forName(JOB_ID); JobId jobId = TypeConverter.toYarn(oldJobId); info.setJobId(jobId); info.setSubmitTime(Long.parseLong(SUBMIT_TIME)); info.setUser(USER_NAME); info.setJobName(JOB_NAME_WITH_DELIMITER); info.setFinishTime(Long.parseLong(FINISH_TIME)); info.setNumMaps(Integer.parseInt(NUM_MAPS)); info.setNumReduces(Integer.parseInt(NUM_REDUCES)); info.setJobStatus(JOB_STATUS); info.setQueueName(QUEUE_NAME); info.setJobStartTime(Long.parseLong(JOB_START_TIME)); String jobHistoryFile = FileNameIndexUtils.getDoneFileName(info); Assert.assertTrue("Job name not encoded correctly into job history file", jobHistoryFile.contains(JOB_NAME_WITH_DELIMITER_ESCAPE)); }
@Test public void testQueueNamePercentEncoding() throws IOException { JobIndexInfo info = new JobIndexInfo(); JobID oldJobId = JobID.forName(JOB_ID); JobId jobId = TypeConverter.toYarn(oldJobId); info.setJobId(jobId); info.setSubmitTime(Long.parseLong(SUBMIT_TIME)); info.setUser(USER_NAME); info.setJobName(JOB_NAME); info.setFinishTime(Long.parseLong(FINISH_TIME)); info.setNumMaps(Integer.parseInt(NUM_MAPS)); info.setNumReduces(Integer.parseInt(NUM_REDUCES)); info.setJobStatus(JOB_STATUS); info.setQueueName(QUEUE_NAME_WITH_DELIMITER); info.setJobStartTime(Long.parseLong(JOB_START_TIME)); String jobHistoryFile = FileNameIndexUtils.getDoneFileName(info); Assert.assertTrue("Queue name not encoded correctly into job history file", jobHistoryFile.contains(QUEUE_NAME_WITH_DELIMITER_ESCAPE)); }