我创建了一个Mapper&使用AVRO进行输入,map-output的减速器减少输出。创建MRUnit测试时,我得到以下堆栈跟踪:
java.lang.NullPointerException
at org.apache.hadoop.io.serializer.SerializationFactory.getSerializer(SerializationFactory.java:73)
at org.apache.hadoop.mrunit.mock.MockOutputCollector.deepCopy(MockOutputCollector.java:74)
at org.apache.hadoop.mrunit.mock.MockOutputCollector.collect(MockOutputCollector.java:110)
at org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper$MockMapContext.write(MockMapContextWrapper.java:119)
at org.apache.avro.mapreduce.AvroMapper.writePair(AvroMapper.java:22)
at com.bol.searchrank.phase.day.DayMapper.doMap(DayMapper.java:29)
at com.bol.searchrank.phase.day.DayMapper.doMap(DayMapper.java:1)
at org.apache.avro.mapreduce.AvroMapper.map(AvroMapper.java:16)
at org.apache.avro.mapreduce.AvroMapper.map(AvroMapper.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
at org.apache.hadoop.mrunit.mapreduce.MapDriver.run(MapDriver.java:200)
at org.apache.hadoop.mrunit.mapreduce.MapReduceDriver.run(MapReduceDriver.java:207)
at com.bol.searchrank.phase.day.DayMapReduceTest.shouldProduceAndCountTerms(DayMapReduceTest.java:39)
驱动程序初始化如下(我创建了一个Avro MapReduce API实现):
driver = new MapReduceDriver<AvroWrapper<Pair<Utf8, LiveTrackingLine>>, NullWritable, AvroKey<Utf8>, AvroValue<Product>, AvroWrapper<Pair<Utf8, Product>>, NullWritable>().withMapper(new DayMapper()).withReducer(new DayReducer());
使用io.serialization添加配置对象无济于事:
Configuration configuration = new Configuration();
configuration.setStrings("io.serializations", new String[] {
AvroSerialization.class.getName()
});
driver = new MapReduceDriver<AvroWrapper<Pair<Utf8, LiveTrackingLine>>, NullWritable, AvroKey<Utf8>, AvroValue<Product>, AvroWrapper<Pair<Utf8, Product>>, NullWritable>().withMapper(new DayMapper()).withReducer(new DayReducer()).withConfiguration(configuration);
我使用Hadoop&amp;来自Cloudera和Avro MapRed 1.6.3的MRUnit 0.20.2-cdh3u2。
答案 0 :(得分:1)
您正在获取NPE,因为SerializationFactory未找到在io.serializations中实现序列化的可接受类。
除了Writable之外,MRUnit还有几个与序列化有关的错误,包括https://issues.apache.org/jira/browse/MRUNIT的MRUNIT-45,MRUNIT-70,MRUNIT-77,MRUNIT-86。这些错误涉及到conf没有正确传递给SerializationFactory构造函数,或者代码需要所有Writable所具有的Key或Value的默认构造函数。所有这些修复都出现在Apache MRUnit 0.9.0孵化中,这将在本周某个时候发布。Cloudera的0.20.2-cdh3u2 MRUnit接近Apache MRUnit 0.5.0孵化。我认为你的代码可能仍然是一个问题,即使在0.9.0孵化,请将你的完整代码示例发送到mrunit-user@incubator.apache.org,Apache MRUnit项目很乐意看看它
这将立即编译MRUNIT-99放宽对K2类型参数的限制,不必是可比较的