use of jnr.ffi.Pointer 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.Pointer 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");
FileInfo fi = new FileInfo();
fi.setFolder(false);
URIStatus status = new URIStatus(fi);
when(mFileSystem.exists(expectedPath)).thenReturn(true);
when(mFileSystem.getStatus(expectedPath)).thenReturn(status);
FileInStream fakeInStream = mock(FileInStream.class);
when(fakeInStream.read(any(byte[].class), anyInt(), anyInt())).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocationOnMock) throws Throwable {
byte[] myDest = (byte[]) invocationOnMock.getArguments()[0];
for (byte i = 0; i < 4; i++) {
myDest[i] = i;
}
return 4;
}
});
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.Pointer in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method write.
@Test
public void write() throws Exception {
FileOutStream fos = mock(FileOutStream.class);
AlluxioURI anyURI = any();
when(mFileSystem.createFile(anyURI)).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);
}
Aggregations