Esempio n. 1
0
        public virtual void TestListStatus()
        {
            string hPrefix = "test/hadoop";

            string[] dirs = new string[] { hPrefix + "/a", hPrefix + "/b", hPrefix + "/c", hPrefix
                                           + "/1", hPrefix + "/#@#@", hPrefix + "/&*#$#$@234" };
            AList <Path> testDirs = new AList <Path>();

            foreach (string d in dirs)
            {
                if (!IsTestableFileNameOnPlatform(d))
                {
                    continue;
                }
                testDirs.AddItem(QualifiedPath(d, fc2));
            }
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc1, testDirs[0]));
            foreach (Path path in testDirs)
            {
                fc1.Mkdir(path, FsPermission.GetDefault(), true);
            }
            // test listStatus that returns an array of FileStatus
            FileStatus[] paths = fc1.Util().ListStatus(QualifiedPath("test", fc1));
            Assert.Equal(1, paths.Length);
            Assert.Equal(QualifiedPath(hPrefix, fc1), paths[0].GetPath());
            paths = fc1.Util().ListStatus(QualifiedPath(hPrefix, fc1));
            Assert.Equal(testDirs.Count, paths.Length);
            for (int i = 0; i < testDirs.Count; i++)
            {
                bool found = false;
                for (int j = 0; j < paths.Length; j++)
                {
                    if (QualifiedPath(testDirs[i].ToString(), fc1).Equals(paths[j].GetPath()))
                    {
                        found = true;
                    }
                }
                Assert.True(testDirs[i] + " not found", found);
            }
            paths = fc1.Util().ListStatus(QualifiedPath(dirs[0], fc1));
            Assert.Equal(0, paths.Length);
            // test listStatus that returns an iterator of FileStatus
            RemoteIterator <FileStatus> pathsItor = fc1.ListStatus(QualifiedPath("test", fc1));

            Assert.Equal(QualifiedPath(hPrefix, fc1), pathsItor.Next().GetPath
                             ());
            NUnit.Framework.Assert.IsFalse(pathsItor.HasNext());
            pathsItor = fc1.ListStatus(QualifiedPath(hPrefix, fc1));
            int dirLen = 0;

            for (; pathsItor.HasNext(); dirLen++)
            {
                bool       found = false;
                FileStatus stat  = pathsItor.Next();
                for (int j = 0; j < dirs.Length; j++)
                {
                    if (QualifiedPath(dirs[j], fc1).Equals(stat.GetPath()))
                    {
                        found = true;
                        break;
                    }
                }
                Assert.True(stat.GetPath() + " not found", found);
            }
            Assert.Equal(testDirs.Count, dirLen);
            pathsItor = fc1.ListStatus(QualifiedPath(dirs[0], fc1));
            NUnit.Framework.Assert.IsFalse(pathsItor.HasNext());
        }