Java Code Examples for org.apache.hadoop.fs.contract.ContractTestUtils#touch()

The following examples show how to use org.apache.hadoop.fs.contract.ContractTestUtils#touch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private void testCreateDoesNotAddParentDirKeys() throws Exception {
  Path grandparent = new Path("/testCreateDoesNotAddParentDirKeys");
  Path parent = new Path(grandparent, "parent");
  Path child = new Path(parent, "child");
  ContractTestUtils.touch(fs, child);
  rootItemCount++; // grandparent

  OzoneKeyDetails key = getKey(child, false);
  assertEquals(key.getName(), o3fs.pathToKey(child));

  // Creating a child should not add parent keys to the bucket
  try {
    getKey(parent, true);
  } catch (IOException ex) {
    assertKeyNotFoundException(ex);
  }

  // List status on the parent should show the child file
  assertEquals("List status of parent should include the 1 child file", 1L,
      fs.listStatus(parent).length);
  assertTrue("Parent directory does not appear to be a directory",
      fs.getFileStatus(parent).isDirectory());
}
 
Example 2
Source File: TestOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private void testDeleteCreatesFakeParentDir() throws Exception {
  Path grandparent = new Path("/testDeleteCreatesFakeParentDir");
  Path parent = new Path(grandparent, "parent");
  Path child = new Path(parent, "child");
  ContractTestUtils.touch(fs, child);
  rootItemCount++; // grandparent

  // Verify that parent dir key does not exist
  // Creating a child should not add parent keys to the bucket
  try {
    getKey(parent, true);
  } catch (IOException ex) {
    assertKeyNotFoundException(ex);
  }

  // Delete the child key
  fs.delete(child, false);

  // Deleting the only child should create the parent dir key if it does
  // not exist
  String parentKey = o3fs.pathToKey(parent) + "/";
  OzoneKeyDetails parentKeyInfo = getKey(parent, true);
  assertEquals(parentKey, parentKeyInfo.getName());
}
 
Example 3
Source File: TestOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private void testListStatus() throws Exception {
  Path parent = new Path("/testListStatus");
  Path file1 = new Path(parent, "key1");
  Path file2 = new Path(parent, "key2");
  ContractTestUtils.touch(fs, file1);
  ContractTestUtils.touch(fs, file2);
  rootItemCount++; // parent

  // ListStatus on a directory should return all subdirs along with
  // files, even if there exists a file and sub-dir with the same name.
  FileStatus[] fileStatuses = o3fs.listStatus(parent);
  assertEquals("FileStatus did not return all children of the directory",
      2, fileStatuses.length);

  // ListStatus should return only the immediate children of a directory.
  Path file3 = new Path(parent, "dir1/key3");
  Path file4 = new Path(parent, "dir1/key4");
  ContractTestUtils.touch(fs, file3);
  ContractTestUtils.touch(fs, file4);
  fileStatuses = o3fs.listStatus(parent);
  assertEquals("FileStatus did not return all children of the directory",
      3, fileStatuses.length);
}
 
Example 4
Source File: TestOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Tests listStatus on a path with subdirs.
 */
private void testListStatusOnSubDirs() throws Exception {
  // Create the following key structure
  //      /dir1/dir11/dir111
  //      /dir1/dir12
  //      /dir1/dir12/file121
  //      /dir2
  // ListStatus on /dir1 should return all its immediated subdirs only
  // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
  // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
  // listStatus.
  Path dir1 = new Path("/dir1");
  Path dir11 = new Path(dir1, "dir11");
  Path dir111 = new Path(dir11, "dir111");
  Path dir12 = new Path(dir1, "dir12");
  Path file121 = new Path(dir12, "file121");
  Path dir2 = new Path("/dir2");
  fs.mkdirs(dir111);
  fs.mkdirs(dir12);
  ContractTestUtils.touch(fs, file121);
  fs.mkdirs(dir2);

  FileStatus[] fileStatuses = o3fs.listStatus(dir1);
  assertEquals("FileStatus should return only the immediate children", 2,
      fileStatuses.length);

  // Verify that the two children of /dir1 returned by listStatus operation
  // are /dir1/dir11 and /dir1/dir12.
  String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
  String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
  assertTrue(fileStatus1.equals(dir11.toString()) ||
      fileStatus1.equals(dir12.toString()));
  assertTrue(fileStatus2.equals(dir11.toString()) ||
      fileStatus2.equals(dir12.toString()));
}
 
