我已经编写了一个定制的记录阅读器,并寻找样本测试代码来测试我的定制阅读器使用mrunit或任何其他测试框架。它的工作正常,根据功能,但我想添加测试用例之前,我安装。任何帮助都是值得赞赏的。
i2byvkas1#
在我看来,定制的记录阅读器就像任何迭代器一样。为了测试我的记录阅读器,我可以在没有mrunit或任何其他hadoop junit框架的情况下工作。测试执行得很快,占用空间也很小。在测试用例中初始化记录读取器并继续对其进行迭代。这是我的一个测试的伪代码。如果你想朝这个方向前进,我可以提供更多的细节。
MyInputFormat myInputFormat = new MyInputFormat();//configure job and provide input format configurationJob job = Job.getInstance(conf, "test"); conf = job.getConfiguration();// verify split type and count if you want to verify the input format alsoList<InputSplit> splits = myInputFormat.getSplits(job);TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());RecordReader<LongWritable, Text> reader = myInputFormat.createRecordReader(splits.get(1), context);reader.initialize(splits.get(1), context);for (; number of expected value;) { assertTrue(reader.nextKeyValue()); // verify key and value assertEquals(expectedLong, reader.getCurrentKey());}
MyInputFormat myInputFormat = new MyInputFormat();
//configure job and provide input format configuration
Job job = Job.getInstance(conf, "test");
conf = job.getConfiguration();
// verify split type and count if you want to verify the input format also
List<InputSplit> splits = myInputFormat.getSplits(job);
TaskAttemptContext context = new TaskAttemptContextImpl(conf, new TaskAttemptID());
RecordReader<LongWritable, Text> reader = myInputFormat.createRecordReader(splits.get(1), context);
reader.initialize(splits.get(1), context);
for (; number of expected value;) {
assertTrue(reader.nextKeyValue());
// verify key and value
assertEquals(expectedLong, reader.getCurrentKey());
}
1条答案
按热度按时间i2byvkas1#
在我看来,定制的记录阅读器就像任何迭代器一样。为了测试我的记录阅读器,我可以在没有mrunit或任何其他hadoop junit框架的情况下工作。测试执行得很快,占用空间也很小。在测试用例中初始化记录读取器并继续对其进行迭代。这是我的一个测试的伪代码。如果你想朝这个方向前进,我可以提供更多的细节。