Skip to content

Commit f474af2

Browse files
committed
Moved nested mount points tests to ViewFileSystemBaseTest
1 parent e42ccc5 commit f474af2

File tree

3 files changed

+143
-266
lines changed

3 files changed

+143
-266
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public static String getDefaultMountTableName(final Configuration conf) {
249249
}
250250

251251
/**
252-
* Get the bool config whether nested mount point is supported.
252+
* Check the bool config whether nested mount point is supported.
253253
* @param conf - from this conf
254254
* @return whether nested mount point is supported
255255
*/

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,148 @@ public void testRenameAcrossMounts4() throws IOException {
460460
.assertIsFile(fsTarget, new Path(targetTestRoot, "data/fooBar"));
461461
}
462462

463+
464+
// rename across nested mount points that point to same target also fail
465+
@Test
466+
public void testRenameAcrossNestedMountPointSameTarget() throws IOException {
467+
setUpNestedMountPoint();
468+
fileSystemTestHelper.createFile(fsView, "/user/foo");
469+
try {
470+
// Nested mount points point to the same target should fail
471+
// /user -> /user
472+
// /user/userA -> /user
473+
// Rename strategy: SAME_MOUNTPOINT
474+
fsView.rename(new Path("/user/foo"), new Path("/user/userA/foo"));
475+
ContractTestUtils.fail("IOException is not thrown on rename operation");
476+
} catch (IOException e) {
477+
GenericTestUtils
478+
.assertExceptionContains("Renames across Mount points not supported",
479+
e);
480+
}
481+
}
482+
483+
484+
// rename across nested mount points fail if the mount link targets are different
485+
// even if the targets are part of the same target FS
486+
@Test
487+
public void testRenameAcrossMountPointDifferentTarget() throws IOException {
488+
setUpNestedMountPoint();
489+
fileSystemTestHelper.createFile(fsView, "/data/foo");
490+
// /data -> /data
491+
// /data/dataA -> /dataA
492+
// Rename strategy: SAME_MOUNTPOINT
493+
try {
494+
fsView.rename(new Path("/data/foo"), new Path("/data/dataA/fooBar"));
495+
ContractTestUtils.fail("IOException is not thrown on rename operation");
496+
} catch (IOException e) {
497+
GenericTestUtils
498+
.assertExceptionContains("Renames across Mount points not supported",
499+
e);
500+
}
501+
}
502+
503+
// RenameStrategy SAME_TARGET_URI_ACROSS_MOUNTPOINT enabled
504+
// to rename across nested mount points that point to same target URI
505+
@Test
506+
public void testRenameAcrossNestedMountPointSameTargetUriAcrossMountPoint() throws IOException {
507+
setUpNestedMountPoint();
508+
// /user/foo -> /user
509+
// /user/userA/fooBarBar -> /user
510+
// Rename strategy: SAME_TARGET_URI_ACROSS_MOUNTPOINT
511+
Configuration conf2 = new Configuration(conf);
512+
conf2.set(Constants.CONFIG_VIEWFS_RENAME_STRATEGY,
513+
ViewFileSystem.RenameStrategy.SAME_TARGET_URI_ACROSS_MOUNTPOINT
514+
.toString());
515+
FileSystem fsView2 = FileSystem.newInstance(FsConstants.VIEWFS_URI, conf2);
516+
fileSystemTestHelper.createFile(fsView2, "/user/foo");
517+
fsView2.rename(new Path("/user/foo"), new Path("/user/userA/fooBarBar"));
518+
ContractTestUtils.assertPathDoesNotExist(fsView2, "src should not exist after rename",
519+
new Path("/user/foo"));
520+
ContractTestUtils.assertPathDoesNotExist(fsTarget, "src should not exist after rename",
521+
new Path(targetTestRoot, "user/foo"));
522+
ContractTestUtils.assertIsFile(fsView2, fileSystemTestHelper.getTestRootPath(fsView2, "/user/userA/fooBarBar"));
523+
ContractTestUtils.assertIsFile(fsTarget, new Path(targetTestRoot, "user/fooBarBar"));
524+
}
525+
526+
// RenameStrategy SAME_FILESYSTEM_ACROSS_MOUNTPOINT enabled
527+
// to rename across mount points where the mount link targets are different
528+
// but are part of the same target FS
529+
@Test
530+
public void testRenameAcrossNestedMountPointSameFileSystemAcrossMountPoint() throws IOException {
531+
setUpNestedMountPoint();
532+
// /data/foo -> /data
533+
// /data/dataA/fooBar -> /dataA
534+
// Rename strategy: SAME_FILESYSTEM_ACROSS_MOUNTPOINT
535+
Configuration conf2 = new Configuration(conf);
536+
conf2.set(Constants.CONFIG_VIEWFS_RENAME_STRATEGY,
537+
ViewFileSystem.RenameStrategy.SAME_FILESYSTEM_ACROSS_MOUNTPOINT
538+
.toString());
539+
FileSystem fsView2 = FileSystem.newInstance(FsConstants.VIEWFS_URI, conf2);
540+
fileSystemTestHelper.createFile(fsView2, "/data/foo");
541+
fsView2.rename(new Path("/data/foo"), new Path("/data/dataB/fooBar"));
542+
ContractTestUtils
543+
.assertPathDoesNotExist(fsView2, "src should not exist after rename",
544+
new Path("/data/foo"));
545+
ContractTestUtils
546+
.assertPathDoesNotExist(fsTarget, "src should not exist after rename",
547+
new Path(targetTestRoot, "data/foo"));
548+
ContractTestUtils.assertIsFile(fsView2,
549+
fileSystemTestHelper.getTestRootPath(fsView2, "/user/fooBar"));
550+
ContractTestUtils
551+
.assertIsFile(fsTarget, new Path(targetTestRoot, "user/fooBar"));
552+
}
553+
554+
@Test
555+
public void testOperationsThroughNestedMountPointsInternal()
556+
throws IOException {
557+
setUpNestedMountPoint();
558+
// Create file with nested mount point
559+
fileSystemTestHelper.createFile(fsView, "/user/userB/foo");
560+
Assert.assertTrue("Created file should be type file",
561+
fsView.getFileStatus(new Path("/user/userB/foo")).isFile());
562+
Assert.assertTrue("Target of created file should be type file",
563+
fsTarget.getFileStatus(new Path(targetTestRoot,"userB/foo")).isFile());
564+
565+
// Delete the created file with nested mount point
566+
Assert.assertTrue("Delete should succeed",
567+
fsView.delete(new Path("/user/userB/foo"), false));
568+
Assert.assertFalse("File should not exist after delete",
569+
fsView.exists(new Path("/user/userB/foo")));
570+
Assert.assertFalse("Target File should not exist after delete",
571+
fsTarget.exists(new Path(targetTestRoot,"userB/foo")));
572+
573+
// Create file with a 2 component dirs with nested mount point
574+
fileSystemTestHelper.createFile(fsView, "/internalDir/linkToDir2/linkToDir2/foo");
575+
Assert.assertTrue("Created file should be type file",
576+
fsView.getFileStatus(new Path("/internalDir/linkToDir2/linkToDir2/foo")).isFile());
577+
Assert.assertTrue("Target of created file should be type file",
578+
fsTarget.getFileStatus(new Path(targetTestRoot,"linkToDir2/foo")).isFile());
579+
580+
// Delete the created file with nested mount point
581+
Assert.assertTrue("Delete should succeed",
582+
fsView.delete(new Path("/internalDir/linkToDir2/linkToDir2/foo"), false));
583+
Assert.assertFalse("File should not exist after delete",
584+
fsView.exists(new Path("/internalDir/linkToDir2/linkToDir2/foo")));
585+
Assert.assertFalse("Target File should not exist after delete",
586+
fsTarget.exists(new Path(targetTestRoot,"linkToDir2/foo")));
587+
}
588+
589+
private void setUpNestedMountPoint() throws IOException {
590+
// Enable nested mount point, ViewFilesystem should support both non-nested and nested mount points
591+
ConfigUtil.setIsNestedMountPointSupported(conf, true);
592+
ConfigUtil.addLink(conf, "/user/userA",
593+
new Path(targetTestRoot, "user").toUri());
594+
ConfigUtil.addLink(conf, "/user/userB",
595+
new Path(targetTestRoot, "userB").toUri());
596+
ConfigUtil.addLink(conf, "/data/dataA",
597+
new Path(targetTestRoot, "dataA").toUri());
598+
ConfigUtil.addLink(conf, "/data/dataB",
599+
new Path(targetTestRoot, "user").toUri());
600+
ConfigUtil.addLink(conf, "/internalDir/linkToDir2/linkToDir2",
601+
new Path(targetTestRoot,"linkToDir2").toUri());
602+
fsView = FileSystem.get(FsConstants.VIEWFS_URI, conf);
603+
}
604+
463605
static protected boolean SupportsBlocks = false; // local fs use 1 block
464606
// override for HDFS
465607
@Test

0 commit comments

Comments
 (0)