assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
assertEquals(TASK_ID, pipelineExecutorTraceCaptor.getValue().getTaskId()); assertHasSameInfo(internalTaskEntry.getTask(), pipelineExecutorTraceCaptor.getValue().getTask());
@Before public void setUp() { super.setUp(); error = mock(Throwable.class); when(error.getMessage()).thenReturn(ERROR_MESSAGE); pipelineExecutorErrorCaptor = ArgumentCaptor.forClass(PipelineExecutorError.class); pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); //pick an arbitrary stage for events testing. stage = stages.get(0); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); task = spy(taskManagerHelper.createTask(taskDef, TASK_ID)); taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.getTask()).thenReturn(task); //emulate there's a running task. taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); }
@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 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()); }
@Before public void setUp() { super.setUp(); error = mock(Throwable.class); when(error.getMessage()).thenReturn(ERROR_MESSAGE); pipelineExecutorExceptionCaptor = ArgumentCaptor.forClass(PipelineExecutorException.class); pipeline = mock(Pipeline.class); stages = mockStages(PIPELINE_STAGES_SIZE); when(pipeline.getStages()).thenReturn(stages); when(pipeline.getName()).thenReturn(PIPELINE_ID); when(pipelineRegistry.getPipelineByName(PIPELINE_ID)).thenReturn(pipeline); //pick an arbitrary stage for events testing. stage = stages.get(0); taskDef = mock(PipelineExecutorTaskDef.class); input = mock(Input.class); when(taskDef.getInput()).thenReturn(input); when(taskDef.getPipeline()).thenReturn(PIPELINE_ID); task = spy(taskManagerHelper.createTask(taskDef, TASK_ID)); taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.getTask()).thenReturn(task); //emulate there's a running task. taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); }
@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()); }
private void testOnStageErrorExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); OnErrorStageExecutionEvent event = new OnErrorStageExecutionEvent(TASK_ID, pipeline, stage, error); taskManager.localListener.onStageError(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setStageStatus(stage.getName(), PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setStageError(eq(stage.getName()), pipelineExecutorExceptionCaptor.capture()); assertEqualsException(new PipelineExecutorException(ERROR_MESSAGE, error), pipelineExecutorExceptionCaptor.getValue()); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
private void testOnStageErrorExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); OnErrorStageExecutionEvent event = new OnErrorStageExecutionEvent(TASK_ID, pipeline, stage, error); taskManager.localListener.onStageError(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setStageStatus(stage.getName(), PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setStageError(eq(stage.getName()), pipelineExecutorErrorCaptor.capture()); assertEquals(new PipelineExecutorError(ERROR_MESSAGE, error), pipelineExecutorErrorCaptor.getValue()); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
private void testOnPipelineErrorExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); OnErrorPipelineExecutionEvent event = new OnErrorPipelineExecutionEvent(TASK_ID, pipeline, stage, error); taskManager.localListener.onPipelineError(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setPipelineError(pipelineExecutorExceptionCaptor.capture()); assertEqualsException(new PipelineExecutorException(ERROR_MESSAGE, error), pipelineExecutorExceptionCaptor.getValue()); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
/** * Executes a task definition in synchronous mode. * @param taskDef task definition for executing. * @return the taskId assigned to the executed task. */ private String executeSync(final PipelineExecutorTaskDef taskDef) { final PipelineExecutorTaskImpl task = taskManagerHelper.createTask(taskDef); storeTaskEntry(TaskEntry.newSyncEntry(task)); final Pipeline pipeline = pipelineRegistry.getPipelineByName(taskDef.getPipeline()); pipelineExecutor.execute(taskDef.getInput(), pipeline, output -> processPipelineOutput(task, output), localListener); removeTaskEntry(task.getId()); updateExecutorRegistry(task); return task.getId(); }
/** * Executes a task definition in synchronous mode. * @param taskDef task definition for executing. * @return the taskId assigned to the executed task. */ private String executeSync(final PipelineExecutorTaskDef taskDef) { final PipelineExecutorTaskImpl task = taskManagerHelper.createTask(taskDef); storeTaskEntry(TaskEntry.newSyncEntry(task)); final Pipeline pipeline = pipelineRegistry.getPipelineByName(taskDef.getPipeline()); pipelineExecutor.execute(taskDef.getInput(), pipeline, output -> processPipelineOutput(task, output), localListener); removeTaskEntry(task.getId()); updateExecutorRegistry(task); return task.getId(); }
private void testOnPipelineErrorExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); OnErrorPipelineExecutionEvent event = new OnErrorPipelineExecutionEvent(TASK_ID, pipeline, stage, error); taskManager.localListener.onPipelineError(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.ERROR); verify(task, times(1)).setPipelineError(pipelineExecutorErrorCaptor.capture()); assertEquals(new PipelineExecutorError(ERROR_MESSAGE, error), pipelineExecutorErrorCaptor.getValue()); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
@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 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); }
private void testStopTaskInNonStopeableState(PipelineExecutorTask.Status notStopeableStatus) throws PipelineExecutorException { PipelineExecutorTaskImpl task = mock(PipelineExecutorTaskImpl.class); when(task.getId()).thenReturn(TASK_ID); when(task.getPipelineStatus()).thenReturn(notStopeableStatus); PipelineExecutorTaskManagerImpl.TaskEntry taskEntry = mock(PipelineExecutorTaskManagerImpl.TaskEntry.class); when(taskEntry.isAsync()).thenReturn(true); when(taskEntry.getTask()).thenReturn(task); taskManager.currentTasks.put(TASK_ID, taskEntry); taskManager.init(); expectedException.expectMessage(new StartsWith("A PipelineExecutorTask in status: " + notStopeableStatus.name() + " can not be stopped. Stop operation is available for the following status set:")); taskManager.stop(TASK_ID); }