use of org.guvnor.ala.pipeline.execution.PipelineExecutorTask in project kie-wb-common by kiegroup.
the class PipelineExecutorTaskManagerImplExecutionTest method testDestroy.
@Test
public void testDestroy() throws Exception {
int runningTasks = 5;
List<PipelineExecutorTaskImpl> tasks = new ArrayList<>();
// emulate a set of currently running tasks
for (int i = 0; i < runningTasks; i++) {
String taskId = TASK_ID + i;
PipelineExecutorTaskImpl task = mock(PipelineExecutorTaskImpl.class);
when(task.clone()).thenReturn(task);
when(task.getId()).thenReturn(taskId);
when(task.getPipelineStatus()).thenReturn(PipelineExecutorTask.Status.RUNNING);
PipelineExecutorTaskDef taskDef = mock(PipelineExecutorTaskDef.class);
when(task.getTaskDef()).thenReturn(taskDef);
Pipeline pipeline = mock(Pipeline.class);
when(pipeline.getStages()).thenReturn(mock(List.class));
when(taskDef.getPipeline()).thenReturn(PIPELINE_ID);
PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class);
when(taskEntry.isAsync()).thenReturn(true);
when(taskEntry.getTask()).thenReturn(task);
taskManager.currentTasks.put(taskId, taskEntry);
tasks.add(task);
}
taskManager.destroy();
tasks.forEach(task -> verify(taskManagerHelper, times(1)).setTaskInStoppedStatus(task));
verify(pipelineExecutorRegistry, times(5)).register(pipelineExecutorTraceCaptor.capture());
Map<String, PipelineExecutorTask> registeredTasks = new HashMap<>();
pipelineExecutorTraceCaptor.getAllValues().forEach(capture -> registeredTasks.put(capture.getTaskId(), capture.getTask()));
tasks.forEach(task -> assertHasSameInfo(task, registeredTasks.get(task.getId())));
}
use of org.guvnor.ala.pipeline.execution.PipelineExecutorTask in project kie-wb-common by kiegroup.
the class PipelineExecutorTaskManagerImplExecutionTest method testDeleteTaskInNonStopeableState.
private void testDeleteTaskInNonStopeableState(PipelineExecutorTask.Status nonStopeableStatus) throws Exception {
PipelineExecutorTask task = mock(PipelineExecutorTask.class);
when(task.getPipelineStatus()).thenReturn(nonStopeableStatus);
PipelineExecutorTrace trace = mock(PipelineExecutorTrace.class);
when(trace.getTask()).thenReturn(task);
when(pipelineExecutorRegistry.getExecutorTrace(TASK_ID)).thenReturn(trace);
expectedException.expectMessage(new StartsWith("A PipelineExecutorTask in status: " + nonStopeableStatus + " can not" + " be deleted. Delete operation is available for the following status set:"));
taskManager.delete(TASK_ID);
}
use of org.guvnor.ala.pipeline.execution.PipelineExecutorTask in project kie-wb-common by kiegroup.
the class PipelineExecutorTaskManagerImplExecutionTest method testDeleteTask.
@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);
}
use of org.guvnor.ala.pipeline.execution.PipelineExecutorTask in project kie-wb-common by kiegroup.
the class InMemoryPipelineExecutorRegistryTest method getExecutorTraceByRuntimeId.
@Test
public void getExecutorTraceByRuntimeId() {
RuntimeIdMock runtimeId = mock(RuntimeIdMock.class);
when(runtimeId.getId()).thenReturn(RUNTIME_ID);
PipelineExecutorTask task = mock(PipelineExecutorTask.class);
when(task.getOutput()).thenReturn(runtimeId);
when(trace.getTask()).thenReturn(task);
pipelineExecutorRegistry.register(trace);
PipelineExecutorTrace result = pipelineExecutorRegistry.getExecutorTrace(runtimeId);
assertEquals(trace, result);
}
Aggregations