@Provides TaskExecutionService executionService() { return new DefaultTaskExecutionService(); }
@Override public void execute(TaskParameters parameters, CancellationOption cancellationOption) { TaskExecutionContext executionContext = null; LOG.trace("Starting execution for {}", parameters); try { validateIfRequired(parameters); executionContext = new TaskExecutionContext(context.getTask(parameters), parameters.isLenient()); cancellationOption.setExecutionContext(executionContext); LOG.info("Starting task ({}) execution.", executionContext.task()); preExecution(executionContext); actualExecution(parameters, executionContext); postExecution(executionContext); } catch (InvalidTaskParametersException i) { LOG.error("Task execution failed due to invalid parameters: " + String.join(". ", i.getReasons()), i); executionFailed(i, executionContext); } catch (TaskException e) { LOG.error(String.format("Task (%s) execution failed.", ofNullable(executionContext).map(c -> c.task().toString()).orElse("")), e); executionFailed(e, executionContext); } catch (RuntimeException e) { executionFailed(e, executionContext); throw e; } }
public void execute(TaskParameters parameters, CancellationOption cancellationOption) { service.execute(parameters, cancellationOption); }
private void validateIfRequired(TaskParameters parameters) throws InvalidTaskParametersException { if (context.isValidation()) { LOG.debug("Validating parameters."); validate(parameters); } else { LOG.info("Validation skipped."); } }
@Override public void execute(TaskParameters parameters, CancellationOption cancellationOption) { TaskExecutionContext executionContext = null; LOG.trace("Starting execution for {}", parameters); try { validateIfRequired(parameters); executionContext = new TaskExecutionContext(context.getTask(parameters), parameters.isLenient()); cancellationOption.setExecutionContext(executionContext); LOG.info("Starting task ({}) execution.", executionContext.task()); preExecution(executionContext); actualExecution(parameters, executionContext); postExecution(executionContext); } catch (InvalidTaskParametersException i) { LOG.error("Task execution failed due to invalid parameters: " + String.join(". ", i.getReasons()), i); executionFailed(i, executionContext); } catch (TaskException e) { LOG.error(String.format("Task (%s) execution failed.", ofNullable(executionContext).map(c -> c.task().toString()).orElse("")), e); executionFailed(e, executionContext); } catch (RuntimeException e) { executionFailed(e, executionContext); throw e; } }
@Override public void execute(TaskParameters parameters) { execute(parameters, new CancellationOption()); }
private void validateIfRequired(TaskParameters parameters) throws InvalidTaskParametersException { if (context.isValidation()) { LOG.debug("Validating parameters."); validate(parameters); } else { LOG.info("Validation skipped."); } }
@Override public void execute(TaskParameters parameters) { execute(parameters, new CancellationOption()); }
private static TaskExecutionAdapter getTaskExecutionAdapter() { return new DefaultTaskExecutionAdapter(new DefaultTaskExecutionService()); }
@Test public void testNegativeBeforeExecution() throws TaskException { doThrow(new TaskExecutionException("Mock exception")).when(task).before(Matchers.any(TaskParameters.class), Matchers.any(TaskExecutionContext.class)); SingleTaskOutput output = mock(SingleTaskOutput.class); parameters.setOutput(output); TestUtils.setProperty(victim, "context", context); victim.execute(parameters); verify(task).before(eq(parameters), any()); verify(task).after(); verify(task, never()).execute(parameters); }
CommandLineExecuteTestHelper(boolean useMockTaskExecutionService, Map<CustomizableProps, String> customs) { if (useMockTaskExecutionService) { taskExecutionService = mock(TaskExecutionService.class); } else { taskExecutionService = new DefaultTaskExecutionService(); } this.customs = customs; }
@Test public void testInvalidParameters() throws TaskException { parameters.setVersion(PdfVersion.VERSION_1_4); parameters.setCompress(true); victim.execute(parameters); verify(task, never()).before(eq(parameters), any()); verify(task, never()).after(); verify(task, never()).execute(parameters); }
public void execute(TaskParameters parameters) { testContext.listenForTaskFailure(); testContext.listenForTaskWarnings(); service.execute(parameters); }
@Test public void testExecute() { TestListenerStart listener = TestListenerFactory.newStartListener(); GlobalNotificationContext.getContext().addListener(listener); victim.execute(parameters); assertTrue(listener.isStarted()); }