@Test public void testRead() throws Exception { FileHandleFiller filler = mock(FileHandleFiller.class); ArgumentCaptor<Integer> handleCaptor = ArgumentCaptor.forClass(Integer.class); doNothing().when(filler).setFileHandle(handleCaptor.capture()); Path fooBar = mockPath("foo.bar"); FileChannel fileChannel = mock(FileChannel.class); when(fileSystem.provider().newFileChannel(eq(fooBar), eq(set(StandardOpenOption.READ)))).thenReturn(fileChannel); fs.open("foo.bar", filler); Integer fileHandle = handleCaptor.getValue(); ArgumentCaptor<ByteBuffer> bufferCaptor = ArgumentCaptor.forClass(ByteBuffer.class); when(fileChannel.read(bufferCaptor.capture(), eq(1234L))).thenReturn(10); int result = fs.read("foo.bar", (data) -> assertThat(data).hasSize(10), 10, 1234L, fileHandle); assertThat(result).isEqualTo(10); verify(fileChannel).read(any(), eq(1234L)); verifyNoMoreInteractions(fileChannel); assertThat(bufferCaptor.getValue().limit()).isEqualTo(10); }
@Override public int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle) { FileChannel fileChannel = openFiles.get(fileHandle); logger.trace("{} {} {}", path, size, offset); return readFromFileChannel(buf, offset, size, fileChannel); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle) { FileChannel fileChannel = openFiles.get(fileHandle); logger.trace("{} {} {}", path, size, offset); return readFromFileChannel(buf, offset, size, fileChannel); } }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle) { FileChannel fileChannel = openFiles.get(fileHandle); logger.trace("{} {} {}", path, size, offset); return readFromFileChannel(buf, offset, size, fileChannel); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle) { FileChannel fileChannel = openFiles.get(fileHandle); logger.trace("{} {} {}", path, size, offset); return readFromFileChannel(buf, offset, size, fileChannel); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); @Override String getFSName(); @Override int getattr(String path, StatFiller stat); @Override int readdir(String path, DirectoryFiller filler); @Override int readLink(String path, Consumer<String> buf, int size); @Override int open(String path, FileHandleFiller filler); @Override int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle); @Override int release(String path, int fileHandle); @Override void destroy(); }
MirrorFs implements se.tfiskgul.mux2fs.fs.base.FileSystem { @Override public int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle) { FileChannel fileChannel = openFiles.get(fileHandle); logger.trace("{} {} {}", path, size, offset); return readFromFileChannel(buf, offset, size, fileChannel); } MirrorFs(Path mirroredPath); @VisibleForTesting protected  MirrorFs(Path mirroredPath, FileChannelCloser fileChannelCloser); @Override String getFSName(); @Override int getattr(String path, StatFiller stat); @Override int readdir(String path, DirectoryFiller filler); @Override int readLink(String path, Consumer<String> buf, int size); @Override int open(String path, FileHandleFiller filler); @Override int read(String path, Consumer<byte[]> buf, int size, long offset, int fileHandle); @Override int release(String path, int fileHandle); @Override void destroy();  }