Search in sources :

Example 36 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class FileSystemMasterTest method listStatus.

@Test
public void listStatus() throws Exception {
    final int files = 10;
    List<FileInfo> infos;
    List<String> filenames;
    // Test files in root directory.
    for (int i = 0; i < files; i++) {
        createFileWithSingleBlock(ROOT_URI.join("file" + String.format("%05d", i)));
    }
    infos = mFileSystemMaster.listStatus(ROOT_URI, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Never));
    Assert.assertEquals(files, infos.size());
    // Copy out filenames to use List contains.
    filenames = new ArrayList<>();
    for (FileInfo info : infos) {
        filenames.add(info.getPath());
    }
    // Compare all filenames.
    for (int i = 0; i < files; i++) {
        Assert.assertTrue(filenames.contains(ROOT_URI.join("file" + String.format("%05d", i)).toString()));
    }
    // Test single file.
    createFileWithSingleBlock(ROOT_FILE_URI);
    infos = mFileSystemMaster.listStatus(ROOT_FILE_URI, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Never));
    Assert.assertEquals(1, infos.size());
    Assert.assertEquals(ROOT_FILE_URI.getPath(), infos.get(0).getPath());
    // Test files in nested directory.
    for (int i = 0; i < files; i++) {
        createFileWithSingleBlock(NESTED_URI.join("file" + String.format("%05d", i)));
    }
    infos = mFileSystemMaster.listStatus(NESTED_URI, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Never));
    Assert.assertEquals(files, infos.size());
    // Copy out filenames to use List contains.
    filenames = new ArrayList<>();
    for (FileInfo info : infos) {
        filenames.add(info.getPath());
    }
    // Compare all filenames.
    for (int i = 0; i < files; i++) {
        Assert.assertTrue(filenames.contains(NESTED_URI.join("file" + String.format("%05d", i)).toString()));
    }
    // Test non-existent URIs.
    try {
        mFileSystemMaster.listStatus(NESTED_URI.join("DNE"), ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Never));
        Assert.fail("listStatus() for a non-existent URI should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 37 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class FileSystemMasterTest method getPath.

@Test
public void getPath() throws Exception {
    AlluxioURI rootUri = new AlluxioURI("/");
    long rootId = mFileSystemMaster.getFileId(rootUri);
    Assert.assertEquals(rootUri, mFileSystemMaster.getPath(rootId));
    // get non-existent id
    try {
        mFileSystemMaster.getPath(rootId + 1234);
        Assert.fail("getPath() for a non-existent id should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 38 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class FileSystemMasterTest method getFileInfo.

/**
   * Tests the {@link FileSystemMaster#getFileInfo(AlluxioURI)} method.
   */
@Test
public void getFileInfo() throws Exception {
    createFileWithSingleBlock(NESTED_FILE_URI);
    long fileId;
    FileInfo info;
    fileId = mFileSystemMaster.getFileId(ROOT_URI);
    info = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(ROOT_URI.getPath(), info.getPath());
    Assert.assertEquals(ROOT_URI.getPath(), mFileSystemMaster.getFileInfo(ROOT_URI).getPath());
    fileId = mFileSystemMaster.getFileId(NESTED_URI);
    info = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(NESTED_URI.getPath(), info.getPath());
    Assert.assertEquals(NESTED_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_URI).getPath());
    fileId = mFileSystemMaster.getFileId(NESTED_FILE_URI);
    info = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(NESTED_FILE_URI.getPath(), info.getPath());
    Assert.assertEquals(NESTED_FILE_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getPath());
    // Test non-existent id.
    try {
        mFileSystemMaster.getFileInfo(fileId + 1234);
        Assert.fail("getFileInfo() for a non-existent id should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
    // Test non-existent URIs.
    try {
        mFileSystemMaster.getFileInfo(ROOT_FILE_URI);
        Assert.fail("getFileInfo() for a non-existent URI should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
    try {
        mFileSystemMaster.getFileInfo(TEST_URI);
        Assert.fail("getFileInfo() for a non-existent URI should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
    try {
        mFileSystemMaster.getFileInfo(NESTED_URI.join("DNE"));
        Assert.fail("getFileInfo() for a non-existent URI should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 39 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class FileSystemMasterTest method getPersistenceState.

/**
   * Tests the {@link FileSystemMaster#getPersistenceState(long)} method.
   */
@Test
public void getPersistenceState() throws Exception {
    AlluxioURI rootUri = new AlluxioURI("/");
    long rootId = mFileSystemMaster.getFileId(rootUri);
    Assert.assertEquals(PersistenceState.PERSISTED, mFileSystemMaster.getPersistenceState(rootId));
    // get non-existent id
    try {
        mFileSystemMaster.getPersistenceState(rootId + 1234);
        Assert.fail("getPath() for a non-existent id should fail.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 40 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.

the class RmCommand method runCommand.

@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    // TODO(calvin): Remove explicit state checking.
    boolean recursive = cl.hasOption("R");
    if (!mFileSystem.exists(path)) {
        throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
    }
    if (!recursive && mFileSystem.getStatus(path).isFolder()) {
        throw new IOException(path.getPath() + " is a directory, to remove it, please use \"rm -R <path>\"");
    }
    DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive);
    mFileSystem.delete(path, options);
    System.out.println(path + " has been removed");
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) DeleteOptions(alluxio.client.file.options.DeleteOptions) IOException(java.io.IOException)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)51 AlluxioURI (alluxio.AlluxioURI)36 InvalidPathException (alluxio.exception.InvalidPathException)20 IOException (java.io.IOException)19 AlluxioException (alluxio.exception.AlluxioException)16 Test (org.junit.Test)14 URIStatus (alluxio.client.file.URIStatus)13 ArrayList (java.util.ArrayList)10 AccessControlException (alluxio.exception.AccessControlException)7 FileInfo (alluxio.wire.FileInfo)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 RestApiTest (alluxio.rest.RestApiTest)4 TestCase (alluxio.rest.TestCase)4 HashMap (java.util.HashMap)4 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)3 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)3 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)3 Inode (alluxio.master.file.meta.Inode)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3