Beispiel #1
0
        // check maximum depth is handled
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessArgumentsMaxDepth()
        {
            List <PathData> items = CreateDirectories();

            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.GetOptions().SetMaxDepth(1);
            find.SetConf(conf);
            TextWriter @out = Org.Mockito.Mockito.Mock <TextWriter>();

            find.GetOptions().SetOut(@out);
            TextWriter err = Org.Mockito.Mockito.Mock <TextWriter>();

            find.GetOptions().SetErr(err);
            Expression expr = Org.Mockito.Mockito.Mock <Expression>();

            Org.Mockito.Mockito.When(expr.Apply((PathData)Matchers.Any(), Matchers.AnyInt()))
            .ThenReturn(Result.Pass);
            TestFind.FileStatusChecker fsCheck = Org.Mockito.Mockito.Mock <TestFind.FileStatusChecker
                                                                           >();
            Expression test = new TestFind.TestExpression(this, expr, fsCheck);

            find.SetRootExpression(test);
            find.ProcessArguments(items);
            InOrder inOrder = Org.Mockito.Mockito.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();
            Org.Mockito.Mockito.VerifyNoMoreInteractions(expr);
            InOrder inOrderFsCheck = Org.Mockito.Mockito.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);
            Org.Mockito.Mockito.VerifyNoMoreInteractions(fsCheck);
            Org.Mockito.Mockito.VerifyNoMoreInteractions(@out);
            Org.Mockito.Mockito.VerifyNoMoreInteractions(err);
        }
Beispiel #2
0
        // check no path defaults to current working directory
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessOptionsNoPath()
        {
            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.SetConf(conf);
            string        args     = "-print";
            List <string> argsList = GetArgs(args);

            find.ProcessOptions(argsList);
            Assert.Equal(Collections.SingletonList(Path.CurDir), argsList
                         );
        }
Beispiel #3
0
        // check print is used as the default expression
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessOptionsNoExpression()
        {
            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.SetConf(conf);
            string args     = "path";
            string expected = "Print(;)";

            find.ProcessOptions(GetArgs(args));
            Expression expression = find.GetRootExpression();

            Assert.Equal(expected, expression.ToString());
        }
Beispiel #4
0
        // check -and is handled correctly
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessOptionsAnd()
        {
            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.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();

            Assert.Equal(expected, expression.ToString());
        }
Beispiel #5
0
        // check options and expressions are stripped from args leaving paths
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessOptionsExpression()
        {
            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.SetConf(conf);
            string        paths    = "path1 path2 path3";
            string        args     = "-L -H " + paths + " -print -name test";
            List <string> argsList = GetArgs(args);

            find.ProcessOptions(argsList);
            List <string> pathList = GetArgs(paths);

            Assert.Equal(pathList, argsList);
        }
Beispiel #6
0
        // check unknown options are rejected when mixed with known options
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessOptionsKnownUnknown()
        {
            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.SetConf(conf);
            string args = "path -print -unknown -print";

            try
            {
                find.ProcessOptions(GetArgs(args));
                NUnit.Framework.Assert.Fail("Unknown expression not caught");
            }
            catch (IOException)
            {
            }
        }
Beispiel #7
0
        // check symlinks given as path arguments are processed correctly with the
        // follow option
        /// <exception cref="System.IO.IOException"/>
        public virtual void ProcessArgumentsOptionFollow()
        {
            List <PathData> items = CreateDirectories();

            Org.Apache.Hadoop.FS.Shell.Find.Find find = new Org.Apache.Hadoop.FS.Shell.Find.Find
                                                            ();
            find.GetOptions().SetFollowLink(true);
            find.SetConf(conf);
            TextWriter @out = Org.Mockito.Mockito.Mock <TextWriter>();

            find.GetOptions().SetOut(@out);
            TextWriter err = Org.Mockito.Mockito.Mock <TextWriter>();

            find.GetOptions().SetErr(err);
            Expression expr = Org.Mockito.Mockito.Mock <Expression>();

            Org.Mockito.Mockito.When(expr.Apply((PathData)Matchers.Any(), Matchers.AnyInt()))
            .ThenReturn(Result.Pass);
            TestFind.FileStatusChecker fsCheck = Org.Mockito.Mockito.Mock <TestFind.FileStatusChecker
                                                                           >();
            Expression test = new TestFind.TestExpression(this, expr, fsCheck);

            find.SetRootExpression(test);
            find.ProcessArguments(items);
            InOrder inOrder = Org.Mockito.Mockito.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);
            // triggers infinite loop message
            inOrder.Verify(expr).Apply(item5c, 1);
            inOrder.Verify(expr).Apply(item5ca, 2);
            inOrder.Verify(expr).Apply(item5d, 1);
            inOrder.Verify(expr).Apply(item5ca, 2);
            // following item5d symlink
            inOrder.Verify(expr).Apply(item5e, 1);
            inOrder.Verify(expr).Finish();
            Org.Mockito.Mockito.VerifyNoMoreInteractions(expr);
            InOrder inOrderFsCheck = Org.Mockito.Mockito.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, Org.Mockito.Mockito.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, Org.Mockito.Mockito.Times(2)).Check(item5ca.stat);
            Org.Mockito.Mockito.VerifyNoMoreInteractions(fsCheck);
            Org.Mockito.Mockito.VerifyNoMoreInteractions(@out);
            Org.Mockito.Mockito.Verify(err).WriteLine("Infinite loop ignored: " + item5b.ToString
                                                          () + " -> " + item5.ToString());
            Org.Mockito.Mockito.VerifyNoMoreInteractions(err);
        }