例如,我有一个类,如下所示:
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()) + "]";
}
}
这是Map器:
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()方法手动Assert结果?
暂无答案!
目前还没有任何答案,快来回答吧!