Bläddra i källkod

MAPREDUCE-818. Fixes Counters#getGroup API. Contributed by Amareshwari Sriramadasu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20@806506 13f79535-47bb-0310-9956-ffa450edef68
Sharad Agarwal 16 år sedan
förälder
incheckning
b6545d8252

+ 3 - 0
CHANGES.txt

@@ -225,6 +225,9 @@ Release 0.20.1 - Unreleased
     memory management parameters are used in configuration.
     (Sreekanth Ramakrishnan via yhemanth)
 
+    MAPREDUCE-818. Fixes Counters#getGroup API. (Amareshwari Sriramadasu 
+    via sharad)
+
 Release 0.20.0 - 2009-04-15
 
   INCOMPATIBLE CHANGES

+ 7 - 6
src/mapred/org/apache/hadoop/mapreduce/Counters.java

@@ -37,11 +37,7 @@ public class Counters implements Writable,Iterable<CounterGroup> {
   }
 
   public Counter findCounter(String groupName, String counterName) {
-    CounterGroup grp = groups.get(groupName);
-    if (grp == null) {
-      grp = new CounterGroup(groupName);
-      groups.put(groupName, grp);
-    }
+    CounterGroup grp = getGroup(groupName);
     return grp.findCounter(counterName);
   }
 
@@ -78,7 +74,12 @@ public class Counters implements Writable,Iterable<CounterGroup> {
    * with the specified name.
    */
   public synchronized CounterGroup getGroup(String groupName) {
-    return groups.get(groupName);
+    CounterGroup grp = groups.get(groupName);
+    if (grp == null) {
+      grp = new CounterGroup(groupName);
+      groups.put(groupName, grp);
+    }
+    return grp;
   }
 
   /**

+ 3 - 0
src/test/org/apache/hadoop/mapreduce/TestMapReduceLocal.java

@@ -155,6 +155,9 @@ public class TestMapReduceLocal extends TestCase {
     assertEquals("map out = combine in", mapOut, combineIn);
     assertEquals("combine out = reduce in", combineOut, reduceIn);
     assertTrue("combine in > combine out", combineIn > combineOut);
+    String group = "Random Group";
+    CounterGroup ctrGrp = ctrs.getGroup(group);
+    assertEquals(0, ctrGrp.size());
   }
 
 }