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

            FileContextTestHelper.CreateFile(fc, f);
            Assert.True(FileContextTestHelper.IsFile(fc, f));
        }
        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);
            }
        }
        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);
        }
Exemple #4
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));
        }
Exemple #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));
        }
Exemple #6
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());
        }
        /// <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());
        }
        public virtual void TestCreatePermission()
        {
            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, filename);
            DoFilePermissionCheck(FileContext.FileDefaultPerm.ApplyUMask(fc.GetUMask()), fc.GetFileStatus
                                      (f).GetPermission());
        }
Exemple #9
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);
        }
Exemple #10
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));
        }
Exemple #11
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());
        }
Exemple #13
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);
        }
Exemple #14
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)
            {
            }
        }
Exemple #15
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));
     }
 }
Exemple #16
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));
        }
Exemple #17
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));
        }
        public virtual void TestSetOwner()
        {
            if (Path.Windows)
            {
                System.Console.Out.WriteLine("Cannot run test for Windows");
                return;
            }
            string filename = "bar";
            Path   f        = fileContextTestHelper.GetTestRootPath(fc, filename);

            FileContextTestHelper.CreateFile(fc, f);
            IList <string> groups = null;

            try
            {
                groups = GetGroups();
                System.Console.Out.WriteLine(filename + ": " + fc.GetFileStatus(f).GetPermission(
                                                 ));
            }
            catch (IOException e)
            {
                System.Console.Out.WriteLine(StringUtils.StringifyException(e));
                System.Console.Out.WriteLine("Cannot run test");
                return;
            }
            if (groups == null || groups.Count < 1)
            {
                System.Console.Out.WriteLine("Cannot run test: need at least one group.  groups="
                                             + groups);
                return;
            }
            // create files and manipulate them.
            try
            {
                string g0 = groups[0];
                fc.SetOwner(f, null, g0);
                Assert.Equal(g0, fc.GetFileStatus(f).GetGroup());
                if (groups.Count > 1)
                {
                    string g1 = groups[1];
                    fc.SetOwner(f, null, g1);
                    Assert.Equal(g1, fc.GetFileStatus(f).GetGroup());
                }
                else
                {
                    System.Console.Out.WriteLine("Not testing changing the group since user " + "belongs to only one group."
                                                 );
                }
                try
                {
                    fc.SetOwner(f, null, null);
                    NUnit.Framework.Assert.Fail("Exception expected.");
                }
                catch (ArgumentException)
                {
                }
            }
            finally
            {
                // okay
                CleanupFile(fc, f);
            }
        }