|
@@ -25,10 +25,15 @@ import static org.junit.Assert.fail;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.Options;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.PathIsNotDirectoryException;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.fs.permission.PermissionStatus;
|
|
|
+import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
+import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
|
+import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
|
import org.junit.Test;
|
|
|
|
|
@@ -157,6 +162,48 @@ public class TestINodeFile {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * FSDirectory#unprotectedSetQuota creates a new INodeDirectoryWithQuota to
|
|
|
+ * replace the original INodeDirectory. Before HDFS-4243, the parent field of
|
|
|
+ * all the children INodes of the target INodeDirectory is not changed to
|
|
|
+ * point to the new INodeDirectoryWithQuota. This testcase tests this
|
|
|
+ * scenario.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testGetFullPathNameAfterSetQuota() throws Exception {
|
|
|
+ long fileLen = 1024;
|
|
|
+ replication = 3;
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(
|
|
|
+ replication).build();
|
|
|
+ cluster.waitActive();
|
|
|
+ FSNamesystem fsn = cluster.getNamesystem();
|
|
|
+ FSDirectory fsdir = fsn.getFSDirectory();
|
|
|
+ DistributedFileSystem dfs = cluster.getFileSystem();
|
|
|
+
|
|
|
+ // Create a file for test
|
|
|
+ final Path dir = new Path("/dir");
|
|
|
+ final Path file = new Path(dir, "file");
|
|
|
+ DFSTestUtil.createFile(dfs, file, fileLen, replication, 0L);
|
|
|
+
|
|
|
+ // Check the full path name of the INode associating with the file
|
|
|
+ INode fnode = fsdir.getINode(file.toString());
|
|
|
+ assertEquals(file.toString(), fnode.getFullPathName());
|
|
|
+
|
|
|
+ // Call FSDirectory#unprotectedSetQuota which calls
|
|
|
+ // INodeDirectory#replaceChild
|
|
|
+ dfs.setQuota(dir, Long.MAX_VALUE - 1, replication * fileLen * 10);
|
|
|
+ final Path newDir = new Path("/newdir");
|
|
|
+ final Path newFile = new Path(newDir, "file");
|
|
|
+ // Also rename dir
|
|
|
+ dfs.rename(dir, newDir, Options.Rename.OVERWRITE);
|
|
|
+ // /dir/file now should be renamed to /newdir/file
|
|
|
+ fnode = fsdir.getINode(newFile.toString());
|
|
|
+ // getFullPathName can return correct result only if the parent field of
|
|
|
+ // child node is set correctly
|
|
|
+ assertEquals(newFile.toString(), fnode.getFullPathName());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testAppendBlocks() {
|
|
|
INodeFile origFile = createINodeFiles(1, "origfile")[0];
|