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 TestCreateDelete()
 {
     // Create file
     fileContextTestHelper.CreateFileNonRecursive(fc, "/foo");
     Assert.True(FileContextTestHelper.IsFile(fc, new Path("/foo")));
     Assert.True(FileContextTestHelper.IsFile(fcTarget, new Path(chrootedTo
                                                                 , "foo")));
     // Create file with recursive dir
     fileContextTestHelper.CreateFile(fc, "/newDir/foo");
     Assert.True(FileContextTestHelper.IsFile(fc, new Path("/newDir/foo"
                                                           )));
     Assert.True(FileContextTestHelper.IsFile(fcTarget, new Path(chrootedTo
                                                                 , "newDir/foo")));
     // Delete the created file
     Assert.True(fc.Delete(new Path("/newDir/foo"), false));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/newDir/foo"
                                                                              )));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "newDir/foo")));
     // Create file with a 2 component dirs recursively
     fileContextTestHelper.CreateFile(fc, "/newDir/newDir2/foo");
     Assert.True(FileContextTestHelper.IsFile(fc, new Path("/newDir/newDir2/foo"
                                                           )));
     Assert.True(FileContextTestHelper.IsFile(fcTarget, new Path(chrootedTo
                                                                 , "newDir/newDir2/foo")));
     // Delete the created file
     Assert.True(fc.Delete(new Path("/newDir/newDir2/foo"), false));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fc, new Path("/newDir/newDir2/foo"
                                                                              )));
     NUnit.Framework.Assert.IsFalse(FileContextTestHelper.Exists(fcTarget, new Path(chrootedTo
                                                                                    , "newDir/newDir2/foo")));
 }
Beispiel #3
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 #4
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 #5
0
        /// <summary>delete the test directory in the target local fs</summary>
        /// <exception cref="System.Exception"/>
        public static void TearDownForViewFsLocalFs(FileContextTestHelper helper)
        {
            FileContext fclocal       = FileContext.GetLocalFSFileContext();
            Path        targetOfTests = helper.GetTestRootPath(fclocal);

            fclocal.Delete(targetOfTests, true);
        }
Beispiel #6
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 #7
0
 public virtual void SetUp()
 {
     InitializeTargetTestRoot();
     // Make  user and data dirs - we creates links to them in the mount table
     fcTarget.Mkdir(new Path(targetTestRoot, "user"), FileContext.DefaultPerm, true);
     fcTarget.Mkdir(new Path(targetTestRoot, "data"), FileContext.DefaultPerm, true);
     fcTarget.Mkdir(new Path(targetTestRoot, "dir2"), FileContext.DefaultPerm, true);
     fcTarget.Mkdir(new Path(targetTestRoot, "dir3"), FileContext.DefaultPerm, true);
     FileContextTestHelper.CreateFile(fcTarget, new Path(targetTestRoot, "aFile"));
     // Now we use the mount fs to set links to user and dir
     // in the test root
     // Set up the defaultMT in the config with our mount point links
     conf = new Configuration();
     ConfigUtil.AddLink(conf, "/targetRoot", targetTestRoot.ToUri());
     ConfigUtil.AddLink(conf, "/user", new Path(targetTestRoot, "user").ToUri());
     ConfigUtil.AddLink(conf, "/user2", new Path(targetTestRoot, "user").ToUri());
     ConfigUtil.AddLink(conf, "/data", new Path(targetTestRoot, "data").ToUri());
     ConfigUtil.AddLink(conf, "/internalDir/linkToDir2", new Path(targetTestRoot, "dir2"
                                                                  ).ToUri());
     ConfigUtil.AddLink(conf, "/internalDir/internalDir2/linkToDir3", new Path(targetTestRoot
                                                                               , "dir3").ToUri());
     ConfigUtil.AddLink(conf, "/danglingLink", new Path(targetTestRoot, "missingTarget"
                                                        ).ToUri());
     ConfigUtil.AddLink(conf, "/linkToAFile", new Path(targetTestRoot, "aFile").ToUri(
                            ));
     fcView = FileContext.GetFileContext(FsConstants.ViewfsUri, conf);
 }
