zoukankan      html  css  js  c++  java
  • Mapreduce(7)----单元测试

    1.MRUnit

    使用MRUnit框架进行单元测试,该框架对不同的测试对象使用不同的Driver,因此分为了:MapDriver、ReduceDriver和MapReduceDriver。

    2. 代码:

    (1)主要的包:

    import org.apache.hadoop.mrunit.mapreduce.MapDriver;
    import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
    import org.junit.Rule;
    import org.junit.Test;

     (2)代码主要部分:

    public class MRJobTest {
      private MapDriver<LongWritable,Text, Text, Text> mapDriver =
          MapDriver.newMapDriver(new MRJob.MRJobMapper());
      private ReduceDriver<Text, Text, Text, Text> reduceDriver = ReduceDriver.newReduceDriver(new MRJob.MRJobReducer());
    
      @Test
      public void testMap() throws IOException {
        mapDriver.addInput(new LongWritable(), new Text(
            "2	4	101,10")); //输入数据
        mapDriver.addInput(new LongWritable(), new Text(
            "3	5"));
        mapDriver.addInput(new LongWritable(), new Text(
            ""));
        assertEquals(7,mapDriver.run().size());  //执行map代码
    
      }
    
      @Test
      public void testReducer() throws IOException {
        reduceDriver.addInput(new Text("1"), Lists.newArrayList(new Text("101"), new Text("101"), new Text("303")));  //输入reduce数据
        reduceDriver.addInput(new Text("3"), Lists.newArrayList(new Text("101"), new Text("202"), new Text("303")));
    
        assertEquals(3, reduceDriver.run().size());  //执行reduce.run代码
        assertEquals("Expected 2 counter increment", 2, reduceDriver.getCounters()
            .findCounter(MRJob.MRJobCounter.LOW5).getValue());  //获取reduce中的自定义枚举名为MRJobCounter.LOW5的counter
    } }
  • 相关阅读:
    TIDB-存储
    MySQL的ACID
    MySQL MVCC
    MySQL 悲观锁、乐观锁、MVCC一
    MySQL写放大总结
    基于Linux上的wifi密码爆破
    Stack与Queue的实现(c++模板实现)
    vector 实现二维数组
    Linux下的静态链接与动态链接
    260. Single Number III
  • 原文地址:https://www.cnblogs.com/Lee-yl/p/13345517.html
Copyright © 2011-2022 走看看