Esempio n. 1
0
        public virtual void TestCreateRecursiveWithNonExistingDir()
        {
            Path f = GetTestRootPath(fc, "NonExisting/foo");

            FileContextTestHelper.CreateFile(fc, f);
            Assert.True(FileContextTestHelper.IsFile(fc, f));
        }
Esempio n. 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));
            }
        }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestCreateRecursiveWithExistingDir(FsPermission umask, FsPermission
                                                               expectedPerms)
        {
            Path f = fileContextTestHelper.GetTestRootPath(fc, "foo");

            fc.SetUMask(umask);
            FileContextTestHelper.CreateFile(fc, f);
            NUnit.Framework.Assert.IsTrue(FileContextTestHelper.IsFile(fc, f));
            NUnit.Framework.Assert.AreEqual("permissions on file are wrong", expectedPerms, fc
                                            .GetFileStatus(f).GetPermission());
        }
Esempio n. 4
0
        /// <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());
        }