Beispiel #1
0
        public virtual void TestMkdirsFailsForSubdirectoryOfExistingFile()
        {
            Path testDir = QualifiedPath("test/hadoop", fc2);

            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testDir));
            fc2.Mkdir(testDir, FsPermission.GetDefault(), true);
            Assert.True(FileContextTestHelper.Exists(fc2, testDir));
            // Create file on fc1 using fc2 context
            FileContextTestHelper.CreateFile(fc1, QualifiedPath("test/hadoop/file", fc2));
            Path testSubDir = QualifiedPath("test/hadoop/file/subdir", fc2);

            try
            {
                fc1.Mkdir(testSubDir, FsPermission.GetDefault(), true);
                NUnit.Framework.Assert.Fail("Should throw IOException.");
            }
            catch (IOException)
            {
            }
            // expected
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc1, testSubDir));
            Path testDeepSubDir = QualifiedPath("test/hadoop/file/deep/sub/dir", fc1);

            try
            {
                fc2.Mkdir(testDeepSubDir, FsPermission.GetDefault(), true);
                NUnit.Framework.Assert.Fail("Should throw IOException.");
            }
            catch (IOException)
            {
            }
            // expected
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc1, testDeepSubDir));
        }
Beispiel #2
0
        public virtual void TestDeleteOnExit()
        {
            // Create deleteOnExit entries
            Path file1 = helper.GetTestRootPath(fc, "file1");

            FileContextTestHelper.CreateFile(fc, file1, numBlocks, blockSize);
            fc.DeleteOnExit(file1);
            CheckDeleteOnExitData(1, fc, file1);
            // Ensure shutdown hook is added
            Assert.True(ShutdownHookManager.Get().HasShutdownHook(FileContext
                                                                  .Finalizer));
            Path file2 = helper.GetTestRootPath(fc, "dir1/file2");

            FileContextTestHelper.CreateFile(fc, file2, numBlocks, blockSize);
            fc.DeleteOnExit(file2);
            CheckDeleteOnExitData(1, fc, file1, file2);
            Path dir = helper.GetTestRootPath(fc, "dir3/dir4/dir5/dir6");

            FileContextTestHelper.CreateFile(fc, dir, numBlocks, blockSize);
            fc.DeleteOnExit(dir);
            CheckDeleteOnExitData(1, fc, file1, file2, dir);
            // trigger deleteOnExit and ensure the registered
            // paths are cleaned up
            FileContext.Finalizer.Run();
            CheckDeleteOnExitData(0, fc, new Path[0]);
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, file1));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, file2));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, dir));
        }
Beispiel #3
0
        public virtual void TestCreateDirectory()
        {
            Path path       = QualifiedPath("test/hadoop", fc2);
            Path falsePath  = QualifiedPath("path/doesnot.exist", fc2);
            Path subDirPath = QualifiedPath("dir0", fc2);

            // Ensure that testPath does not exist in fc1
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc1, path));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsFile(fc1, path));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsDir(fc1, path));
            // Create a directory on fc2's file system using fc1
            fc1.Mkdir(path, FsPermission.GetDefault(), true);
            // Ensure fc2 has directory
            Assert.True(FileContextTestHelper.IsDir(fc2, path));
            Assert.True(FileContextTestHelper.Exists(fc2, path));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsFile(fc2, path));
            // Test to create same dir twice, (HDFS mkdir is similar to mkdir -p )
            fc1.Mkdir(subDirPath, FsPermission.GetDefault(), true);
            // This should not throw exception
            fc1.Mkdir(subDirPath, FsPermission.GetDefault(), true);
            // Create Sub Dirs
            fc1.Mkdir(subDirPath, FsPermission.GetDefault(), true);
            // Check parent dir
            Path parentDir = path.GetParent();

            Assert.True(FileContextTestHelper.Exists(fc2, parentDir));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsFile(fc2, parentDir));
            // Check parent parent dir
            Path grandparentDir = parentDir.GetParent();

            Assert.True(FileContextTestHelper.Exists(fc2, grandparentDir));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsFile(fc2, grandparentDir));
            // Negative test cases
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, falsePath));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsDir(fc2, falsePath));
            // TestCase - Create multiple directories
            string[] dirNames = new string[] { "createTest/testDir", "createTest/test Dir", "deleteTest/test*Dir"
                                               , "deleteTest/test#Dir", "deleteTest/test1234", "deleteTest/test_DIr", "deleteTest/1234Test"
                                               , "deleteTest/test)Dir", "deleteTest/()&^%$#@!~_+}{><?", "  ", "^ " };
            foreach (string f in dirNames)
            {
                if (!IsTestableFileNameOnPlatform(f))
                {
                    continue;
                }
                // Create a file on fc2's file system using fc1
                Path testPath = QualifiedPath(f, fc2);
                // Ensure file does not exist
                NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
                // Now create directory
                fc1.Mkdir(testPath, FsPermission.GetDefault(), true);
                // Ensure fc2 has the created directory
                Assert.True(FileContextTestHelper.Exists(fc2, testPath));
                Assert.True(FileContextTestHelper.IsDir(fc2, testPath));
            }
        }
