Java 类org.springframework.batch.core.UnexpectedJobExecutionException 实例源码

项目:composed-task-runner    文件:TaskLauncherTaskletTests.java   
@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));
}
项目:composed-task-runner    文件:TaskLauncherTasklet.java   
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));
        }
    }
}
项目:marklogic-spring-batch    文件:JobSupport.java   
@Override
public void execute(JobExecution execution) throws UnexpectedJobExecutionException {
    throw new UnsupportedOperationException(
            "JobSupport does not provide an implementation of execute().  Use a smarter subclass.");
}
项目:spring-boot-starter-batch-web    文件:JobOperationsController.java   
@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();
}
项目:marklogic-spring-batch    文件:StepSupport.java   
/**
 * 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.");
}