微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.apache.hadoop.fs.TrashPolicy的实例源码

项目:incubator-gobblin    文件HadoopUtilsTest.java   
@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));
}
项目:hadoop-EAR    文件TestFileDeleteWhitelist.java   
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.getHomeDirectory());
    Path trashRoot = trashPolicy.getCurrentTrashDir();
    TestTrash.checkTrash(fs,trashRoot,file1);
    TestTrash.checknotinTrash(fs,file2.toString());
  } finally {
    fs.close();
    cluster.shutdown();
  }
}
项目:RDFS    文件TestFileDeleteWhitelist.java   
public void testFileDeleteWithTrash() throws IOException {
  Configuration conf = new Configuration();
  conf.set("fs.trash.interval",file2.toString());
  } finally {
    fs.close();
    cluster.shutdown();
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。