diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index bb34392b669..709ec703b79 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -366,6 +366,9 @@ Release 2.0.4-beta - UNRELEASED HADOOP-9297. remove old record IO generation and tests. (tucu) + HADOOP-9154. SortedMapWritable#putAll() doesn't add key/value classes to + the map. (Karthik Kambatla via tomwhite) + Release 2.0.3-alpha - 2013-02-06 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java index 6bd9efc689e..54903394feb 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java @@ -29,6 +29,8 @@ import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; +import com.google.common.annotations.VisibleForTesting; + /** * Abstract base class for MapWritable and SortedMapWritable * @@ -45,10 +47,12 @@ public abstract class AbstractMapWritable implements Writable, Configurable { private AtomicReference conf; /* Class to id mappings */ - private Map classToIdMap = new ConcurrentHashMap(); + @VisibleForTesting + Map classToIdMap = new ConcurrentHashMap(); /* Id to Class mappings */ - private Map idToClassMap = new ConcurrentHashMap(); + @VisibleForTesting + Map idToClassMap = new ConcurrentHashMap(); /* The number of new classes (those not established by the constructor) */ private volatile byte newClasses = 0; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SortedMapWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SortedMapWritable.java index c80af15c9e2..3b51fc25ffc 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SortedMapWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SortedMapWritable.java @@ -141,7 +141,7 @@ public class SortedMapWritable extends AbstractMapWritable for (Map.Entry e: t.entrySet()) { - instance.put(e.getKey(), e.getValue()); + put(e.getKey(), e.getValue()); } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSortedMapWritable.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSortedMapWritable.java index 1fbfcad7627..5ed1db25ffb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSortedMapWritable.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestSortedMapWritable.java @@ -164,4 +164,18 @@ public class TestSortedMapWritable { assertTrue(failureReason, !mapA.equals(mapB)); assertTrue(failureReason, !mapB.equals(mapA)); } + + @Test(timeout = 1000) + public void testPutAll() { + SortedMapWritable map1 = new SortedMapWritable(); + SortedMapWritable map2 = new SortedMapWritable(); + map1.put(new Text("key"), new Text("value")); + map2.putAll(map1); + + assertEquals("map1 entries don't match map2 entries", map1, map2); + assertTrue( + "map2 doesn't have class information from map1", + map2.classToIdMap.containsKey(Text.class) + && map2.idToClassMap.containsValue(Text.class)); + } }