Grep extends BaseExampleJob { @Override public int run(String[] args) throws Exception { if(args.length != 3) { failArguments("Wrond number of arguments"); return -1; } String regex = args[0]; String input = args[1]; String output = args[2]; delete(output); MapOnlyJobBuilder b = new MapOnlyJobBuilder(conf); b.setOutput(new Path(output), new HadoopOutputFormat(TextOutputFormat.class), Text.class, NullWritable.class); b.addInput(new Path(input), new HadoopInputFormat(TextInputFormat.class), new GrepHandler(regex)); Job job = b.createJob(); try { job.waitForCompletion(true); } finally { b.cleanUpInstanceFiles(); } return 0; } Grep(); @Override int run(String[] args); static void main(String args[]);  }
@Test public void test() throws Exception { Files.write("foo\nbar", new File(INPUT), Charset.forName("UTF-8")); ToolRunner.run(getConf(),new Grep(), new String[] { "foo", INPUT, OUTPUT }); assertEquals("foo", Files.toString(new File(OUTPUT + "/part-m-00000"), Charset.forName("UTF-8")).trim()); trash(INPUT, OUTPUT); }