【问题标题】:How to do Mapper testing using MRUnit Test?如何使用 MRUnit Test 进行 Mapper 测试?
【发布时间】:2014-10-05 09:53:11
【问题描述】:

我是 Hadoop 新手。我想使用 MRUnit Test 单独测试我的映射器部分。我已经尝试了很多。但我不知道如何解决以下错误-
“MapDriver 类型中的方法 setMapper(Mapper) 不适用于参数 (Recommand.IdIndexMapper)”。我正在使用 Hadoop-1.2.1、Eclipse Juno、mrunit-1.0.0-hadoop1.jar、junit-4.11、mockito-all-1.9.5.jar。下面是我的代码,

我的映射器类:
类名:推荐,

public static class IdIndexMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text>{

        public void map(LongWritable key, Text val, OutputCollector<Text, Text> output,Reporter reporter)throws IOException{
            String[] ids;
            String ln=val.toString();
            ids=ln.split("\t");
            output.collect(new Text(ids[0]),new Text(ids[1]));
   // System.out.println(ids[0]+" "+ids[1]);

    }

我的测试代码:

package org.apache.hadoop.examples;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;



import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.examples.WordCount.IntSumReducer;
//import org.apache.hadoop.examples.WordCount.TokenizerMapper;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.junit.Before;
import org.junit.Test;
import org.myorg.Recommand.IdIndexMapper;

public class RecomTest {
    MapDriver<LongWritable, Text, Text, Text> mapDriver;

     @Before
     public void setUp() throws Exception {
         IdIndexMapper mapper=new IdIndexMapper();
         mapper.configure(new JobConf());
        mapDriver=new MapDriver<LongWritable, Text, Text,Text>();
        mapDriver.setMapper(mapper);
     }

    @Test
    public void testMapper() throws IOException {

        final LongWritable inputKey = new LongWritable(0);
         final Text inputValue = new Text("M1023    M1024,M1022,M1025");

         final Text outputKey = new Text("M1023");
         final Text outputValue = new Text("M1024,M1022,M1025");

         mapDriver.withInput(inputKey, inputValue);
         mapDriver.withOutput(outputKey, outputValue);
         mapDriver.runTest();



    }

}

我得到的错误是:

类型MapDriver中的setMapper(Mapper)方法不适用于参数(Recommand.IdIndexMapper)

谁能帮我解决这个问题?

【问题讨论】:

    标签: java eclipse hadoop hadoop-streaming mrunit


    【解决方案1】:

    1.0.0 MapDriver.setMapper() 需要 org.apache.hadoop.mapred.Mapper。您使用的是较旧的org.apache.hadoop.mapreduce.Mapper。它们是两种不同的动物。如果你想使用MRUnit 0.8.x,你可以使用旧的Mapper。你可以得到0.8.x here


    编辑

    我看到了真正的问题。以上是不正确的。有两个MapDrivers - org.apache.hadoop.mrunit.mapreduce.MapDriver(您正在使用的那个)和org.apache.hadoop.mrunit.MapDriver。你应该使用后者MapDriver

    另请注意,有两种不同的 MRUnit。有一个 hadoop1 和 hadoop2 版本。后者MapDriver(你需要的那个)在hadoop2中。你可以得到download here

    【讨论】:

    • 我已经更改了 mapred.Mapper 并且我也尝试使用 MRUnit 0.8.0。但我还是遇到了同样的错误。
    • 查看我的 EDIT 我现在看到了您的问题。您使用了错误的 mrunit jar。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2016-10-30
    • 2011-06-22
    相关资源
    最近更新 更多