第2.2章 hadoop之mrunit 多个结果验证

来源:互联网 发布:多线程网络爬虫 编辑:程序博客网 时间:2024/06/06 05:35

mrunit基础配置参考,这里只写核心的单元测试用例

@Test    public void test_mapper() throws IOException{        String text = "{\"business\":\"wcnInviteInfoUpload\",\"params\":{\"username\":\"wanghui\",\"provinceId\":\"789\",\"subscribe_time\":\"2017-02-10 00:04:28\",\"openId\":\"ou7nSs1fX2IWh3iXBGYbTMVxDQy2\"}}";        mapDriver.withInput(new LongWritable(), new Text(text));        text = "{\"business\":\"wcnInviteInfoUpload\",\"params\":{\"username\":\"liyan\",\"provinceId\":\"111\",\"subscribe_time\":\"2017-02-10 00:04:28\",\"openId\":\"ou7nSs1fX2IWh3iXBGYbTMVxDQy2\"}}";        mapDriver.withInput(new LongWritable(), new Text(text));        text = "{\"business\":\"wcnInviteInfoUpload\",\"params\":{\"username\":\"wanghui\",\"provinceId\":\"789\",\"subscribe_time\":\"2017-02-10 00:05:28\",\"openId\":\"ou7nSs1fX2IWh3iXBGYbTMVxDQy1\"}}";        mapDriver.withInput(new LongWritable(), new Text(text));        // 按照account、provinceId、countDate作为分组        InviteInfoWritable out1 = new InviteInfoWritable();        out1.setAccount("wanghui");        out1.setProvinceId("789");        InviteInfoWritable out2 = new InviteInfoWritable();        out2.setAccount("liyan");        out2.setProvinceId("111");        try {            out1.setCountDate(DateUtil.parseDate("2017-02-10", "yyyy-MM-dd"));            out2.setCountDate(DateUtil.parseDate("2017-02-10", "yyyy-MM-dd"));        } catch (ParseException e) {            e.printStackTrace();        }        // 多条结果验证        List<Pair<InviteInfoWritable, Text>>  outputs = new ArrayList<>();        outputs.add(new Pair<InviteInfoWritable, Text>(out1, new Text("ou7nSs1fX2IWh3iXBGYbTMVxDQy2")));        outputs.add(new Pair<InviteInfoWritable, Text>(out2, new Text("ou7nSs1fX2IWh3iXBGYbTMVxDQy2")));        outputs.add(new Pair<InviteInfoWritable, Text>(out1, new Text("ou7nSs1fX2IWh3iXBGYbTMVxDQy1")));        mapDriver.withAllOutput(outputs);        // mapper运行        mapDriver.runTest();    }
原创粉丝点击