@Inject public PipelineExecutorTaskManagerImpl(final PipelineRegistry pipelineRegistry, final Instance<ConfigExecutor> configExecutorInstance, final Instance<PipelineEventListener> pipelineEventListenerInstance, final PipelineExecutorRegistry pipelineExecutorRegistry) { this.pipelineRegistry = pipelineRegistry; this.taskManagerHelper = new PipelineExecutorTaskManagerImplHelper(configExecutorInstance, pipelineEventListenerInstance); this.pipelineExecutorRegistry = pipelineExecutorRegistry; }
private void initExecutor() { executor = taskManagerHelper.createExecutorService(); }
private void initExternalListeners() { externalListeners = taskManagerHelper.createExternalListeners(); }
public PipelineExecutorTaskImpl createTask(final PipelineExecutorTaskDef taskDef) { String executionId = generateTaskId(); return createTask(taskDef, executionId); }
@Before public void setUp() { pipelineExecutorTraceCaptor = ArgumentCaptor.forClass(PipelineExecutorTrace.class); taskEntryCaptor = ArgumentCaptor.forClass(PipelineExecutorTaskManagerImpl.TaskEntry.class); stringCaptor = ArgumentCaptor.forClass(String.class); configExecutors = mockConfigExecutors(CONFIG_EXECUTORS_SIZE); when(configExecutorsInstance.iterator()).thenReturn(configExecutors.iterator()); externalListeners = mockEventListeners(PIPELINE_EVENT_LISTENERS); when(eventListenersInstance.iterator()).thenReturn(externalListeners.iterator()); taskManagerHelper = spy(new PipelineExecutorTaskManagerImplHelper(configExecutorsInstance, eventListenersInstance)); doReturn(executorService).when(taskManagerHelper).createExecutorService(); doReturn(pipelineExecutor).when(taskManagerHelper).createPipelineExecutor(); taskManager = spy(new PipelineExecutorTaskManagerImpl(pipelineRegistry, configExecutorsInstance, eventListenersInstance, pipelineExecutorRegistry) { { super.taskManagerHelper = PipelineExecutorTaskManagerImplTestBase.this.taskManagerHelper; } @Override protected void init() { super.init(); super.futureTaskMap = spy(super.futureTaskMap); } }); }
@Test public void testCreatePipelineExecutor() { assertNotNull(taskManagerHelper.createPipelineExecutor()); verify(configExecutorsInstance, times(1)).iterator(); verify(taskManagerHelper, times(1)).newPipelineExecutor(configExecutors); }
if (stopEnabledStatus.contains(task.getPipelineStatus())) { try { taskManagerHelper.setTaskInStoppedStatus(task); updateExecutorRegistry(task); } catch (Exception e) {
@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()); }
/** * Executes the task definition in asynchronous mode. * @param taskDef task definition for executing. * @return the taskId assigned to the running task. * @see PipelineExecutorTaskDef */ private synchronized String executeAsync(final PipelineExecutorTaskDef taskDef) { final PipelineExecutorTaskImpl task = taskManagerHelper.createTask(taskDef); storeTaskEntry(TaskEntry.newAsyncEntry(task)); startAsyncTask(task); updateExecutorRegistry(task); return task.getId(); }
private void initPipelineExecutor() { pipelineExecutor = taskManagerHelper.createPipelineExecutor(); }
@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); }
public PipelineExecutor createPipelineExecutor() { final Collection<ConfigExecutor> configs = new ArrayList<>(); configExecutorInstance.iterator().forEachRemaining(configs::add); return newPipelineExecutor(configs); }
private void notifyExternalListeners(final PipelineEvent event) { taskManagerHelper.notifyExternalListeners(externalListeners, event); }
@Before public void setUp() { pipelineExecutorTraceCaptor = ArgumentCaptor.forClass(PipelineExecutorTrace.class); taskEntryCaptor = ArgumentCaptor.forClass(PipelineExecutorTaskManagerImpl.TaskEntry.class); stringCaptor = ArgumentCaptor.forClass(String.class); configExecutors = mockConfigExecutors(CONFIG_EXECUTORS_SIZE); when(configExecutorsInstance.iterator()).thenReturn(configExecutors.iterator()); externalListeners = mockEventListeners(PIPELINE_EVENT_LISTENERS); when(eventListenersInstance.iterator()).thenReturn(externalListeners.iterator()); taskManagerHelper = spy(new PipelineExecutorTaskManagerImplHelper(configExecutorsInstance, eventListenersInstance)); doReturn(executorService).when(taskManagerHelper).createExecutorService(); doReturn(pipelineExecutor).when(taskManagerHelper).createPipelineExecutor(); taskManager = spy(new PipelineExecutorTaskManagerImpl(pipelineRegistry, configExecutorsInstance, eventListenersInstance, pipelineExecutorRegistry) { { super.taskManagerHelper = PipelineExecutorTaskManagerImplTestBase.this.taskManagerHelper; } @Override protected void init() { super.init(); super.futureTaskMap = spy(super.futureTaskMap); } }); }
public PipelineExecutorTaskImpl createTask(final PipelineExecutorTaskDef taskDef) { String executionId = generateTaskId(); return createTask(taskDef, executionId); }
@Test public void testCreatePipelineExecutor() { assertNotNull(taskManagerHelper.createPipelineExecutor()); verify(configExecutorsInstance, times(1)).iterator(); verify(taskManagerHelper, times(1)).newPipelineExecutor(configExecutors); }
if (stopEnabledStatus.contains(task.getPipelineStatus())) { try { taskManagerHelper.setTaskInStoppedStatus(task); updateExecutorRegistry(task); } catch (Exception e) {
@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()); }
/** * Executes the task definition in asynchronous mode. * @param taskDef task definition for executing. * @return the taskId assigned to the running task. * @see PipelineExecutorTaskDef */ private synchronized String executeAsync(final PipelineExecutorTaskDef taskDef) { final PipelineExecutorTaskImpl task = taskManagerHelper.createTask(taskDef); storeTaskEntry(TaskEntry.newAsyncEntry(task)); startAsyncTask(task); updateExecutorRegistry(task); return task.getId(); }
private void initPipelineExecutor() { pipelineExecutor = taskManagerHelper.createPipelineExecutor(); }