{
Path path = new Path("test_file_1");
writeFile(fs, path);
assertTrue(fs.exists(path));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-rm";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(!fs.exists(path));
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
}
// test undelete of file that was deleted programatically
{
Path path = new Path("test_file_2");
writeFile(fs, path);
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
}
// test undelete of directory that was deleted via shell
{
Path path = new Path("test_dir_1");
assertTrue(fs.mkdirs(path));
assertTrue(fs.exists(path));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-rmr";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(!fs.exists(path));
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
}
// test undelete of directory that was deleted programatically
{
Path path = new Path("test_dir_2");
assertTrue(fs.mkdirs(path));
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
}
// test undelete of most recently deleted version
{
Path path = new Path("test_file_multiversion");
writeFileContents(fs, path, "wrong version");
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
writeFileContents(fs, path, "right version");
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
String verify = readFileContents(fs, path);
System.err.println("verify=" + verify);
assertTrue(verify.equals("right version"));
}
// test undelete of file from another user's trash
{
// make a fake trash for a different user
Path path = new Path("my_file_in_joes_trash");
Path joesTrashDir = new Path(
"/user/joe/.Trash/Current/user/" + getUserName(fs));
Path joesTrashFile = new Path(joesTrashDir, path);
mkdir(fs, joesTrashDir);
writeFileContents(fs, joesTrashFile, "some file contents");
assertTrue(fs.exists(joesTrashFile));
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[4];
argv[0] = "-undelete";
argv[1] = "-u";
argv[2] = "joe";
argv[3] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
}
// test undelete of most recently deleted version across
// checkpoint intervals
{
Path path = new Path("test_file_interval");
writeFileContents(fs, path, "wrong version");
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
writeFileContents(fs, path, "right version");
assertTrue(fs.exists(path));
assertTrue(fs.delete(path, true));
assertTrue(!fs.exists(path));
// wait for the next interval before checking
Thread.sleep(60500);
FsShell shell = new FsShell();
shell.setConf(conf);
String argv[] = new String[2];
argv[0] = "-undelete";
argv[1] = path.toString();
assertTrue(shell.run(argv) == 0);
assertTrue(fs.exists(path));
String verify = readFileContents(fs, path);
System.err.println("verify=" + verify);
assertTrue(verify.equals("right version"));