List of usage examples for org.apache.mahout.common AbstractJob getInputPath
protected Path getInputPath()
From source file:org.gpfvic.mahout.common.AbstractJobTest.java
License:Apache License
@Test public void testInputOutputPaths() throws Exception { AbstractJobFactory fact = new AbstractJobFactory() { @Override/*from w w w . j av a2 s . c om*/ public AbstractJob getJob() { return new AbstractJob() { @Override public int run(String[] args) throws IOException { addInputOption(); addOutputOption(); // arg map should be null if a required option is missing. Map<String, List<String>> argMap = parseArguments(args); if (argMap == null) { return -1; } Path inputPath = getInputPath(); assertNotNull("getInputPath() returns non-null", inputPath); Path outputPath = getInputPath(); assertNotNull("getOutputPath() returns non-null", outputPath); return 0; } }; } }; int ret = ToolRunner.run(fact.getJob(), new String[0]); assertEquals("-1 for missing input option", -1, ret); String testInputPath = "testInputPath"; AbstractJob job = fact.getJob(); ret = ToolRunner.run(job, new String[] { "--input", testInputPath }); assertEquals("-1 for missing output option", -1, ret); assertEquals("input path is correct", testInputPath, job.getInputPath().toString()); job = fact.getJob(); String testOutputPath = "testOutputPath"; ret = ToolRunner.run(job, new String[] { "--output", testOutputPath }); assertEquals("-1 for missing input option", -1, ret); assertEquals("output path is correct", testOutputPath, job.getOutputPath().toString()); job = fact.getJob(); ret = ToolRunner.run(job, new String[] { "--input", testInputPath, "--output", testOutputPath }); assertEquals("0 for complete options", 0, ret); assertEquals("input path is correct", testInputPath, job.getInputPath().toString()); assertEquals("output path is correct", testOutputPath, job.getOutputPath().toString()); job = fact.getJob(); ret = ToolRunner.run(job, new String[] { "--input", testInputPath, "--output", testOutputPath }); assertEquals("0 for complete options", 0, ret); assertEquals("input path is correct", testInputPath, job.getInputPath().toString()); assertEquals("output path is correct", testOutputPath, job.getOutputPath().toString()); job = fact.getJob(); String testInputPropertyPath = "testInputPropertyPath"; String testOutputPropertyPath = "testOutputPropertyPath"; ret = ToolRunner.run(job, new String[] { "-Dmapred.input.dir=" + testInputPropertyPath, "-Dmapred.output.dir=" + testOutputPropertyPath }); assertEquals("0 for complete options", 0, ret); assertEquals("input path from property is correct", testInputPropertyPath, job.getInputPath().toString()); assertEquals("output path from property is correct", testOutputPropertyPath, job.getOutputPath().toString()); job = fact.getJob(); ret = ToolRunner.run(job, new String[] { "-Dmapred.input.dir=" + testInputPropertyPath, "-Dmapred.output.dir=" + testOutputPropertyPath, "--input", testInputPath, "--output", testOutputPath }); assertEquals("0 for complete options", 0, ret); assertEquals("input command-line option precedes property", testInputPath, job.getInputPath().toString()); assertEquals("output command-line option precedes property", testOutputPath, job.getOutputPath().toString()); }