|
@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_PROTECTED_SUBDIRECTORIES_ENABLE;
|
|
|
import static org.hamcrest.core.Is.is;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertFalse;
|
|
@@ -193,6 +194,25 @@ public class TestProtectedDirectories {
|
|
|
return matrix;
|
|
|
}
|
|
|
|
|
|
+ private Collection<TestMatrixEntry> createTestMatrixForProtectSubDirs() {
|
|
|
+ Collection<TestMatrixEntry> matrix = new ArrayList<TestMatrixEntry>();
|
|
|
+
|
|
|
+ // Nested unprotected dirs.
|
|
|
+ matrix.add(TestMatrixEntry.get()
|
|
|
+ .addUnprotectedDir("/1", true)
|
|
|
+ .addUnprotectedDir("/1/2", true)
|
|
|
+ .addUnprotectedDir("/1/2/3", true)
|
|
|
+ .addUnprotectedDir("/1/2/3/4", true));
|
|
|
+
|
|
|
+ // Non-empty protected dir.
|
|
|
+ matrix.add(TestMatrixEntry.get()
|
|
|
+ .addProtectedDir("/1", false)
|
|
|
+ .addUnprotectedDir("/1/2", false)
|
|
|
+ .addUnprotectedDir("/1/2/3", false)
|
|
|
+ .addUnprotectedDir("/1/2/3/4", true));
|
|
|
+ return matrix;
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testReconfigureProtectedPaths() throws Throwable {
|
|
|
Configuration conf = new HdfsConfiguration();
|
|
@@ -292,6 +312,67 @@ public class TestProtectedDirectories {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testRenameProtectSubDirs() throws Throwable {
|
|
|
+ for (TestMatrixEntry testMatrixEntry :
|
|
|
+ createTestMatrixForProtectSubDirs()) {
|
|
|
+ Configuration conf = new HdfsConfiguration();
|
|
|
+ conf.setBoolean(DFS_PROTECTED_SUBDIRECTORIES_ENABLE, true);
|
|
|
+ MiniDFSCluster cluster = setupTestCase(
|
|
|
+ conf, testMatrixEntry.getProtectedPaths(),
|
|
|
+ testMatrixEntry.getUnprotectedPaths());
|
|
|
+
|
|
|
+ try {
|
|
|
+ LOG.info("Running {}", testMatrixEntry);
|
|
|
+ FileSystem fs = cluster.getFileSystem();
|
|
|
+ for (Path srcPath : testMatrixEntry.getAllPathsToBeDeleted()) {
|
|
|
+ assertThat(
|
|
|
+ testMatrixEntry + ": Testing whether "
|
|
|
+ + srcPath + " can be renamed",
|
|
|
+ renamePath(fs, srcPath,
|
|
|
+ new Path(srcPath.toString() + "_renamed")),
|
|
|
+ is(testMatrixEntry.canPathBeRenamed(srcPath)));
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDeleteProtectSubDirs() throws Throwable {
|
|
|
+ for (TestMatrixEntry testMatrixEntry :
|
|
|
+ createTestMatrixForProtectSubDirs()) {
|
|
|
+ Configuration conf = new HdfsConfiguration();
|
|
|
+ conf.setBoolean(DFS_PROTECTED_SUBDIRECTORIES_ENABLE, true);
|
|
|
+ MiniDFSCluster cluster = setupTestCase(
|
|
|
+ conf, testMatrixEntry.getProtectedPaths(),
|
|
|
+ testMatrixEntry.getUnprotectedPaths());
|
|
|
+
|
|
|
+ try {
|
|
|
+ LOG.info("Running {}", testMatrixEntry);
|
|
|
+ FileSystem fs = cluster.getFileSystem();
|
|
|
+ for (Path path : testMatrixEntry.getAllPathsToBeDeleted()) {
|
|
|
+ final long countBefore = cluster.getNamesystem().getFilesTotal();
|
|
|
+ assertThat(
|
|
|
+ testMatrixEntry + ": Testing whether "
|
|
|
+ + path + " can be deleted",
|
|
|
+ deletePath(fs, path),
|
|
|
+ is(testMatrixEntry.canPathBeDeleted(path)));
|
|
|
+ final long countAfter = cluster.getNamesystem().getFilesTotal();
|
|
|
+
|
|
|
+ if (!testMatrixEntry.canPathBeDeleted(path)) {
|
|
|
+ assertThat(
|
|
|
+ "Either all paths should be deleted or none",
|
|
|
+ countAfter, is(countBefore));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Verify that configured paths are normalized by removing
|
|
|
* redundant separators.
|