比如说,我有一个像下面这样的类:
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 测试映射器?注意:我问的原因是因为使用 .withOutput 不会验证结果
或者我应该使用 .run() 方法并手动断言结果?