@Test public void test_load_tape_KO() { when(tapeRobotConf.getMtxPath()).thenReturn(COMMAND_MTX); when(tapeRobotConf.getDevice()).thenReturn(ROBOT_DEVICE); when(tapeRobotConf.getTimeoutInMilliseconds()).thenReturn(1_000l); Output output = mock(Output.class); when(output.getExitCode()).thenReturn(1); when(output.getStderr()).thenReturn("Error on load command"); when(processExecutor.execute(anyString(), anyBoolean(), anyLong(), anyList())).thenReturn(output); MtxTapeLibraryService mtxTapeLibraryService = new MtxTapeLibraryService(tapeRobotConf, processExecutor); TapeResponse response = mtxTapeLibraryService.loadTape(0, 1); assertThat(response.isOK()).isFalse(); assertThat(response.getEntity(Output.class).getStderr()).contains("Error on load command"); 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_MTX); assertThat(timeout.getValue()).isEqualTo(1_000l); assertThat(args.getValue()).contains("-f", ROBOT_DEVICE, "load", "0", "1"); }
@Override public synchronized TapeResponse loadTape(String tapeIndex, String driveIndex) { ParametersChecker.checkParameter("Arguments tapeIndex and deriveIndex are required", tapeIndex, driveIndex); List<String> args = Lists.newArrayList(F, tapeRobotConf.getDevice(), LOAD, tapeIndex, driveIndex); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeRobotConf.getMtxPath(), tapeRobotConf.getTimeoutInMilliseconds(), args); Output output = getExecutor().execute(tapeRobotConf.getMtxPath(), tapeRobotConf.isUseSudo(), tapeRobotConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); }
MtxTapeLibraryService implements TapeLoadUnloadService { @Override public synchronized TapeResponse loadTape(String tapeIndex, String driveIndex) { ParametersChecker.checkParameter("Arguments tapeIndex and deriveIndex are required", tapeIndex, driveIndex); List<String> args = Lists.newArrayList(F, tapeRobotConf.getDevice(), LOAD, tapeIndex, driveIndex); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeRobotConf.getMtxPath(), tapeRobotConf.getTimeoutInMilliseconds(), args); Output output = getExecutor().execute(tapeRobotConf.getMtxPath(), tapeRobotConf.isUseSudo(), tapeRobotConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } }
MtxTapeLibraryService implements TapeLoadUnloadService { @Override public synchronized TapeResponse loadTape(String tapeIndex, String driveIndex) { ParametersChecker.checkParameter("Arguments tapeIndex and deriveIndex are required", tapeIndex, driveIndex); List<String> args = Lists.newArrayList(F, tapeRobotConf.getDevice(), LOAD, tapeIndex, driveIndex); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeRobotConf.getMtxPath(), tapeRobotConf.getTimeoutInMilliseconds(), args); Output output = getExecutor().execute(tapeRobotConf.getMtxPath(), tapeRobotConf.isUseSudo(), tapeRobotConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } MtxTapeLibraryService(TapeRobotConf tapeRobotConf, ProcessExecutor processExecutor); }
MtxTapeLibraryService implements TapeLoadUnloadService { @Override public synchronized TapeResponse loadTape(String tapeIndex, String driveIndex) { ParametersChecker.checkParameter("Arguments tapeIndex and deriveIndex are required", tapeIndex, driveIndex); List<String> args = Lists.newArrayList(F, tapeRobotConf.getDevice(), LOAD, tapeIndex, driveIndex); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeRobotConf.getMtxPath(), tapeRobotConf.getTimeoutInMilliseconds(), args); Output output = getExecutor().execute(tapeRobotConf.getMtxPath(), tapeRobotConf.isUseSudo(), tapeRobotConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } MtxTapeLibraryService(TapeRobotConf tapeRobotConf, ProcessExecutor processExecutor); @Override synchronized TapeLibrarySpec status(); @Override synchronized TapeResponse loadTape(String tapeIndex, String driveIndex); @Override synchronized TapeResponse unloadTape(String tapeIndex, String driveIndex); @Override synchronized TapeResponse loadTape(Integer tapeIndex, Integer driveIndex); @Override synchronized TapeResponse unloadTape(Integer tapeIndex, Integer driveIndex); @Override ProcessExecutor getExecutor(); }
MtxTapeLibraryService implements TapeLoadUnloadService { @Override public synchronized TapeResponse loadTape(String tapeIndex, String driveIndex) { ParametersChecker.checkParameter("Arguments tapeIndex and deriveIndex are required", tapeIndex, driveIndex); List<String> args = Lists.newArrayList(F, tapeRobotConf.getDevice(), LOAD, tapeIndex, driveIndex); LOGGER.debug("Execute script : {},timeout: {}, args : {}", tapeRobotConf.getMtxPath(), tapeRobotConf.getTimeoutInMilliseconds(), args); Output output = getExecutor().execute(tapeRobotConf.getMtxPath(), tapeRobotConf.isUseSudo(), tapeRobotConf.getTimeoutInMilliseconds(), args); return parseCommonResponse(output); } MtxTapeLibraryService(TapeRobotConf tapeRobotConf, ProcessExecutor processExecutor); @Override synchronized TapeLibrarySpec status(); @Override synchronized TapeResponse loadTape(String tapeIndex, String driveIndex); @Override synchronized TapeResponse unloadTape(String tapeIndex, String driveIndex); @Override synchronized TapeResponse loadTape(Integer tapeIndex, Integer driveIndex); @Override synchronized TapeResponse unloadTape(Integer tapeIndex, Integer driveIndex); @Override ProcessExecutor getExecutor(); static final String F; static final String UNLOAD; static final String LOAD; static final String STATUS; }