public virtual void SetUp()
 {
     fileContextTestHelper = GetFileContextHelper();
     fc = GetFileContext();
     fc.Mkdir(fileContextTestHelper.GetTestRootPath(fc), FileContext.DefaultPerm, true
              );
 }
Пример #2
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));
        }
        public virtual void TestSetPermission()
        {
            if (Path.Windows)
            {
                System.Console.Out.WriteLine("Cannot run test for Windows");
                return;
            }
            string filename = "foo";
            Path   f        = fileContextTestHelper.GetTestRootPath(fc, filename);

            FileContextTestHelper.CreateFile(fc, f);
            try
            {
                // create files and manipulate them.
                FsPermission all  = new FsPermission((short)0x1ff);
                FsPermission none = new FsPermission((short)0);
                fc.SetPermission(f, none);
                DoFilePermissionCheck(none, fc.GetFileStatus(f).GetPermission());
                fc.SetPermission(f, all);
                DoFilePermissionCheck(all, fc.GetFileStatus(f).GetPermission());
            }
            finally
            {
                CleanupFile(fc, f);
            }
        }
Пример #4
0
        public virtual void TestStatistics()
        {
            URI fsUri = GetFsUri();

            FileSystem.Statistics stats = FileContext.GetStatistics(fsUri);
            Assert.Equal(0, stats.GetBytesRead());
            Path filePath = fileContextTestHelper.GetTestRootPath(fc, "file1");

            FileContextTestHelper.CreateFile(fc, filePath, numBlocks, blockSize);
            Assert.Equal(0, stats.GetBytesRead());
            VerifyWrittenBytes(stats);
            FSDataInputStream fstr = fc.Open(filePath);

            byte[] buf       = new byte[blockSize];
            int    bytesRead = fstr.Read(buf, 0, blockSize);

            fstr.Read(0, buf, 0, blockSize);
            Assert.Equal(blockSize, bytesRead);
            VerifyReadBytes(stats);
            VerifyWrittenBytes(stats);
            VerifyReadBytes(FileContext.GetStatistics(GetFsUri()));
            IDictionary <URI, FileSystem.Statistics> statsMap = FileContext.GetAllStatistics();
            URI exactUri = GetSchemeAuthorityUri();

            VerifyWrittenBytes(statsMap[exactUri]);
            fc.Delete(filePath, true);
        }
Пример #5
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));
        }
Пример #6
0
        public virtual void TestMkdirNonRecursiveWithExistingDir()
        {
            Path f = GetTestRootPath(fc, "aDir");

            fc.Mkdir(f, FileContext.DefaultPerm, false);
            Assert.True(FileContextTestHelper.IsDir(fc, f));
        }
Пример #7
0
        public virtual void TestCreateRecursiveWithNonExistingDir()
        {
            Path f = GetTestRootPath(fc, "NonExisting/foo");

            FileContextTestHelper.CreateFile(fc, f);
            Assert.True(FileContextTestHelper.IsFile(fc, f));
        }
Пример #8
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));
            }
        }
Пример #9
0
        public virtual void TestDefaultFilePermission()
        {
            Path file = fileContextTestHelper.GetTestRootPath(fc, "testDefaultFilePermission"
                                                              );

            FileContextTestHelper.CreateFile(fc, file);
            FsPermission expect = FileContext.FileDefaultPerm.ApplyUMask(fc.GetUMask());

            Assert.Equal(expect, fc.GetFileStatus(file).GetPermission());
        }
Пример #10
0
        /// <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());
        }
Пример #11
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());
        }
Пример #12
0
 public virtual void TestCreateNonRecursiveWithNonExistingDir()
 {
     try
     {
         FileContextTestHelper.CreateFileNonRecursive(fc, GetTestRootPath(fc, "NonExisting/foo"
                                                                          ));
         NUnit.Framework.Assert.Fail("Create with non existing parent dir should have failed"
                                     );
     }
     catch (IOException)
     {
     }
 }
Пример #13
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));
        }
Пример #14
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));
        }
