|
@@ -24,6 +24,7 @@ import static org.apache.hadoop.hdfs.client.HdfsAdmin.TRASH_PERMISSION;
|
|
|
import static org.apache.hadoop.hdfs.client.HdfsClientConfigKeys.DFS_CLIENT_CONTEXT;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
import static org.junit.Assert.fail;
|
|
@@ -1620,7 +1621,7 @@ public class TestDistributedFileSystem {
|
|
|
cluster.waitActive();
|
|
|
DistributedFileSystem dfs = cluster.getFileSystem();
|
|
|
FsServerDefaults fsServerDefaults = dfs.getServerDefaults();
|
|
|
- Assert.assertNotNull(fsServerDefaults);
|
|
|
+ assertNotNull(fsServerDefaults);
|
|
|
} finally {
|
|
|
cluster.shutdown();
|
|
|
}
|
|
@@ -2513,4 +2514,43 @@ public class TestDistributedFileSystem {
|
|
|
() -> FileUtil.copy(dfs, fstatus, dfs, filePath, false, true, conf));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testNameNodeCreateSnapshotTrashRootOnStartup()
|
|
|
+ throws Exception {
|
|
|
+ // Start NN with dfs.namenode.snapshot.trashroot.enabled=false
|
|
|
+ Configuration conf = getTestConfiguration();
|
|
|
+ conf.setBoolean("dfs.namenode.snapshot.trashroot.enabled", false);
|
|
|
+ MiniDFSCluster cluster =
|
|
|
+ new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
|
|
|
+ try {
|
|
|
+ final DistributedFileSystem dfs = cluster.getFileSystem();
|
|
|
+ final Path testDir = new Path("/disallowss/test2/");
|
|
|
+ final Path file0path = new Path(testDir, "file-0");
|
|
|
+ dfs.create(file0path).close();
|
|
|
+ dfs.allowSnapshot(testDir);
|
|
|
+ // .Trash won't be created right now since snapshot trash is disabled
|
|
|
+ final Path trashRoot = new Path(testDir, FileSystem.TRASH_PREFIX);
|
|
|
+ assertFalse(dfs.exists(trashRoot));
|
|
|
+ // Set dfs.namenode.snapshot.trashroot.enabled=true
|
|
|
+ conf.setBoolean("dfs.namenode.snapshot.trashroot.enabled", true);
|
|
|
+ cluster.setNameNodeConf(0, conf);
|
|
|
+ cluster.restartNameNode(0);
|
|
|
+ // Check .Trash existence, should be created now
|
|
|
+ assertTrue(dfs.exists(trashRoot));
|
|
|
+ // Check permission
|
|
|
+ FileStatus trashRootStatus = dfs.getFileStatus(trashRoot);
|
|
|
+ assertNotNull(trashRootStatus);
|
|
|
+ assertEquals(TRASH_PERMISSION, trashRootStatus.getPermission());
|
|
|
+
|
|
|
+ // Cleanup
|
|
|
+ dfs.delete(trashRoot, true);
|
|
|
+ dfs.disallowSnapshot(testDir);
|
|
|
+ dfs.delete(testDir, true);
|
|
|
+ } finally {
|
|
|
+ if (cluster != null) {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|