I'm trying to unit test a Mapper program using MRUnit (from Hadoop:The definitive guide book, page 153, section: Writing a unit test with MRUnit: Mapper). I'm using intellij Idea and it is showing an error in method
new org.apache.hadoop.mrunit.MapDriver<>().withMapper(myMapper)
The error message says, withMapper(org.apache.hadoop.mapreduce.Mapper) in MapDriver cannot be applied to (complexmapreduce.MaxTempMapper )
MaxTempMapper is declared as a subclass of org.apache.hadoop.mapreduce.Mapper , so I'm not really sure what is wrong here.
Here are the complete Mapper and Unit test classes
MaxTempMapper
package complexmapreduce;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class MaxTempMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
private static final int MISSING = 9999;
private NDCRecordParser myParser = new NDCRecordParser();
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
myParser.parse(value);
if (myParser.isValidTemperature()) {
context.write(new Text(myParser.getYear()), new IntWritable(myParser.getMaxTemperature()));
}
}
}
MaxTempUnitTest
package complexmapreduce;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.junit.Test;
import java.io.IOException;
public class MaxTempSingleLineUnitTest {
@Test
public void testMaxTempMapper() throws IOException {
Text value = new Text("0029029070999991901010106004+64333+023450FM-12+000599999V0202701N015919999999N0000001N9-00781+99999102001ADDGF108991999999999999999999");
LongWritable key = new LongWritable(0);
MaxTempMapper myMapper = new MaxTempMapper();
new org.apache.hadoop.mrunit.mapreduce.MapDriver<>()
.withMapper(myMapper) // <<<===Error here
.withInput(key, value)
.withOutput(new Text("1901"),
new IntWritable(0210))
.runTest();
}
}
Note: Already tried the solution here, but no luck.
Here is a screenshot from Intellij
You need to change:
new org.apache.hadoop.mrunit.mapreduce.MapDriver<>()
to
new org.apache.hadoop.mrunit.mapreduce.MapDriver<LongWritable, Text, Text, IntWritable>()
You need to add the generic types so that it knows how to run the mapper.