Search in sources :

Example 1 with FileStat

use of ru.serce.jnrfuse.struct.FileStat in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method getattrWhenWriting.

@Test
public void getattrWhenWriting() throws Exception {
    String path = "/foo/bar";
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join(path);
    FileOutStream fos = mock(FileOutStream.class);
    when(mFileSystem.createFile(expectedPath)).thenReturn(fos);
    mFuseFs.create(path, 0, mFileInfo);
    // Prepare file status
    FileInfo info = new FileInfo();
    info.setLength(0);
    info.setCompleted(false);
    URIStatus status = new URIStatus(info);
    when(mFileSystem.exists(any(AlluxioURI.class))).thenReturn(true);
    when(mFileSystem.getStatus(any(AlluxioURI.class))).thenReturn(status);
    FileStat stat = new FileStat(Runtime.getSystemRuntime());
    // getattr() will not be blocked when writing
    mFuseFs.getattr(path, stat);
    // If getattr() is blocking, it will continuously get status of the file
    verify(mFileSystem, atMost(300)).getStatus(expectedPath);
    assertEquals(0, stat.st_size.longValue());
    mFuseFs.release(path, mFileInfo);
    // getattr() will be blocked waiting for the file to be completed
    // If release() is called (returned) but does not finished
    Thread t = new Thread(() -> mFuseFs.getattr(path, stat));
    t.start();
    Thread.sleep(1000);
    verify(mFileSystem, atLeast(10)).getStatus(expectedPath);
    assertEquals(0, stat.st_size.longValue());
    info.setCompleted(true);
    info.setLength(1000);
    t.join();
    // getattr() completed and set the file size
    assertEquals(1000, stat.st_size.longValue());
}
Also used : FileStat(ru.serce.jnrfuse.struct.FileStat) FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with FileStat

use of ru.serce.jnrfuse.struct.FileStat in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method getattr.

@Test
public void getattr() throws Exception {
    // set up status
    FileInfo info = new FileInfo();
    info.setLength(4 * Constants.KB + 1);
    info.setLastModificationTimeMs(1000);
    String userName = System.getProperty("user.name");
    info.setOwner(userName);
    info.setGroup(AlluxioFuseUtils.getGroupName(userName));
    info.setFolder(true);
    info.setMode(123);
    info.setCompleted(true);
    URIStatus status = new URIStatus(info);
    // mock fs
    when(mFileSystem.getStatus(any(AlluxioURI.class))).thenReturn(status);
    FileStat stat = new FileStat(Runtime.getSystemRuntime());
    assertEquals(0, mFuseFs.getattr("/foo", stat));
    assertEquals(status.getLength(), stat.st_size.longValue());
    assertEquals(9, stat.st_blocks.intValue());
    assertEquals(status.getLastModificationTimeMs() / 1000, stat.st_ctim.tv_sec.get());
    assertEquals((status.getLastModificationTimeMs() % 1000) * 1000, stat.st_ctim.tv_nsec.longValue());
    assertEquals(status.getLastModificationTimeMs() / 1000, stat.st_mtim.tv_sec.get());
    assertEquals((status.getLastModificationTimeMs() % 1000) * 1000, stat.st_mtim.tv_nsec.longValue());
    assertEquals(AlluxioFuseUtils.getUid(System.getProperty("user.name")), stat.st_uid.get());
    assertEquals(AlluxioFuseUtils.getGid(System.getProperty("user.name")), stat.st_gid.get());
    assertEquals(123 | FileStat.S_IFDIR, stat.st_mode.intValue());
}
Also used : FileStat(ru.serce.jnrfuse.struct.FileStat) FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with FileStat

use of ru.serce.jnrfuse.struct.FileStat in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method getattrWithDelay.

@Test
public void getattrWithDelay() throws Exception {
    String path = "/foo/bar";
    AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
    // set up status
    FileInfo info = new FileInfo();
    info.setLength(0);
    info.setCompleted(false);
    URIStatus status = new URIStatus(info);
    // mock fs
    when(mFileSystem.getStatus(any(AlluxioURI.class))).thenReturn(status);
    FileStat stat = new FileStat(Runtime.getSystemRuntime());
    // Use another thread to open file so that
    // we could change the file status when opening it
    Thread t = new Thread(() -> mFuseFs.getattr(path, stat));
    t.start();
    Thread.sleep(1000);
    // If the file is not being written and is not completed,
    // we will wait for the file to complete
    verify(mFileSystem, atLeast(10)).getStatus(expectedPath);
    assertEquals(0, stat.st_size.longValue());
    info.setCompleted(true);
    info.setLength(1000);
    t.join();
    assertEquals(1000, stat.st_size.longValue());
}
Also used : FileStat(ru.serce.jnrfuse.struct.FileStat) FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileInfo(alluxio.wire.FileInfo) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AlluxioURI (alluxio.AlluxioURI)3 URIStatus (alluxio.client.file.URIStatus)3 FileInfo (alluxio.wire.FileInfo)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 FileStat (ru.serce.jnrfuse.struct.FileStat)3 FuseFileInfo (ru.serce.jnrfuse.struct.FuseFileInfo)3 FileOutStream (alluxio.client.file.FileOutStream)1