1. 程式人生 > >MapReduce單元測試

MapReduce單元測試

except 測試的 exc 單元測試 spa out depend ble inpu

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單元測試