Beispiel #8
0
        /*
         * return the ViewFS File context to be used for tests
         */
        /// <exception cref="System.Exception"/>
        public static FileContext SetupForViewFsLocalFs(FileContextTestHelper helper)
        {
            FileContext fsTarget      = FileContext.GetLocalFSFileContext();
            Path        targetOfTests = helper.GetTestRootPath(fsTarget);

            // In case previous test was killed before cleanup
            fsTarget.Delete(targetOfTests, true);
            fsTarget.Mkdir(targetOfTests, FileContext.DefaultPerm, true);
            Configuration conf = new Configuration();
            // Set up viewfs link for test dir as described above
            string testDir = helper.GetTestRootPath(fsTarget).ToUri().GetPath();

            LinkUpFirstComponents(conf, testDir, fsTarget, "test dir");
            // Set up viewfs link for home dir as described above
            SetUpHomeDir(conf, fsTarget);
            // the test path may be relative to working dir - we need to make that work:
            // Set up viewfs link for wd as described above
            string wdDir = fsTarget.GetWorkingDirectory().ToUri().GetPath();

            LinkUpFirstComponents(conf, wdDir, fsTarget, "working dir");
            FileContext fc = FileContext.GetFileContext(FsConstants.ViewfsUri, conf);

            fc.SetWorkingDirectory(new Path(wdDir));
            // in case testdir relative to wd.
            Org.Mortbay.Log.Log.Info("Working dir is: " + fc.GetWorkingDirectory());
            //System.out.println("SRCOfTests = "+ getTestRootPath(fc, "test"));
            //System.out.println("TargetOfTests = "+ targetOfTests.toUri());
            return(fc);
        }
Beispiel #9
0
 public virtual void TestFileStatusOnMountLink()
 {
     Assert.True("Slash should appear as dir", fcView.GetFileStatus(
                     new Path("/")).IsDirectory());
     FileContextTestHelper.CheckFileStatus(fcView, "/", FileContextTestHelper.FileType
                                           .isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/user", FileContextTestHelper.FileType
                                           .isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/data", FileContextTestHelper.FileType
                                           .isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/internalDir", FileContextTestHelper.FileType
                                           .isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/internalDir/linkToDir2", FileContextTestHelper.FileType
                                           .isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/internalDir/internalDir2/linkToDir3"
                                           , FileContextTestHelper.FileType.isDir);
     FileContextTestHelper.CheckFileStatus(fcView, "/linkToAFile", FileContextTestHelper.FileType
                                           .isFile);
     try
     {
         fcView.GetFileStatus(new Path("/danglingLink"));
         NUnit.Framework.Assert.Fail("Excepted a not found exception here");
     }
     catch (FileNotFoundException)
     {
     }
 }
Beispiel #10
0
 public virtual void TestgetFileLinkStatus()
 {
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/user", FileContextTestHelper.FileType
                                               .isSymlink);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/data", FileContextTestHelper.FileType
                                               .isSymlink);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/internalDir/linkToDir2", FileContextTestHelper.FileType
                                               .isSymlink);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/internalDir/internalDir2/linkToDir3"
                                               , FileContextTestHelper.FileType.isSymlink);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/linkToAFile", FileContextTestHelper.FileType
                                               .isSymlink);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/internalDir", FileContextTestHelper.FileType
                                               .isDir);
     FileContextTestHelper.CheckFileLinkStatus(fcView, "/internalDir/internalDir2", FileContextTestHelper.FileType
                                               .isDir);
 }
Beispiel #11
0
        public virtual void TestGetBlockLocations()
        {
            Path targetFilePath = new Path(targetTestRoot, "data/largeFile");

            FileContextTestHelper.CreateFile(fcTarget, targetFilePath, 10, 1024);
            Path viewFilePath = new Path("/data/largeFile");

            FileContextTestHelper.CheckFileStatus(fcView, viewFilePath.ToString(), FileContextTestHelper.FileType
                                                  .isFile);
            BlockLocation[] viewBL = fcView.GetFileBlockLocations(viewFilePath, 0, 10240 + 100
                                                                  );
            Assert.Equal(SupportsBlocks ? 10 : 1, viewBL.Length);
            BlockLocation[] targetBL = fcTarget.GetFileBlockLocations(targetFilePath, 0, 10240
                                                                      + 100);
            CompareBLs(viewBL, targetBL);
            // Same test but now get it via the FileStatus Parameter
            fcView.GetFileBlockLocations(viewFilePath, 0, 10240 + 100);
            targetBL = fcTarget.GetFileBlockLocations(targetFilePath, 0, 10240 + 100);
            CompareBLs(viewBL, targetBL);
        }
Beispiel #12
0
 public ViewFsBaseTest()
 {
     fileContextTestHelper = CreateFileContextHelper();
 }
Beispiel #13
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);
        }