/// <exception cref="System.Exception"/>
        public virtual void TestRmWithNonexistentGlob()
        {
            Configuration conf  = new Configuration();
            FsShell       shell = new FsShell();

            shell.SetConf(conf);
            ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
            TextWriter            err    = new TextWriter(bytes);
            TextWriter            oldErr = System.Console.Error;

            Runtime.SetErr(err);
            string results;

            try
            {
                int exit = shell.Run(new string[] { "-rm", "nomatch*" });
                Assert.Equal(1, exit);
                results = bytes.ToString();
                Assert.True(results.Contains("rm: `nomatch*': No such file or directory"
                                             ));
            }
            finally
            {
                IOUtils.CloseStream(err);
                Runtime.SetErr(oldErr);
            }
        }
        /// <exception cref="System.IO.IOException"/>
        internal static void Setrep(int fromREP, int toREP, bool simulatedStorage)
        {
            Configuration conf = new HdfsConfiguration();

            if (simulatedStorage)
            {
                SimulatedFSDataset.SetFactory(conf);
            }
            conf.Set(DFSConfigKeys.DfsReplicationKey, string.Empty + fromREP);
            conf.SetLong(DFSConfigKeys.DfsBlockreportIntervalMsecKey, 1000L);
            conf.Set(DFSConfigKeys.DfsNamenodeReplicationPendingTimeoutSecKey, Sharpen.Extensions.ToString
                         (2));
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(10).Build(
                );
            FileSystem fs = cluster.GetFileSystem();

            NUnit.Framework.Assert.IsTrue("Not a HDFS: " + fs.GetUri(), fs is DistributedFileSystem
                                          );
            try
            {
                Path root = TestDFSShell.Mkdir(fs, new Path("/test/setrep" + fromREP + "-" + toREP
                                                            ));
                Path f = TestDFSShell.WriteFile(fs, new Path(root, "foo"));
                {
                    // Verify setrep for changing replication
                    string[] args = new string[] { "-setrep", "-w", string.Empty + toREP, string.Empty
                                                   + f };
                    FsShell shell = new FsShell();
                    shell.SetConf(conf);
                    try
                    {
                        NUnit.Framework.Assert.AreEqual(0, shell.Run(args));
                    }
                    catch (Exception e)
                    {
                        NUnit.Framework.Assert.IsTrue("-setrep " + e, false);
                    }
                }
                //get fs again since the old one may be closed
                fs = cluster.GetFileSystem();
                FileStatus file = fs.GetFileStatus(f);
                long       len  = file.GetLen();
                foreach (BlockLocation locations in fs.GetFileBlockLocations(file, 0, len))
                {
                    NUnit.Framework.Assert.IsTrue(locations.GetHosts().Length == toREP);
                }
                TestDFSShell.Show("done setrep waiting: " + root);
            }
            finally
            {
                try
                {
                    fs.Close();
                }
                catch (Exception)
                {
                }
                cluster.Shutdown();
            }
        }
Beispiel #3
0
        public virtual void TestRenameSnapshotCommandWithIllegalArguments()
        {
            ByteArrayOutputStream @out  = new ByteArrayOutputStream();
            TextWriter            psOut = new TextWriter(@out);

            Runtime.SetOut(psOut);
            Runtime.SetErr(psOut);
            FsShell shell = new FsShell();

            shell.SetConf(conf);
            string[] argv1 = new string[] { "-renameSnapshot", "/tmp", "s1" };
            int      val   = shell.Run(argv1);

            NUnit.Framework.Assert.IsTrue(val == -1);
            NUnit.Framework.Assert.IsTrue(@out.ToString().Contains(argv1[0] + ": Incorrect number of arguments."
                                                                   ));
            @out.Reset();
            string[] argv2 = new string[] { "-renameSnapshot", "/tmp", "s1", "s2", "s3" };
            val = shell.Run(argv2);
            NUnit.Framework.Assert.IsTrue(val == -1);
            NUnit.Framework.Assert.IsTrue(@out.ToString().Contains(argv2[0] + ": Incorrect number of arguments."
                                                                   ));
            psOut.Close();
            @out.Close();
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidDefaultFS()
        {
            // if default fs doesn't exist or is invalid, but the path provided in
            // arguments is valid - fsshell should work
            FsShell       shell = new FsShell();
            Configuration conf  = new Configuration();

            conf.Set(CommonConfigurationKeysPublic.FsDefaultNameKey, "hhhh://doesnotexist/");
            shell.SetConf(conf);
            string[] args = new string[2];
            args[0] = "-ls";
            args[1] = "file:///";
            // this is valid, so command should run
            int res = shell.Run(args);

            System.Console.Out.WriteLine("res =" + res);
            shell.SetConf(conf);
            ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
            TextWriter            @out   = new TextWriter(bytes);
            TextWriter            oldErr = System.Console.Error;

            Runtime.SetErr(@out);
            string results;

            try
            {
                int run = shell.Run(args);
                results = bytes.ToString();
                Log.Info("result=" + results);
                Assert.True("Return code should be 0", run == 0);
            }
            finally
            {
                IOUtils.CloseStream(@out);
                Runtime.SetErr(oldErr);
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestGetWithInvalidSourcePathShouldNotDisplayNullInConsole()
        {
            Configuration conf  = new Configuration();
            FsShell       shell = new FsShell();

            shell.SetConf(conf);
            ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
            TextWriter            @out   = new TextWriter(bytes);
            TextWriter            oldErr = System.Console.Error;

            Runtime.SetErr(@out);
            string results;

            try
            {
                Path tdir = new Path(TestRootDir, "notNullCopy");
                fileSys.Delete(tdir, true);
                fileSys.Mkdirs(tdir);
                string[] args = new string[3];
                args[0] = "-get";
                args[1] = new Path(tdir.ToUri().GetPath(), "/invalidSrc").ToString();
                args[2] = new Path(tdir.ToUri().GetPath(), "/invalidDst").ToString();
                Assert.True("file exists", !fileSys.Exists(new Path(args[1])));
                Assert.True("file exists", !fileSys.Exists(new Path(args[2])));
                int run = shell.Run(args);
                results = bytes.ToString();
                Assert.Equal("Return code should be 1", 1, run);
                Assert.True(" Null is coming when source path is invalid. ", !results
                            .Contains("get: null"));
                Assert.True(" Not displaying the intended message ", results.Contains
                                ("get: `" + args[1] + "': No such file or directory"));
            }
            finally
            {
                IOUtils.CloseStream(@out);
                Runtime.SetErr(oldErr);
            }
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestRmForceWithNonexistentGlob()
        {
            Configuration conf  = new Configuration();
            FsShell       shell = new FsShell();

            shell.SetConf(conf);
            ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
            TextWriter            err    = new TextWriter(bytes);
            TextWriter            oldErr = System.Console.Error;

            Runtime.SetErr(err);
            try
            {
                int exit = shell.Run(new string[] { "-rm", "-f", "nomatch*" });
                Assert.Equal(0, exit);
                Assert.True(bytes.ToString().IsEmpty());
            }
            finally
            {
                IOUtils.CloseStream(err);
                Runtime.SetErr(oldErr);
            }
        }