【发布时间】:2014-12-15 11:53:33
【问题描述】:
我是 Hadoop 新手,这是我的第一个映射程序,我正在通过 MR 单元对其进行单元测试。
我正在传递我通过配置对象设置的参数(年份)
Configuration config =new Configuration()
config.set("Year", "2012");
Job job=new Job(config ,"Yearly");
我的映射器:
public void map(ImmutableBytesWritable row, Result values, Context context)throws IOException, InterruptedException
{
Configuration conf = context.getConfiguration();
String Year= conf.get("Year");
}
在 MR 单元测试中,我正在模拟上下文类以及键、值
@Test
public void testMapper() throws IOException, InterruptedException
{
context = mock(Mapper.Context.class);
Configuration conf=mock(Configuration.class);
when(conf.get("Year")).thenReturn("2012");
when(context.getConfiguration()).thenReturn(conf);
mapper.map(row, result, context);
}
但是无法获取映射中的值(Year),接收 null。我这样做是正确的还是有更好的方法来测试映射。
【问题讨论】:
-
您为什么不使用 MRUnit 的
MapperDriver来测试这个? -
我使用了MRUnit的MapDriver,这样就不需要mock配置对象了,我们可以用MapDriver.setConfiguration(conf)来设置conf。但是我需要模拟键和值并将测试运行为 mapDriver.withInputKey(key).withInputValue().withOutput()..runTest();谢谢。
-
您在评论结束时迷失了我 - 您能否将您的问题更新为您目前的问题,并列出仍然导致您出现问题的问题 - 谢谢