use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method read.
@Test
public void read() 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 < 4; i++) {
myDest[i] = i;
}
return 4;
});
when(fakeInStream.remaining()).thenReturn(4L);
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, 0, mFileInfo);
final byte[] dst = new byte[4];
ptr.get(0, dst, 0, 4);
final byte[] expected = new byte[] { 0, 1, 2, 3 };
assertArrayEquals("Source and dst data should be equal", expected, dst);
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method readOffset.
@Test
public void readOffset() 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] = (byte) (i + 1);
}
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(2, true);
// actual test
mFuseFs.open("/foo/bar", mFileInfo);
mFuseFs.read("/foo/bar", ptr, 2, 1, mFileInfo);
final byte[] dst = new byte[2];
ptr.get(0, dst, 0, 2);
final byte[] expected = new byte[] { 1, 2 };
assertArrayEquals("Source and dst data should be equal", expected, dst);
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class FuseContext method of.
public static FuseContext of(ByteBuffer buffer) {
Runtime runtime = Runtime.getSystemRuntime();
FuseContext context = new FuseContext(runtime, buffer);
context.useMemory(jnr.ffi.Pointer.wrap(runtime, buffer));
return context;
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class Statvfs method of.
public static Statvfs of(ByteBuffer buffer) {
Runtime runtime = Runtime.getSystemRuntime();
Statvfs statvfs = new Statvfs(runtime, buffer);
statvfs.useMemory(jnr.ffi.Pointer.wrap(runtime, buffer));
return statvfs;
}
use of jnr.ffi.Runtime in project alluxio by Alluxio.
the class FileStat method of.
public static FileStat of(ByteBuffer buffer) {
Runtime runtime = Runtime.getSystemRuntime();
FileStat stat = new FileStat(runtime, buffer);
stat.useMemory(jnr.ffi.Pointer.wrap(runtime, buffer));
return stat;
}
Aggregations