Skip to content

Commit 912a139

Browse files
committed
'addDFSPermission'
1 parent d8aa3b3 commit 912a139

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSPermission.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Map;
3131
import java.util.Random;
3232

33+
import org.apache.hadoop.test.GenericTestUtils;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
3536
import org.apache.hadoop.conf.Configuration;
@@ -260,6 +261,33 @@ private void createAndCheckPermission(OpType op, Path name, short umask,
260261
checkPermission(name, expectedPermission, delete);
261262
}
262263

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+
263291
/* Check if the permission of a file/directory is the same as the
264292
* expected permission; If the delete flag is true, delete the
265293
* file/directory afterwards.
@@ -289,7 +317,7 @@ public void testImmutableFsPermission() throws IOException {
289317
fs.setPermission(new Path("/"),
290318
FsPermission.createImmutable((short)0777));
291319
}
292-
320+
293321
@Test(timeout=30000)
294322
public void testTrashPermission() throws Exception {
295323
// /BSS user1:group2 777

0 commit comments

Comments
 (0)