MiniDFSCluster cluster = new MiniDFSCluster(conf, 4, true, null);
SnapshotNode ssNode = new SnapshotNode(conf);
WaitingRoom wr = new WaitingRoom(conf);
DFSClient client = new DFSClient(conf);
SnapshotClient ssClient = new SnapshotClient(conf);
FileSystem dfs = cluster.getFileSystem();
String ssDir = conf.get("fs.snapshot.dir", "/.SNAPSHOT");
Path foo = new Path("/foo");
Path bar = new Path("/bar");
FSDataOutputStream out;
out = dfs.create(foo);
out.write(0);
out.close();
out = dfs.create(bar);
out.write(1);
out.sync();
ssNode.createSnapshot("test", true);
out.write(2);
out.close();
wr.moveToWaitingRoom(foo); // delete
// Current system has foo deleted and bar with length 2
// test snapshot has foo with length 1 and bar with length 1
// Checking current file system
assertTrue(!dfs.exists(foo));
DFSInputStream in = client.open("/bar");
assertTrue(in.getFileLength() == 2);
assertTrue(in.read() == 1);
assertTrue(in.read() == 2);
assertTrue(in.read() == -1); //eof
// Checking test snapshot
in = ssClient.open("test", "/foo");
assertTrue(in.getFileLength() == 1);
assertTrue(in.read() == 0);
assertTrue(in.read() == -1); //eof
in = ssClient.open("test", "/bar");
assertTrue(in.getFileLength() == 1);
assertTrue(in.read() == 1);
assertTrue(in.read() == -1); //eof
}