Skip unnecessary attempt at executing Job

...that was already executed as part of the "local" set.

Also added some howto docs on executing Batch jobs.

See gh-382
This commit is contained in:
Dave Syer
2014-02-24 14:56:17 +00:00
parent 3ad6c96ce5
commit 09f3ee14a4
3 changed files with 80 additions and 29 deletions

View File

@@ -114,29 +114,30 @@ public class BatchAutoConfigurationTests {
assertNotNull(this.context.getBean(JobRepository.class).getLastJobExecution(
"job", new JobParameters()));
}
@Test
public void testDefinesAndLaunchesNamedJob() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.batch.job.names:discreteRegisteredJob");
this.context.register(NamedJobConfigurationWithRegisteredJob.class, BatchAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class,
this.context.register(NamedJobConfigurationWithRegisteredJob.class,
BatchAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
JobRepository repository = this.context.getBean(JobRepository.class);
assertNotNull(this.context.getBean(JobLauncher.class));
this.context.getBean(JobLauncherCommandLineRunner.class).run();
assertNotNull(this.context.getBean(JobRepository.class).getLastJobExecution(
"discreteRegisteredJob", new JobParameters()));
assertNotNull(repository.getLastJobExecution("discreteRegisteredJob",
new JobParameters()));
}
@Test
public void testDefinesAndLaunchesLocalJob() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.batch.job.names:discreteLocalJob");
this.context.register(NamedJobConfigurationWithLocalJob.class, BatchAutoConfiguration.class,
EmbeddedDataSourceConfiguration.class,
this.context.register(NamedJobConfigurationWithLocalJob.class,
BatchAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(JobLauncher.class));
@@ -206,17 +207,17 @@ public class BatchAutoConfigurationTests {
protected static class NamedJobConfigurationWithRegisteredJob {
@Autowired
private JobRegistry jobRegistry;
@Autowired
private JobRepository jobRepository;
@Bean
public JobRegistryBeanPostProcessor registryProcessor() {
JobRegistryBeanPostProcessor processor = new JobRegistryBeanPostProcessor();
processor.setJobRegistry(jobRegistry);
processor.setJobRegistry(this.jobRegistry);
return processor;
}
@Bean
public Job discreteJob() {
AbstractJob job = new AbstractJob("discreteRegisteredJob") {
@@ -241,13 +242,13 @@ public class BatchAutoConfigurationTests {
return job;
}
}
@EnableBatchProcessing
protected static class NamedJobConfigurationWithLocalJob {
@Autowired
private JobRepository jobRepository;
@Bean
public Job discreteJob() {
AbstractJob job = new AbstractJob("discreteLocalJob") {
@@ -272,7 +273,7 @@ public class BatchAutoConfigurationTests {
return job;
}
}
@EnableBatchProcessing
protected static class JobConfiguration {
@Autowired