Java Code Examples for org.apache.hadoop.fs.TrashPolicy#getCurrentTrashDir()
The following examples show how to use
org.apache.hadoop.fs.TrashPolicy#getCurrentTrashDir() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HadoopUtilsTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Test public void testMoveToTrash() throws IOException { Path hadoopUtilsTestDir = new Path(Files.createTempDir().getAbsolutePath(), "HadoopUtilsTestDir"); Configuration conf = new Configuration(); // Set the time to keep it in trash to 10 minutes. // 0 means object will be deleted instantly. conf.set("fs.trash.interval", "10"); FileSystem fs = FileSystem.getLocal(conf); Trash trash = new Trash(fs, conf); TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory()); Path trashPath = trashPolicy.getCurrentTrashDir(); fs.mkdirs(hadoopUtilsTestDir); Assert.assertTrue(fs.exists(hadoopUtilsTestDir)); trash.moveToTrash(hadoopUtilsTestDir.getParent()); Assert.assertFalse(fs.exists(hadoopUtilsTestDir)); Assert.assertTrue(fs.exists(trashPath)); }
Example 2
Source File: TestFileDeleteWhitelist.java From RDFS with Apache License 2.0 | 5 votes |
public void testFileDeleteWithTrash() throws IOException { Configuration conf = new Configuration(); conf.set("fs.trash.interval", "10"); // 10 minute // create cluster MiniDFSCluster cluster = new MiniDFSCluster(conf, 1, true, null); FileSystem fs = null; try { cluster.waitActive(); fs = cluster.getFileSystem(); // create file1. Path dir = new Path("/foo"); Path file1 = new Path(dir, "file1"); createFile(fs, file1); System.out.println("testFileCreationDeleteParent: " + "Created file " + file1); fs.delete(file1, true); // create file2. Path file2 = new Path("/tmp", "file2"); createFile(fs, file2); System.out.println("testFileCreationDeleteParent: " + "Created file " + file2); fs.delete(file2, true); TrashPolicy trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory()); Path trashRoot = trashPolicy.getCurrentTrashDir(); TestTrash.checkTrash(fs, trashRoot, file1); TestTrash.checkNotInTrash(fs, trashRoot, file2.toString()); } finally { fs.close(); cluster.shutdown(); } }
Example 3
Source File: TestFileSystemView.java From kite with Apache License 2.0 | 5 votes |
public static void assertDirectoriesInTrash(FileSystem fs, TrashPolicy trashPolicy, Path... dirs) throws IOException { Path trashDir = trashPolicy.getCurrentTrashDir(); for (Path path : dirs) { Path trashPath = Path.mergePaths(trashDir, fs.makeQualified(path)); assertTrue("Directory should exist in trash: " + trashPath, fs.exists(trashPath)); } }