use of alluxio.wire.FileInfo 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.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method listStatusWithLoadMetadataNonPersistedDir.
/**
* Tests listing status on a non-persisted directory.
*/
@Test
public void listStatusWithLoadMetadataNonPersistedDir() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
// Create ufs file
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
// 3 directories exist.
Assert.assertEquals(3, mFileSystemMaster.getNumberOfPaths());
// Create a drectory in alluxio which is not persisted.
AlluxioURI folder = new AlluxioURI("/mnt/local/folder");
mFileSystemMaster.createDirectory(folder, CreateDirectoryOptions.defaults());
Assert.assertFalse(mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local/folder")).isPersisted());
// Create files in ufs.
Files.createDirectory(Paths.get(ufsMount.join("folder").getPath()));
Files.createFile(Paths.get(ufsMount.join("folder").join("file1").getPath()));
Files.createFile(Paths.get(ufsMount.join("folder").join("file2").getPath()));
// getStatus won't mark folder as persisted.
Assert.assertFalse(mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local/folder")).isPersisted());
List<FileInfo> fileInfoList = mFileSystemMaster.listStatus(folder, ListStatusOptions.defaults());
Assert.assertEquals(2, fileInfoList.size());
// listStatus should have loaded files (folder, folder/file1, folder/file2), so now 6 paths
// exist.
Assert.assertEquals(6, mFileSystemMaster.getNumberOfPaths());
Set<String> paths = new HashSet<>();
for (FileInfo f : fileInfoList) {
paths.add(f.getPath());
}
Assert.assertEquals(2, paths.size());
Assert.assertTrue(paths.contains("/mnt/local/folder/file1"));
Assert.assertTrue(paths.contains("/mnt/local/folder/file2"));
Assert.assertTrue(mFileSystemMaster.getFileInfo(new AlluxioURI("/mnt/local/folder")).isPersisted());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlFileDeleteReplay.
/**
* Tests that TTL delete of a file is not forgotten across restarts.
*/
@Test
public void ttlFileDeleteReplay() throws Exception {
CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(0);
long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
// Simulate restart.
stopServices();
startServices();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(fileInfo.getFileId(), fileId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(fileId);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method getNewBlockIdForFile.
/**
* Tests the {@link FileSystemMaster#getNewBlockIdForFile(AlluxioURI)} method.
*/
@Test
public void getNewBlockIdForFile() throws Exception {
mFileSystemMaster.createFile(NESTED_FILE_URI, mNestedFileOptions);
long blockId = mFileSystemMaster.getNewBlockIdForFile(NESTED_FILE_URI);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
Assert.assertEquals(Lists.newArrayList(blockId), fileInfo.getBlockIds());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method ttlDirectoryDeleteReplay.
/**
* Tests that TTL delete of a directory is not forgotten across restarts.
*/
@Test
public void ttlDirectoryDeleteReplay() throws Exception {
CreateDirectoryOptions directoryOptions = CreateDirectoryOptions.defaults().setRecursive(true).setTtl(0);
long dirId = mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryOptions);
// Simulate restart.
stopServices();
startServices();
FileInfo fileInfo = mFileSystemMaster.getFileInfo(dirId);
Assert.assertEquals(fileInfo.getFileId(), dirId);
HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
mThrown.expect(FileDoesNotExistException.class);
mFileSystemMaster.getFileInfo(dirId);
}
Aggregations