Beispiel #4
0
        public virtual void TestDeleteFile()
        {
            Path testPath = QualifiedPath("testFile", fc2);

            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // First create a file on file system using fc1
            FileContextTestHelper.CreateFile(fc1, testPath);
            // Ensure file exist
            Assert.True(FileContextTestHelper.Exists(fc2, testPath));
            // Delete file using fc2
            fc2.Delete(testPath, false);
            // Ensure fc2 does not have deleted file
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
        }
Beispiel #5
0
        public virtual void TestCreateFileInNonExistingDirectory()
        {
            string fileName = "testDir/testFile";
            Path   testPath = QualifiedPath(fileName, fc2);

            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Create a file on fc2's file system using fc1
            FileContextTestHelper.CreateFile(fc1, testPath);
            // Ensure using fc2 that file is created
            Assert.True(FileContextTestHelper.IsDir(fc2, testPath.GetParent
                                                        ()));
            Assert.Equal("testDir", testPath.GetParent().GetName());
            Assert.True(FileContextTestHelper.Exists(fc2, testPath));
        }
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestCreateRecursiveWithNonExistingDir(FsPermission umask, FsPermission
                                                                  expectedDirPerms, FsPermission expectedFilePerms)
        {
            Path f       = fileContextTestHelper.GetTestRootPath(fc, "NonExisting/foo");
            Path fParent = fileContextTestHelper.GetTestRootPath(fc, "NonExisting");

            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, fParent));
            fc.SetUMask(umask);
            FileContextTestHelper.CreateFile(fc, f);
            NUnit.Framework.Assert.IsTrue(FileContextTestHelper.IsFile(fc, f));
            NUnit.Framework.Assert.AreEqual("permissions on file are wrong", expectedFilePerms
                                            , fc.GetFileStatus(f).GetPermission());
            NUnit.Framework.Assert.AreEqual("permissions on parent directory are wrong", expectedDirPerms
                                            , fc.GetFileStatus(fParent).GetPermission());
        }
Beispiel #7
0
 /// <exception cref="System.IO.IOException"/>
 private void Rename(Path src, Path dst, bool exception, bool srcExists, bool dstExists
                     , params Options.Rename[] options)
 {
     try
     {
         fc.Rename(src, dst, options);
         NUnit.Framework.Assert.IsFalse("Expected exception is not thrown", exception);
     }
     catch (Exception e)
     {
         Log.Warn("Exception ", e);
         NUnit.Framework.Assert.IsTrue(exception);
     }
     NUnit.Framework.Assert.AreEqual(srcExists, FileContextTestHelper.Exists(fc, src));
     NUnit.Framework.Assert.AreEqual(dstExists, FileContextTestHelper.Exists(fc, dst));
 }
 /// <exception cref="System.Exception"/>
 private void Rename(Path src, Path dst, bool dstExists, bool renameSucceeds, bool
                     exception, params Options.Rename[] options)
 {
     try
     {
         fc.Rename(src, dst, options);
         NUnit.Framework.Assert.IsTrue(renameSucceeds);
     }
     catch (Exception)
     {
         NUnit.Framework.Assert.IsTrue(exception);
     }
     NUnit.Framework.Assert.AreEqual(renameSucceeds, !FileContextTestHelper.Exists(fc,
                                                                                   src));
     NUnit.Framework.Assert.AreEqual((dstExists || renameSucceeds), FileContextTestHelper.Exists
                                         (fc, dst));
 }
        /// <exception cref="System.Exception"/>
        private void OldRename(Path src, Path dst, bool renameSucceeds, bool exception)
        {
            DistributedFileSystem fs = cluster.GetFileSystem();

            try
            {
                NUnit.Framework.Assert.AreEqual(renameSucceeds, fs.Rename(src, dst));
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.IsTrue(exception);
            }
            NUnit.Framework.Assert.AreEqual(renameSucceeds, !FileContextTestHelper.Exists(fc,
                                                                                          src));
            NUnit.Framework.Assert.AreEqual(renameSucceeds, FileContextTestHelper.Exists(fc,
                                                                                         dst));
        }
