博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在Hadoop中使用MRUnit进行单元测试
阅读量:2394 次
发布时间:2019-05-10

本文共 1222 字,大约阅读时间需要 4 分钟。

最近在学习TF-IDF示例的时候,需要用到MRUnit来对Map、Reduce、MapReduce做测试,

网上找了一个极其简单的教程:

 

介绍:

       MRUnit是一款由Couldera公司开发的专门针对Hadoop中编写MapReduce单元测试的框架。

它可以用于0.18.x版本中的经典org.apache.hadoop.mapred.*的模型,也能在0.20.x版本org.apache.hadoop.mapreduce.*的新模型中使用。

安装:

       在目前Hadoop的发行版中,并没有默认包含MRUnit。你需要去Couldera公司的官网中去下载一个由他们再次发行的版本。

      推荐的版本为: 。

       下载这个文件后,你将在hadoop-0.20.1+133/contrib/mrunit目录中找到我们需要的jar包:hadoop-0.20.1+133-mrunit.jar。

       为了使用MRUnit,我们需要将hadoop-0.20.1+133-mrunit.jar和Junit4.x使用的jar包:junit.jar都添加到我们开发Hadoop程序项目的classpath中。

示例:

 

package gpcuster.cnblogs.com;import junit.framework.TestCase;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapred.Mapper;import org.apache.hadoop.mapred.lib.IdentityMapper;import org.junit.Before;import org.junit.Test;import org.apache.hadoop.mrunit.MapDriver;public class TestExample extends TestCase {  private Mapper
mapper; private MapDriver
driver; @Before public void setUp() { mapper = new IdentityMapper
(); driver = new MapDriver
(mapper); } @Test public void testIdentityMapper() { driver.withInput(new Text("foo"), new Text("bar")) .withOutput(new Text("foo"), new Text("bar")) .runTest(); }}
 

 

参考材料:

博客园 逖靖寒 

 

转载地址:http://qvwob.baihongyu.com/

你可能感兴趣的文章
SpringBoot--嵌入式Servlet容器启动原理
查看>>
SpringBoot--整合MyBatis(XML方式)
查看>>
SpringBoot--整合MyBatis(注解方式)
查看>>
SpringBoot--整合JDBC
查看>>
SpringBoot--整合Druid&配置数据源监控
查看>>
JPA--4种主键生成策略
查看>>
JPA--单表操作二、(条件查询、统计查询、排序查询、分组查询、分页查询)
查看>>
JPA--SpringData JPA环境搭建及简单操作
查看>>
JPA--SpringDataJPA的四种查询方式
查看>>
JPA--SpringDataJpa之Specifications动态查询
查看>>
JPA--SpringDataJPA一对多关联、级联操作
查看>>
JPA--SpringDataJPA多对多关联、级联操作
查看>>
JPA--SpringDataJPA对象导航查询及加载策略
查看>>
SpringBoot--启动流程、原理
查看>>
SpringBoot--整合JPA
查看>>
Git--创建仓库/创建新项目、操作文件
查看>>
Git--查看历史记录、版本的前进和后退、找回删除文件
查看>>
Git--分支操作、合并分支、解决冲突
查看>>
Git--SSH登录
查看>>
Git--Eclipse操作、忽略文件、推送到远程库
查看>>