org.apache.hadoop.fs.TrashPolicy Java Examples

The following examples show how to use org.apache.hadoop.fs.TrashPolicy. 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 vote down vote up
@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 vote down vote up
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 vote down vote up
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));
  }
}
 
Example #4
Source File: TestRefinableViews.java    From kite with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  this.conf = (distributed ?
      MiniDFSTest.getConfiguration() :
      new Configuration());
  this.fs = FileSystem.get(conf);

  this.trashPolicy = TrashPolicy.getInstance(conf, fs, fs.getHomeDirectory());

  this.repo = newRepo();
  this.strategy = new PartitionStrategy.Builder()
      .year("timestamp")
      .month("timestamp")
      .day("timestamp")
      .build();
  this.testDescriptor = new DatasetDescriptor.Builder()
      .schemaUri("resource:standard_event.avsc")
      .partitionStrategy(strategy)
      .build();
  repo.delete("ns", "test");
  this.unbounded = repo.create("ns", "test", testDescriptor);
  
  this.valueDescriptor = new DatasetDescriptor.Builder().schemaUri("resource:value.avsc").build();
  repo.delete("ns", "value");
  this.valueView = repo.create("ns", "value", valueDescriptor); 
  this.testValueView = repo.load("ns", "value", TestValue.class);
}