MapReduce单元测试

Posted 代号菜鸟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MapReduce单元测试相关的知识,希望对你有一定的参考价值。

MapReduce进行单元测试的步骤:

1. 在POM中添加MRUnit

<dependency>
            <groupId>org.apache.mrunit</groupId>
            <artifactId>mrunit</artifactId>
            <version>1.1.0</version>
            <classifier>hadoop2</classifier>
            <scope>test</scope>
 </dependency>

2. Mapper测试用例

    @Test
    public void testCountMapper() throws IOException {
        LongWritable key = new LongWritable(0);
        Text value = new Text("hadoop yarn");
        new MapDriver<LongWritable,Text,Text,IntWritable>()
                .withMapper(new WordCountMapper())
                .withInput(key,value)
                .withOutput(new Text("hadoop"),new IntWritable(1))
                .withOutput(new Text("yarn"),new IntWritable(1))
                .runTest();
    }

 3. Reducer测试用例

    @Test
    public void testCountReducer() throws IOException {
        new ReduceDriver<Text,IntWritable,Text,IntWritable>()
                .withReducer(new WordCountReducer())
                .withInput(new Text("hadoop"), Arrays.asList(new IntWritable(1),new IntWritable(1)))
                .withOutput(new Text("hadoop"),new IntWritable(2))
                .runTest();
    }

 

以上是关于MapReduce单元测试的主要内容,如果未能解决你的问题,请参考以下文章

单元测试 NPE,当我添加片段自定义转换时

Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2

单元测试不了解 XCTest 期望的异步 UI 代码?

如何配置Hadoop得以开始Mapreduce编程

四则运算单元测试

单元测试很棒,但是