@Test public void testStop() throws InterruptedException { final List<StatusMessage> statusMessages = new Vector<>(); StatusReporter reporter = new StatusReporter() { @Override public void report(StatusMessage status) { statusMessages.add(status); } }; CmdletExecutor executor = new CmdletExecutor(new SmartConf()); StatusReportTask statusReportTask = new StatusReportTask(reporter, executor, new SmartConf()); ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleAtFixedRate( statusReportTask, 100, 10, TimeUnit.MILLISECONDS); SmartAction action = new HangingAction(); action.setActionId(101); Cmdlet cmdlet = new Cmdlet(Arrays.asList(action)); cmdlet.setId(10); executor.execute(cmdlet); Thread.sleep(1000); executor.stop(10L); Thread.sleep(2000); StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1); ActionStatus status = lastReport.getActionStatuses().get(0); Assert.assertTrue(status.isFinished()); Assert.assertNotNull(status.getThrowable()); executor.shutdown(); }
public void stop(Long cmdletId) { if (this.listenableFutures.containsKey(cmdletId)) { runningCmdlets.get(cmdletId).setState(CmdletState.FAILED); this.listenableFutures.get(cmdletId).cancel(true); } removeCmdlet(cmdletId); }
CmdletExecutor { public void stop(Long cmdletId) { if (this.listenableFutures.containsKey(cmdletId)) { runningCmdlets.get(cmdletId).setState(CmdletState.FAILED); this.listenableFutures.get(cmdletId).cancel(true); } removeCmdlet(cmdletId); } }
CmdletExecutor { public void stop(Long cmdletId) { if (this.listenableFutures.containsKey(cmdletId)) { runningCmdlets.get(cmdletId).setState(CmdletState.FAILED); this.listenableFutures.get(cmdletId).cancel(true); } removeCmdlet(cmdletId); } CmdletExecutor(SmartConf smartConf); }
CmdletExecutor { public void stop(Long cmdletId) { if (this.listenableFutures.containsKey(cmdletId)) { runningCmdlets.get(cmdletId).setState(CmdletState.FAILED); this.listenableFutures.get(cmdletId).cancel(true); } removeCmdlet(cmdletId); } CmdletExecutor(SmartConf smartConf); void execute(Cmdlet cmdlet); void stop(Long cmdletId); void shutdown(); StatusReport getStatusReport(); }
CmdletExecutor { public void stop(Long cmdletId) { if (this.listenableFutures.containsKey(cmdletId)) { runningCmdlets.get(cmdletId).setState(CmdletState.FAILED); this.listenableFutures.get(cmdletId).cancel(true); } removeCmdlet(cmdletId); } CmdletExecutor(SmartConf smartConf); void execute(Cmdlet cmdlet); void stop(Long cmdletId); void shutdown(); StatusReport getStatusReport();  }