public static org.apache.hadoop.mapred.JobID fromYarn(JobId id) {
    String identifier = fromClusterTimeStamp(id.getAppId().getClusterTimestamp());
    return new org.apache.hadoop.mapred.JobID(identifier, id.getId());
  }
@Test
  public void testFromYarnApplicationReport() {
    ApplicationId mockAppId = mock(ApplicationId.class);
    when(mockAppId.getClusterTimestamp()).thenReturn(12345L);
    when(mockAppId.getId()).thenReturn(6789);

    ApplicationReport mockReport = mock(ApplicationReport.class);
    when(mockReport.getTrackingUrl()).thenReturn("dummy-tracking-url");
    when(mockReport.getApplicationId()).thenReturn(mockAppId);
    when(mockReport.getYarnApplicationState()).thenReturn(YarnApplicationState.KILLED);
    when(mockReport.getUser()).thenReturn("dummy-user");
    when(mockReport.getQueue()).thenReturn("dummy-queue");
    when(mockReport.getPriority()).thenReturn(Priority.newInstance(4));
    String jobFile = "dummy-path/job.xml";

    try {
      JobStatus status = TypeConverter.fromYarn(mockReport, jobFile);
    } catch (NullPointerException npe) {
      fail("Type converstion from YARN fails for jobs without " +
          "ApplicationUsageReport");
    }

    ApplicationResourceUsageReport appUsageRpt = Records
        .newRecord(ApplicationResourceUsageReport.class);
    Resource r = Records.newRecord(Resource.class);
    r.setMemorySize(2048);
    appUsageRpt.setNeededResources(r);
    appUsageRpt.setNumReservedContainers(1);
    appUsageRpt.setNumUsedContainers(3);
    appUsageRpt.setReservedResources(r);
    appUsageRpt.setUsedResources(r);
    when(mockReport.getApplicationResourceUsageReport()).thenReturn(appUsageRpt);
    JobStatus status = TypeConverter.fromYarn(mockReport, jobFile);
    assertNotNull(status, "fromYarn returned null status");
    assertEquals("dummy-path/job.xml", status.getJobFile(), "jobFile set incorrectly");
    assertEquals("dummy-queue", status.getQueue(), "queue set incorrectly");
    assertEquals("dummy-tracking-url", status.getTrackingUrl(), "trackingUrl set incorrectly");
    assertEquals("dummy-user", status.getUsername(), "user set incorrectly");
    assertEquals("dummy-tracking-url", status.getSchedulingInfo(),
        "schedulingInfo set incorrectly");
    assertEquals(6789, status.getJobID().getId(), "jobId set incorrectly");
    assertEquals(JobStatus.State.KILLED, status.getState(), "state set incorrectly");
    assertEquals(2048, status.getNeededMem(), "needed mem info set incorrectly");
    assertEquals(1, status.getNumReservedSlots(), "num rsvd slots info set incorrectly");
    assertEquals(3, status.getNumUsedSlots(), "num used slots info set incorrectly");
    assertEquals(2048, status.getReservedMem(), "rsvd mem info set incorrectly");
    assertEquals(2048, status.getUsedMem(), "used mem info set incorrectly");
    assertEquals(JobPriority.HIGH, status.getPriority(), "priority set incorrectly");
  }