Search in sources :

Example 1 with TrashPolicy

use of org.apache.hadoop.fs.TrashPolicy in project incubator-gobblin by apache.

the class HadoopUtilsTest method testMoveToTrash.

@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));
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) TrashPolicy(org.apache.hadoop.fs.TrashPolicy) FileSystem(org.apache.hadoop.fs.FileSystem) Trash(org.apache.hadoop.fs.Trash) Test(org.testng.annotations.Test)

Example 2 with TrashPolicy

use of org.apache.hadoop.fs.TrashPolicy in project hive by apache.

the class AbstractMetaStoreService method start.

/**
 * Starts the MetaStoreService. Be aware, as the current MetaStore does not implement clean
 * shutdown, starting MetaStoreService is possible only once per test.
 *
 * @throws Exception if any Exception occurs
 */
public void start() throws Exception {
    warehouse = new Warehouse(configuration);
    warehouseRootFs = warehouse.getFs(warehouse.getWhRoot());
    TrashPolicy trashPolicy = TrashPolicy.getInstance(configuration, warehouseRootFs);
    trashDir = trashPolicy.getCurrentTrashDir();
}
Also used : Warehouse(org.apache.hadoop.hive.metastore.Warehouse) TrashPolicy(org.apache.hadoop.fs.TrashPolicy)

Aggregations

TrashPolicy (org.apache.hadoop.fs.TrashPolicy)2 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Trash (org.apache.hadoop.fs.Trash)1 Warehouse (org.apache.hadoop.hive.metastore.Warehouse)1 Test (org.testng.annotations.Test)1