Search in sources :

Example 1 with PipelineExecutorTask

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())));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pipeline(org.guvnor.ala.pipeline.Pipeline) PipelineExecutorTask(org.guvnor.ala.pipeline.execution.PipelineExecutorTask) ArrayList(java.util.ArrayList) List(java.util.List) PipelineExecutorTaskDef(org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef) Test(org.junit.Test)

Example 2 with PipelineExecutorTask

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);
}
Also used : PipelineExecutorTrace(org.guvnor.ala.pipeline.execution.PipelineExecutorTrace) PipelineExecutorTask(org.guvnor.ala.pipeline.execution.PipelineExecutorTask) StartsWith(org.mockito.internal.matchers.StartsWith)

Example 3 with PipelineExecutorTask

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);
}
Also used : PipelineExecutorTrace(org.guvnor.ala.pipeline.execution.PipelineExecutorTrace) PipelineExecutorTask(org.guvnor.ala.pipeline.execution.PipelineExecutorTask) Test(org.junit.Test)

Example 4 with PipelineExecutorTask

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);
}
Also used : PipelineExecutorTrace(org.guvnor.ala.pipeline.execution.PipelineExecutorTrace) PipelineExecutorTask(org.guvnor.ala.pipeline.execution.PipelineExecutorTask) Test(org.junit.Test)

Aggregations

PipelineExecutorTask (org.guvnor.ala.pipeline.execution.PipelineExecutorTask)4 PipelineExecutorTrace (org.guvnor.ala.pipeline.execution.PipelineExecutorTrace)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Pipeline (org.guvnor.ala.pipeline.Pipeline)1 PipelineExecutorTaskDef (org.guvnor.ala.pipeline.execution.PipelineExecutorTaskDef)1 StartsWith (org.mockito.internal.matchers.StartsWith)1