2
내 감속기 단위 테스트는 맵리 듀스 2로 마이그레이션 후 "Mismatch in value class"
예외가 발생합니다 :MRUnit 감속기 테스트 : 값 클래스의 불일치
Mismatch in value class: expected: class org.apache.hadoop.io.IntWritable actual: class com.company.MyWritable
오류 메시지 자체는 나에게 분명하다,하지만 난 이해가 안 돼요 MRUnit이 IntWritable 대신 임시 쓰기 가능한 클래스를 가져 오는 이유.
감속기 구현 :
이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()));
}
}
테스트 설정 :
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);
}
그리고 마지막으로 테스트 케이스 :
이@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();
}