use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method allocateNativeFileInfo.
// Allocate native memory for a FuseFileInfo data struct and return its pointer
private FuseFileInfo allocateNativeFileInfo() {
final Runtime runtime = Runtime.getSystemRuntime();
final Pointer pt = runtime.getMemoryManager().allocateTemporary(36, true);
return FuseFileInfo.of(pt);
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method statfs.
@Test
public void statfs() throws Exception {
Runtime runtime = Runtime.getSystemRuntime();
Pointer pointer = runtime.getMemoryManager().allocateTemporary(4 * Constants.KB, true);
Statvfs stbuf = Statvfs.of(pointer);
int blockSize = 4 * Constants.KB;
int totalBlocks = 4;
int freeBlocks = 3;
BlockMasterClient blockMasterClient = PowerMockito.mock(BlockMasterClient.class);
PowerMockito.mockStatic(BlockMasterClient.Factory.class);
when(BlockMasterClient.Factory.create(any())).thenReturn(blockMasterClient);
BlockMasterInfo blockMasterInfo = new BlockMasterInfo();
blockMasterInfo.setCapacityBytes(totalBlocks * blockSize);
blockMasterInfo.setFreeBytes(freeBlocks * blockSize);
when(blockMasterClient.getBlockMasterInfo(any())).thenReturn(blockMasterInfo);
assertEquals(0, mFuseFs.statfs("/", stbuf));
assertEquals(blockSize, stbuf.f_bsize.intValue());
assertEquals(blockSize, stbuf.f_frsize.intValue());
assertEquals(totalBlocks, stbuf.f_blocks.longValue());
assertEquals(freeBlocks, stbuf.f_bfree.longValue());
assertEquals(freeBlocks, stbuf.f_bavail.longValue());
assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_files.intValue());
assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_ffree.intValue());
assertEquals(AlluxioFuseFileSystem.UNKNOWN_INODES, stbuf.f_favail.intValue());
assertEquals(AlluxioFuseFileSystem.MAX_NAME_LENGTH, stbuf.f_namemax.intValue());
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class FuseFileInfo method of.
public static FuseFileInfo of(ByteBuffer buffer) {
Runtime runtime = Runtime.getSystemRuntime();
FuseFileInfo fi = new FuseFileInfo(runtime, buffer);
fi.useMemory(jnr.ffi.Pointer.wrap(runtime, buffer));
return fi;
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method write.
@Test
public void write() throws Exception {
FileOutStream fos = mock(FileOutStream.class);
AlluxioURI anyURI = any();
CreateFilePOptions options = any();
when(mFileSystem.createFile(anyURI, options)).thenReturn(fos);
// open a file
mFileInfo.flags.set(O_WRONLY.intValue());
mFuseFs.create("/foo/bar", 0, mFileInfo);
// prepare something to write into it
Runtime r = Runtime.getSystemRuntime();
Pointer ptr = r.getMemoryManager().allocateTemporary(4, true);
byte[] expected = { 42, -128, 1, 3 };
ptr.put(0, expected, 0, 4);
mFuseFs.write("/foo/bar", ptr, 4, 0, mFileInfo);
verify(fos).write(expected);
// the second write is no-op because the writes must be sequential and overwriting is supported
mFuseFs.write("/foo/bar", ptr, 4, 0, mFileInfo);
verify(fos, times(1)).write(expected);
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method readOffset2.
@Test
public void readOffset2() throws Exception {
// mocks set-up
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
setUpOpenMock(expectedPath);
FileInStream fakeInStream = mock(FileInStream.class);
when(fakeInStream.read(any(byte[].class), anyInt(), anyInt())).then((Answer<Integer>) invocationOnMock -> {
byte[] myDest = (byte[]) invocationOnMock.getArguments()[0];
for (byte i = 0; i < (int) invocationOnMock.getArgument(2); i++) {
myDest[i] = i;
}
return myDest.length;
});
AtomicInteger callCounter = new AtomicInteger();
when(fakeInStream.remaining()).then((Answer<Long>) invocationOnMock -> {
if (callCounter.getAndIncrement() == 0) {
return 4L;
} else {
return 3L;
}
});
when(mFileSystem.openFile(expectedPath)).thenReturn(fakeInStream);
mFileInfo.flags.set(O_RDONLY.intValue());
// prepare something to read to it
Runtime r = Runtime.getSystemRuntime();
Pointer ptr = r.getMemoryManager().allocateTemporary(4, true);
// actual test
mFuseFs.open("/foo/bar", mFileInfo);
mFuseFs.read("/foo/bar", ptr, 4, 4, mFileInfo);
final byte[] dst = new byte[0];
ptr.get(0, dst, 0, 0);
final byte[] expected = new byte[0];
assertArrayEquals("Source and dst data should be equal", expected, dst);
}
Aggregations