Search in sources :

Example 6 with Runtime

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) LoadingCache(com.google.common.cache.LoadingCache) FileStat(ru.serce.jnrfuse.struct.FileStat) BlockMasterClient(alluxio.client.block.BlockMasterClient) PropertyKey(alluxio.conf.PropertyKey) Mockito.doThrow(org.mockito.Mockito.doThrow) FileSystem(alluxio.client.file.FileSystem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.atLeast(org.mockito.Mockito.atLeast) Statvfs(ru.serce.jnrfuse.struct.Statvfs) ImmutableMap(com.google.common.collect.ImmutableMap) BlockMasterInfo(alluxio.wire.BlockMasterInfo) Mockito.doNothing(org.mockito.Mockito.doNothing) O_WRONLY(jnr.constants.platform.OpenFlags.O_WRONLY) List(java.util.List) O_RDONLY(jnr.constants.platform.OpenFlags.O_RDONLY) Pointer(jnr.ffi.Pointer) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) Mockito.atMost(org.mockito.Mockito.atMost) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) RunWith(org.junit.runner.RunWith) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Runtime(jnr.ffi.Runtime) FileOutStream(alluxio.client.file.FileOutStream) Mode(alluxio.security.authorization.Mode) Answer(org.mockito.stubbing.Answer) ConfigurationRule(alluxio.ConfigurationRule) Constants(alluxio.Constants) ErrorCodes(ru.serce.jnrfuse.ErrorCodes) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AlluxioURI(alluxio.AlluxioURI) FileInStream(alluxio.client.file.FileInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Assume(org.junit.Assume) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) FileIncompleteException(alluxio.exception.FileIncompleteException) Mockito.never(org.mockito.Mockito.never) URIStatus(alluxio.client.file.URIStatus) Rule(org.junit.Rule) FileInfo(alluxio.wire.FileInfo) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Runtime(jnr.ffi.Runtime) FileInStream(alluxio.client.file.FileInStream) Pointer(jnr.ffi.Pointer) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Runtime

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) LoadingCache(com.google.common.cache.LoadingCache) FileStat(ru.serce.jnrfuse.struct.FileStat) BlockMasterClient(alluxio.client.block.BlockMasterClient) PropertyKey(alluxio.conf.PropertyKey) Mockito.doThrow(org.mockito.Mockito.doThrow) FileSystem(alluxio.client.file.FileSystem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.atLeast(org.mockito.Mockito.atLeast) Statvfs(ru.serce.jnrfuse.struct.Statvfs) ImmutableMap(com.google.common.collect.ImmutableMap) BlockMasterInfo(alluxio.wire.BlockMasterInfo) Mockito.doNothing(org.mockito.Mockito.doNothing) O_WRONLY(jnr.constants.platform.OpenFlags.O_WRONLY) List(java.util.List) O_RDONLY(jnr.constants.platform.OpenFlags.O_RDONLY) Pointer(jnr.ffi.Pointer) ConfigurationTestUtils(alluxio.ConfigurationTestUtils) Mockito.atMost(org.mockito.Mockito.atMost) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) InstancedConfiguration(alluxio.conf.InstancedConfiguration) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) RunWith(org.junit.runner.RunWith) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) Runtime(jnr.ffi.Runtime) FileOutStream(alluxio.client.file.FileOutStream) Mode(alluxio.security.authorization.Mode) Answer(org.mockito.stubbing.Answer) ConfigurationRule(alluxio.ConfigurationRule) Constants(alluxio.Constants) ErrorCodes(ru.serce.jnrfuse.ErrorCodes) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AlluxioURI(alluxio.AlluxioURI) FileInStream(alluxio.client.file.FileInStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Assume(org.junit.Assume) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) FuseFileInfo(ru.serce.jnrfuse.struct.FuseFileInfo) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) FileIncompleteException(alluxio.exception.FileIncompleteException) Mockito.never(org.mockito.Mockito.never) URIStatus(alluxio.client.file.URIStatus) Rule(org.junit.Rule) FileInfo(alluxio.wire.FileInfo) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Runtime(jnr.ffi.Runtime) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileInStream(alluxio.client.file.FileInStream) Pointer(jnr.ffi.Pointer) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Runtime

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;
}
Also used : Runtime(jnr.ffi.Runtime)

Example 9 with Runtime

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;
}
Also used : Runtime(jnr.ffi.Runtime)

Example 10 with Runtime

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;
}
Also used : Runtime(jnr.ffi.Runtime)

Aggregations

Runtime (jnr.ffi.Runtime)10 Pointer (jnr.ffi.Pointer)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 AlluxioURI (alluxio.AlluxioURI)4 BlockMasterClient (alluxio.client.block.BlockMasterClient)4 FileOutStream (alluxio.client.file.FileOutStream)4 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)4 BlockMasterInfo (alluxio.wire.BlockMasterInfo)4 ConfigurationRule (alluxio.ConfigurationRule)3 ConfigurationTestUtils (alluxio.ConfigurationTestUtils)3 Constants (alluxio.Constants)3 FileInStream (alluxio.client.file.FileInStream)3 FileSystem (alluxio.client.file.FileSystem)3 URIStatus (alluxio.client.file.URIStatus)3 InstancedConfiguration (alluxio.conf.InstancedConfiguration)3 PropertyKey (alluxio.conf.PropertyKey)3 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 FileIncompleteException (alluxio.exception.FileIncompleteException)3