【问题标题】:Unit testing Mongo-Hadoop jobs with MrUnit使用 MrUnit 对 Mongo-Hadoop 作业进行单元测试
【发布时间】:2014-02-24 15:06:19
【问题描述】:

如何对 mongo-hadoop 作业进行单元测试?

到目前为止我的尝试:

public class MapperTest {

    MapDriver<Object, BSONObject, Text, IntWritable> d;

    @Before
    public void setUp() throws IOException {
        WordMapper mapper = new WordMapper();
        d = MapDriver.newMapDriver(mapper);
    }

    @Test
    public void testMapper() throws IOException {

        BSONObject doc = new BasicBSONObject("sentence", "Two words");
        d.withInput(new Text("anykey"), doc );

        d.withOutput(new Text("Two"), new IntWritable(1));
        d.withOutput(new Text("words"), new IntWritable(1));

        d.runTest();
    }
}

产生这个输出:

类 org.bson.BasicBSONObject 的 io.serializations 中没有适用的类在 conf 中实现序列化

java.lang.IllegalStateException 在 org.apache.hadoop.mrunit.internal.io.Serialization.copy(Serialization.java:67) 在 org.apache.hadoop.mrunit.internal.io.Serialization.copy(Serialization.java:91) 在 org.apache.hadoop.mrunit.internal.io.Serialization.copyWithConf(Serialization.java:104) 在 org.apache.hadoop.mrunit.TestDriver.copy(TestDriver.java:608) 在 org.apache.hadoop.mrunit.TestDriver.copyPair(TestDriver.java:612) 在 org.apache.hadoop.mrunit.MapDriverBase.addInput(MapDriverBase.java:118) 在 org.apache.hadoop.mrunit.MapDriverBase.withInput(MapDriverBase.java:207) ...

【问题讨论】:

  • 尝试将 BSONObject 转换为 BSONWritable
  • 你能解决你的问题吗?我目前面临同样的问题。我猜@Archit 评论不起作用,因为 BSONObject 是您的输入,而不是输出
  • 不,很遗憾没有。我们决定放弃 hadoop。 :)
  • 出于好奇,你切换到了哪个框架?
  • @Archit : mongodb + amazon redshift 中的计数器文档以及来自 rabbitmq 的一些爱。所以这是一个混合体。

标签: java mongodb hadoop mrunit


【解决方案1】:

您需要设置序列化程序。 示例:mapDriver.getConfiguration().setStrings("io.serializations", "org.apache.hadoop.io.serializer.WritableSerialization", MongoSerDe.class.getName());

MongoSerDe 源代码:https://gist.github.com/lfrancke/01d1819a94f14da171e3

但我在使用 this(MongoSerDe) 时遇到错误“org.bson.io.BasicOutputBuffer.pipe(Ljava/io/DataOutput;)I”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 2022-08-14
    • 2018-10-28
    • 1970-01-01
    • 2011-04-22
    相关资源
    最近更新 更多