Example 5
Source File: TestRootedOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDoesNotAddParentDirKeys() throws Exception {
  Path grandparent = new Path(testBucketPath,
      "testCreateDoesNotAddParentDirKeys");
  Path parent = new Path(grandparent, "parent");
  Path child = new Path(parent, "child");
  ContractTestUtils.touch(fs, child);

  OzoneKeyDetails key = getKey(child, false);
  OFSPath childOFSPath = new OFSPath(child);
  Assert.assertEquals(key.getName(), childOFSPath.getKeyName());

  // Creating a child should not add parent keys to the bucket
  try {
    getKey(parent, true);
  } catch (IOException ex) {
    assertKeyNotFoundException(ex);
  }

  // List status on the parent should show the child file
  Assert.assertEquals(
      "List status of parent should include the 1 child file",
      1L, fs.listStatus(parent).length);
  Assert.assertTrue(
      "Parent directory does not appear to be a directory",
      fs.getFileStatus(parent).isDirectory());
}
 
Example 6
Source File: TestRootedOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteCreatesFakeParentDir() throws Exception {
  Path grandparent = new Path(testBucketPath,
      "testDeleteCreatesFakeParentDir");
  Path parent = new Path(grandparent, "parent");
  Path child = new Path(parent, "child");
  ContractTestUtils.touch(fs, child);

  // Verify that parent dir key does not exist
  // Creating a child should not add parent keys to the bucket
  try {
    getKey(parent, true);
  } catch (IOException ex) {
    assertKeyNotFoundException(ex);
  }

  // Delete the child key
  Assert.assertTrue(fs.delete(child, false));

  // Deleting the only child should create the parent dir key if it does
  // not exist
  OFSPath parentOFSPath = new OFSPath(parent);
  String parentKey = parentOFSPath.getKeyName() + "/";
  OzoneKeyDetails parentKeyInfo = getKey(parent, true);
  Assert.assertEquals(parentKey, parentKeyInfo.getName());

  // Recursive delete with DeleteIterator
  Assert.assertTrue(fs.delete(grandparent, true));
}
 
Example 7
Source File: TestRootedOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@Test
public void testListStatus() throws Exception {
  Path parent = new Path(testBucketPath, "testListStatus");
  Path file1 = new Path(parent, "key1");
  Path file2 = new Path(parent, "key2");

  FileStatus[] fileStatuses = ofs.listStatus(testBucketPath);
  Assert.assertEquals("Should be empty", 0, fileStatuses.length);

  ContractTestUtils.touch(fs, file1);
  ContractTestUtils.touch(fs, file2);

  fileStatuses = ofs.listStatus(testBucketPath);
  Assert.assertEquals("Should have created parent",
      1, fileStatuses.length);
  Assert.assertEquals("Parent path doesn't match",
      fileStatuses[0].getPath().toUri().getPath(), parent.toString());

  // ListStatus on a directory should return all subdirs along with
  // files, even if there exists a file and sub-dir with the same name.
  fileStatuses = ofs.listStatus(parent);
  Assert.assertEquals(
      "FileStatus did not return all children of the directory",
      2, fileStatuses.length);

  // ListStatus should return only the immediate children of a directory.
  Path file3 = new Path(parent, "dir1/key3");
  Path file4 = new Path(parent, "dir1/key4");
  ContractTestUtils.touch(fs, file3);
  ContractTestUtils.touch(fs, file4);
  fileStatuses = ofs.listStatus(parent);
  Assert.assertEquals(
      "FileStatus did not return all children of the directory",
      3, fileStatuses.length);
}
 
Example 8
Source File: TestRootedOzoneFileSystem.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Tests listStatus on a path with subdirs.
 */
@Test
public void testListStatusOnSubDirs() throws Exception {
  // Create the following key structure
  //      /dir1/dir11/dir111
  //      /dir1/dir12
  //      /dir1/dir12/file121
  //      /dir2
  // ListStatus on /dir1 should return all its immediated subdirs only
  // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
  // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
  // listStatus.
  Path dir1 = new Path(testBucketPath, "dir1");
  Path dir11 = new Path(dir1, "dir11");
  Path dir111 = new Path(dir11, "dir111");
  Path dir12 = new Path(dir1, "dir12");
  Path file121 = new Path(dir12, "file121");
  Path dir2 = new Path(testBucketPath, "dir2");
  fs.mkdirs(dir111);
  fs.mkdirs(dir12);
  ContractTestUtils.touch(fs, file121);
  fs.mkdirs(dir2);

  FileStatus[] fileStatuses = ofs.listStatus(dir1);
  Assert.assertEquals(
      "FileStatus should return only the immediate children",
      2, fileStatuses.length);

  // Verify that the two children of /dir1 returned by listStatus operation
  // are /dir1/dir11 and /dir1/dir12.
  String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
  String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
  Assert.assertTrue(fileStatus1.equals(dir11.toString()) ||
      fileStatus1.equals(dir12.toString()));
  Assert.assertTrue(fileStatus2.equals(dir11.toString()) ||
      fileStatus2.equals(dir12.toString()));
}