hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r1236961 - in /hadoop/common/branches/branch-0.22/mapreduce: CHANGES.txt src/java/org/apache/hadoop/mapred/JobClient.java src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
Date Sat, 28 Jan 2012 02:32:16 GMT
Author: shv
Date: Sat Jan 28 02:32:15 2012
New Revision: 1236961

URL: http://svn.apache.org/viewvc?rev=1236961&view=rev
Log:
MAPREDUCE-2539. Fixed NPE in getMapTaskReports in JobClient. Contributed by Robert Evans.

Added:
    hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
  (with props)
Modified:
    hadoop/common/branches/branch-0.22/mapreduce/CHANGES.txt
    hadoop/common/branches/branch-0.22/mapreduce/src/java/org/apache/hadoop/mapred/JobClient.java

Modified: hadoop/common/branches/branch-0.22/mapreduce/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/mapreduce/CHANGES.txt?rev=1236961&r1=1236960&r2=1236961&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/mapreduce/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.22/mapreduce/CHANGES.txt Sat Jan 28 02:32:15 2012
@@ -14,6 +14,9 @@ Release 0.22.1 - Unreleased
 
     MAPREDUCE-3593. Fix user impersonation. (Mayank Bansal via shv)
 
+    MAPREDUCE-2539. Fixed NPE in getMapTaskReports in JobClient. 
+    (Robert Evans via shv)
+
 Release 0.22.0 - 2011-11-29
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-0.22/mapreduce/src/java/org/apache/hadoop/mapred/JobClient.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/mapreduce/src/java/org/apache/hadoop/mapred/JobClient.java?rev=1236961&r1=1236960&r2=1236961&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/mapreduce/src/java/org/apache/hadoop/mapred/JobClient.java
(original)
+++ hadoop/common/branches/branch-0.22/mapreduce/src/java/org/apache/hadoop/mapred/JobClient.java
Sat Jan 28 02:32:15 2012
@@ -573,6 +573,8 @@ public class JobClient extends CLI {
     return getJob(JobID.forName(jobid));
   }
   
+  private static final TaskReport[] EMPTY_TASK_REPORTS = new TaskReport[0];
+  
   /**
    * Get the information of the current state of the map tasks of a job.
    * 
@@ -581,9 +583,16 @@ public class JobClient extends CLI {
    * @throws IOException
    */
   public TaskReport[] getMapTaskReports(JobID jobId) throws IOException {
+    return getTaskReports(jobId, TaskType.MAP);
+  }
+  
+  private TaskReport[] getTaskReports(JobID jobId, TaskType type) throws IOException {
     try {
-      return TaskReport.downgradeArray(
-        cluster.getJob(jobId).getTaskReports(TaskType.MAP));
+      Job j = cluster.getJob(jobId);
+      if(j == null) {
+        return EMPTY_TASK_REPORTS;
+      }
+      return TaskReport.downgradeArray(j.getTaskReports(type));
     } catch (InterruptedException ie) {
       throw new IOException(ie);
     }
@@ -603,12 +612,7 @@ public class JobClient extends CLI {
    * @throws IOException
    */    
   public TaskReport[] getReduceTaskReports(JobID jobId) throws IOException {
-    try {
-      return TaskReport.downgradeArray(
-        cluster.getJob(jobId).getTaskReports(TaskType.REDUCE));
-    } catch (InterruptedException ie) {
-      throw new IOException(ie);
-    }
+    return getTaskReports(jobId, TaskType.REDUCE);
   }
 
   /**
@@ -619,12 +623,7 @@ public class JobClient extends CLI {
    * @throws IOException
    */    
   public TaskReport[] getCleanupTaskReports(JobID jobId) throws IOException {
-    try {
-      return TaskReport.downgradeArray(
-        cluster.getJob(jobId).getTaskReports(TaskType.JOB_CLEANUP));
-    } catch (InterruptedException ie) {
-      throw new IOException(ie);
-    }
+    return getTaskReports(jobId, TaskType.JOB_CLEANUP);
   }
 
   /**
@@ -635,12 +634,7 @@ public class JobClient extends CLI {
    * @throws IOException
    */    
   public TaskReport[] getSetupTaskReports(JobID jobId) throws IOException {
-    try {
-      return TaskReport.downgradeArray(
-        cluster.getJob(jobId).getTaskReports(TaskType.JOB_SETUP));
-    } catch (InterruptedException ie) {
-      throw new IOException(ie);
-    }
+    return getTaskReports(jobId, TaskType.JOB_SETUP);
   }
 
   

Added: hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java?rev=1236961&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
(added)
+++ hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
Sat Jan 28 02:32:15 2012
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.mapred;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.hadoop.mapreduce.Cluster;
+import org.junit.Test;
+
+public class JobClientUnitTest {
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testMapTaskReportsWithNullJob() throws Exception {
+    JobClient client = new JobClient();
+    Cluster mockCluster = mock(Cluster.class);
+    client.cluster = mockCluster;
+    JobID id = new JobID("test",0);
+    
+    when(mockCluster.getJob(id)).thenReturn(null);
+    
+    TaskReport[] result = client.getMapTaskReports(id);
+    assertEquals(0, result.length);
+    
+    verify(mockCluster).getJob(id);
+  }
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testReduceTaskReportsWithNullJob() throws Exception {
+    JobClient client = new JobClient();
+    Cluster mockCluster = mock(Cluster.class);
+    client.cluster = mockCluster;
+    JobID id = new JobID("test",0);
+    
+    when(mockCluster.getJob(id)).thenReturn(null);
+    
+    TaskReport[] result = client.getReduceTaskReports(id);
+    assertEquals(0, result.length);
+    
+    verify(mockCluster).getJob(id);
+  }
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testSetupTaskReportsWithNullJob() throws Exception {
+    JobClient client = new JobClient();
+    Cluster mockCluster = mock(Cluster.class);
+    client.cluster = mockCluster;
+    JobID id = new JobID("test",0);
+    
+    when(mockCluster.getJob(id)).thenReturn(null);
+    
+    TaskReport[] result = client.getSetupTaskReports(id);
+    assertEquals(0, result.length);
+    
+    verify(mockCluster).getJob(id);
+  }
+  
+  @SuppressWarnings("deprecation")
+  @Test
+  public void testCleanupTaskReportsWithNullJob() throws Exception {
+    JobClient client = new JobClient();
+    Cluster mockCluster = mock(Cluster.class);
+    client.cluster = mockCluster;
+    JobID id = new JobID("test",0);
+    
+    when(mockCluster.getJob(id)).thenReturn(null);
+    
+    TaskReport[] result = client.getCleanupTaskReports(id);
+    assertEquals(0, result.length);
+    
+    verify(mockCluster).getJob(id);
+  }
+}

Propchange: hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message