Beispiel #1
0
        public virtual void TestWorkingDirectory()
        {
            // First we cd to our test root
            fc.Mkdir(new Path("/testWd"), FileContext.DefaultPerm, false);
            Path workDir = new Path("/testWd");
            Path fqWd    = fc.MakeQualified(workDir);

            fc.SetWorkingDirectory(workDir);
            Assert.Equal(fqWd, fc.GetWorkingDirectory());
            fc.SetWorkingDirectory(new Path("."));
            Assert.Equal(fqWd, fc.GetWorkingDirectory());
            fc.SetWorkingDirectory(new Path(".."));
            Assert.Equal(fqWd.GetParent(), fc.GetWorkingDirectory());
            // cd using a relative path
            // Go back to our test root
            workDir = new Path("/testWd");
            fqWd    = fc.MakeQualified(workDir);
            fc.SetWorkingDirectory(workDir);
            Assert.Equal(fqWd, fc.GetWorkingDirectory());
            Path relativeDir = new Path("existingDir1");
            Path absoluteDir = new Path(workDir, "existingDir1");

            fc.Mkdir(absoluteDir, FileContext.DefaultPerm, true);
            Path fqAbsoluteDir = fc.MakeQualified(absoluteDir);

            fc.SetWorkingDirectory(relativeDir);
            Assert.Equal(fqAbsoluteDir, fc.GetWorkingDirectory());
            // cd using a absolute path
            absoluteDir   = new Path("/test/existingDir2");
            fqAbsoluteDir = fc.MakeQualified(absoluteDir);
            fc.Mkdir(absoluteDir, FileContext.DefaultPerm, true);
            fc.SetWorkingDirectory(absoluteDir);
            Assert.Equal(fqAbsoluteDir, fc.GetWorkingDirectory());
            // Now open a file relative to the wd we just set above.
            Path absolutePath = new Path(absoluteDir, "foo");

            fc.Create(absolutePath, EnumSet.Of(CreateFlag.Create)).Close();
            fc.Open(new Path("foo")).Close();
            // Now mkdir relative to the dir we cd'ed to
            fc.Mkdir(new Path("newDir"), FileContext.DefaultPerm, true);
            Assert.True(FileContextTestHelper.IsDir(fc, new Path(absoluteDir
                                                                 , "newDir")));
            absoluteDir = fileContextTestHelper.GetTestRootPath(fc, "nonexistingPath");
            try
            {
                fc.SetWorkingDirectory(absoluteDir);
                NUnit.Framework.Assert.Fail("cd to non existing dir should have failed");
            }
            catch (Exception)
            {
            }
            // Exception as expected
            // Try a URI
            string LocalFsRootUri = "file:///tmp/test";

            absoluteDir = new Path(LocalFsRootUri + "/existingDir");
            fc.Mkdir(absoluteDir, FileContext.DefaultPerm, true);
            fc.SetWorkingDirectory(absoluteDir);
            Assert.Equal(absoluteDir, fc.GetWorkingDirectory());
        }
Beispiel #2
0
 public virtual void TestRenameAcrossFs()
 {
     fc.Mkdir(new Path("/newDir/dirFoo"), FileContext.DefaultPerm, true);
     // the root will get interpreted to the root of the chrooted fs.
     fc.Rename(new Path("/newDir/dirFoo"), new Path("file:///dirFooBar"));
     FileContextTestHelper.IsDir(fc, new Path("/dirFooBar"));
 }
Beispiel #3
0
 public virtual void TestMkdirDelete()
 {
     fc.Mkdir(fileContextTestHelper.GetTestRootPath(fc, "/dirX"), FileContext.DefaultPerm
              , false);
     Assert.True(FileContextTestHelper.IsDir(fc, new Path("/dirX")));
     Assert.True(FileContextTestHelper.IsDir(fcTarget, new Path(chrootedTo
                                                                , "dirX")));
     fc.Mkdir(fileContextTestHelper.GetTestRootPath(fc, "/dirX/dirY"), FileContext.DefaultPerm
              , false);
     Assert.True(FileContextTestHelper.IsDir(fc, new Path("/dirX/dirY"
                                                          )));
     Assert.True(FileContextTestHelper.IsDir(fcTarget, new Path(chrootedTo
                                                                , "dirX/dirY")));
     // Delete the created dir
     Assert.True(fc.Delete(new Path("/dirX/dirY"), false));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/dirX/dirY"
                                                                              )));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "dirX/dirY")));
     Assert.True(fc.Delete(new Path("/dirX"), false));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/dirX")
                                                                 ));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "dirX")));
 }
