@Override public void stop(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("Stop operation is not available for taskId: " + taskId + " running in SYNCHRONOUS mode"); } final PipelineExecutorTask.Status currentStatus = entry.getTask().getPipelineStatus(); if (!stopEnabledStatus.contains(currentStatus)) { throw new PipelineExecutorException("A PipelineExecutorTask in status: " + currentStatus.name() + " can not" + " be stopped. Stop operation is available for the following status set: " + stopEnabledStatus); } destroyFutureTask(taskId); removeTaskEntry(taskId); taskManagerHelper.setTaskInStoppedStatus(entry.getTask()); updateExecutorRegistry(entry.getTask()); }
@Override public String execute(final PipelineExecutorTaskDef taskDef, final ExecutionMode executionMode) { if (executionMode == ExecutionMode.ASYNCHRONOUS) { return executeAsync(taskDef); } else { return executeSync(taskDef); } }
@Override protected void init() { super.init(); super.futureTaskMap = spy(super.futureTaskMap); } });
@PostConstruct protected void init() { initExecutor(); initPipelineExecutor(); initLocalListener(); initExternalListeners(); }
@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); }
@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 testStopAsyncTask() 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); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = taskManager.currentTasks.get(TASK_ID); taskManager.stop(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(taskEntry.getTask()); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(2)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(pipelineExecutorTraceCaptor.getAllValues().get(1).getTask(), pipelineExecutorTraceCaptor.getValue().getTask()); }
@Test public void testExecuteSync() { when(taskManagerHelper.generateTaskId()).thenReturn(TASK_ID); taskManager.init(); //prepare the input parameters. prepareExecution(); String result = taskManager.execute(taskDef, PipelineExecutorTaskManager.ExecutionMode.SYNCHRONOUS); assertEquals(TASK_ID, result); //verify the task to execute was properly initialized. verify(taskManagerHelper, times(1)).createTask(taskDef); //verify the pipeline was properly executed. verify(pipelineExecutor, times(1)).execute(eq(taskDef.getInput()), eq(pipeline), any(Consumer.class), eq(taskManager.localListener)); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertEquals(PIPELINE_ID, pipelineExecutorTraceCaptor.getValue().getPipelineId()); assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); }
@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); }
@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); } } }
taskManager.destroy(); tasks.forEach(task -> verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(task));
@PostConstruct protected void init() { initExecutor(); initPipelineExecutor(); initLocalListener(); initExternalListeners(); }
@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); }
@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 testStopAsyncTask() 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); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = taskManager.currentTasks.get(TASK_ID); taskManager.stop(TASK_ID); verify(future, times(1)).cancel(true); assertFalse(taskManager.currentTasks.containsKey(TASK_ID)); verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(taskEntry.getTask()); //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(2)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(pipelineExecutorTraceCaptor.getAllValues().get(1).getTask(), pipelineExecutorTraceCaptor.getValue().getTask()); }