use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.
the class TestFind method processOptionsNoPath.
// check no path defaults to current working directory
@Test
public void processOptionsNoPath() throws IOException {
Find find = new Find();
find.setConf(conf);
String args = "-print";
LinkedList<String> argsList = getArgs(args);
find.processOptions(argsList);
assertEquals(Collections.singletonList(Path.CUR_DIR), argsList);
}
use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.
the class TestFind method processArgumentsOptionFollowArg.
// check symlinks given as path arguments are processed correctly with the
// follow arg option set
@Test
public void processArgumentsOptionFollowArg() throws IOException {
LinkedList<PathData> items = createDirectories();
Find find = new Find();
find.getOptions().setFollowArgLink(true);
find.setConf(conf);
PrintStream out = mock(PrintStream.class);
find.getOptions().setOut(out);
PrintStream err = mock(PrintStream.class);
find.getOptions().setErr(err);
Expression expr = mock(Expression.class);
when(expr.apply((PathData) any(), anyInt())).thenReturn(Result.PASS);
FileStatusChecker fsCheck = mock(FileStatusChecker.class);
Expression test = new TestExpression(expr, fsCheck);
find.setRootExpression(test);
find.processArguments(items);
InOrder inOrder = inOrder(expr);
inOrder.verify(expr).setOptions(find.getOptions());
inOrder.verify(expr).prepare();
inOrder.verify(expr).apply(item1, 0);
inOrder.verify(expr).apply(item1a, 1);
inOrder.verify(expr).apply(item1aa, 2);
inOrder.verify(expr).apply(item1b, 1);
inOrder.verify(expr).apply(item2, 0);
inOrder.verify(expr).apply(item3, 0);
inOrder.verify(expr).apply(item4, 0);
inOrder.verify(expr).apply(item5, 0);
inOrder.verify(expr).apply(item5a, 1);
inOrder.verify(expr).apply(item5b, 1);
inOrder.verify(expr).apply(item5c, 1);
inOrder.verify(expr).apply(item5ca, 2);
inOrder.verify(expr).apply(item5d, 1);
inOrder.verify(expr).apply(item5e, 1);
inOrder.verify(expr).finish();
verifyNoMoreInteractions(expr);
InOrder inOrderFsCheck = inOrder(fsCheck);
inOrderFsCheck.verify(fsCheck).check(item1.stat);
inOrderFsCheck.verify(fsCheck).check(item1a.stat);
inOrderFsCheck.verify(fsCheck).check(item1aa.stat);
inOrderFsCheck.verify(fsCheck).check(item1b.stat);
inOrderFsCheck.verify(fsCheck).check(item2.stat);
inOrderFsCheck.verify(fsCheck, times(2)).check(item3.stat);
inOrderFsCheck.verify(fsCheck).check(item5.stat);
inOrderFsCheck.verify(fsCheck).check(item5a.stat);
inOrderFsCheck.verify(fsCheck).check(item5b.stat);
inOrderFsCheck.verify(fsCheck).check(item5c.stat);
inOrderFsCheck.verify(fsCheck).check(item5ca.stat);
inOrderFsCheck.verify(fsCheck).check(item5d.stat);
inOrderFsCheck.verify(fsCheck).check(item5e.stat);
verifyNoMoreInteractions(fsCheck);
verifyNoMoreInteractions(out);
verifyNoMoreInteractions(err);
}
use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.
the class TestFind method processArgumentsOptionFollow.
// check symlinks given as path arguments are processed correctly with the
// follow option
@Test
public void processArgumentsOptionFollow() throws IOException {
LinkedList<PathData> items = createDirectories();
Find find = new Find();
find.getOptions().setFollowLink(true);
find.setConf(conf);
PrintStream out = mock(PrintStream.class);
find.getOptions().setOut(out);
PrintStream err = mock(PrintStream.class);
find.getOptions().setErr(err);
Expression expr = mock(Expression.class);
when(expr.apply((PathData) any(), anyInt())).thenReturn(Result.PASS);
FileStatusChecker fsCheck = mock(FileStatusChecker.class);
Expression test = new TestExpression(expr, fsCheck);
find.setRootExpression(test);
find.processArguments(items);
InOrder inOrder = inOrder(expr);
inOrder.verify(expr).setOptions(find.getOptions());
inOrder.verify(expr).prepare();
inOrder.verify(expr).apply(item1, 0);
inOrder.verify(expr).apply(item1a, 1);
inOrder.verify(expr).apply(item1aa, 2);
inOrder.verify(expr).apply(item1b, 1);
inOrder.verify(expr).apply(item2, 0);
inOrder.verify(expr).apply(item3, 0);
inOrder.verify(expr).apply(item4, 0);
inOrder.verify(expr).apply(item5, 0);
inOrder.verify(expr).apply(item5a, 1);
// triggers infinite loop message
inOrder.verify(expr).apply(item5b, 1);
inOrder.verify(expr).apply(item5c, 1);
inOrder.verify(expr).apply(item5ca, 2);
inOrder.verify(expr).apply(item5d, 1);
// following item5d symlink
inOrder.verify(expr).apply(item5ca, 2);
inOrder.verify(expr).apply(item5e, 1);
inOrder.verify(expr).finish();
verifyNoMoreInteractions(expr);
InOrder inOrderFsCheck = inOrder(fsCheck);
inOrderFsCheck.verify(fsCheck).check(item1.stat);
inOrderFsCheck.verify(fsCheck).check(item1a.stat);
inOrderFsCheck.verify(fsCheck).check(item1aa.stat);
inOrderFsCheck.verify(fsCheck).check(item1b.stat);
inOrderFsCheck.verify(fsCheck).check(item2.stat);
inOrderFsCheck.verify(fsCheck, times(2)).check(item3.stat);
inOrderFsCheck.verify(fsCheck).check(item5.stat);
inOrderFsCheck.verify(fsCheck).check(item1b.stat);
inOrderFsCheck.verify(fsCheck).check(item5.stat);
inOrderFsCheck.verify(fsCheck).check(item5c.stat);
inOrderFsCheck.verify(fsCheck).check(item5ca.stat);
inOrderFsCheck.verify(fsCheck).check(item5c.stat);
inOrderFsCheck.verify(fsCheck, times(2)).check(item5ca.stat);
verifyNoMoreInteractions(fsCheck);
verifyNoMoreInteractions(out);
verify(err).println("Infinite loop ignored: " + item5b.toString() + " -> " + item5.toString());
verifyNoMoreInteractions(err);
}
use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.
the class TestFind method processOptionsIname.
// check -iname is handled correctly
@Test
public void processOptionsIname() throws IOException {
Find find = new Find();
find.setConf(conf);
String args = "path -iname namemask";
String expected = "And(;Iname-Name(namemask;),Print(;))";
find.processOptions(getArgs(args));
Expression expression = find.getRootExpression();
assertEquals(expected, expression.toString());
}
use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.
the class TestFind method processOptionsAnd.
// check -and is handled correctly
@Test
public void processOptionsAnd() throws IOException {
Find find = new Find();
find.setConf(conf);
String args = "path -name one -and -name two -and -print";
String expected = "And(;And(;Name(one;),Name(two;)),Print(;))";
find.processOptions(getArgs(args));
Expression expression = find.getRootExpression();
assertEquals(expected, expression.toString());
}
Aggregations