@Test
public void testAllowAndDisallowSnapshot() throws Exception {

  final Path dir = new Path("/dir");
  final Path file0 = new Path(dir, "file0");
  final Path file1 = new Path(dir, "file1");
  DFSTestUtil.createFile(hdfs, file0, BLOCKSIZE, REPLICATION, seed);
  DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPLICATION, seed);
  
  INodeDirectory dirNode = fsdir.getINode4Write(dir.toString()).asDirectory();
  assertFalse(dirNode.isSnapshottable());
  
  hdfs.allowSnapshot(dir);
  dirNode = fsdir.getINode4Write(dir.toString()).asDirectory();
  assertTrue(dirNode.isSnapshottable());
  // call allowSnapshot again
  hdfs.allowSnapshot(dir);
  dirNode = fsdir.getINode4Write(dir.toString()).asDirectory();
  assertTrue(dirNode.isSnapshottable());
  
  // disallowSnapshot on dir
  hdfs.disallowSnapshot(dir);
  dirNode = fsdir.getINode4Write(dir.toString()).asDirectory();
  assertFalse(dirNode.isSnapshottable());
  // do it again
  hdfs.disallowSnapshot(dir);
  dirNode = fsdir.getINode4Write(dir.toString()).asDirectory();
  assertFalse(dirNode.isSnapshottable());
  
  // same process on root
  
  final Path root = new Path("/");
  INodeDirectory rootNode = fsdir.getINode4Write(root.toString())
      .asDirectory();
  assertTrue(rootNode.isSnapshottable());
  // root is snapshottable dir, but with 0 snapshot quota
  assertEquals(0, rootNode.getDirectorySnapshottableFeature()
      .getSnapshotQuota());
  
  hdfs.allowSnapshot(root);
  rootNode = fsdir.getINode4Write(root.toString()).asDirectory();
  assertTrue(rootNode.isSnapshottable());
  assertEquals(DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT,
      rootNode.getDirectorySnapshottableFeature().getSnapshotQuota());
  // call allowSnapshot again
  hdfs.allowSnapshot(root);
  rootNode = fsdir.getINode4Write(root.toString()).asDirectory();
  assertTrue(rootNode.isSnapshottable());
  assertEquals(DirectorySnapshottableFeature.SNAPSHOT_QUOTA_DEFAULT,
      rootNode.getDirectorySnapshottableFeature().getSnapshotQuota());
  
  // disallowSnapshot on dir
  hdfs.disallowSnapshot(root);
  rootNode = fsdir.getINode4Write(root.toString()).asDirectory();
  assertTrue(rootNode.isSnapshottable());
  assertEquals(0, rootNode.getDirectorySnapshottableFeature().getSnapshotQuota());
  // do it again
  hdfs.disallowSnapshot(root);
  rootNode = fsdir.getINode4Write(root.toString()).asDirectory();
  assertTrue(rootNode.isSnapshottable());
  assertEquals(0, rootNode.getDirectorySnapshottableFeature().getSnapshotQuota());
}