在为mapreduce进行单元测试时如何跳过真正的调用?

xt0899hw  于 2021-05-30  发布在  Hadoop
关注(0)|答案(0)|浏览(231)

我正在为map reduce程序编写单元测试,在reduce中的setup()期间,它有一些上下文和配置以及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和connections错误。
我怎样才能解决这个问题?谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题