Пример #15
0
        public virtual void TestModificationTime()
        {
            string testFile = "file1";
            long   fc2ModificationTime;
            long   fc1ModificationTime;
            Path   testPath = QualifiedPath(testFile, fc2);

            // Create a file on fc2's file system using fc1
            FileContextTestHelper.CreateFile(fc1, testPath);
            // Get modification time using fc2 and fc1
            fc1ModificationTime = fc1.GetFileStatus(testPath).GetModificationTime();
            fc2ModificationTime = fc2.GetFileStatus(testPath).GetModificationTime();
            // Ensure fc1 and fc2 reports same modification time
            Assert.Equal(fc1ModificationTime, fc2ModificationTime);
        }
Пример #16
0
        public virtual void TestFileStatus()
        {
            string fileName = "file1";
            Path   path2    = fc2.MakeQualified(new Path(Base, fileName));

            // Create a file on fc2's file system using fc1
            FileContextTestHelper.CreateFile(fc1, path2);
            FsStatus fc2Status = fc2.GetFsStatus(path2);

            // FsStatus , used, free and capacity are non-negative longs
            NUnit.Framework.Assert.IsNotNull(fc2Status);
            Assert.True(fc2Status.GetCapacity() > 0);
            Assert.True(fc2Status.GetRemaining() > 0);
            Assert.True(fc2Status.GetUsed() > 0);
        }
Пример #17
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());
        }
Пример #18
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));
 }
Пример #19
0
        public virtual void TestFcCopy()
        {
            string ts    = "some random text";
            Path   file1 = fileContextTestHelper.GetTestRootPath(fc, "file1");
            Path   file2 = fileContextTestHelper.GetTestRootPath(fc, "file2");

            FileContextTestHelper.WriteFile(fc, file1, Runtime.GetBytesForString(ts));
            Assert.True(fc.Util().Exists(file1));
            fc.Util().Copy(file1, file2);
            // verify that newly copied file2 exists
            Assert.True("Failed to copy file2  ", fc.Util().Exists(file2));
            // verify that file2 contains test string
            Assert.True("Copied files does not match ", Arrays.Equals(Runtime.GetBytesForString
                                                                          (ts), FileContextTestHelper.ReadFile(fc, file2, Runtime.GetBytesForString
                                                                                                                   (ts).Length)));
        }
Пример #20
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));
        }
 /// <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));
        }
Пример #23
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)
            {
            }
        }
Пример #24
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));
     }
 }
Пример #25
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));
        }
Пример #26
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));
            }
        }
Пример #27
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));
        }
Пример #28
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));
        }
Пример #29
0
        /// <exception cref="System.Exception"/>
        public virtual void TestSymlinkHdfsDisable()
        {
            Configuration conf = new HdfsConfiguration();

            // disable symlink resolution
            conf.SetBoolean(CommonConfigurationKeys.FsClientResolveRemoteSymlinksKey, false);
            // spin up minicluster, get dfs and filecontext
            MiniDFSCluster        cluster = new MiniDFSCluster.Builder(conf).Build();
            DistributedFileSystem dfs     = cluster.GetFileSystem();
            FileContext           fc      = FileContext.GetFileContext(cluster.GetURI(0), conf);
            // Create test files/links
            FileContextTestHelper helper = new FileContextTestHelper("/tmp/TestSymlinkHdfsDisable"
                                                                     );
            Path root   = helper.GetTestRootPath(fc);
            Path target = new Path(root, "target");
            Path link   = new Path(root, "link");

            DFSTestUtil.CreateFile(dfs, target, 4096, (short)1, unchecked ((int)(0xDEADDEAD)));
            fc.CreateSymlink(target, link, false);
            // Try to resolve links with FileSystem and FileContext
            try
            {
                fc.Open(link);
                NUnit.Framework.Assert.Fail("Expected error when attempting to resolve link");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("resolution is disabled", e);
            }
            try
            {
                dfs.Open(link);
                NUnit.Framework.Assert.Fail("Expected error when attempting to resolve link");
            }
            catch (IOException e)
            {
                GenericTestUtils.AssertExceptionContains("resolution is disabled", e);
            }
        }
Пример #30
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));
        }