@Test @DirtiesContext public void testTaskLauncherTaskletFailure() throws Exception { boolean isException = false; mockReturnValForTaskExecution(1L); TaskLauncherTasklet taskLauncherTasklet = getTaskExecutionTasklet(); ChunkContext chunkContext = chunkContext(); getCompleteTaskExecution(1); try { taskLauncherTasklet.execute(null, chunkContext); } catch (UnexpectedJobExecutionException jobExecutionException) { isException = true; assertThat(jobExecutionException.getMessage(),is(equalTo("Task returned a non zero exit code."))); } assertThat(isException,is(true)); }
private void waitForTaskToComplete(long taskExecutionId) { long timeout = System.currentTimeMillis() + this.composedTaskProperties.getMaxWaitTime(); logger.debug("Wait time for this task to complete is " + this.composedTaskProperties.getMaxWaitTime()); logger.debug("Interval check time for this task to complete is " + this.composedTaskProperties.getIntervalTimeBetweenChecks()); while (true) { try { Thread.sleep(this.composedTaskProperties.getIntervalTimeBetweenChecks()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e.getMessage(), e); } TaskExecution taskExecution = this.taskExplorer.getTaskExecution(taskExecutionId); if(taskExecution != null && taskExecution.getEndTime() != null) { if(taskExecution.getExitCode() != 0 ) { throw new UnexpectedJobExecutionException("Task returned a non zero exit code."); } break; } if(this.composedTaskProperties.getMaxWaitTime() > 0 && System.currentTimeMillis() > timeout) { throw new TaskExecutionTimeoutException(String.format( "Timeout occurred while processing task with Execution Id %s", taskExecutionId)); } } }
@Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { throw new UnsupportedOperationException( "JobSupport does not provide an implementation of execute(). Use a smarter subclass."); }
@ResponseStatus(HttpStatus.CONFLICT) @ExceptionHandler({UnexpectedJobExecutionException.class, JobInstanceAlreadyExistsException.class, JobInstanceAlreadyCompleteException.class}) public String handleAlreadyExists(Exception ex) { LOG.warn("JobInstance or JobExecution already exists.",ex); return ex.getMessage(); }
/** * Not supported but provided so that tests can easily create a step. * * @throws UnsupportedOperationException always * * @see org.springframework.batch.core.Step#execute(org.springframework.batch.core.StepExecution) */ @Override public void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException { throw new UnsupportedOperationException( "Cannot process a StepExecution. Use a smarter subclass of StepSupport."); }