Search in sources :

Example 21 with PathData

use of org.apache.hadoop.fs.shell.PathData in project hadoop by apache.

the class TestAnd method testStopFirst.

// test the first expression stopping
@Test
public void testStopFirst() throws IOException {
    And and = new And();
    PathData pathData = mock(PathData.class);
    Expression first = mock(Expression.class);
    when(first.apply(pathData, -1)).thenReturn(Result.STOP);
    Expression second = mock(Expression.class);
    when(second.apply(pathData, -1)).thenReturn(Result.PASS);
    Deque<Expression> children = new LinkedList<Expression>();
    children.add(second);
    children.add(first);
    and.addChildren(children);
    assertEquals(Result.STOP, and.apply(pathData, -1));
    verify(first).apply(pathData, -1);
    verify(second).apply(pathData, -1);
    verifyNoMoreInteractions(first);
    verifyNoMoreInteractions(second);
}
Also used : PathData(org.apache.hadoop.fs.shell.PathData) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with PathData

use of org.apache.hadoop.fs.shell.PathData in project hadoop by apache.

the class TestFind method processArgumentsDepthFirstMaxDepth.

// check max depth is handled when -depth is specified
@Test
public void processArgumentsDepthFirstMaxDepth() throws IOException {
    LinkedList<PathData> items = createDirectories();
    Find find = new Find();
    find.getOptions().setDepthFirst(true);
    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(item1a, 1);
    inOrder.verify(expr).apply(item1b, 1);
    inOrder.verify(expr).apply(item1, 0);
    inOrder.verify(expr).apply(item2, 0);
    inOrder.verify(expr).apply(item3, 0);
    inOrder.verify(expr).apply(item4, 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).apply(item5, 0);
    inOrder.verify(expr).finish();
    verifyNoMoreInteractions(expr);
    InOrder inOrderFsCheck = inOrder(fsCheck);
    inOrderFsCheck.verify(fsCheck).check(item1a.stat);
    inOrderFsCheck.verify(fsCheck).check(item1b.stat);
    inOrderFsCheck.verify(fsCheck).check(item1.stat);
    inOrderFsCheck.verify(fsCheck).check(item2.stat);
    inOrderFsCheck.verify(fsCheck).check(item3.stat);
    inOrderFsCheck.verify(fsCheck).check(item4.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);
    inOrderFsCheck.verify(fsCheck).check(item5.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 23 with PathData

use of org.apache.hadoop.fs.shell.PathData in project hadoop by apache.

the class TestFind method processArgumentsMinDepth.

// check minimum depth is handledfollowLink
@Test
public void processArgumentsMinDepth() throws IOException {
    LinkedList<PathData> items = createDirectories();
    Find find = new Find();
    find.getOptions().setMinDepth(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(item1a, 1);
    inOrder.verify(expr).apply(item1aa, 2);
    inOrder.verify(expr).apply(item1b, 1);
    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(item1a.stat);
    inOrderFsCheck.verify(fsCheck).check(item1aa.stat);
    inOrderFsCheck.verify(fsCheck).check(item1b.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);
}
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 24 with PathData

use of org.apache.hadoop.fs.shell.PathData in project hadoop by apache.

the class TestFind method processArguments.

// check expressions are called in the correct order
@Test
public void processArguments() throws IOException {
    LinkedList<PathData> items = createDirectories();
    Find find = new Find();
    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).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(item5ca.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 25 with PathData

use of org.apache.hadoop.fs.shell.PathData in project hadoop by apache.

the class TestFind method processArgumentsDepthFirst.

// check that directories are descended correctly when -depth is specified
@Test
public void processArgumentsDepthFirst() throws IOException {
    LinkedList<PathData> items = createDirectories();
    Find find = new Find();
    find.getOptions().setDepthFirst(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(item1aa, 2);
    inOrder.verify(expr).apply(item1a, 1);
    inOrder.verify(expr).apply(item1b, 1);
    inOrder.verify(expr).apply(item1, 0);
    inOrder.verify(expr).apply(item2, 0);
    inOrder.verify(expr).apply(item3, 0);
    inOrder.verify(expr).apply(item4, 0);
    inOrder.verify(expr).apply(item5a, 1);
    inOrder.verify(expr).apply(item5b, 1);
    inOrder.verify(expr).apply(item5ca, 2);
    inOrder.verify(expr).apply(item5c, 1);
    inOrder.verify(expr).apply(item5d, 1);
    inOrder.verify(expr).apply(item5e, 1);
    inOrder.verify(expr).apply(item5, 0);
    inOrder.verify(expr).finish();
    verifyNoMoreInteractions(expr);
    InOrder inOrderFsCheck = inOrder(fsCheck);
    inOrderFsCheck.verify(fsCheck).check(item1aa.stat);
    inOrderFsCheck.verify(fsCheck).check(item1a.stat);
    inOrderFsCheck.verify(fsCheck).check(item1b.stat);
    inOrderFsCheck.verify(fsCheck).check(item1.stat);
    inOrderFsCheck.verify(fsCheck).check(item2.stat);
    inOrderFsCheck.verify(fsCheck).check(item3.stat);
    inOrderFsCheck.verify(fsCheck).check(item4.stat);
    inOrderFsCheck.verify(fsCheck).check(item5a.stat);
    inOrderFsCheck.verify(fsCheck).check(item5b.stat);
    inOrderFsCheck.verify(fsCheck).check(item5ca.stat);
    inOrderFsCheck.verify(fsCheck).check(item5c.stat);
    inOrderFsCheck.verify(fsCheck).check(item5d.stat);
    inOrderFsCheck.verify(fsCheck).check(item5e.stat);
    inOrderFsCheck.verify(fsCheck).check(item5.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)

Aggregations

PathData (org.apache.hadoop.fs.shell.PathData)32 Test (org.junit.Test)31 PrintStream (java.io.PrintStream)11 BaseExpression (org.apache.hadoop.fs.shell.find.BaseExpression)9 Expression (org.apache.hadoop.fs.shell.find.Expression)9 Find (org.apache.hadoop.fs.shell.find.Find)9 InOrder (org.mockito.InOrder)9 LinkedList (java.util.LinkedList)7 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1