Beispiel #1
0
        public virtual void TestMkdirNonRecursiveWithExistingDir()
        {
            Path f = GetTestRootPath(fc, "aDir");

            fc.Mkdir(f, FileContext.DefaultPerm, false);
            Assert.True(FileContextTestHelper.IsDir(fc, f));
        }
Beispiel #2
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));
            }
        }
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestMkdirWithExistingDir(FsPermission umask, FsPermission expectedPerms
                                                     )
        {
            Path f = fileContextTestHelper.GetTestRootPath(fc, "aDir");

            fc.SetUMask(umask);
            fc.Mkdir(f, FileContext.DefaultPerm, true);
            NUnit.Framework.Assert.IsTrue(FileContextTestHelper.IsDir(fc, f));
            NUnit.Framework.Assert.AreEqual("permissions on directory are wrong", expectedPerms
                                            , fc.GetFileStatus(f).GetPermission());
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public virtual void TestIsDirectory()
        {
            string dirName         = "dirTest";
            string invalidDir      = "nonExistantDir";
            string rootDir         = "/";
            Path   existingPath    = QualifiedPath(dirName, fc2);
            Path   nonExistingPath = QualifiedPath(invalidDir, fc2);
            Path   pathToRootDir   = QualifiedPath(rootDir, fc2);

            // Create a directory on fc2's file system using fc1
            fc1.Mkdir(existingPath, FsPermission.GetDefault(), true);
            // Ensure fc2 has directory
            Assert.True(FileContextTestHelper.IsDir(fc2, existingPath));
            Assert.True(FileContextTestHelper.IsDir(fc2, pathToRootDir));
            // Negative test case
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.IsDir(fc2, nonExistingPath));
        }
Beispiel #6
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));
            }
        }