@Test
public void testAllowDisallowSnapshot() throws Exception {

  final Path dirPath = new Path("/ssdir1");
  final Path trashRoot = new Path(dirPath, ".Trash");
  final DistributedFileSystem dfs = cluster.getFileSystem();
  final DFSAdmin dfsAdmin = new DFSAdmin(conf);
  dfs.mkdirs(dirPath);
  assertEquals(0, ToolRunner.run(dfsAdmin,
      new String[]{"-allowSnapshot", dirPath.toString()}));
  // Verify .Trash creation after -allowSnapshot command
  assertTrue(dfs.exists(trashRoot));
  assertEquals(TRASH_PERMISSION,
      dfs.getFileStatus(trashRoot).getPermission());
  // Move a file to trash
  final Path file1 = new Path(dirPath, "file1");
  try (FSDataOutputStream s = dfs.create(file1)) {
    s.write(0);
  }
  FsShell fsShell = new FsShell(dfs.getConf());
  assertEquals(0, ToolRunner.run(fsShell,
      new String[]{"-rm", file1.toString()}));
  // User directory inside snapshottable directory trash should have 700
  final String username =
      UserGroupInformation.getLoginUser().getShortUserName();
  final Path trashRootUserSubdir = new Path(trashRoot, username);
  assertTrue(dfs.exists(trashRootUserSubdir));
  final FsPermission trashUserdirPermission = new FsPermission(
      FsAction.ALL, FsAction.NONE, FsAction.NONE, false);
  assertEquals(trashUserdirPermission,
      dfs.getFileStatus(trashRootUserSubdir).getPermission());
  // disallowSnapshot should fail when .Trash is not empty
  assertNotEquals(0, ToolRunner.run(dfsAdmin,
      new String[]{"-disallowSnapshot", dirPath.toString()}));
  dfs.delete(trashRootUserSubdir, true);
  // disallowSnapshot should succeed now that we have an empty .Trash
  assertEquals(0, ToolRunner.run(dfsAdmin,
      new String[]{"-disallowSnapshot", dirPath.toString()}));
  // Cleanup
  dfs.delete(dirPath, true);
}