示例#1
0
        public virtual void TestDirectory()
        {
            fs.Mkdirs(Dir1);
            // test empty directory
            RemoteIterator <LocatedFileStatus> itor = fs.ListFiles(Dir1, true);

            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            itor = fs.ListFiles(Dir1, false);
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            // testing directory with 1 file
            WriteFile(fs, File2, FileLen);
            itor = fs.ListFiles(Dir1, true);
            LocatedFileStatus stat = itor.Next();

            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            Assert.True(stat.IsFile());
            Assert.Equal(FileLen, stat.GetLen());
            Assert.Equal(fs.MakeQualified(File2), stat.GetPath());
            Assert.Equal(1, stat.GetBlockLocations().Length);
            itor = fs.ListFiles(Dir1, false);
            stat = itor.Next();
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            Assert.True(stat.IsFile());
            Assert.Equal(FileLen, stat.GetLen());
            Assert.Equal(fs.MakeQualified(File2), stat.GetPath());
            Assert.Equal(1, stat.GetBlockLocations().Length);
            // test more complicated directory
            WriteFile(fs, File1, FileLen);
            WriteFile(fs, File3, FileLen);
            ICollection <Path> filesToFind = new HashSet <Path>();

            filesToFind.AddItem(fs.MakeQualified(File1));
            filesToFind.AddItem(fs.MakeQualified(File2));
            filesToFind.AddItem(fs.MakeQualified(File3));
            itor = fs.ListFiles(TestDir, true);
            stat = itor.Next();
            Assert.True(stat.IsFile());
            Assert.True("Path " + stat.GetPath() + " unexpected", filesToFind
                        .Remove(stat.GetPath()));
            stat = itor.Next();
            Assert.True(stat.IsFile());
            Assert.True("Path " + stat.GetPath() + " unexpected", filesToFind
                        .Remove(stat.GetPath()));
            stat = itor.Next();
            Assert.True(stat.IsFile());
            Assert.True("Path " + stat.GetPath() + " unexpected", filesToFind
                        .Remove(stat.GetPath()));
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            Assert.True(filesToFind.IsEmpty());
            itor = fs.ListFiles(TestDir, false);
            stat = itor.Next();
            Assert.True(stat.IsFile());
            Assert.Equal(fs.MakeQualified(File1), stat.GetPath());
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            fs.Delete(TestDir, true);
        }
示例#2
0
        public virtual void TestFile()
        {
            fs.Mkdirs(TestDir);
            WriteFile(fs, File1, FileLen);
            RemoteIterator <LocatedFileStatus> itor = fs.ListFiles(File1, true);
            LocatedFileStatus stat = itor.Next();

            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            Assert.True(stat.IsFile());
            Assert.Equal(FileLen, stat.GetLen());
            Assert.Equal(fs.MakeQualified(File1), stat.GetPath());
            Assert.Equal(1, stat.GetBlockLocations().Length);
            itor = fs.ListFiles(File1, false);
            stat = itor.Next();
            NUnit.Framework.Assert.IsFalse(itor.HasNext());
            Assert.True(stat.IsFile());
            Assert.Equal(FileLen, stat.GetLen());
            Assert.Equal(fs.MakeQualified(File1), stat.GetPath());
            Assert.Equal(1, stat.GetBlockLocations().Length);
            fs.Delete(File1, true);
        }