Beispiel #4
0
 public virtual void TestRename()
 {
     // Rename a file
     fileContextTestHelper.CreateFile(fc, "/newDir/foo");
     fc.Rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/newDir/foo"
                                                                              )));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "newDir/foo")));
     Assert.True(FileContextTestHelper.IsFile(fc, fileContextTestHelper
                                              .GetTestRootPath(fc, "/newDir/fooBar")));
     Assert.True(FileContextTestHelper.IsFile(fcTarget, new Path(chrootedTo
                                                                 , "newDir/fooBar")));
     // Rename a dir
     fc.Mkdir(new Path("/newDir/dirFoo"), FileContext.DefaultPerm, false);
     fc.Rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/newDir/dirFoo"
                                                                              )));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "newDir/dirFoo")));
     Assert.True(FileContextTestHelper.IsDir(fc, fileContextTestHelper
                                             .GetTestRootPath(fc, "/newDir/dirFooBar")));
     Assert.True(FileContextTestHelper.IsDir(fcTarget, new Path(chrootedTo
                                                                , "newDir/dirFooBar")));
 }
Beispiel #5
0
        public virtual void TestOperationsThroughMountLinks()
        {
            // Create file
            fileContextTestHelper.CreateFileNonRecursive(fcView, "/user/foo");
            Assert.True("Create file should be file", FileContextTestHelper.IsFile
                            (fcView, new Path("/user/foo")));
            Assert.True("Target of created file should be type file", FileContextTestHelper.IsFile
                            (fcTarget, new Path(targetTestRoot, "user/foo")));
            // Delete the created file
            Assert.True("Delete should succeed", fcView.Delete(new Path("/user/foo"
                                                                        ), false));
            NUnit.Framework.Assert.IsFalse("File should not exist after delete", FileContextTestHelper.Exists
                                               (fcView, new Path("/user/foo")));
            NUnit.Framework.Assert.IsFalse("Target File should not exist after delete", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "user/foo")));
            // Create file with a 2 component dirs
            fileContextTestHelper.CreateFileNonRecursive(fcView, "/internalDir/linkToDir2/foo"
                                                         );
            Assert.True("Created file should be type file", FileContextTestHelper.IsFile
                            (fcView, new Path("/internalDir/linkToDir2/foo")));
            Assert.True("Target of created file should be type file", FileContextTestHelper.IsFile
                            (fcTarget, new Path(targetTestRoot, "dir2/foo")));
            // Delete the created file
            Assert.True("Delete should suceed", fcView.Delete(new Path("/internalDir/linkToDir2/foo"
                                                                       ), false));
            NUnit.Framework.Assert.IsFalse("File should not exist after deletion", FileContextTestHelper.Exists
                                               (fcView, new Path("/internalDir/linkToDir2/foo")));
            NUnit.Framework.Assert.IsFalse("Target should not exist after deletion", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "dir2/foo")));
            // Create file with a 3 component dirs
            fileContextTestHelper.CreateFileNonRecursive(fcView, "/internalDir/internalDir2/linkToDir3/foo"
                                                         );
            Assert.True("Created file should be of type file", FileContextTestHelper.IsFile
                            (fcView, new Path("/internalDir/internalDir2/linkToDir3/foo")));
            Assert.True("Target of created file should also be type file",
                        FileContextTestHelper.IsFile(fcTarget, new Path(targetTestRoot, "dir3/foo")));
            // Recursive Create file with missing dirs
            fileContextTestHelper.CreateFile(fcView, "/internalDir/linkToDir2/missingDir/miss2/foo"
                                             );
            Assert.True("Created file should be of type file", FileContextTestHelper.IsFile
                            (fcView, new Path("/internalDir/linkToDir2/missingDir/miss2/foo")));
            Assert.True("Target of created file should also be type file",
                        FileContextTestHelper.IsFile(fcTarget, new Path(targetTestRoot, "dir2/missingDir/miss2/foo"
                                                                        )));
            // Delete the created file
            Assert.True("Delete should succeed", fcView.Delete(new Path("/internalDir/internalDir2/linkToDir3/foo"
                                                                        ), false));
            NUnit.Framework.Assert.IsFalse("Deleted File should not exist", FileContextTestHelper.Exists
                                               (fcView, new Path("/internalDir/internalDir2/linkToDir3/foo")));
            NUnit.Framework.Assert.IsFalse("Target of deleted file should not exist", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "dir3/foo")));
            // mkdir
            fcView.Mkdir(fileContextTestHelper.GetTestRootPath(fcView, "/user/dirX"), FileContext
                         .DefaultPerm, false);
            Assert.True("New dir should be type dir", FileContextTestHelper.IsDir
                            (fcView, new Path("/user/dirX")));
            Assert.True("Target of new dir should be of type dir", FileContextTestHelper.IsDir
                            (fcTarget, new Path(targetTestRoot, "user/dirX")));
            fcView.Mkdir(fileContextTestHelper.GetTestRootPath(fcView, "/user/dirX/dirY"), FileContext
                         .DefaultPerm, false);
            Assert.True("New dir should be type dir", FileContextTestHelper.IsDir
                            (fcView, new Path("/user/dirX/dirY")));
            Assert.True("Target of new dir should be of type dir", FileContextTestHelper.IsDir
                            (fcTarget, new Path(targetTestRoot, "user/dirX/dirY")));
            // Delete the created dir
            Assert.True("Delete should succeed", fcView.Delete(new Path("/user/dirX/dirY"
                                                                        ), false));
            NUnit.Framework.Assert.IsFalse("Deleted File should not exist", FileContextTestHelper.Exists
                                               (fcView, new Path("/user/dirX/dirY")));
            NUnit.Framework.Assert.IsFalse("Deleted Target should not exist", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "user/dirX/dirY")));
            Assert.True("Delete should succeed", fcView.Delete(new Path("/user/dirX"
                                                                        ), false));
            NUnit.Framework.Assert.IsFalse("Deleted File should not exist", FileContextTestHelper.Exists
                                               (fcView, new Path("/user/dirX")));
            NUnit.Framework.Assert.IsFalse("Deleted Target should not exist", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "user/dirX")));
            // Rename a file
            fileContextTestHelper.CreateFile(fcView, "/user/foo");
            fcView.Rename(new Path("/user/foo"), new Path("/user/fooBar"));
            NUnit.Framework.Assert.IsFalse("Renamed src should not exist", FileContextTestHelper.Exists
                                               (fcView, new Path("/user/foo")));
            NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(targetTestRoot
                                                                                           , "user/foo")));
            Assert.True(FileContextTestHelper.IsFile(fcView, fileContextTestHelper
                                                     .GetTestRootPath(fcView, "/user/fooBar")));
            Assert.True(FileContextTestHelper.IsFile(fcTarget, new Path(targetTestRoot
                                                                        , "user/fooBar")));
            fcView.Mkdir(new Path("/user/dirFoo"), FileContext.DefaultPerm, false);
            fcView.Rename(new Path("/user/dirFoo"), new Path("/user/dirFooBar"));
            NUnit.Framework.Assert.IsFalse("Renamed src should not exist", FileContextTestHelper.Exists
                                               (fcView, new Path("/user/dirFoo")));
            NUnit.Framework.Assert.IsFalse("Renamed src should not exist in target", FileContextTestHelper.Exists
                                               (fcTarget, new Path(targetTestRoot, "user/dirFoo")));
            Assert.True("Renamed dest should  exist as dir", FileContextTestHelper.IsDir
                            (fcView, fileContextTestHelper.GetTestRootPath(fcView, "/user/dirFooBar")));
            Assert.True("Renamed dest should  exist as dir in target", FileContextTestHelper.IsDir
                            (fcTarget, new Path(targetTestRoot, "user/dirFooBar")));
            // Make a directory under a directory that's mounted from the root of another FS
            fcView.Mkdir(new Path("/targetRoot/dirFoo"), FileContext.DefaultPerm, false);
            Assert.True(FileContextTestHelper.Exists(fcView, new Path("/targetRoot/dirFoo"
                                                                      )));
            bool dirFooPresent = false;
            RemoteIterator <FileStatus> dirContents = fcView.ListStatus(new Path("/targetRoot/"
                                                                                 ));

            while (dirContents.HasNext())
            {
                FileStatus fileStatus = dirContents.Next();
                if (fileStatus.GetPath().GetName().Equals("dirFoo"))
                {
                    dirFooPresent = true;
                }
            }
            Assert.True(dirFooPresent);
        }