MAPREDUCE-6762. ControlledJob#toString failed with NPE when job status is not successfully updated (Weiwei Yang via Varun Saxena)
This commit is contained in:
parent
0faee62a0c
commit
d37b45d613
|
@ -422,7 +422,7 @@ public class Job extends JobContextImpl implements JobContext {
|
|||
* The user-specified job name.
|
||||
*/
|
||||
public String getJobName() {
|
||||
if (state == JobState.DEFINE) {
|
||||
if (state == JobState.DEFINE || status == null) {
|
||||
return super.getJobName();
|
||||
}
|
||||
ensureState(JobState.RUNNING);
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||
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 class TestJob {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue