Search in sources :

Example 1 with RunIdIncrementer

use of org.springframework.batch.core.launch.support.RunIdIncrementer in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method retryFailedExecution.

@Test
public void retryFailedExecution() throws Exception {
    this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(new Tasklet() {

        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            throw new RuntimeException("Planned");
        }
    }).build()).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
Also used : StepContribution(org.springframework.batch.core.StepContribution) JobParameters(org.springframework.batch.core.JobParameters) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Example 2 with RunIdIncrementer

use of org.springframework.batch.core.launch.support.RunIdIncrementer in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method incrementExistingExecution.

@Test
public void incrementExistingExecution() throws Exception {
    this.job = this.jobs.get("job").start(this.step).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Example 3 with RunIdIncrementer

use of org.springframework.batch.core.launch.support.RunIdIncrementer in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method retryFailedExecutionOnNonRestartableJob.

@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
    this.job = this.jobs.get("job").preventRestart().start(this.steps.get("step").tasklet(new Tasklet() {

        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            throw new RuntimeException("Planned");
        }
    }).build()).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    // A failed job that is not restartable does not re-use the job params of
    // the last execution, but creates a new job instance when running it again.
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
Also used : StepContribution(org.springframework.batch.core.StepContribution) JobParameters(org.springframework.batch.core.JobParameters) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Example 4 with RunIdIncrementer

use of org.springframework.batch.core.launch.support.RunIdIncrementer in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunnerTests method retryFailedExecutionWithNonIdentifyingParameters.

@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
    this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(new Tasklet() {

        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            throw new RuntimeException("Planned");
        }
    }).build()).incrementer(new RunIdIncrementer()).build();
    JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false).toJobParameters();
    this.runner.execute(this.job, jobParameters);
    this.runner.execute(this.job, jobParameters);
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
Also used : StepContribution(org.springframework.batch.core.StepContribution) JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 JobParameters (org.springframework.batch.core.JobParameters)4 RunIdIncrementer (org.springframework.batch.core.launch.support.RunIdIncrementer)4 StepContribution (org.springframework.batch.core.StepContribution)3 ChunkContext (org.springframework.batch.core.scope.context.ChunkContext)3 Tasklet (org.springframework.batch.core.step.tasklet.Tasklet)3 JobParametersBuilder (org.springframework.batch.core.JobParametersBuilder)1