Beispiel #10
0
        public virtual void TestCreateFileWithNullName()
        {
            string fileName = null;

            try
            {
                Path testPath = QualifiedPath(fileName, fc2);
                // Ensure file does not exist
                NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
                // Create a file on fc2's file system using fc1
                FileContextTestHelper.CreateFile(fc1, testPath);
                NUnit.Framework.Assert.Fail("Create file with null name should throw IllegalArgumentException."
                                            );
            }
            catch (ArgumentException)
            {
            }
        }
Beispiel #11
0
 public virtual void TestCreateFile()
 {
     string[] fileNames = new string[] { "testFile", "test File", "test*File", "test#File"
                                         , "test1234", "1234Test", "test)File", "test_File", "()&^%$#@!~_+}{><?", "  ", "^ " };
     foreach (string f in fileNames)
     {
         if (!IsTestableFileNameOnPlatform(f))
         {
             continue;
         }
         // Create a file on fc2's file system using fc1
         Path testPath = QualifiedPath(f, fc2);
         // Ensure file does not exist
         NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
         // Now create file
         FileContextTestHelper.CreateFile(fc1, testPath);
         // Ensure fc2 has the created file
         Assert.True(FileContextTestHelper.Exists(fc2, testPath));
     }
 }
Beispiel #12
0
        public virtual void TestDeletionOfDstFile()
        {
            Path src = GetTestPath("testDeletionOfDstFile/dir/src");
            Path dst = GetTestPath("testDeletionOfDstFile/newdir/dst");

            CreateFile(src);
            CreateFile(dst);
            FSNamesystem namesystem = cluster.GetNamesystem();
            long         blocks     = namesystem.GetBlocksTotal();
            long         fileCount  = namesystem.GetFilesTotal();

            Rename(src, dst, false, false, true, Options.Rename.Overwrite);
            // After successful rename the blocks corresponing dst are deleted
            NUnit.Framework.Assert.AreEqual(blocks - 1, namesystem.GetBlocksTotal());
            // After successful rename dst file is deleted
            NUnit.Framework.Assert.AreEqual(fileCount - 1, namesystem.GetFilesTotal());
            // Restart the cluster to ensure new rename operation
            // recorded in editlog is processed right
            RestartCluster(false);
            int  count     = 0;
            bool exception = true;

            src = GetTestPath("testDeletionOfDstFile/dir/src");
            dst = GetTestPath("testDeletionOfDstFile/newdir/dst");
            while (exception && count < 5)
            {
                try
                {
                    FileContextTestHelper.Exists(fc, src);
                    exception = false;
                }
                catch (Exception e)
                {
                    Log.Warn("Exception " + " count " + count + " " + e.Message);
                    Sharpen.Thread.Sleep(1000);
                    count++;
                }
            }
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, src));
            NUnit.Framework.Assert.IsTrue(FileContextTestHelper.Exists(fc, dst));
        }
