Search in sources :

Example 46 with FileInfo

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.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 47 with FileInfo

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());
}
Also used : FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 48 with FileInfo

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);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 49 with FileInfo

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());
}
Also used : FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 50 with FileInfo

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);
}
Also used : FileInfo(alluxio.wire.FileInfo) CreateDirectoryOptions(alluxio.master.file.options.CreateDirectoryOptions) Test(org.junit.Test)

Aggregations

FileInfo (alluxio.wire.FileInfo)81 AlluxioURI (alluxio.AlluxioURI)60 Test (org.junit.Test)54 URIStatus (alluxio.client.file.URIStatus)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 CreateFileOptions (alluxio.master.file.options.CreateFileOptions)9 ArrayList (java.util.ArrayList)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 RestApiTest (alluxio.rest.RestApiTest)7 TestCase (alluxio.rest.TestCase)7 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)4 CreateOptions (alluxio.underfs.options.CreateOptions)4 OutputStream (java.io.OutputStream)4 InvalidPathException (alluxio.exception.InvalidPathException)3 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3 FileBlockInfo (alluxio.wire.FileBlockInfo)3 IOException (java.io.IOException)3