My reducer unit test throws a "Mismatch in value class"
exception after the migration to MapReduce 2:
Mismatch in value class: expected: class org.apache.hadoop.io.IntWritable actual: class com.company.MyWritable
The error message itself is clear to me, but I don't understand why MRUnit gets the temporary writable class instead of IntWritable.
The reducer implementation:
public static class TestCountReduce extends
Reducer<Text, MyWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<MyWritable> values,
Context context) throws IOException, InterruptedException {
...
context.write(key, new IntWritable(s.size()));
}
}
The test setup:
public void setUp() throws IOException {
Mapper<Object, Text, Text, MyWritable> mapper = new MyMapper();
Reducer<Text, MyWritable, Text, IntWritable> reducer = new MyReducer();
mapDriver = new MapDriver<Object, Text, Text, MyWritable>();
mapDriver.setMapper(mapper);
reduceDriver = new ReduceDriver<Text, MyWritable, Text, IntWritable>();
reduceDriver.setReducer(reducer);
}
And finally the test case:
@Test
public void testReducer() throws IOException {
List<MyWritable> values = new ArrayList<MyWritable>();
values.add(new MyWritable("1"));
values.add(new MyWritable("1"));
reduceDriver.withInput(new Text("testkey"), values);
reduceDriver.withOutput(new Text("testkey"), new IntWritable(1));
reduceDriver.runTest();
}
Please check the reduce method signature in your reducer implementation
It should be
public void reduce(Text key, Iterable<MyWritable> values, Context context) throws IOException, InterruptedException {
instead of
public void reduce(Text key, Iterator<MyWritable> values, Context context) throws IOException, InterruptedException {