|
24 | 24 |
|
25 | 25 | import java.io.FileNotFoundException; |
26 | 26 | import java.io.IOException; |
| 27 | +import java.net.URISyntaxException; |
27 | 28 | import java.util.Collections; |
28 | 29 | import java.util.HashMap; |
29 | 30 | import java.util.Iterator; |
|
53 | 54 | import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest; |
54 | 55 | import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; |
55 | 56 | import org.apache.hadoop.security.AccessControlException; |
| 57 | +import org.apache.hadoop.security.UserGroupInformation; |
56 | 58 | import org.apache.hadoop.test.LambdaTestUtils; |
57 | 59 | import org.apache.hadoop.util.Time; |
58 | 60 | import org.junit.After; |
@@ -254,6 +256,61 @@ public void testListFilesTime() throws Exception { |
254 | 256 | } |
255 | 257 | } |
256 | 258 |
|
| 259 | + /** |
| 260 | + * Verify that the file/dir status with IOException in getMountPointStatus. |
| 261 | + */ |
| 262 | + @Test |
| 263 | + public void testGetMountPointStatusWithIOException() |
| 264 | + throws IOException, InterruptedException { |
| 265 | + try { |
| 266 | + // Add mount table entry. |
| 267 | + MountTable addEntry = MountTable.newInstance("/testA", |
| 268 | + Collections.singletonMap("ns0", "/testA")); |
| 269 | + assertTrue(addMountTable(addEntry)); |
| 270 | + addEntry = MountTable.newInstance("/testA/testB", |
| 271 | + Collections.singletonMap("ns0", "/testA/testB")); |
| 272 | + assertTrue(addMountTable(addEntry)); |
| 273 | + addEntry = MountTable.newInstance("/testB", |
| 274 | + Collections.singletonMap("ns0", "/test1/testB")); |
| 275 | + addEntry.setOwnerName("userB"); |
| 276 | + addEntry.setGroupName("groupB"); |
| 277 | + assertTrue(addMountTable(addEntry)); |
| 278 | + |
| 279 | + assertTrue(nnFs0.mkdirs(new Path("/test1"))); |
| 280 | + nnFs0.setPermission(new Path("/test1"), |
| 281 | + FsPermission.createImmutable((short) 0700)); |
| 282 | + |
| 283 | + // Use mock user to getListing through router. |
| 284 | + UserGroupInformation user = UserGroupInformation.createUserForTesting( |
| 285 | + "mock_user", new String[] {"mock_group"}); |
| 286 | + LambdaTestUtils.doAs(user, () -> getListing("/testA")); |
| 287 | + } finally { |
| 288 | + nnFs0.delete(new Path("/test1"), true); |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + /** |
| 293 | + * GetListing of testPath through router. |
| 294 | + */ |
| 295 | + private void getListing(String testPath) |
| 296 | + throws IOException, URISyntaxException { |
| 297 | + ClientProtocol clientProtocol1 = |
| 298 | + routerContext.getClient().getNamenode(); |
| 299 | + DirectoryListing listing = clientProtocol1.getListing(testPath, |
| 300 | + HdfsFileStatus.EMPTY_NAME, false); |
| 301 | + |
| 302 | + assertEquals(1, listing.getPartialListing().length); |
| 303 | + HdfsFileStatus fileStatus = listing.getPartialListing()[0]; |
| 304 | + String currentOwner = fileStatus.getOwner(); |
| 305 | + String currentGroup = fileStatus.getGroup(); |
| 306 | + String currentFileName = |
| 307 | + fileStatus.getFullPath(new Path("/")).getName(); |
| 308 | + |
| 309 | + assertEquals("testB", currentFileName); |
| 310 | + assertEquals("userB", currentOwner); |
| 311 | + assertEquals("groupB", currentGroup); |
| 312 | + } |
| 313 | + |
257 | 314 | /** |
258 | 315 | * Verify permission for a mount point when the actual destination is not |
259 | 316 | * present. It returns the permissions of the mount point. |
|
0 commit comments