Search in sources :

Example 1 with Find

use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.

the class TestFind method processOptionsA.

// check -a is handled correctly
@Test
public void processOptionsA() throws IOException {
    Find find = new Find();
    find.setConf(conf);
    String args = "path -name one -a -name two -a -print";
    String expected = "And(;And(;Name(one;),Name(two;)),Print(;))";
    find.processOptions(getArgs(args));
    Expression expression = find.getRootExpression();
    assertEquals(expected, expression.toString());
}
Also used : BaseExpression(org.apache.hadoop.fs.shell.find.BaseExpression) Expression(org.apache.hadoop.fs.shell.find.Expression) Find(org.apache.hadoop.fs.shell.find.Find) Test(org.junit.Test)

Example 2 with Find

use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.

the class TestFind method processArgumentsMaxDepth.

// check maximum depth is handled
@Test
public void processArgumentsMaxDepth() throws IOException {
    LinkedList<PathData> items = createDirectories();
    Find find = new Find();
    find.getOptions().setMaxDepth(1);
    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(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(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(item1b.stat);
    inOrderFsCheck.verify(fsCheck).check(item2.stat);
    inOrderFsCheck.verify(fsCheck).check(item3.stat);
    inOrderFsCheck.verify(fsCheck).check(item4.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(item5d.stat);
    inOrderFsCheck.verify(fsCheck).check(item5e.stat);
    verifyNoMoreInteractions(fsCheck);
    verifyNoMoreInteractions(out);
    verifyNoMoreInteractions(err);
}
Also used : PrintStream(java.io.PrintStream) InOrder(org.mockito.InOrder) BaseExpression(org.apache.hadoop.fs.shell.find.BaseExpression) Expression(org.apache.hadoop.fs.shell.find.Expression) Find(org.apache.hadoop.fs.shell.find.Find) PathData(org.apache.hadoop.fs.shell.PathData) Test(org.junit.Test)

Example 3 with Find

use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.

the class TestFind method processOptionsNoop.

// check an implicit and is handled correctly
@Test
public void processOptionsNoop() throws IOException {
    Find find = new Find();
    find.setConf(conf);
    String args = "path -name one -name two -print";
    String expected = "And(;And(;Name(one;),Name(two;)),Print(;))";
    find.processOptions(getArgs(args));
    Expression expression = find.getRootExpression();
    assertEquals(expected, expression.toString());
}
Also used : BaseExpression(org.apache.hadoop.fs.shell.find.BaseExpression) Expression(org.apache.hadoop.fs.shell.find.Expression) Find(org.apache.hadoop.fs.shell.find.Find) Test(org.junit.Test)

Example 4 with Find

use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.

the class TestFind method processOptionsUnknown.

// check unknown options are rejected
@Test
public void processOptionsUnknown() throws IOException {
    Find find = new Find();
    find.setConf(conf);
    String args = "path -unknown";
    try {
        find.processOptions(getArgs(args));
        fail("Unknown expression not caught");
    } catch (IOException e) {
    }
}
Also used : Find(org.apache.hadoop.fs.shell.find.Find) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with Find

use of org.apache.hadoop.fs.shell.find.Find in project hadoop by apache.

the class TestFind method processOptionsName.

// check -name is handled correctly
@Test
public void processOptionsName() throws IOException {
    Find find = new Find();
    find.setConf(conf);
    String args = "path -name namemask";
    String expected = "And(;Name(namemask;),Print(;))";
    find.processOptions(getArgs(args));
    Expression expression = find.getRootExpression();
    assertEquals(expected, expression.toString());
}
Also used : BaseExpression(org.apache.hadoop.fs.shell.find.BaseExpression) Expression(org.apache.hadoop.fs.shell.find.Expression) Find(org.apache.hadoop.fs.shell.find.Find) Test(org.junit.Test)

Aggregations

Find (org.apache.hadoop.fs.shell.find.Find)24 Test (org.junit.Test)24 BaseExpression (org.apache.hadoop.fs.shell.find.BaseExpression)17 Expression (org.apache.hadoop.fs.shell.find.Expression)17 PrintStream (java.io.PrintStream)9 PathData (org.apache.hadoop.fs.shell.PathData)9 InOrder (org.mockito.InOrder)9 IOException (java.io.IOException)2