@Test public void testAfterPipelineExecutionEventForSyncTask() { testAfterPipelineExecutionEvent(true); }
@Test public void testAfterStageExecutionEventForAsyncTask() { testAfterStageExecutionEvent(true); }
@Test public void testBeforePipelineExecutionEventForAsyncTask() { testBeforePipelineExecutionEvent(true); }
private void testAfterPipelineExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); AfterPipelineExecutionEvent event = new AfterPipelineExecutionEvent(TASK_ID, pipeline); taskManager.localListener.afterPipelineExecution(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.FINISHED); 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); }
@Test public void testOnStageErrorExecutionEventForAsyncTask() { testOnStageErrorExecutionEvent(true); }
@Test public void testBeforeStageExecutionEventForAsyncTask() { testBeforeStageExecutionEvent(true); }
@Test public void testOnPipelineErrorExecutionEventForSyncTask() { testOnPipelineErrorExecutionEvent(false); }
private void verifyExecutorRegistryUpdated(boolean async) { if (async) { //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(task, pipelineExecutorTraceCaptor.getValue().getTask()); } else { verify(pipelineExecutorRegistry, never()).register(anyObject()); } }
@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(); }
private void testBeforePipelineExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); BeforePipelineExecutionEvent event = new BeforePipelineExecutionEvent(TASK_ID, pipeline); taskManager.localListener.beforePipelineExecution(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.RUNNING); 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()), pipelineExecutorExceptionCaptor.capture()); assertEqualsException(new PipelineExecutorException(ERROR_MESSAGE, error), pipelineExecutorExceptionCaptor.getValue()); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
@Test public void testOnStageErrorExecutionEventForSyncTask() { testOnStageErrorExecutionEvent(false); }
@Test public void testBeforeStageExecutionEventForSyncTask() { testBeforeStageExecutionEvent(false); }
@Test public void testOnPipelineErrorExecutionEventForAsyncTask() { testOnPipelineErrorExecutionEvent(true); }
private void verifyExecutorRegistryUpdated(boolean async) { if (async) { //verify the pipeline executor registry was properly updated. verify(pipelineExecutorRegistry, times(1)).register(pipelineExecutorTraceCaptor.capture()); assertHasSameInfo(task, pipelineExecutorTraceCaptor.getValue().getTask()); } else { verify(pipelineExecutorRegistry, never()).register(anyObject()); } }
@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(); }
private void testAfterPipelineExecutionEvent(boolean async) { when(taskEntry.isAsync()).thenReturn(async); AfterPipelineExecutionEvent event = new AfterPipelineExecutionEvent(TASK_ID, pipeline); taskManager.localListener.afterPipelineExecution(event); verify(task, times(1)).setPipelineStatus(PipelineExecutorTask.Status.FINISHED); verifyExecutorRegistryUpdated(async); verifyExternalListenersNotified(event); }
@Test public void testBeforePipelineExecutionEventForAsyncTask() { testBeforePipelineExecutionEvent(true); }
@Test public void testOnStageErrorExecutionEventForAsyncTask() { testOnStageErrorExecutionEvent(true); }