如何在mapreduce进行单元测试时跳过真正的调用?
我正在编写map reduce程序的单元测试,在setup()中reduce,它有一些上下文和配置以及htable操作,如下所示:
protected void setup(Context context) {
try {
Configuration c = context.getConfiguration();
table =
new HTable(c,"TableName");
table.setAutoFlushTo(false);
} catch (Exception e) {
System.out.printly(e.toString());
}
}
我试图使用MRUnit,PowerMock(和Mockito一起)来模拟conext和配置,但它似乎不起作用。
单元测试代码:
Reduce.Context c = reducedriver.getContext();
Configuration confReduce = reducedriver.getConfiguration();
confReduce.setStrings("io.serializations",
confReduce.get("io.serializations"),
MutationSerialization.class.getName(),
ResultSerialization.class.getName(),
KeyValueSerialization.class.getName());
when(c.getConfiguration()).thenReturn(confReduce);
当我运行单元测试时,context.getConfiguration()似乎仍尝试连接真正的hadoop环境,并产生大量zookeeper和连接错误。
我该如何解决这个问题? 谢谢。
链接地址: http://www.djcxy.com/p/67709.html上一篇: How to skip real call when doing unit test for mapreduce?