Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertEquals(hook1, mgr.getShutdownHooksInOrder().get(0)); mgr.removeShutdownHook(hook1); Assert.assertFalse(mgr.hasShutdownHook(hook1)); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertTrue(mgr.hasShutdownHook(hook2)); Assert.assertEquals(2, mgr.getShutdownHooksInOrder().size()); Assert.assertEquals(hook2, mgr.getShutdownHooksInOrder().get(0));
Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertEquals(hook1, mgr.getShutdownHooksInOrder().get(0)); mgr.removeShutdownHook(hook1); Assert.assertFalse(mgr.hasShutdownHook(hook1)); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertEquals(1, mgr.getShutdownHooksInOrder().size()); Assert.assertTrue(mgr.hasShutdownHook(hook1)); Assert.assertTrue(mgr.hasShutdownHook(hook2)); Assert.assertEquals(2, mgr.getShutdownHooksInOrder().size()); Assert.assertEquals(hook2, mgr.getShutdownHooksInOrder().get(0));
@Test public void testDeleteOnExit() throws Exception { // Create deleteOnExit entries Path file1 = helper.getTestRootPath(fc, "file1"); createFile(fc, file1, numBlocks, blockSize); fc.deleteOnExit(file1); checkDeleteOnExitData(1, fc, file1); // Ensure shutdown hook is added Assert.assertTrue(ShutdownHookManager.get().hasShutdownHook(FileContext.FINALIZER)); Path file2 = helper.getTestRootPath(fc, "dir1/file2"); createFile(fc, file2, numBlocks, blockSize); fc.deleteOnExit(file2); checkDeleteOnExitData(1, fc, file1, file2); Path dir = helper.getTestRootPath(fc, "dir3/dir4/dir5/dir6"); 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]); Assert.assertFalse(exists(fc, file1)); Assert.assertFalse(exists(fc, file2)); Assert.assertFalse(exists(fc, dir)); } }
@Test public void testDeleteOnExit() throws Exception { // Create deleteOnExit entries Path file1 = helper.getTestRootPath(fc, "file1"); createFile(fc, file1, numBlocks, blockSize); fc.deleteOnExit(file1); checkDeleteOnExitData(1, fc, file1); // Ensure shutdown hook is added Assert.assertTrue(ShutdownHookManager.get().hasShutdownHook(FileContext.FINALIZER)); Path file2 = helper.getTestRootPath(fc, "dir1/file2"); createFile(fc, file2, numBlocks, blockSize); fc.deleteOnExit(file2); checkDeleteOnExitData(1, fc, file1, file2); Path dir = helper.getTestRootPath(fc, "dir3/dir4/dir5/dir6"); 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]); Assert.assertFalse(exists(fc, file1)); Assert.assertFalse(exists(fc, file2)); Assert.assertFalse(exists(fc, dir)); } }