hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1358933 - in /hadoop/common/branches/branch-1.1: CHANGES.txt src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java
Date Mon, 09 Jul 2012 06:45:36 GMT
Author: mattf
Date: Mon Jul  9 06:45:35 2012
New Revision: 1358933

URL: http://svn.apache.org/viewvc?rev=1358933&view=rev
Log:
MAPREDUCE-2903. Map Tasks graph is throwing XML Parse error when Job is executed with 0 maps.
Contributed by Devaraj K.

Added:
    hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java
Modified:
    hadoop/common/branches/branch-1.1/CHANGES.txt
    hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java

Modified: hadoop/common/branches/branch-1.1/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/CHANGES.txt?rev=1358933&r1=1358932&r2=1358933&view=diff
==============================================================================
--- hadoop/common/branches/branch-1.1/CHANGES.txt (original)
+++ hadoop/common/branches/branch-1.1/CHANGES.txt Mon Jul  9 06:45:35 2012
@@ -276,6 +276,9 @@ Release 1.1.0 - unreleased
     HADOOP-8445. Token should not print the password in toString
     (Ravi Prakash via tgraves)
 
+    MAPREDUCE-2903. Map Tasks graph is throwing XML Parse error when Job is 
+    executed with 0 maps. (Devaraj K via mattf)
+
 Release 1.0.3 - 2012.05.07
 
   NEW FEATURES

Modified: hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java?rev=1358933&r1=1358932&r2=1358933&view=diff
==============================================================================
--- hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java
(original)
+++ hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TaskGraphServlet.java
Mon Jul  9 06:45:35 2012
@@ -72,13 +72,13 @@ public class TaskGraphServlet extends Ht
     final boolean isMap = "map".equalsIgnoreCase(request.getParameter("type"));
     final TaskReport[] reports = isMap? tracker.getMapTaskReports(jobId) 
                                       : tracker.getReduceTaskReports(jobId);
-    if(reports == null || reports.length == 0) {
+    if(reports == null) {
       return;
     }
 
     final int numTasks = reports.length;     
     int tasksPerBar = (int)Math.ceil(numTasks / 600d);
-    int numBars = (int) Math.ceil((double)numTasks / tasksPerBar);
+    int numBars = (numTasks==0)?600:(int) Math.ceil((double)numTasks / tasksPerBar);
     int w = Math.max(600, numBars);
     int barWidth = Math.min(10,  w / numBars); //min 1px, max 10px
     int barsPerNotch = (int)Math.ceil(10d / barWidth);

Added: hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java?rev=1358933&view=auto
==============================================================================
--- hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java
(added)
+++ hadoop/common/branches/branch-1.1/src/mapred/org/apache/hadoop/mapred/TestTaskGraphServlet.java
Mon Jul  9 06:45:35 2012
@@ -0,0 +1,68 @@
+/**
+ * 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 java.io.PrintWriter;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestTaskGraphServlet {
+  @Test
+  public void testTaskGraphServletShouldNotReturnEmptyContForNotasks()
+      throws Exception {
+    String jobId = "job_201108291216_0002";
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    Mockito.doReturn(jobId).when(request).getParameter("jobid");
+    Mockito.doReturn("map").when(request).getParameter("type");
+
+    JobTracker jobTracker = Mockito.mock(JobTracker.class);
+    Mockito.doReturn(new TaskReport[0]).when(jobTracker).getMapTaskReports(
+        JobID.forName(jobId));
+
+    ServletContext servletContext = Mockito.mock(ServletContext.class);
+    Mockito.doReturn(jobTracker).when(servletContext).getAttribute(
+        "job.tracker");
+
+    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
+    PrintWriter printWriter = Mockito.mock(PrintWriter.class);
+    Mockito.doReturn(printWriter).when(response).getWriter();
+
+    TaskGraphServlet taskGraphServlet = getTaskGraphServlet(servletContext);
+
+    taskGraphServlet.doGet(request, response);
+    Mockito.verify(printWriter, Mockito.atLeastOnce()).print("</svg>");
+  }
+
+  private TaskGraphServlet getTaskGraphServlet(
+      final ServletContext servletContext) {
+    TaskGraphServlet taskGraphServlet = new TaskGraphServlet() {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public ServletContext getServletContext() {
+        return servletContext;
+      }
+    };
+    return taskGraphServlet;
+  }
+}



Mime
View raw message