diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java index 33e820b3b1..45c065da5e 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/Job.java @@ -422,7 +422,7 @@ public JobPriority getPriority() throws IOException, InterruptedException { * The user-specified job name. */ public String getJobName() { - if (state == JobState.DEFINE) { + if (state == JobState.DEFINE || status == null) { return super.getJobName(); } ensureState(JobState.RUNNING); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJob.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJob.java index 71bacf7472..60f390f446 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJob.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/TestJob.java @@ -26,6 +26,7 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapreduce.JobStatus.State; +import org.apache.hadoop.mapreduce.lib.jobcontrol.ControlledJob; import org.apache.hadoop.mapreduce.protocol.ClientProtocol; import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.UserGroupInformation; @@ -54,6 +55,41 @@ public void testJobToString() throws IOException, InterruptedException { Assert.assertNotNull(job.toString()); } + @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()); + + // ensurer job status is RUNNING + Assert.assertNotNull(job.getStatus()); + Assert.assertTrue(job.getStatus().getState() == State.RUNNING); + + // when updating job status, job client could not retrieve + // job status, and status reset to null + 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"); + } + } + @Test public void testUGICredentialsPropogation() throws Exception { Credentials creds = new Credentials();