ayushtkn commented on a change in pull request #3987:
URL: https://github.com/apache/hadoop/pull/3987#discussion_r812563504



##########
File path: 
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java
##########
@@ -1671,4 +1675,62 @@ public void 
testTargetFileSystemLazyInitializationForChecksumMethods()
     // viewfs inner cache is disabled
     assertEquals(cacheSize + 1, TestFileUtil.getCacheSize());
   }
+
+  @Test
+  public void testInternalDirectoryOwnership() throws IOException {
+    Configuration localConf = new Configuration(conf);
+    FileSystem fs = FileSystem.get(FsConstants.VIEWFS_URI, localConf);
+
+    // Check default owner/group.
+    final UserGroupInformation currentUser =
+        UserGroupInformation.getCurrentUser();
+    FileStatus status = fs.getFileStatus(new Path("/internalDir"));
+    assertEquals(currentUser.getUserName(), status.getOwner());
+    assertEquals(currentUser.getGroupNames()[0], status.getGroup());
+    assertEquals(PERMISSION_555, status.getPermission());
+
+    UserGroupInformation currUgi = UserGroupInformation.getCurrentUser();
+    try {
+      // Force exception when currUgi.getPrimaryGroupName() is called. This 
will
+      // not be triggered when viewfs mount link configs are defined.
+      UserGroupInformation spyUgi = spy(currUgi);
+      String failureMessage = "Fail on group check";
+      when(spyUgi.getPrimaryGroupName()).thenThrow(
+          new IOException(failureMessage));
+      UserGroupInformation.setLoginUser(spyUgi);
+
+      fs = FileSystem.get(FsConstants.VIEWFS_URI, localConf);
+      try {
+        // Exception triggered as currUgi.getPrimaryGroupName() is called.
+        fs.getFileStatus(new Path("/internalDir"));
+        fail("IOException expected");
+      } catch (IOException e) {
+        assertEquals(failureMessage, e.getMessage());
+      }

Review comment:
       Use `LambdaTestUtils.intercept` instead




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to