|
30 | 30 | import java.util.Map; |
31 | 31 | import java.util.Random; |
32 | 32 |
|
| 33 | +import org.apache.hadoop.test.GenericTestUtils; |
33 | 34 | import org.slf4j.Logger; |
34 | 35 | import org.slf4j.LoggerFactory; |
35 | 36 | import org.apache.hadoop.conf.Configuration; |
@@ -260,6 +261,33 @@ private void createAndCheckPermission(OpType op, Path name, short umask, |
260 | 261 | checkPermission(name, expectedPermission, delete); |
261 | 262 | } |
262 | 263 |
|
| 264 | + @Test |
| 265 | + public void testFSNamesystemCheckAccess() throws Exception { |
| 266 | + Path testValidDir = new Path("/test1"); |
| 267 | + Path testValidFile = new Path("/test1/file1"); |
| 268 | + Path testInvalidPath = new Path("/test2"); |
| 269 | + fs = FileSystem.get(conf); |
| 270 | + |
| 271 | + fs.mkdirs(testValidDir); |
| 272 | + fs.create(testValidFile); |
| 273 | + |
| 274 | + fs.access(testValidDir,FsAction.READ); |
| 275 | + fs.access(testValidFile,FsAction.READ); |
| 276 | + |
| 277 | + assertTrue(fs.exists(testValidDir)); |
| 278 | + assertTrue(fs.exists(testValidFile)); |
| 279 | + |
| 280 | + try { |
| 281 | + fs.access(testInvalidPath,FsAction.READ); |
| 282 | + fail("Failed to get expected FileNotFoundException"); |
| 283 | + } catch (FileNotFoundException e) { |
| 284 | + GenericTestUtils.assertExceptionContains( |
| 285 | + "Path not found: " + testInvalidPath, e); |
| 286 | + } finally { |
| 287 | + fs.delete(testValidDir,true); |
| 288 | + } |
| 289 | + } |
| 290 | + |
263 | 291 | /* Check if the permission of a file/directory is the same as the |
264 | 292 | * expected permission; If the delete flag is true, delete the |
265 | 293 | * file/directory afterwards. |
@@ -289,7 +317,7 @@ public void testImmutableFsPermission() throws IOException { |
289 | 317 | fs.setPermission(new Path("/"), |
290 | 318 | FsPermission.createImmutable((short)0777)); |
291 | 319 | } |
292 | | - |
| 320 | + |
293 | 321 | @Test(timeout=30000) |
294 | 322 | public void testTrashPermission() throws Exception { |
295 | 323 | // /BSS user1:group2 777 |
|
0 commit comments