比如说,我有一个类如下:
public class MyGenericWritable extends GenericWritable {
private static Class<? extends Writable>[] CLASSES = null;
static {
CLASSES = (Class<? extends Writable>[]) new Class[] {
FirstClass.class,
SecondClass.class
//add as many different class as you want
};
}
//this empty initialize is required by Hadoop
public MyGenericWritable() {
}
public MyGenericWritable(Writable instance) {
set(instance);
}
@Override
protected Class<? extends Writable>[] getTypes() {
return CLASSES;
}
@Override
public String toString() {
return "MyGenericWritable [getTypes()=" + Arrays.toString(getTypes()) + "]";
}
}
这是映射器:
public static class FirstMap extends Mapper<Text, FirstClass, Text, MyGenericWritable> {
public void map(Text key, FirstClass value, Context context) throws IOException, InterruptedException {
System.out.println("FirstMap:" + key.toString() + " " + value.toString());
context.write(key, new MyGenericWritable(value));
}
}
有没有办法在MRUnit中使用MapDriver测试mapper? 注意:我问的原因是因为使用.withOutput不会验证结果
或者我应该使用.run()方法并手动断言结果吗?