List of usage examples for java.io FileSystem delete
public abstract boolean delete(File f);
true
if and only if the operation succeeds. From source file:org.apache.hadoop.hdfs.server.namenode.TestWaitingRoomPurger.java
public void testWaitingRoomPurger() throws IOException { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster(conf, 1, true, null); cluster.waitClusterUp();/*w ww. ja v a2s . c o m*/ FileSystem fs = cluster.getFileSystem(); WaitingRoom wr = new WaitingRoom(conf); WaitingRoomPurger purger = wr.getPurger(); SnapshotNode ssNode = new SnapshotNode(conf); ssNode.shutdownWaitingRoomPurger(); String wrPath = conf.get("fs.snapshot.waitingroom", "/.WR"); String ssDir = conf.get("fs.snapshot.dir", "/.SNAPSHOT"); Path foo = new Path("/foo"); Path bar = new Path("/hadoop/bar"); Path mash = new Path("/hadoop/mash"); FSDataOutputStream stream; // Create foo stream = fs.create(foo); stream.writeByte(0); stream.close(); // Move foo to waiting room. assertTrue(wr.moveToWaitingRoom(foo)); // Create snapshot ssNode.createSnapshot("first", false); // contains nothing // Create bar (V1) stream = fs.create(bar); stream.write(0); stream.close(); // Create mash (empty) stream = fs.create(mash); stream.close(); // Create snapshot ssNode.createSnapshot("second", false); // contains bar (V1), mash // Move mash, bar to waiting room assertTrue(wr.moveToWaitingRoom(mash)); assertTrue(wr.moveToWaitingRoom(bar)); // Create bar (V2) stream = fs.create(bar); stream.write(0); stream.close(); ssNode.createSnapshot("third", false); // contains bar (V2) // Verify fs state right now assertTrue(fs.exists(bar)); assertFalse(fs.exists(foo)); assertFalse(fs.exists(mash)); assertTrue(fs.exists(new Path(wrPath + "/foo"))); assertTrue(fs.exists(new Path(wrPath + "/hadoop/bar"))); assertTrue(fs.exists(new Path(wrPath + "/hadoop/mash"))); // Run purger purger.purge(); // Verify fs state right now assertTrue(fs.exists(bar)); assertFalse(fs.exists(foo)); assertFalse(fs.exists(mash)); assertFalse(fs.exists(new Path(wrPath + "/foo"))); // deleted: unreferenced assertTrue(fs.exists(new Path(wrPath + "/hadoop/bar"))); assertFalse(fs.exists(new Path(wrPath + "/hadoop/mash"))); // deleted: empty // Delete snapshot 'second' boolean success = fs.delete(new Path(ssDir + "/" + SnapshotNode.SSNAME + "second")); assertTrue(success); // Run purger again purger.purge(); // Verify fs state right now assertTrue(fs.exists(bar)); assertFalse(fs.exists(foo)); assertFalse(fs.exists(mash)); assertFalse(fs.exists(new Path(wrPath + "/foo"))); // deleted: last run assertFalse(fs.exists(new Path(wrPath + "/hadoop/bar"))); // deleted: unreferenced assertFalse(fs.exists(new Path(wrPath + "/hadoop/mash"))); // deleted: last run }