Search in sources :

Example 6 with JobParameters

use of org.springframework.batch.core.JobParameters in project spring-boot by spring-projects.

the class BatchAutoConfigurationTests method testDefinesAndLaunchesJob.

@Test
public void testDefinesAndLaunchesJob() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(JobConfiguration.class, EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class, TransactionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(JobLauncher.class)).isNotNull();
    this.context.getBean(JobLauncherCommandLineRunner.class).run();
    assertThat(this.context.getBean(JobRepository.class).getLastJobExecution("job", new JobParameters())).isNotNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) JobParameters(org.springframework.batch.core.JobParameters) JobRepository(org.springframework.batch.core.repository.JobRepository) Test(org.junit.Test)

Example 7 with JobParameters

use of org.springframework.batch.core.JobParameters 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 8 with JobParameters

use of org.springframework.batch.core.JobParameters in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunner method launchJobFromProperties.

protected void launchJobFromProperties(Properties properties) throws JobExecutionException {
    JobParameters jobParameters = this.converter.getJobParameters(properties);
    executeLocalJobs(jobParameters);
    executeRegisteredJobs(jobParameters);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters)

Example 9 with JobParameters

use of org.springframework.batch.core.JobParameters in project camel by apache.

the class SpringBatchEndpointTest method shouldConvertDateHeadersToJobParams.

@Test
public void shouldConvertDateHeadersToJobParams() throws Exception {
    // Given
    String headerKey = "headerKey";
    Date headerValue = new Date();
    // When
    template.sendBodyAndHeader("direct:start", "Start the job, please.", headerKey, headerValue);
    // Then
    ArgumentCaptor<JobParameters> jobParameters = ArgumentCaptor.forClass(JobParameters.class);
    verify(jobLauncher).run(any(Job.class), jobParameters.capture());
    Date parameter = jobParameters.getValue().getDate(headerKey);
    assertEquals(parameter, headerValue);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) Date(java.util.Date) Test(org.junit.Test)

Example 10 with JobParameters

use of org.springframework.batch.core.JobParameters in project camel by apache.

the class SpringBatchEndpointTest method setNullValueToJobParams.

@Test
public void setNullValueToJobParams() throws Exception {
    // Given
    String headerKey = "headerKey";
    Date headerValue = null;
    // When
    template.sendBodyAndHeader("direct:start", "Start the job, please.", headerKey, headerValue);
    // Then
    ArgumentCaptor<JobParameters> jobParameters = ArgumentCaptor.forClass(JobParameters.class);
    verify(jobLauncher).run(any(Job.class), jobParameters.capture());
    Date parameter = jobParameters.getValue().getDate(headerKey);
    assertEquals(parameter, headerValue);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) Job(org.springframework.batch.core.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

JobParameters (org.springframework.batch.core.JobParameters)20 Test (org.junit.Test)12 Date (java.util.Date)5 JobRepository (org.springframework.batch.core.repository.JobRepository)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 RunIdIncrementer (org.springframework.batch.core.launch.support.RunIdIncrementer)4 Job (org.springframework.batch.core.Job)3 JobParameter (org.springframework.batch.core.JobParameter)3 JobParametersBuilder (org.springframework.batch.core.JobParametersBuilder)3 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 HashMap (java.util.HashMap)2 JobExecution (org.springframework.batch.core.JobExecution)2 JobInstance (org.springframework.batch.core.JobInstance)2 Map (java.util.Map)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 CronTrigger (org.quartz.CronTrigger)1 SimpleTrigger (org.quartz.SimpleTrigger)1