Search in sources :

Example 1 with TestHdfs

use of org.apache.hadoop.test.TestHdfs in project hadoop by apache.

the class TestHttpFSServer method testPerms.

/**
   * Validate that files are created with 755 permissions when no
   * 'permissions' attribute is specified, and when 'permissions'
   * is specified, that value is honored.
   */
@Test
@TestDir
@TestJetty
@TestHdfs
public void testPerms() throws Exception {
    createHttpFSServer(false);
    FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
    fs.mkdirs(new Path("/perm"));
    createWithHttp("/perm/none", null);
    String statusJson = getStatus("/perm/none", "GETFILESTATUS");
    Assert.assertTrue("755".equals(getPerms(statusJson)));
    createWithHttp("/perm/p-777", "777");
    statusJson = getStatus("/perm/p-777", "GETFILESTATUS");
    Assert.assertTrue("777".equals(getPerms(statusJson)));
    createWithHttp("/perm/p-654", "654");
    statusJson = getStatus("/perm/p-654", "GETFILESTATUS");
    Assert.assertTrue("654".equals(getPerms(statusJson)));
    createWithHttp("/perm/p-321", "321");
    statusJson = getStatus("/perm/p-321", "GETFILESTATUS");
    Assert.assertTrue("321".equals(getPerms(statusJson)));
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 2 with TestHdfs

use of org.apache.hadoop.test.TestHdfs in project hadoop by apache.

the class TestHttpFSServer method testDirAcls.

/**
   * Test ACL operations on a directory, including default ACLs.
   * General strategy is to use GETFILESTATUS and GETACLSTATUS to verify:
   * <ol>
   *   <li>Initial status with no ACLs</li>
   *   <li>The addition of a default ACL</li>
   *   <li>The removal of default ACLs</li>
   * </ol>
   *
   * @throws Exception
   */
@Test
@TestDir
@TestJetty
@TestHdfs
public void testDirAcls() throws Exception {
    final String defUser1 = "default:user:glarch:r-x";
    final String defSpec1 = "aclspec=" + defUser1;
    final String dir = "/aclDirTest";
    String statusJson;
    List<String> aclEntries;
    createHttpFSServer(false);
    FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
    fs.mkdirs(new Path(dir));
    /* getfilestatus and liststatus don't have 'aclBit' in their reply */
    statusJson = getStatus(dir, "GETFILESTATUS");
    Assert.assertEquals(-1, statusJson.indexOf("aclBit"));
    /* No ACLs, either */
    statusJson = getStatus(dir, "GETACLSTATUS");
    aclEntries = getAclEntries(statusJson);
    Assert.assertTrue(aclEntries.size() == 0);
    /* Give it a default ACL and verify */
    putCmd(dir, "SETACL", defSpec1);
    statusJson = getStatus(dir, "GETFILESTATUS");
    Assert.assertNotEquals(-1, statusJson.indexOf("aclBit"));
    statusJson = getStatus(dir, "GETACLSTATUS");
    aclEntries = getAclEntries(statusJson);
    Assert.assertTrue(aclEntries.size() == 5);
    /* 4 Entries are default:(user|group|mask|other):perm */
    Assert.assertTrue(aclEntries.contains(defUser1));
    /* Remove the default ACL and re-verify */
    putCmd(dir, "REMOVEDEFAULTACL", null);
    statusJson = getStatus(dir, "GETFILESTATUS");
    Assert.assertEquals(-1, statusJson.indexOf("aclBit"));
    statusJson = getStatus(dir, "GETACLSTATUS");
    aclEntries = getAclEntries(statusJson);
    Assert.assertTrue(aclEntries.size() == 0);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 3 with TestHdfs

use of org.apache.hadoop.test.TestHdfs in project hadoop by apache.

the class TestHttpFSServer method testGetTrashRoot.

@Test
@TestDir
@TestJetty
@TestHdfs
public void testGetTrashRoot() throws Exception {
    String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
    createHttpFSServer(false);
    String trashJson = getStatus("/", "GETTRASHROOT");
    String trashPath = getPath(trashJson);
    Path expectedPath = new Path(FileSystem.USER_HOME_PREFIX, new Path(user, FileSystem.TRASH_PREFIX));
    Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
    byte[] array = new byte[] { 0, 1, 2, 3 };
    FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
    fs.mkdirs(new Path("/tmp"));
    OutputStream os = fs.create(new Path("/tmp/foo"));
    os.write(array);
    os.close();
    trashJson = getStatus("/tmp/foo", "GETTRASHROOT");
    trashPath = getPath(trashJson);
    Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
    //TestHdfsHelp has already set up EZ environment
    final Path ezFile = TestHdfsHelper.ENCRYPTED_FILE;
    final Path ezPath = TestHdfsHelper.ENCRYPTION_ZONE;
    trashJson = getStatus(ezFile.toUri().getPath(), "GETTRASHROOT");
    trashPath = getPath(trashJson);
    expectedPath = new Path(ezPath, new Path(FileSystem.TRASH_PREFIX, user));
    Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 4 with TestHdfs

use of org.apache.hadoop.test.TestHdfs in project hadoop by apache.

the class TestHttpFSServer method testGlobFilter.

@Test
@TestDir
@TestJetty
@TestHdfs
public void testGlobFilter() throws Exception {
    createHttpFSServer(false);
    FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
    fs.mkdirs(new Path("/tmp"));
    fs.create(new Path("/tmp/foo.txt")).close();
    String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
    URL url = new URL(TestJettyHelper.getJettyURL(), MessageFormat.format("/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*", user));
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
    BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    reader.readLine();
    reader.close();
}
Also used : Path(org.apache.hadoop.fs.Path) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 5 with TestHdfs

use of org.apache.hadoop.test.TestHdfs in project hadoop by apache.

the class TestHttpFSServer method testXAttrs.

/**
   * Validate XAttr get/set/remove calls.
   */
@Test
@TestDir
@TestJetty
@TestHdfs
public void testXAttrs() throws Exception {
    final String name1 = "user.a1";
    final byte[] value1 = new byte[] { 0x31, 0x32, 0x33 };
    final String name2 = "user.a2";
    final byte[] value2 = new byte[] { 0x41, 0x42, 0x43 };
    final String dir = "/xattrTest";
    final String path = dir + "/file";
    createHttpFSServer(false);
    FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
    fs.mkdirs(new Path(dir));
    createWithHttp(path, null);
    String statusJson = getStatus(path, "GETXATTRS");
    Map<String, byte[]> xAttrs = getXAttrs(statusJson);
    Assert.assertEquals(0, xAttrs.size());
    // Set two xattrs
    putCmd(path, "SETXATTR", setXAttrParam(name1, value1));
    putCmd(path, "SETXATTR", setXAttrParam(name2, value2));
    statusJson = getStatus(path, "GETXATTRS");
    xAttrs = getXAttrs(statusJson);
    Assert.assertEquals(2, xAttrs.size());
    Assert.assertArrayEquals(value1, xAttrs.get(name1));
    Assert.assertArrayEquals(value2, xAttrs.get(name2));
    // Remove one xattr
    putCmd(path, "REMOVEXATTR", "xattr.name=" + name1);
    statusJson = getStatus(path, "GETXATTRS");
    xAttrs = getXAttrs(statusJson);
    Assert.assertEquals(1, xAttrs.size());
    Assert.assertArrayEquals(value2, xAttrs.get(name2));
    // Remove another xattr, then there is no xattr
    putCmd(path, "REMOVEXATTR", "xattr.name=" + name2);
    statusJson = getStatus(path, "GETXATTRS");
    xAttrs = getXAttrs(statusJson);
    Assert.assertEquals(0, xAttrs.size());
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) TestJetty(org.apache.hadoop.test.TestJetty) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Aggregations

TestDir (org.apache.hadoop.test.TestDir)21 TestHdfs (org.apache.hadoop.test.TestHdfs)21 Test (org.junit.Test)21 TestJetty (org.apache.hadoop.test.TestJetty)16 FileSystem (org.apache.hadoop.fs.FileSystem)13 Path (org.apache.hadoop.fs.Path)12 HttpURLConnection (java.net.HttpURLConnection)9 URL (java.net.URL)9 AuthenticatedURL (org.apache.hadoop.security.authentication.client.AuthenticatedURL)9 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)5 Configuration (org.apache.hadoop.conf.Configuration)5 Server (org.apache.hadoop.lib.server.Server)5 FileSystemAccess (org.apache.hadoop.lib.service.FileSystemAccess)5 TestException (org.apache.hadoop.test.TestException)5 ServiceException (org.apache.hadoop.lib.server.ServiceException)4 FileSystemAccessException (org.apache.hadoop.lib.service.FileSystemAccessException)4 BufferedReader (java.io.BufferedReader)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3