示例#1
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));
        }