Browse Source

Start building against Spring Batch 6.0.0-RC1 snapshots

See gh-47477
pull/47549/head
Mahmoud Ben Hassine 2 months ago committed by Stéphane Nicoll
parent
commit
491019d4fe
  1. 23
      module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java
  2. 21
      module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java
  3. 2
      module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java
  4. 2
      platform/spring-boot-dependencies/build.gradle
  5. 2
      smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java
  6. 2
      smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java

23
module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java

@ -31,13 +31,12 @@ import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.job.Job; import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.JobExecution; import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.core.job.JobExecutionException; import org.springframework.batch.core.job.JobExecutionException;
import org.springframework.batch.core.job.parameters.InvalidJobParametersException;
import org.springframework.batch.core.job.parameters.JobParameters; import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.job.parameters.JobParametersInvalidException; import org.springframework.batch.core.launch.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.launch.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.launch.JobOperator; import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.launch.NoSuchJobException; import org.springframework.batch.core.launch.JobRestartException;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
@ -146,10 +145,11 @@ public class JobLauncherApplicationRunner
public void run(String... args) throws JobExecutionException { public void run(String... args) throws JobExecutionException {
logger.info("Running default command line with: " + Arrays.asList(args)); logger.info("Running default command line with: " + Arrays.asList(args));
launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); Properties properties = StringUtils.splitArrayElementsIntoProperties(args, "=");
launchJobFromProperties((properties != null) ? properties : new Properties());
} }
protected void launchJobFromProperties(@Nullable Properties properties) throws JobExecutionException { protected void launchJobFromProperties(Properties properties) throws JobExecutionException {
JobParameters jobParameters = this.converter.getJobParameters(properties); JobParameters jobParameters = this.converter.getJobParameters(properties);
executeLocalJobs(jobParameters); executeLocalJobs(jobParameters);
executeRegisteredJobs(jobParameters); executeRegisteredJobs(jobParameters);
@ -179,14 +179,15 @@ public class JobLauncherApplicationRunner
if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) { if (this.jobRegistry != null && StringUtils.hasText(this.jobName)) {
if (!isLocalJob(this.jobName)) { if (!isLocalJob(this.jobName)) {
Job job = this.jobRegistry.getJob(this.jobName); Job job = this.jobRegistry.getJob(this.jobName);
execute(job, jobParameters); if (job != null) {
execute(job, jobParameters);
}
} }
} }
} }
protected void execute(Job job, JobParameters jobParameters) protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
throws JobExecutionAlreadyRunningException, NoSuchJobException, JobRestartException, JobRestartException, JobInstanceAlreadyCompleteException, InvalidJobParametersException {
JobInstanceAlreadyCompleteException, JobParametersInvalidException {
JobExecution execution = this.jobOperator.start(job, jobParameters); JobExecution execution = this.jobOperator.start(job, jobParameters);
if (this.publisher != null) { if (this.publisher != null) {
this.publisher.publishEvent(new JobExecutionEvent(execution)); this.publisher.publishEvent(new JobExecutionEvent(execution));

21
module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobExecutionExitCodeGeneratorTests.java

@ -20,6 +20,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.job.JobExecution; import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.core.job.JobInstance;
import org.springframework.batch.core.job.parameters.JobParameters;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -27,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link JobExecutionExitCodeGenerator}. * Tests for {@link JobExecutionExitCodeGenerator}.
* *
* @author Dave Syer * @author Dave Syer
* @author Mahmoud Ben Hassine
*/ */
class JobExecutionExitCodeGeneratorTests { class JobExecutionExitCodeGeneratorTests {
@ -34,23 +37,27 @@ class JobExecutionExitCodeGeneratorTests {
@Test @Test
void testExitCodeForRunning() { void testExitCodeForRunning() {
this.generator.onApplicationEvent(new JobExecutionEvent(new JobExecution(0L))); JobInstance jobInstance = new JobInstance(1L, "job");
JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters());
this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution));
assertThat(this.generator.getExitCode()).isOne(); assertThat(this.generator.getExitCode()).isOne();
} }
@Test @Test
void testExitCodeForCompleted() { void testExitCodeForCompleted() {
JobExecution execution = new JobExecution(0L); JobInstance jobInstance = new JobInstance(1L, "job");
execution.setStatus(BatchStatus.COMPLETED); JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters());
this.generator.onApplicationEvent(new JobExecutionEvent(execution)); jobExecution.setStatus(BatchStatus.COMPLETED);
this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution));
assertThat(this.generator.getExitCode()).isZero(); assertThat(this.generator.getExitCode()).isZero();
} }
@Test @Test
void testExitCodeForFailed() { void testExitCodeForFailed() {
JobExecution execution = new JobExecution(0L); JobInstance jobInstance = new JobInstance(1L, "job");
execution.setStatus(BatchStatus.FAILED); JobExecution jobExecution = new JobExecution(1L, jobInstance, new JobParameters());
this.generator.onApplicationEvent(new JobExecutionEvent(execution)); jobExecution.setStatus(BatchStatus.FAILED);
this.generator.onApplicationEvent(new JobExecutionEvent(jobExecution));
assertThat(this.generator.getExitCode()).isEqualTo(5); assertThat(this.generator.getExitCode()).isEqualTo(5);
} }

2
module/spring-boot-batch/src/test/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunnerTests.java

@ -33,7 +33,7 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.infrastructure.support.transaction.ResourcelessTransactionManager;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

2
platform/spring-boot-dependencies/build.gradle

@ -2372,7 +2372,7 @@ bom {
releaseNotes("https://github.com/spring-projects/spring-amqp/releases/tag/v{version}") releaseNotes("https://github.com/spring-projects/spring-amqp/releases/tag/v{version}")
} }
} }
library("Spring Batch", "6.0.0-M3") { library("Spring Batch", "6.0.0-SNAPSHOT") {
considerSnapshots() considerSnapshots()
group("org.springframework.batch") { group("org.springframework.batch") {
bom("spring-batch-bom") bom("spring-batch-bom")

2
smoke-test/spring-boot-smoke-test-batch-jdbc/src/main/java/smoketest/batch/SampleBatchApplication.java

@ -22,7 +22,7 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.infrastructure.repeat.RepeatStatus;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

2
smoke-test/spring-boot-smoke-test-batch/src/main/java/smoketest/batch/SampleBatchApplication.java

@ -22,7 +22,7 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.Step; import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.infrastructure.repeat.RepeatStatus;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;

Loading…
Cancel
Save