Merge -r 1446182:1446183 from trunk to branch-2. Fixes: HADOOP-9154. SortedMapWritable#putAll() doesn't add key/value classes to the map. Contributed by Karthik Kambatla.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1446186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas White 2013-02-14 14:09:23 +00:00
parent 67aaee865f
commit b1a31d484d
4 changed files with 24 additions and 3 deletions

View File

@ -34,6 +34,9 @@ Release 2.0.4-beta - UNRELEASED
HADOOP-9297. remove old record IO generation and tests. (tucu) 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 Release 2.0.3-alpha - 2013-02-06
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -29,6 +29,8 @@ import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import com.google.common.annotations.VisibleForTesting;
/** /**
* Abstract base class for MapWritable and SortedMapWritable * Abstract base class for MapWritable and SortedMapWritable
* *
@ -45,10 +47,12 @@ public abstract class AbstractMapWritable implements Writable, Configurable {
private AtomicReference<Configuration> conf; private AtomicReference<Configuration> conf;
/* Class to id mappings */ /* Class to id mappings */
private Map<Class, Byte> classToIdMap = new ConcurrentHashMap<Class, Byte>(); @VisibleForTesting
Map<Class, Byte> classToIdMap = new ConcurrentHashMap<Class, Byte>();
/* Id to Class mappings */ /* Id to Class mappings */
private Map<Byte, Class> idToClassMap = new ConcurrentHashMap<Byte, Class>(); @VisibleForTesting
Map<Byte, Class> idToClassMap = new ConcurrentHashMap<Byte, Class>();
/* The number of new classes (those not established by the constructor) */ /* The number of new classes (those not established by the constructor) */
private volatile byte newClasses = 0; private volatile byte newClasses = 0;

View File

@ -141,7 +141,7 @@ public class SortedMapWritable extends AbstractMapWritable
for (Map.Entry<? extends WritableComparable, ? extends Writable> e: for (Map.Entry<? extends WritableComparable, ? extends Writable> e:
t.entrySet()) { t.entrySet()) {
instance.put(e.getKey(), e.getValue()); put(e.getKey(), e.getValue());
} }
} }

View File

@ -164,4 +164,18 @@ public class TestSortedMapWritable {
assertTrue(failureReason, !mapA.equals(mapB)); assertTrue(failureReason, !mapA.equals(mapB));
assertTrue(failureReason, !mapB.equals(mapA)); 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));
}
} }