当我尝试在Hadoop集群上运行map / reduce作业而不指定任何输入文件时,我得到以下异常:
java.io.IOException: No input paths specified in job
好吧,我可以想象在没有输入文件的情况下运行作业的情况确实有意义。生成测试文件就是这种情况。是否可以使用Hadoop做到这一点?如果没有,你有一些生成文件的经验?有没有更好的方法,然后保持虚拟文件与群集上的一个记录用作生成作业的输入文件?
答案 0 :(得分:1)
文件路径与基于FileInputFormat的输入相关,如SequenceInputFormat等。但是从hbase读取的输入格式,数据库不读取文件,因此您可以自己实现InputFormat并在getSplits,RecordReader中定义自己的行为, createRecordReader。有关检查,请查看TextInputFormat类的源代码。
答案 1 :(得分:0)
如果你想从你的文件中测试一行输出的mapper / combiner / reducer,那么最好的就是为每个输出使用UnitTest。
示例代码: -
在java中使用Mocking Frame工作使用可以在IDE中运行这些测试用例
这里我使用了Mockito 或者也可以使用MRunit,它也依赖于Mockito(Java Mocking Framework)
public class BoxPlotMapperTest {
@Test
public void validOutputTextMapper() throws IOException, InterruptedException
{
Mapper mapper=new Mapper();//Your Mapper Object
Text line=new Text("single line from input-file"); // single line input from file
Mapper.Context context=Mockito.mock(Mapper.Context.class);
mapper.map(null, line, context);//(key=null,value=line,context)//key was not used in my code so its null
Mockito.verify(context).write(new Text("your expected key-output"), new Text("your expected value-output")); //
}
@Test
public void validOutputTextReducer() throws IOException, InterruptedException
{
Reducer reduer=new Reducer();
final List<Text> values=new ArrayList<Text>();
values.add(new Text("value1"));
values.add(new Text("value2"));
values.add(new Text("value3"));
values.add(new Text("value4"));
Iterable<Text> iterable=new Iterable<Text>() {
@Override
public Iterator<Text> iterator() {
// TODO Auto-generated method stub
return values.iterator();
}
};
Reducer.Context context=Mockito.mock(Reducer.Context.class);
reduer.reduce(new Text("key"),iterable, context);
Mockito.verify(context).write(new Text("your expected key-output"), new Text("your expected value-output"));
}
}
答案 2 :(得分:0)
答案 3 :(得分:0)
如果要生成测试文件,为什么首先需要使用hadoop?您可以使用mapreduce步骤之外的类型特定API创建任何类型的文件,您可以使用mapreduce步骤的输入,甚至是HDFS文件。
答案 4 :(得分:0)
我知道我正在复活一个旧线程,但没有选择最佳答案,所以我想我会把它扔出去。我认为MRUnit很适合很多事情,但有时候我只是想玩一些真实的数据(特别是对于我需要嘲笑它以使其在MRUnit中工作的测试)。 当这是我的目标时,我创建了一个单独的小工作来测试我的想法,并使用SleepInputFormat基本上骗到Hadoop,并说当有真的没有时输入。旧API在此处提供了一个示例:https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.22/mapreduce/src/test/mapred/org/apache/hadoop/mapreduce/SleepJob.java,我在此处将输入格式转换为新API:https://gist.github.com/keeganwitt/6053872。