Beispiel #13
0
        public virtual void TestDeleteDirectory()
        {
            string dirName     = "dirTest";
            Path   testDirPath = QualifiedPath(dirName, fc2);

            // Ensure directory does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testDirPath));
            // Create a directory on fc2's file system using fc1
            fc1.Mkdir(testDirPath, FsPermission.GetDefault(), true);
            // Ensure dir is created
            Assert.True(FileContextTestHelper.Exists(fc2, testDirPath));
            Assert.True(FileContextTestHelper.IsDir(fc2, testDirPath));
            fc2.Delete(testDirPath, true);
            // Ensure that directory is deleted
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsDir(fc2, testDirPath));
            // TestCase - Create and delete multiple directories
            string[] dirNames = new string[] { "deleteTest/testDir", "deleteTest/test Dir", "deleteTest/test*Dir"
                                               , "deleteTest/test#Dir", "deleteTest/test1234", "deleteTest/1234Test", "deleteTest/test)Dir"
                                               , "deleteTest/test_DIr", "deleteTest/()&^%$#@!~_+}{><?", "  ", "^ " };
            foreach (string f in dirNames)
            {
                if (!IsTestableFileNameOnPlatform(f))
                {
                    continue;
                }
                // Create a file on fc2's file system using fc1
                Path testPath = QualifiedPath(f, fc2);
                // Ensure file does not exist
                NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
                // Now create directory
                fc1.Mkdir(testPath, FsPermission.GetDefault(), true);
                // Ensure fc2 has the created directory
                Assert.True(FileContextTestHelper.Exists(fc2, testPath));
                Assert.True(FileContextTestHelper.IsDir(fc2, testPath));
                // Delete dir
                Assert.True(fc2.Delete(testPath, true));
                // verify if directory is deleted
                NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
                NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsDir(fc2, testPath));
            }
        }
Beispiel #14
0
        public virtual void TestDeleteNonExistingFileInDir()
        {
            string testFileInDir = "testDir/testDir/TestFile";
            Path   testPath      = QualifiedPath(testFileInDir, fc2);

            // TestCase1 : Test delete on file never existed
            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Delete on non existing file should return false
            NUnit.Framework.Assert.IsFalse(fc2.Delete(testPath, false));
            // TestCase2 : Create , Delete , Delete file
            // Create a file on fc2's file system using fc1
            FileContextTestHelper.CreateFile(fc1, testPath);
            // Ensure file exist
            Assert.True(FileContextTestHelper.Exists(fc2, testPath));
            // Delete test file, deleting existing file should return true
            Assert.True(fc2.Delete(testPath, false));
            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Delete on non existing file should return false
            NUnit.Framework.Assert.IsFalse(fc2.Delete(testPath, false));
        }
Beispiel #15
0
        public virtual void TestCreateExistingFile()
        {
            string fileName = "testFile";
            Path   testPath = QualifiedPath(fileName, fc2);

            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Create a file on fc2's file system using fc1
            FileContextTestHelper.CreateFile(fc1, testPath);
            // Create same file with fc1
            try
            {
                FileContextTestHelper.CreateFile(fc2, testPath);
                NUnit.Framework.Assert.Fail("Create existing file should throw an IOException.");
            }
            catch (IOException)
            {
            }
            // expected
            // Ensure fc2 has the created file
            Assert.True(FileContextTestHelper.Exists(fc2, testPath));
        }
Beispiel #16
0
        public virtual void TestDeleteNonExistingDirectory()
        {
            string testDirName = "testFile";
            Path   testPath    = QualifiedPath(testDirName, fc2);

            // TestCase1 : Test delete on directory never existed
            // Ensure directory does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Delete on non existing directory should return false
            NUnit.Framework.Assert.IsFalse(fc2.Delete(testPath, false));
            // TestCase2 : Create dir, Delete dir, Delete dir
            // Create a file on fc2's file system using fc1
            fc1.Mkdir(testPath, FsPermission.GetDefault(), true);
            // Ensure dir exist
            Assert.True(FileContextTestHelper.Exists(fc2, testPath));
            // Delete test file, deleting existing file should return true
            Assert.True(fc2.Delete(testPath, false));
            // Ensure file does not exist
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc2, testPath));
            // Delete on non existing file should return false
            NUnit.Framework.Assert.IsFalse(fc2.Delete(testPath, false));
        }
Beispiel #17
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());
        }
 /// <exception cref="System.IO.IOException"/>
 private void CleanupFile(FileContext fc, Path name)
 {
     Assert.True(FileContextTestHelper.Exists(fc, name));
     fc.Delete(name, true);
     Assert.True(!FileContextTestHelper.Exists(fc, name));
 }