@Test public void testGetAttrManyFiles() throws Exception { StatFiller stat = mock(StatFiller.class); Path mkv1 = mockPath("file1.mkv", 6736L); Path mkv1txt1 = mockPath("file1.txt", 123456789L); Path mkv1srt1 = mockPath("file1.eng.srt", 2893756L); Path mkv1srt2 = mockPath("file1.der.srt", 2345L); Path mkv1srt3 = mockPath("file1.swe.srt", 78568L); Path mkv2 = mockPath("file2.mkv"); Path mkv3srt1 = mockPath("file3.srt", 324685L); Path mkv4 = mockPath("file4.mkv"); Path mkv4txt1 = mockPath("file4.txt", 4725L); Path mkv4srt1 = mockPath("file4.esp.srt", 235468L); Path mkv4srt2 = mockPath("file4.klingon.srt", 62369L); Path mkv4srt3 = mockPath("file4.elvish.srt", 468L); mockShuffledDirectoryStream(mirrorRoot, mkv1txt1, mkv1srt1, mkv1, mkv1srt3, mkv1srt2, mkv2, mkv3srt1, mkv4, mkv4txt1, mkv4srt1, mkv4srt2, mkv4srt3); mockAttributes(mkv1, 1234, 6736L); when(stat.statWithSize(eq(mkv1), sizeGetterCaptor.capture(), extraSizeGetterCaptor.capture())).thenReturn(mock(UnixFileStat.class)); int result = fs.getattr("file1.mkv", stat); assertThat(result).isEqualTo(SUCCESS); verify(stat).statWithSize(eq(mkv1), any(), any()); verifyNoMoreInteractions(stat); assertThat(sizeGetterCaptor.getValue().apply(FileInfo.of(mkv1))).isEmpty(); assertThat(extraSizeGetterCaptor.getValue().get()).isEqualTo(2893756L + 2345L + 78568L); }
@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();  }