@Test public void test_read_from_tape_KO() { when(tapeDriveConf.getDdPath()).thenReturn(COMMAND_DD); when(tapeDriveConf.getDevice()).thenReturn(DEVICE_NST_0); when(tapeDriveConf.getTimeoutInMilliseconds()).thenReturn(1_000l); DdTapeLibraryService ddTapeLibraryService = new DdTapeLibraryService(tapeDriveConf, processExecutor, "/tmp", "/tmp"); Output output = mock(Output.class); when(output.getExitCode()).thenReturn(0); when(processExecutor.execute(anyString(), anyBoolean(), anyLong(), anyList())).thenReturn(output); TapeResponse response = ddTapeLibraryService.readFromTape(MY_FAKE_FILE_TAR); assertThat(response.isOK()).isTrue(); ArgumentCaptor<String> commandPath = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Long> timeout = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<List> args = ArgumentCaptor.forClass(List.class); verify(processExecutor, VerificationModeFactory.times(1)) .execute(commandPath.capture(), anyBoolean(), timeout.capture(), args.capture()); assertThat(commandPath.getValue()).isEqualTo(COMMAND_DD); assertThat(timeout.getValue()).isEqualTo(1_000l); assertThat(args.getValue()).contains("of=/tmp/my_fake_file.tar", "if=/dev/nst0"); }
@Override public TapeResponse readFromTape(String outputPath) { ParametersChecker.checkParameter("Arguments outputPath is required", outputPath); List<String> args = Lists.newArrayList(IF + tapeDriveConf.getDevice(), OF + Paths.get(this.getOutputDirectory()).resolve(outputPath).toAbsolutePath()); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeDriveConf.getDdPath(), tapeDriveConf.getTimeoutInMilliseconds(), args); Output output = getExecutor() .execute(tapeDriveConf.getDdPath(), tapeDriveConf.isUseSudo(), tapeDriveConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); }
DdTapeLibraryService implements TapeReadWriteService { @Override public TapeResponse readFromTape(String outputPath) { ParametersChecker.checkParameter("Arguments outputPath is required", outputPath); List<String> args = Lists.newArrayList(IF + tapeDriveConf.getDevice(), OF + Paths.get(this.getOutputDirectory()).resolve(outputPath).toAbsolutePath()); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeDriveConf.getDdPath(), tapeDriveConf.getTimeoutInMilliseconds(), args); Output output = getExecutor() .execute(tapeDriveConf.getDdPath(), tapeDriveConf.isUseSudo(), tapeDriveConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } }
DdTapeLibraryService implements TapeReadWriteService { @Override public TapeResponse readFromTape(String outputPath) { ParametersChecker.checkParameter("Arguments outputPath is required", outputPath); List<String> args = Lists.newArrayList(IF + tapeDriveConf.getDevice(), OF + Paths.get(this.getOutputDirectory()).resolve(outputPath).toAbsolutePath()); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeDriveConf.getDdPath(), tapeDriveConf.getTimeoutInMilliseconds(), args); Output output = getExecutor() .execute(tapeDriveConf.getDdPath(), tapeDriveConf.isUseSudo(), tapeDriveConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } DdTapeLibraryService(TapeDriveConf tapeDriveConf, ProcessExecutor processExecutor,
        String inputDirectory, String outputDirectory); }
DdTapeLibraryService implements TapeReadWriteService { @Override public TapeResponse readFromTape(String outputPath) { ParametersChecker.checkParameter("Arguments outputPath is required", outputPath); List<String> args = Lists.newArrayList(IF + tapeDriveConf.getDevice(), OF + Paths.get(this.getOutputDirectory()).resolve(outputPath).toAbsolutePath()); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeDriveConf.getDdPath(), tapeDriveConf.getTimeoutInMilliseconds(), args); Output output = getExecutor() .execute(tapeDriveConf.getDdPath(), tapeDriveConf.isUseSudo(), tapeDriveConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } DdTapeLibraryService(TapeDriveConf tapeDriveConf, ProcessExecutor processExecutor,
        String inputDirectory, String outputDirectory); @Override TapeResponse writeToTape(String inputPath); @Override TapeResponse readFromTape(String outputPath); @Override ProcessExecutor getExecutor(); @Override String getOutputDirectory(); @Override String getInputDirectory(); }
DdTapeLibraryService implements TapeReadWriteService { @Override public TapeResponse readFromTape(String outputPath) { ParametersChecker.checkParameter("Arguments outputPath is required", outputPath); List<String> args = Lists.newArrayList(IF + tapeDriveConf.getDevice(), OF + Paths.get(this.getOutputDirectory()).resolve(outputPath).toAbsolutePath()); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeDriveConf.getDdPath(), tapeDriveConf.getTimeoutInMilliseconds(), args); Output output = getExecutor() .execute(tapeDriveConf.getDdPath(), tapeDriveConf.isUseSudo(), tapeDriveConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } DdTapeLibraryService(TapeDriveConf tapeDriveConf, ProcessExecutor processExecutor,
        String inputDirectory, String outputDirectory); @Override TapeResponse writeToTape(String inputPath); @Override TapeResponse readFromTape(String outputPath); @Override ProcessExecutor getExecutor(); @Override String getOutputDirectory(); @Override String getInputDirectory(); static final String IF; static final String OF; }