From c3f13a7fefa524e4bcc35d736d53bea3fab16ae0 Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Tue, 20 Nov 2012 21:13:48 +0000 Subject: [PATCH] HADOOP-9042. Add a test for umask in FileSystemContractBaseTest. Contributed by Colin McCabe git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1411879 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/fs/FileSystemContractBaseTest.java | 25 +++++++++++++++++-- .../hdfs/TestHDFSFileSystemContract.java | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index a09b3f55c3..ab9ed3d820 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -373,6 +373,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-9035. Generalize setup of LoginContext (daryn via bobby) + HADOOP-9042. Add a test for umask in FileSystemContractBaseTest. + (Colin McCabe via eli) + OPTIMIZATIONS HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileSystemContractBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileSystemContractBaseTest.java index 94c4b0c31f..523feabee8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileSystemContractBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/FileSystemContractBaseTest.java @@ -23,11 +23,13 @@ import junit.framework.TestCase; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; /** *

@@ -43,7 +45,7 @@ *

*/ public abstract class FileSystemContractBaseTest extends TestCase { - + protected final static String TEST_UMASK = "062"; protected FileSystem fs; protected byte[] data = new byte[getBlockSize() * 2]; // two blocks of data { @@ -151,7 +153,26 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception { assertFalse(fs.exists(testDeepSubDir)); } - + + public void testMkdirsWithUmask() throws Exception { + if (fs.getScheme().equals("s3") || fs.getScheme().equals("s3n")) { + // skip permission tests for S3FileSystem until HDFS-1333 is fixed. + return; + } + Configuration conf = fs.getConf(); + String oldUmask = conf.get(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY); + try { + conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, TEST_UMASK); + final Path dir = new Path("/test/newDir"); + assertTrue(fs.mkdirs(dir, new FsPermission((short)0777))); + FileStatus status = fs.getFileStatus(dir); + assertTrue(status.isDirectory()); + assertEquals((short)0715, status.getPermission().toShort()); + } finally { + conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, oldUmask); + } + } + public void testGetFileStatusThrowsExceptionForNonExistentFile() throws Exception { try { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java index cd0a9e0e18..b4345f0367 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHDFSFileSystemContract.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.FileSystemContractBaseTest; import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.UserGroupInformation; @@ -33,6 +34,8 @@ public class TestHDFSFileSystemContract extends FileSystemContractBaseTest { @Override protected void setUp() throws Exception { Configuration conf = new HdfsConfiguration(); + conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, + FileSystemContractBaseTest.TEST_UMASK); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); fs = cluster.getFileSystem(); defaultWorkingDirectory = "/user/" +