hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acmur...@apache.org
Subject svn commit: r1130994 - in /hadoop/mapreduce/trunk: CHANGES.txt src/java/org/apache/hadoop/mapred/JobClient.java src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
Date Fri, 03 Jun 2011 11:25:53 GMT
Author: acmurthy
Date: Fri Jun  3 11:25:53 2011
New Revision: 1130994

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

Added:
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/JobClient.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=1130994&r1=1130993&r2=1130994&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Fri Jun  3 11:25:53 2011
@@ -163,6 +163,9 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    MAPREDUCE-2539. Fixed NPE in getMapTaskReports in JobClient. (Robert Evans via
+    acmurthy) 
+
     MAPREDUCE-2531. Fixed jobcontrol to downgrade JobID. (Robert Evans via
     acmurthy) 
 

Modified: hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/JobClient.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/JobClient.java?rev=1130994&r1=1130993&r2=1130994&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/JobClient.java (original)
+++ hadoop/mapreduce/trunk/src/java/org/apache/hadoop/mapred/JobClient.java Fri Jun  3 11:25:53
2011
@@ -576,6 +576,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.
    * 
@@ -584,9 +586,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);
     }
@@ -606,12 +615,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);
   }
 
   /**
@@ -622,12 +626,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);
   }
 
   /**
@@ -638,12 +637,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/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java?rev=1130994&view=auto
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
(added)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/JobClientUnitTest.java
Fri Jun  3 11:25:53 2011
@@ -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);
+  }
+}



Mime
View raw message