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