@Test public void testMuxedFileSizeCacheIsEmptyBeforeMuxing() throws Exception { mux2fs = new MuxFs(mirrorRoot, tempDir, muxerFactory, sleeper, fileChannelCloser, MoreExecutors.newDirectExecutorService()); fs = mux2fs; StatFiller stat = mock(StatFiller.class); Path mkv = mockPath("file.mkv", 700000000L); Path srt = mockPath("file.srt", 2000L); mockDirectoryStream(mirrorRoot, srt, mkv); when(stat.statWithSize(eq(mkv), sizeGetterCaptor.capture(), extraSizeGetterCaptor.capture())).thenReturn(mock(UnixFileStat.class)); mockAttributes(mkv, 234); FileInfo info = FileInfo.of(mkv); int result = fs.getattr("file.mkv", stat); assertThat(result).isEqualTo(SUCCESS); verify(stat).statWithSize(eq(mkv), any(), any()); verifyNoMoreInteractions(stat); assertThat(sizeGetterCaptor.getValue().apply(info)).isEmpty(); assertThat(extraSizeGetterCaptor.getValue().get()).isEqualTo(2000L); }
@Override public int getattr(String path, StatFiller stat) { logger.debug(path); if (!path.endsWith(".mkv")) { return super.getattr(path, stat); } Path muxFile = real(path); return tryCatchRunnable.apply(() -> { stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)), () -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get()); }); }
MuxFs extends MirrorFs { @Override public int getattr(String path, StatFiller stat) { logger.debug(path); if (!path.endsWith(".mkv")) { return super.getattr(path, stat); } Path muxFile = real(path); return tryCatchRunnable.apply(() -> { stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)), () -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get()); }); } }
MuxFs extends MirrorFs { @Override public int getattr(String path, StatFiller stat) { logger.debug(path); if (!path.endsWith(".mkv")) { return super.getattr(path, stat); } Path muxFile = real(path); return tryCatchRunnable.apply(() -> { stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)), () -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get()); }); } MuxFs(Path mirroredPath, Path tempDir); @VisibleForTesting  MuxFs(Path mirroredPath, Path tempDir, MuxerFactory muxerFactory, Sleeper sleeper, FileChannelCloser fileChannelCloser, ExecutorService executorService); }
MuxFs extends MirrorFs { @Override public int getattr(String path, StatFiller stat) { logger.debug(path); if (!path.endsWith(".mkv")) { return super.getattr(path, stat); } Path muxFile = real(path); return tryCatchRunnable.apply(() -> { stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)), () -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get()); }); } MuxFs(Path mirroredPath, Path tempDir); @VisibleForTesting  MuxFs(Path mirroredPath, Path tempDir, MuxerFactory muxerFactory, Sleeper sleeper, FileChannelCloser fileChannelCloser, ExecutorService executorService); @Override String getFSName(); @Override int readdir(String path, DirectoryFiller filler); @Override int getattr(String path, StatFiller stat); @Override // TODO: Multiple SRT file support 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(); }
MuxFs extends MirrorFs { @Override public int getattr(String path, StatFiller stat) { logger.debug(path); if (!path.endsWith(".mkv")) { return super.getattr(path, stat); } Path muxFile = real(path); return tryCatchRunnable.apply(() -> { stat.statWithSize(muxFile, info -> Optional.ofNullable(muxedSizeCache.getIfPresent(info)), () -> Try.withCatch(() -> extraSizeCache.get(muxFile)).get()); }); } MuxFs(Path mirroredPath, Path tempDir); @VisibleForTesting  MuxFs(Path mirroredPath, Path tempDir, MuxerFactory muxerFactory, Sleeper sleeper, FileChannelCloser fileChannelCloser, ExecutorService executorService); @Override String getFSName(); @Override int readdir(String path, DirectoryFiller filler); @Override int getattr(String path, StatFiller stat); @Override // TODO: Multiple SRT file support 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();  }