Search in sources :

Example 11 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class InodeDirectoryTest method generateClientFileInfo.

/**
   * Tests the {@link InodeDirectory#generateClientFileInfo(String)} method.
   */
@Test
public void generateClientFileInfo() {
    InodeDirectory inodeDirectory = createInodeDirectory();
    String path = "/test/path";
    FileInfo info = inodeDirectory.generateClientFileInfo(path);
    Assert.assertEquals(inodeDirectory.getId(), info.getFileId());
    Assert.assertEquals(inodeDirectory.getName(), info.getName());
    Assert.assertEquals(path, info.getPath());
    Assert.assertEquals("", info.getUfsPath());
    Assert.assertEquals(0, info.getLength());
    Assert.assertEquals(0, info.getBlockSizeBytes());
    Assert.assertEquals(inodeDirectory.getCreationTimeMs(), info.getCreationTimeMs());
    Assert.assertTrue(info.isCompleted());
    Assert.assertTrue(info.isFolder());
    Assert.assertEquals(inodeDirectory.isPinned(), info.isPinned());
    Assert.assertFalse(info.isCacheable());
    Assert.assertNotNull(info.getBlockIds());
    Assert.assertEquals(inodeDirectory.getLastModificationTimeMs(), info.getLastModificationTimeMs());
}
Also used : FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 12 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class FileSystemMasterTest method listStatusWithLoadMetadataOnce.

@Test
public void listStatusWithLoadMetadataOnce() throws Exception {
    AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
    mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
    // Create ufs file
    Files.createDirectory(Paths.get(ufsMount.join("dir1").getPath()));
    Files.createFile(Paths.get(ufsMount.join("dir1").join("file1").getPath()));
    Files.createFile(Paths.get(ufsMount.join("dir1").join("file2").getPath()));
    mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
    // 3 directories exist.
    Assert.assertEquals(3, mFileSystemMaster.getNumberOfPaths());
    // getFileId should load metadata automatically.
    AlluxioURI uri = new AlluxioURI("/mnt/local/dir1");
    List<FileInfo> fileInfoList = mFileSystemMaster.listStatus(uri, ListStatusOptions.defaults());
    Set<String> paths = new HashSet<>();
    for (FileInfo fileInfo : fileInfoList) {
        paths.add(fileInfo.getPath());
    }
    Assert.assertEquals(2, paths.size());
    Assert.assertTrue(paths.contains("/mnt/local/dir1/file1"));
    Assert.assertTrue(paths.contains("/mnt/local/dir1/file2"));
    // listStatus should have loaded another 3 files (dir1, dir1/file1, dir1/file2), so now 6
    // paths exist.
    Assert.assertEquals(6, mFileSystemMaster.getNumberOfPaths());
}
Also used : FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class FileSystemMasterTest method listStatusWithLoadMetadataAlways.

@Test
public void listStatusWithLoadMetadataAlways() throws Exception {
    AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
    mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
    // Create ufs file
    Files.createDirectory(Paths.get(ufsMount.join("dir1").getPath()));
    mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
    // 3 directories exist.
    Assert.assertEquals(3, mFileSystemMaster.getNumberOfPaths());
    // getFileId should load metadata automatically.
    AlluxioURI uri = new AlluxioURI("/mnt/local/dir1");
    List<FileInfo> fileInfoList = mFileSystemMaster.listStatus(uri, ListStatusOptions.defaults());
    Assert.assertEquals(0, fileInfoList.size());
    // listStatus should have loaded another files (dir1), so now 4 paths exist.
    Assert.assertEquals(4, mFileSystemMaster.getNumberOfPaths());
    // Add two files.
    Files.createFile(Paths.get(ufsMount.join("dir1").join("file1").getPath()));
    Files.createFile(Paths.get(ufsMount.join("dir1").join("file2").getPath()));
    fileInfoList = mFileSystemMaster.listStatus(uri, ListStatusOptions.defaults());
    Assert.assertEquals(0, fileInfoList.size());
    // No file is loaded since dir1 has been loaded once.
    Assert.assertEquals(4, mFileSystemMaster.getNumberOfPaths());
    fileInfoList = mFileSystemMaster.listStatus(uri, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Always));
    Set<String> paths = new HashSet<>();
    for (FileInfo fileInfo : fileInfoList) {
        paths.add(fileInfo.getPath());
    }
    Assert.assertEquals(2, paths.size());
    Assert.assertTrue(paths.contains("/mnt/local/dir1/file1"));
    Assert.assertTrue(paths.contains("/mnt/local/dir1/file2"));
    // listStatus should have loaded another 2 files (dir1/file1, dir1/file2), so now 6
    // paths exist.
    Assert.assertEquals(6, mFileSystemMaster.getNumberOfPaths());
}
Also used : FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class FileSystemMasterTest method ttlDirectoryDelete.

/**
   * Tests that an exception is in the
   * {@link FileSystemMaster#createDirectory(AlluxioURI, CreateDirectoryOptions)} with a TTL
   * set in the {@link CreateDirectoryOptions} after the TTL check was done once.
   */
@Test
public void ttlDirectoryDelete() throws Exception {
    CreateDirectoryOptions directoryOptions = CreateDirectoryOptions.defaults().setRecursive(true).setTtl(0);
    long dirId = mFileSystemMaster.createDirectory(NESTED_DIR_URI, directoryOptions);
    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)

Example 15 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class FileSystemMasterTest method lostFilesDetection.

/**
   * Tests that lost files can successfully be detected.
   */
@Test
public void lostFilesDetection() throws Exception {
    createFileWithSingleBlock(NESTED_FILE_URI);
    long fileId = mFileSystemMaster.getFileId(NESTED_FILE_URI);
    mFileSystemMaster.reportLostFile(fileId);
    FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(PersistenceState.NOT_PERSISTED.name(), fileInfo.getPersistenceState());
    // Check with getPersistenceState
    Assert.assertEquals(PersistenceState.NOT_PERSISTED, mFileSystemMaster.getPersistenceState(fileId));
    // run the detector
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_LOST_FILES_DETECTION);
    fileInfo = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(PersistenceState.LOST.name(), fileInfo.getPersistenceState());
    // Check with getPersistenceState
    Assert.assertEquals(PersistenceState.LOST, mFileSystemMaster.getPersistenceState(fileId));
}
Also used : FileInfo(alluxio.wire.FileInfo) 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