@Test public void testOpenMkvMatchingSubShouldBeMuxed() throws Exception { FileHandleFiller filler = mock(FileHandleFiller.class); Path mkv1 = mockPath("file1.mkv"); Path mkv2 = mockPath("file2.mkv"); Path mkv2txt1 = mockPath("file2.txt", 123456789L); Path mkv2srt1 = mockPath("file2.eng.srt", 2893756L); mockShuffledDirectoryStream(mirrorRoot, mkv1, mkv2, mkv2txt1, mkv2srt1); mockAttributes(mkv2, 1); Muxer muxer = mock(Muxer.class); when(muxerFactory.from(mkv2, mkv2srt1, tempDir)).thenReturn(muxer); Path muxedFile = mockPath(tempDir, "file1.mkv"); when(muxer.getOutput()).thenReturn(Optional.of(muxedFile)); when(fileSystem.provider().newFileChannel(eq(muxedFile), eq(set(StandardOpenOption.READ)))).thenReturn(mock(FileChannel.class)); int result = fs.open("file2.mkv", filler); assertThat(result).isEqualTo(SUCCESS); verify(muxerFactory).from(mkv2, mkv2srt1, tempDir); verifyNoMoreInteractions(muxerFactory); verify(muxer).start(); verify(muxer).waitForOutput(); verify(muxer).getOutput(); verifyNoMoreInteractions(muxer); verify(filler).setFileHandle(gt(1)); verify(fileSystem.provider()).newFileChannel(eq(muxedFile), eq(set(StandardOpenOption.READ))); }
@Override public int open(String path, FileHandleFiller filler) { if (!path.endsWith(".mkv")) { return super.open(path, filler); } logger.info(path); Path muxFile = real(path); List<Path> subFiles = getMatchingSubFiles(muxFile); if (subFiles.isEmpty()) { logger.debug("{} doesn't need muxing", path); return super.open(path, filler); } return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).get(); }
MuxFs extends MirrorFs { @Override public int open(String path, FileHandleFiller filler) { if (!path.endsWith(".mkv")) { return super.open(path, filler); } logger.info(path); Path muxFile = real(path); List<Path> subFiles = getMatchingSubFiles(muxFile); if (subFiles.isEmpty()) { logger.debug("{} doesn't need muxing", path); return super.open(path, filler); } return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).get(); } }
MuxFs extends MirrorFs { @Override public int open(String path, FileHandleFiller filler) { if (!path.endsWith(".mkv")) { return super.open(path, filler); } logger.info(path); Path muxFile = real(path); List<Path> subFiles = getMatchingSubFiles(muxFile); if (subFiles.isEmpty()) { logger.debug("{} doesn't need muxing", path); return super.open(path, filler); } return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).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 open(String path, FileHandleFiller filler) { if (!path.endsWith(".mkv")) { return super.open(path, filler); } logger.info(path); Path muxFile = real(path); List<Path> subFiles = getMatchingSubFiles(muxFile); if (subFiles.isEmpty()) { logger.debug("{} doesn't need muxing", path); return super.open(path, filler); } return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).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 open(String path, FileHandleFiller filler) { if (!path.endsWith(".mkv")) { return super.open(path, filler); } logger.info(path); Path muxFile = real(path); List<Path> subFiles = getMatchingSubFiles(muxFile); if (subFiles.isEmpty()) { logger.debug("{} doesn't need muxing", path); return super.open(path, filler); } return Try.withCatch(() -> FileInfo.of(muxFile), Exception.class).map(info -> open(path, filler, muxFile, subFiles, info)).recover(this::translateOrThrow).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();  }