@Test public void testDeleteTask() throws Exception { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); PipelineExecutorTask task = mock(PipelineExecutorTask.class); PipelineExecutorTask.Status status = PipelineExecutorTask.Status.STOPPED; when(task.getPipelineStatus()).thenReturn(status); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); taskManager.delete(TASK_ID); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
@Test public void testDeleteTask() throws Exception { PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class); PipelineExecutorTask task = mock(PipelineExecutorTask.class); PipelineExecutorTask.Status status = PipelineExecutorTask.Status.STOPPED; when(task.getPipelineStatus()).thenReturn(status); when(trace.getTask()).thenReturn(task); when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace); taskManager.delete(TASK_ID); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
@Test public void testDestroyAsyncTask() throws PipelineExecutorException { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); Future future = mock(Future.class); when(executorService.submit(any(Runnable.class))).thenReturn(future); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS); assertEquals(TASK_ID, result); taskManager.destroy(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
@Test public void testDestroyAsyncTask() throws PipelineExecutorException { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); Future future = mock(Future.class); when(executorService.submit(any(Runnable.class))).thenReturn(future); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.ASYNCHRONOUS); assertEquals(TASK_ID, result); taskManager.destroy(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(pipelineExecutorRegistry, times(1)).deregister(TASK_ID); }
@Override public void destroyRuntime(String runtimeId, boolean forced) throws BusinessException { final Runtime runtimeById = runtimeRegistry.getRuntimeById(runtimeId); if (runtimeById == null) { throw new BusinessException("No runtime was found for runtimeId: " + runtimeId); } final PipelineExecutorTrace pipelineTrace = pipelineExecutorRegistry.getExecutorTrace(runtimeById); try { runtimeFactory.destroyRuntime(runtimeById); } catch (Exception e) { if (forced) { LOG.warn("Runtime destroy raised the following error for runtime: " + runtimeId + " but forced destroy will still remove the runtime from registry.", e); runtimeRegistry.deregisterRuntime(runtimeById); } else { throw e; } } if (pipelineTrace != null) { pipelineExecutorRegistry.deregister(pipelineTrace.getTaskId()); } }
@Override public void destroy(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } if (!entry.isAsync()) { throw new PipelineExecutorException("Destroy operation is not available for taskId: " + taskId + " running in SYNCHRONOUS mode"); } destroyFutureTask(taskId); removeTaskEntry(taskId); pipelineExecutorRegistry.deregister(taskId); }
@Override public void destroy(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } if (!entry.isAsync()) { throw new PipelineExecutorException("Destroy operation is not available for taskId: " + taskId + " running in SYNCHRONOUS mode"); } destroyFutureTask(taskId); removeTaskEntry(taskId); pipelineExecutorRegistry.deregister(taskId); }
@Override public void delete(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry != null) { throw new PipelineExecutorException("An active PipelineExecutorTask was found for taskId: " + taskId + " delete operation is only available for the following status set: " + deleteEnabledStatus); } final PipelineExecutorTrace trace = pipelineExecutorRegistry.getExecutorTrace(taskId); if (trace == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } else { if (!deleteEnabledStatus.contains(trace.getTask().getPipelineStatus())) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + trace.getTask().getPipelineStatus().name() + " can not" + " be deleted. Delete operation is available for the following status set: " + deleteEnabledStatus); } else { pipelineExecutorRegistry.deregister(taskId); } } }
@Override public void delete(final String taskId) throws PipelineExecutorException { final TaskEntry entry = getTaskEntry(taskId); if (entry != null) { throw new PipelineExecutorException("An active PipelineExecutorTask was found for taskId: " + taskId + " delete operation is only available for the following status set: " + deleteEnabledStatus); } final PipelineExecutorTrace trace = pipelineExecutorRegistry.getExecutorTrace(taskId); if (trace == null) { throw new PipelineExecutorException("No PipelineExecutorTask was found for taskId: " + taskId); } else { if (!deleteEnabledStatus.contains(trace.getTask().getPipelineStatus())) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + trace.getTask().getPipelineStatus().name() + " can not" + " be deleted. Delete operation is available for the following status set: " + deleteEnabledStatus); } else { pipelineExecutorRegistry.deregister(taskId); } } }