public virtual void TestRenameWithNonEmptySubDir() { Path renameTestDir = Path("testRenameWithNonEmptySubDir"); Path srcDir = new Path(renameTestDir, "src1"); Path srcSubDir = new Path(srcDir, "sub"); Path finalDir = new Path(renameTestDir, "dest"); FileSystem fs = GetFileSystem(); bool renameRemoveEmptyDest = IsSupported(RenameRemoveDestIfEmptyDir); ContractTestUtils.Rm(fs, renameTestDir, true, false); fs.Mkdirs(srcDir); fs.Mkdirs(finalDir); ContractTestUtils.WriteTextFile(fs, new Path(srcDir, "source.txt"), "this is the file in src dir" , false); ContractTestUtils.WriteTextFile(fs, new Path(srcSubDir, "subfile.txt"), "this is the file in src/sub dir" , false); ContractTestUtils.AssertPathExists(fs, "not created in src dir", new Path(srcDir, "source.txt")); ContractTestUtils.AssertPathExists(fs, "not created in src/sub dir", new Path(srcSubDir , "subfile.txt")); fs.Rename(srcDir, finalDir); // Accept both POSIX rename behavior and CLI rename behavior if (renameRemoveEmptyDest) { // POSIX rename behavior ContractTestUtils.AssertPathExists(fs, "not renamed into dest dir", new Path(finalDir , "source.txt")); ContractTestUtils.AssertPathExists(fs, "not renamed into dest/sub dir", new Path( finalDir, "sub/subfile.txt")); } else { // CLI rename behavior ContractTestUtils.AssertPathExists(fs, "not renamed into dest dir", new Path(finalDir , "src1/source.txt")); ContractTestUtils.AssertPathExists(fs, "not renamed into dest/sub dir", new Path( finalDir, "src1/sub/subfile.txt")); } ContractTestUtils.AssertPathDoesNotExist(fs, "not deleted", new Path(srcDir, "source.txt" )); }