|
@@ -23,15 +23,20 @@ import static org.apache.hadoop.io.TestGenericWritable.CONF_TEST_VALUE;
|
|
import junit.framework.TestCase;
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.io.DataOutputBuffer;
|
|
import org.apache.hadoop.io.DataOutputBuffer;
|
|
|
|
+import org.apache.hadoop.io.RawComparator;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.io.TestGenericWritable.Foo;
|
|
import org.apache.hadoop.io.TestGenericWritable.Foo;
|
|
import org.apache.hadoop.io.TestGenericWritable.Bar;
|
|
import org.apache.hadoop.io.TestGenericWritable.Bar;
|
|
import org.apache.hadoop.io.TestGenericWritable.Baz;
|
|
import org.apache.hadoop.io.TestGenericWritable.Baz;
|
|
import org.apache.hadoop.io.TestGenericWritable.FooGenericWritable;
|
|
import org.apache.hadoop.io.TestGenericWritable.FooGenericWritable;
|
|
|
|
+import org.apache.hadoop.io.serializer.DeserializerBase;
|
|
|
|
+import org.apache.hadoop.io.serializer.SerializationBase;
|
|
|
|
+import org.apache.hadoop.io.serializer.SerializerBase;
|
|
import org.apache.hadoop.util.GenericsUtil;
|
|
import org.apache.hadoop.util.GenericsUtil;
|
|
|
|
|
|
public class TestWritableSerialization extends TestCase {
|
|
public class TestWritableSerialization extends TestCase {
|
|
@@ -61,6 +66,26 @@ public class TestWritableSerialization extends TestCase {
|
|
assertNotNull(result.getConf());
|
|
assertNotNull(result.getConf());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
+ public void testIgnoreMisconfiguredMetadata() throws IOException {
|
|
|
|
+ // If SERIALIZATION_KEY is set, still need class name.
|
|
|
|
+
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ Map<String, String> metadata = new HashMap<String, String>();
|
|
|
|
+ metadata.put(SerializationBase.SERIALIZATION_KEY,
|
|
|
|
+ WritableSerialization.class.getName());
|
|
|
|
+ SerializationFactory factory = new SerializationFactory(conf);
|
|
|
|
+ SerializationBase serialization = factory.getSerialization(metadata);
|
|
|
|
+ assertNull("Got serializer without any class info", serialization);
|
|
|
|
+
|
|
|
|
+ metadata.put(SerializationBase.CLASS_KEY,
|
|
|
|
+ Text.class.getName());
|
|
|
|
+ serialization = factory.getSerialization(metadata);
|
|
|
|
+ assertNotNull("Didn't get serialization!", serialization);
|
|
|
|
+ assertTrue("Wrong serialization class",
|
|
|
|
+ serialization instanceof WritableSerialization);
|
|
|
|
+ }
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
public void testReuseSerializer() throws IOException {
|
|
public void testReuseSerializer() throws IOException {
|
|
// Test that we can write multiple objects of the same type
|
|
// Test that we can write multiple objects of the same type
|
|
@@ -112,4 +137,46 @@ public class TestWritableSerialization extends TestCase {
|
|
barSerializer.close();
|
|
barSerializer.close();
|
|
out.reset();
|
|
out.reset();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Test the SerializationBase.checkSerializationKey() method.
|
|
|
|
+ class DummySerializationBase extends SerializationBase<Object> {
|
|
|
|
+ public boolean accept(Map<String, String> metadata) {
|
|
|
|
+ return checkSerializationKey(metadata);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public SerializerBase<Object> getSerializer(Map<String, String> metadata) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DeserializerBase<Object> getDeserializer(Map<String, String> metadata) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public RawComparator<Object> getRawComparator(Map<String, String> metadata) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void testSerializationKeyCheck() {
|
|
|
|
+ DummySerializationBase dummy = new DummySerializationBase();
|
|
|
|
+ Map<String, String> metadata = new HashMap<String, String>();
|
|
|
|
+
|
|
|
|
+ assertTrue("Didn't accept empty metadata", dummy.accept(metadata));
|
|
|
|
+
|
|
|
|
+ metadata.put(SerializationBase.SERIALIZATION_KEY,
|
|
|
|
+ DummySerializationBase.class.getName());
|
|
|
|
+ assertTrue("Didn't accept valid metadata", dummy.accept(metadata));
|
|
|
|
+
|
|
|
|
+ metadata.put(SerializationBase.SERIALIZATION_KEY, "foo");
|
|
|
|
+ assertFalse("Accepted invalid metadata", dummy.accept(metadata));
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ dummy.accept((Map<String, String>) null);
|
|
|
|
+ // Shouldn't get here!
|
|
|
|
+ fail("Somehow didn't actually test the method we expected");
|
|
|
|
+ } catch (NullPointerException npe) {
|
|
|
|
+ // expected this.
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|