|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright (c) 2014 Gluster, Inc. <http://www.gluster.com> |
| 4 | + * This file is part of GlusterFS. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 |
| 7 | + * (the "License"); you may not use this file except in compliance with |
| 8 | + * the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 15 | + * implied. See the License for the specific language governing |
| 16 | + * permissions and limitations under the License. |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.hadoop.fs.test.unit; |
| 21 | + |
| 22 | +import static org.apache.hadoop.fs.FileSystemTestHelper.getTestRootPath; |
| 23 | +import static org.junit.Assert.assertEquals; |
| 24 | +import static org.junit.Assert.assertFalse; |
| 25 | +import static org.junit.Assert.assertTrue; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +import org.apache.hadoop.fs.FSDataInputStream; |
| 30 | +import org.apache.hadoop.fs.FSDataOutputStream; |
| 31 | +import org.apache.hadoop.fs.FileStatus; |
| 32 | +import org.apache.hadoop.fs.FileSystem; |
| 33 | +import org.apache.hadoop.fs.Path; |
| 34 | +import org.apache.hadoop.conf.Configuration; |
| 35 | +import org.apache.hadoop.fs.permission.FsAction; |
| 36 | +import org.apache.hadoop.fs.permission.FsPermission; |
| 37 | +import org.apache.hadoop.fs.test.connector.HcfsTestConnectorFactory; |
| 38 | +import org.apache.hadoop.fs.test.connector.HcfsTestConnectorInterface; |
| 39 | +import org.junit.After; |
| 40 | +import org.junit.AfterClass; |
| 41 | +import org.junit.Assert; |
| 42 | +import org.junit.BeforeClass; |
| 43 | +import org.junit.Test; |
| 44 | + |
| 45 | +/** |
| 46 | + * Unit test for HCFS classes. |
| 47 | + * |
| 48 | + */ |
| 49 | +public class HcfsUmaskTest{ |
| 50 | + |
| 51 | + static FileSystem fs ; |
| 52 | + |
| 53 | + @BeforeClass |
| 54 | + public static void setup() throws Exception { |
| 55 | + HcfsTestConnectorInterface connector = HcfsTestConnectorFactory.getHcfsTestConnector(); |
| 56 | + fs= connector.create(); |
| 57 | + } |
| 58 | + |
| 59 | + @AfterClass |
| 60 | + public static void after() throws IOException{ |
| 61 | + fs.close(); |
| 62 | + } |
| 63 | + |
| 64 | + @After |
| 65 | + public void tearDown() throws Exception { |
| 66 | + fs.delete(getTestRootPath(fs, "test"),true); |
| 67 | + } |
| 68 | + |
| 69 | + @org.junit.Test |
| 70 | + public void testMkdirsWithUmask() throws Exception { |
| 71 | + Configuration conf = fs.getConf(); |
| 72 | + String oldUmask = conf.get("fs.permissions.umask-mode"); |
| 73 | + Path dir = new Path("/dirUmask022"); |
| 74 | + conf.set("fs.permissions.umask-mode", "022"); |
| 75 | + assertTrue(fs.mkdirs(dir)); |
| 76 | + conf.set("fs.permissions.umask-mode", oldUmask); |
| 77 | + FileStatus status = fs.getFileStatus(dir); |
| 78 | + assertTrue(status.isDirectory()); |
| 79 | + assertEquals((short)0755, status.getPermission().toShort()); |
| 80 | + |
| 81 | + } |
| 82 | +} |
0 commit comments