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.
}
}
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.
}
}
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.
}
}
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.
}
}
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");
}
Aggregations