From 14e6f1e796bfd77a9505063dfbb36579f124a2e9 Mon Sep 17 00:00:00 2001 From: Mahadev Konar Date: Mon, 12 Dec 2011 22:08:09 +0000 Subject: [PATCH] MAPREDUCE-3518. mapred queue -info -showJobs throws NPE. (Jonathan Eagles via mahadev) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1213464 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 + .../org/apache/hadoop/mapred/JobClient.java | 1 - .../apache/hadoop/mapreduce/tools/CLI.java | 2 +- .../hadoop/mapred/JobClientUnitTest.java | 81 +++++++++++++++++-- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 0285fe80ef..f53ffec718 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -144,6 +144,9 @@ Release 0.23.1 - Unreleased MAPREDUCE-3369. Migrate MR1 tests to run on MR2 using the new interfaces introduced in MAPREDUCE-3169. (Ahmed Radwan via tomwhite) + MAPREDUCE-3518. mapred queue -info -showJobs throws NPE. + (Jonathan Eagles via mahadev) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java index cc586bf2f9..fa3d799fe7 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java @@ -432,7 +432,6 @@ public String getFailureInfo() throws IOException { } - Cluster cluster; /** * Ugi of the client. We store this ugi when the client is created and * then make sure that the same ugi is used to run the various protocols. diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java index 27ccb8a27e..f7ac9c40a6 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java @@ -55,7 +55,7 @@ @InterfaceStability.Stable public class CLI extends Configured implements Tool { private static final Log LOG = LogFactory.getLog(CLI.class); - private Cluster cluster; + protected Cluster cluster; public CLI() { } diff --git a/hadoop-mapreduce-project/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java b/hadoop-mapreduce-project/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java index 11873c1423..3f54e09a33 100644 --- a/hadoop-mapreduce-project/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java +++ b/hadoop-mapreduce-project/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java @@ -19,21 +19,41 @@ package org.apache.hadoop.mapred; import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.IOException; +import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapreduce.Cluster; +import org.apache.hadoop.mapreduce.Job; +import org.apache.hadoop.mapreduce.JobPriority; +import org.apache.hadoop.mapreduce.JobStatus; +import org.apache.hadoop.mapreduce.TaskType; +import org.apache.hadoop.mapreduce.TaskReport; import org.junit.Test; public class JobClientUnitTest { + public class TestJobClient extends JobClient { + + TestJobClient(JobConf jobConf) throws IOException { + super(jobConf); + } + + void setCluster(Cluster cluster) { + this.cluster = cluster; + } + } + @SuppressWarnings("deprecation") @Test public void testMapTaskReportsWithNullJob() throws Exception { - JobClient client = new JobClient(); + TestJobClient client = new TestJobClient(new JobConf()); Cluster mockCluster = mock(Cluster.class); - client.cluster = mockCluster; + client.setCluster(mockCluster); JobID id = new JobID("test",0); when(mockCluster.getJob(id)).thenReturn(null); @@ -47,9 +67,9 @@ public void testMapTaskReportsWithNullJob() throws Exception { @SuppressWarnings("deprecation") @Test public void testReduceTaskReportsWithNullJob() throws Exception { - JobClient client = new JobClient(); + TestJobClient client = new TestJobClient(new JobConf()); Cluster mockCluster = mock(Cluster.class); - client.cluster = mockCluster; + client.setCluster(mockCluster); JobID id = new JobID("test",0); when(mockCluster.getJob(id)).thenReturn(null); @@ -63,9 +83,9 @@ public void testReduceTaskReportsWithNullJob() throws Exception { @SuppressWarnings("deprecation") @Test public void testSetupTaskReportsWithNullJob() throws Exception { - JobClient client = new JobClient(); + TestJobClient client = new TestJobClient(new JobConf()); Cluster mockCluster = mock(Cluster.class); - client.cluster = mockCluster; + client.setCluster(mockCluster); JobID id = new JobID("test",0); when(mockCluster.getJob(id)).thenReturn(null); @@ -79,9 +99,9 @@ public void testSetupTaskReportsWithNullJob() throws Exception { @SuppressWarnings("deprecation") @Test public void testCleanupTaskReportsWithNullJob() throws Exception { - JobClient client = new JobClient(); + TestJobClient client = new TestJobClient(new JobConf()); Cluster mockCluster = mock(Cluster.class); - client.cluster = mockCluster; + client.setCluster(mockCluster); JobID id = new JobID("test",0); when(mockCluster.getJob(id)).thenReturn(null); @@ -91,4 +111,49 @@ public void testCleanupTaskReportsWithNullJob() throws Exception { verify(mockCluster).getJob(id); } + + @Test + public void testShowJob() throws Exception { + TestJobClient client = new TestJobClient(new JobConf()); + JobID jobID = new JobID("test", 0); + + JobStatus mockJobStatus = mock(JobStatus.class); + when(mockJobStatus.getJobID()).thenReturn(jobID); + when(mockJobStatus.getState()).thenReturn(JobStatus.State.RUNNING); + when(mockJobStatus.getStartTime()).thenReturn(0L); + when(mockJobStatus.getUsername()).thenReturn("mockuser"); + when(mockJobStatus.getQueue()).thenReturn("mockqueue"); + when(mockJobStatus.getPriority()).thenReturn(JobPriority.NORMAL); + when(mockJobStatus.getNumUsedSlots()).thenReturn(1); + when(mockJobStatus.getNumReservedSlots()).thenReturn(1); + when(mockJobStatus.getUsedMem()).thenReturn(1024); + when(mockJobStatus.getReservedMem()).thenReturn(512); + when(mockJobStatus.getNeededMem()).thenReturn(2048); + when(mockJobStatus.getSchedulingInfo()).thenReturn("NA"); + + Job mockJob = mock(Job.class); + when(mockJob.getTaskReports(isA(TaskType.class))).thenReturn(new TaskReport[0]); + + Cluster mockCluster = mock(Cluster.class); + when(mockCluster.getJob(jobID)).thenReturn(mockJob); + + client.setCluster(mockCluster); + + + client.displayJobList(new JobStatus[] {mockJobStatus}); + verify(mockJobStatus, atLeastOnce()).getJobID(); + verify(mockJob, atLeastOnce()).getTaskReports(isA(TaskType.class)); + verify(mockCluster, atLeastOnce()).getJob(jobID); + verify(mockJobStatus).getState(); + verify(mockJobStatus).getStartTime(); + verify(mockJobStatus).getUsername(); + verify(mockJobStatus).getQueue(); + verify(mockJobStatus).getPriority(); + verify(mockJobStatus).getNumUsedSlots(); + verify(mockJobStatus).getNumReservedSlots(); + verify(mockJobStatus).getUsedMem(); + verify(mockJobStatus).getReservedMem(); + verify(mockJobStatus).getNeededMem(); + verify(mockJobStatus).getSchedulingInfo(); + } }