@Test
public void testUnexpectedJobStatus() throws Exception {
Cluster cluster = mock(Cluster.class);
JobID jobid = new JobID("1014873536921", 6);
ClientProtocol clientProtocol = mock(ClientProtocol.class);
when(cluster.getClient()).thenReturn(clientProtocol);
JobStatus status = new JobStatus(jobid, 0f, 0f, 0f, 0f,
State.RUNNING, JobPriority.DEFAULT, "root",
"testUnexpectedJobStatus", "job file", "tracking URL");
when(clientProtocol.getJobStatus(jobid)).thenReturn(status);
Job job = Job.getInstance(cluster, status, new JobConf());
Assert.assertNotNull(job.getStatus());
Assert.assertTrue(job.getStatus().getState() == State.RUNNING);
when(clientProtocol.getJobStatus(jobid)).thenReturn(null);
try {
job.updateStatus();
} catch (IOException e) {
Assert.assertTrue(e != null
&& e.getMessage().contains("Job status not available"));
}
try {
ControlledJob cj = new ControlledJob(job, null);
Assert.assertNotNull(cj.toString());
} catch (NullPointerException e) {
Assert.fail("job API fails with NPE");
}
}