/** Tests load metadata on list. */
  @Test
  public void loadMetadata() throws Exception {
    String dirName = "loadMetaDataRoot";

    String rootDir = PathUtils.concatPath(mUnderfsAddress, dirName);
    mUfs.mkdirs(rootDir, true);

    String rootFile1 = PathUtils.concatPath(rootDir, "file1");
    createEmptyFile(rootFile1);

    String rootFile2 = PathUtils.concatPath(rootDir, "file2");
    createEmptyFile(rootFile2);

    AlluxioURI rootAlluxioURI = new AlluxioURI("/" + dirName);
    FileSystem client = mLocalAlluxioClusterResource.get().getClient();
    client.listStatus(
        rootAlluxioURI, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Always));

    try {
      client.createDirectory(rootAlluxioURI, CreateDirectoryOptions.defaults());
      Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
      Assert.assertEquals(
          ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(rootAlluxioURI), e.getMessage());
    }

    AlluxioURI file1URI = rootAlluxioURI.join("file1");
    try {
      client.createFile(file1URI, CreateFileOptions.defaults()).close();
      Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
      Assert.assertEquals(
          ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(file1URI), e.getMessage());
    }

    AlluxioURI file2URI = rootAlluxioURI.join("file2");
    try {
      client.createFile(file2URI, CreateFileOptions.defaults()).close();
      Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
      Assert.assertEquals(
          ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(file2URI), e.getMessage());
    }
  }
Ejemplo n.º 2
0
 /**
  * Attempts to create a folder with the specified path. Parent directories will be created.
  *
  * @param path path to create
  * @param permission permissions to grant the created folder
  * @return true if the indicated folder is created successfully or already exists
  * @throws IOException if the folder cannot be created
  */
 @Override
 public boolean mkdirs(Path path, FsPermission permission) throws IOException {
   LOG.info("mkdirs({}, {})", path, permission);
   if (mStatistics != null) {
     mStatistics.incrementWriteOps(1);
   }
   AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path));
   CreateDirectoryOptions options =
       CreateDirectoryOptions.defaults()
           .setRecursive(true)
           .setAllowExists(true)
           .setMode(new Mode(permission.toShort()));
   try {
     mFileSystem.createDirectory(uri, options);
     return true;
   } catch (AlluxioException e) {
     throw new IOException(e);
   }
 }