HADOOP-8588. SerializationFactory shouldn't throw a NullPointerException if the serializations list is empty. Contributed by Sho Shimauchi. (harsh)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1389002 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
28023b7759
commit
28379070d4
@ -104,6 +104,10 @@ Trunk (Unreleased)
|
|||||||
HADOOP-8814. Replace string equals "" by String#isEmpty().
|
HADOOP-8814. Replace string equals "" by String#isEmpty().
|
||||||
(Brandon Li via suresh)
|
(Brandon Li via suresh)
|
||||||
|
|
||||||
|
HADOOP-8588. SerializationFactory shouldn't throw a
|
||||||
|
NullPointerException if the serializations list is empty.
|
||||||
|
(Sho Shimauchi via harsh)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.
|
HADOOP-8177. MBeans shouldn't try to register when it fails to create MBeanName.
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
@InterfaceStability.Evolving
|
@InterfaceStability.Evolving
|
||||||
public class SerializationFactory extends Configured {
|
public class SerializationFactory extends Configured {
|
||||||
|
|
||||||
private static final Log LOG =
|
static final Log LOG =
|
||||||
LogFactory.getLog(SerializationFactory.class.getName());
|
LogFactory.getLog(SerializationFactory.class.getName());
|
||||||
|
|
||||||
private List<Serialization<?>> serializations = new ArrayList<Serialization<?>>();
|
private List<Serialization<?>> serializations = new ArrayList<Serialization<?>>();
|
||||||
@ -55,12 +55,18 @@ public class SerializationFactory extends Configured {
|
|||||||
*/
|
*/
|
||||||
public SerializationFactory(Configuration conf) {
|
public SerializationFactory(Configuration conf) {
|
||||||
super(conf);
|
super(conf);
|
||||||
for (String serializerName : conf.getStrings(
|
if (conf.get(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY).equals("")) {
|
||||||
CommonConfigurationKeys.IO_SERIALIZATIONS_KEY,
|
LOG.warn("Serialization for various data types may not be available. Please configure "
|
||||||
new String[]{WritableSerialization.class.getName(),
|
+ CommonConfigurationKeys.IO_SERIALIZATIONS_KEY
|
||||||
AvroSpecificSerialization.class.getName(),
|
+ " properly to have serialization support (it is currently not set).");
|
||||||
AvroReflectSerialization.class.getName()})) {
|
} else {
|
||||||
add(conf, serializerName);
|
for (String serializerName : conf.getStrings(
|
||||||
|
CommonConfigurationKeys.IO_SERIALIZATIONS_KEY, new String[] {
|
||||||
|
WritableSerialization.class.getName(),
|
||||||
|
AvroSpecificSerialization.class.getName(),
|
||||||
|
AvroReflectSerialization.class.getName() })) {
|
||||||
|
add(conf, serializerName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,27 +17,62 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.io.serializer;
|
package org.apache.hadoop.io.serializer;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.impl.Log4JLogger;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||||
import org.apache.hadoop.io.Writable;
|
import org.apache.hadoop.io.Writable;
|
||||||
|
import org.apache.log4j.Level;
|
||||||
|
|
||||||
public class TestSerializationFactory {
|
public class TestSerializationFactory {
|
||||||
|
|
||||||
|
static {
|
||||||
|
((Log4JLogger) SerializationFactory.LOG).getLogger().setLevel(Level.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Configuration conf;
|
||||||
|
static SerializationFactory factory;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() throws Exception {
|
||||||
|
conf = new Configuration();
|
||||||
|
factory = new SerializationFactory(conf);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializerAvailability() {
|
public void testSerializationKeyIsEmpty() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
|
conf.set(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY, "");
|
||||||
SerializationFactory factory = new SerializationFactory(conf);
|
SerializationFactory factory = new SerializationFactory(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializationKeyIsInvalid() {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.set(CommonConfigurationKeys.IO_SERIALIZATIONS_KEY, "INVALID_KEY_XXX");
|
||||||
|
SerializationFactory factory = new SerializationFactory(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetSerializer() {
|
||||||
// Test that a valid serializer class is returned when its present
|
// Test that a valid serializer class is returned when its present
|
||||||
assertNotNull("A valid class must be returned for default Writable Serde",
|
assertNotNull("A valid class must be returned for default Writable SerDe",
|
||||||
factory.getSerializer(Writable.class));
|
factory.getSerializer(Writable.class));
|
||||||
assertNotNull("A valid class must be returned for default Writable serDe",
|
|
||||||
factory.getDeserializer(Writable.class));
|
|
||||||
// Test that a null is returned when none can be found.
|
// Test that a null is returned when none can be found.
|
||||||
assertNull("A null should be returned if there are no serializers found.",
|
assertNull("A null should be returned if there are no serializers found.",
|
||||||
factory.getSerializer(TestSerializationFactory.class));
|
factory.getSerializer(TestSerializationFactory.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDeserializer() {
|
||||||
|
// Test that a valid serializer class is returned when its present
|
||||||
|
assertNotNull("A valid class must be returned for default Writable SerDe",
|
||||||
|
factory.getDeserializer(Writable.class));
|
||||||
|
// Test that a null is returned when none can be found.
|
||||||
assertNull("A null should be returned if there are no deserializers found",
|
assertNull("A null should be returned if there are no deserializers found",
|
||||||
factory.getDeserializer(TestSerializationFactory.class));
|
factory.getDeserializer(TestSerializationFactory.class));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user