Update versions and update code format

This commit is contained in:
Glenn Renfro
2023-09-25 12:22:51 -04:00
parent 6c5656e73f
commit 63ab5b1daf
95 changed files with 1224 additions and 1035 deletions

View File

@@ -60,7 +60,7 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
+ "have exactly 1 instance of the TaskBatchExecutionListener but has " + length);
}
((AbstractJob) bean)
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
}
return bean;
}

View File

@@ -107,7 +107,8 @@ public class TaskBatchExecutionListenerFactoryBean implements FactoryBean<TaskBa
if (AopUtils.isJdkDynamicProxy(this.taskExplorer)) {
SimpleTaskExplorer dereferencedTaskRepository = (SimpleTaskExplorer) ((Advised) this.taskExplorer)
.getTargetSource().getTarget();
.getTargetSource()
.getTarget();
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField,
dereferencedTaskRepository);

View File

@@ -140,7 +140,8 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
if (incrementer != null) {
JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.taskJobExplorer)
.getNextJobParameters(job).toJobParameters();
.getNextJobParameters(job)
.toJobParameters();
parameters = merge(nextParameters, jobParameters);
}
}

View File

@@ -343,7 +343,7 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
for (StepExecution curStepExecution : executed) {
if (!result.contains(curStepExecution)) {
StepExecution partitionStepExecution = DeployerPartitionHandler.this.jobExplorer
.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId());
.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId());
BatchStatus batchStatus = partitionStepExecution.getStatus();
if (batchStatus != null && isComplete(batchStatus)) {

View File

@@ -88,9 +88,9 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
validateRequest();
Long jobExecutionId = Long
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
Long stepExecutionId = Long
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
if (stepExecution == null) {
@@ -129,7 +129,7 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
Assert.isTrue(
this.stepLocator.getStepNames()
.contains(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)),
.contains(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)),
"The step requested cannot be found in the provided BeanFactory");
}

View File

@@ -187,7 +187,7 @@ public class TaskLauncherHandler implements Runnable {
copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
Map<String, String> environmentVariables = this.environmentVariablesProvider
.getEnvironmentVariables(copyContext);
.getEnvironmentVariables(copyContext);
if (this.defaultArgsAsEnvironmentVars) {
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,

View File

@@ -37,10 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TaskJobLauncherAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
@Test
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
@@ -52,31 +51,37 @@ public class TaskJobLauncherAutoConfigurationTests {
@Test
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.cloud.task.batch.applicationRunnerOrder=100").run(context -> {
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(100);
});
this.contextRunner
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.cloud.task.batch.applicationRunnerOrder=100")
.run(context -> {
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(100);
});
}
@Test
public void testAutoBuiltDataSourceWithBatchJobNames() {
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.batch.job.name=job1", "spring.cloud.task.batch.jobName=foobar").run(context -> {
validateJobNames(context, "job1");
});
this.contextRunner
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true", "spring.batch.job.name=job1",
"spring.cloud.task.batch.jobName=foobar")
.run(context -> {
validateJobNames(context, "job1");
});
}
@Test
public void testAutoBuiltDataSourceWithTaskBatchJobNames() {
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.cloud.task.batch.jobNames=job1,job2").run(context -> {
validateJobNames(context, "job1,job2");
});
this.contextRunner
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
"spring.cloud.task.batch.jobNames=job1,job2")
.run(context -> {
validateJobNames(context, "job1,job2");
});
}
private void validateJobNames(AssertableApplicationContext context, String jobNames) throws Exception {
JobLauncherApplicationRunner jobLauncherApplicationRunner = context
.getBean(TaskJobLauncherApplicationRunner.class);
.getBean(TaskJobLauncherApplicationRunner.class);
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner, "jobName");
assertThat(names).isEqualTo(jobNames);

View File

@@ -63,9 +63,9 @@ import static org.assertj.core.api.Assertions.fail;
public class TaskJobLauncherApplicationRunnerCoreTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
TransactionAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class))
.withUserConfiguration(BatchConfiguration.class);
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, TransactionAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class))
.withUserConfiguration(BatchConfiguration.class);
@Test
void basicExecution() {
@@ -95,8 +95,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.build();
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.build();
// start a job instance
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
runFailedJob(jobLauncherContext, job, jobParameters);
@@ -114,9 +114,11 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
this.contextRunner.run((context) -> {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder().preventRestart()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer()).build();
Job job = jobLauncherContext.jobBuilder()
.preventRestart()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer())
.build();
runFailedJob(jobLauncherContext, job, new JobParameters());
runFailedJob(jobLauncherContext, job, new JobParameters());
// A failed job that is not restartable does not re-use the job params of
@@ -137,10 +139,12 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
Job job = jobLauncherContext.jobBuilder()
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer()).build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
.toJobParameters();
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
.incrementer(new RunIdIncrementer())
.build();
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
.addLong("foo", 2L, false)
.toJobParameters();
runFailedJob(jobLauncherContext, job, jobParameters);
assertThat(jobLauncherContext.jobInstances()).hasSize(1);
// try to re-run a failed execution with non identifying parameters

View File

@@ -113,8 +113,8 @@ public class TaskJobLauncherApplicationRunnerTests {
public void testNoTaskJobLauncher() {
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true",
"--spring.cloud.task.batch.failOnJobFailurePollInterval=500", "--spring.batch.job.enabled=false" };
this.applicationContext = SpringApplication.run(
new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
this.applicationContext = SpringApplication
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
assertThat(jobExplorer.getJobNames().size()).isEqualTo(0);
}
@@ -140,15 +140,15 @@ public class TaskJobLauncherApplicationRunnerTests {
public void testApplicationRunnerSetToFalse() {
String[] enabledArgs = new String[] {};
this.applicationContext = SpringApplication
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
validateContext();
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class)).isNotNull();
Executable executable = () -> this.applicationContext.getBean(TaskJobLauncherApplicationRunner.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(executable::execute)
.withMessage("No qualifying bean of type "
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
.withMessage("No qualifying bean of type "
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
validateContext();
}
@@ -158,7 +158,7 @@ public class TaskJobLauncherApplicationRunnerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(1);
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
@@ -169,10 +169,11 @@ public class TaskJobLauncherApplicationRunnerTests {
private void validateForFail(String errorMessage, Class<?> clazz, String[] enabledArgs) {
Executable executable = () -> this.applicationContext = SpringApplication
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute).havingCause()
.withMessage(errorMessage);
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute)
.havingCause()
.withMessage(errorMessage);
}
@Component
@@ -199,10 +200,11 @@ public class TaskJobLauncherApplicationRunnerTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
@@ -252,19 +254,21 @@ public class TaskJobLauncherApplicationRunnerTests {
@Bean
public Job jobFail() {
return new JobBuilder("jobA", this.jobRepository)
.start(new StepBuilder("step1", this.jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
throw new IllegalStateException("WHOOPS");
}, transactionManager).build()).build();
.start(new StepBuilder("step1", this.jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
throw new IllegalStateException("WHOOPS");
}, transactionManager).build())
.build();
}
@Bean
public Job jobFun() {
return new JobBuilder("jobSucceed", this.jobRepository)
.start(new StepBuilder("step1Succeed", this.jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1Succeed", this.jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
}

View File

@@ -75,16 +75,18 @@ public class PrefixTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-h2.sql").setType(EmbeddedDatabaseType.H2)
.build();
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-h2.sql")
.setType(EmbeddedDatabaseType.H2)
.build();
}
@Bean

View File

@@ -74,16 +74,18 @@ class PrimaryKeyTests {
@Bean
Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-with-primary-keys-h2.sql")
.setType(EmbeddedDatabaseType.H2).build();
.setType(EmbeddedDatabaseType.H2)
.build();
}
@Bean

View File

@@ -144,7 +144,7 @@ public class TaskBatchExecutionListenerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(1);
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
@@ -156,9 +156,9 @@ public class TaskBatchExecutionListenerTests {
this.applicationContext = SpringApplication.run(TaskNotEnabledConfiguration.class, ARGS);
assertThat(applicationContext.getBean(Job.class)).isNotNull();
assertThatThrownBy(() -> applicationContext.getBean(TaskBatchExecutionListenerBeanPostProcessor.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
.isInstanceOf(NoSuchBeanDefinitionException.class);
assertThatThrownBy(() -> applicationContext.getBean(TaskBatchExecutionListener.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
@Test
@@ -170,7 +170,7 @@ public class TaskBatchExecutionListenerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(1);
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
@@ -185,7 +185,7 @@ public class TaskBatchExecutionListenerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(0);
}
@@ -199,11 +199,11 @@ public class TaskBatchExecutionListenerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(1);
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
.isEqualTo(1);
.isEqualTo(1);
}
@Test
@@ -215,7 +215,7 @@ public class TaskBatchExecutionListenerTests {
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
Set<Long> jobExecutionIds = taskExplorer
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
assertThat(jobExecutionIds.size()).isEqualTo(1);
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
@@ -260,7 +260,7 @@ public class TaskBatchExecutionListenerTests {
SingleTaskConfiguration.class }, ARGS);
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = this.applicationContext
.getBean(TaskBatchExecutionListenerBeanPostProcessor.class);
.getBean(TaskBatchExecutionListenerBeanPostProcessor.class);
beanPostProcessor.setJobNames(jobNames);
return beanPostProcessor;
@@ -287,10 +287,11 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
@@ -308,10 +309,11 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
@@ -332,10 +334,11 @@ public class TaskBatchExecutionListenerTests {
@Override
public Job getObject() {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Override
@@ -365,28 +368,29 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}
}, new ResourcelessTransactionManager()).build()).build();
.start(new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}
}, new ResourcelessTransactionManager()).build())
.build();
}
@Bean
@Primary
public DataSource myDataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.setName("myDataSource");
.setName("myDataSource");
return builder.build();
}
@Bean
public DataSource incorrectDataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.setName("incorrectDataSource");
.setName("incorrectDataSource");
return builder.build();
}
@@ -410,19 +414,21 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job1", jobRepository)
.start(new StepBuilder("job1step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed job1");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("job1step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed job1");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
public Job job2(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job2", jobRepository)
.start(new StepBuilder("job2step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed job2");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("job2step1", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("Executed job2");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean

View File

@@ -181,13 +181,13 @@ public class DeployerPartitionHandlerTests {
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
.isTrue();
.isTrue();
assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
@@ -236,18 +236,21 @@ public class DeployerPartitionHandlerTests {
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments().isEmpty()).isTrue();
assertThat(request.getDefinition().getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
assertThat(request.getDefinition().getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
assertThat(request.getDefinition()
.getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
assertThat(request.getDefinition()
.getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.isEqualTo("step1");
.isEqualTo("step1");
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME))
.isEqualTo("partitionedJobTask_partitionedJob_step1:partition1");
assertThat(request.getDefinition().getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
.isEqualTo("partitionedJobTask_partitionedJob_step1:partition1");
assertThat(request.getDefinition()
.getProperties()
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
.isEqualTo("2");
.isEqualTo("2");
assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
@@ -290,7 +293,7 @@ public class DeployerPartitionHandlerTests {
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
}
@Test
@@ -526,11 +529,11 @@ public class DeployerPartitionHandlerTests {
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
@@ -592,11 +595,11 @@ public class DeployerPartitionHandlerTests {
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
@@ -787,11 +790,11 @@ public class DeployerPartitionHandlerTests {
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
@@ -878,14 +881,14 @@ public class DeployerPartitionHandlerTests {
AppDefinition appDefinition = request.getDefinition();
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments().contains(
formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))))
.isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))))
.isTrue();
assertThat(request.getCommandlineArguments()
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
.isTrue();
.isTrue();
}
}

View File

@@ -140,19 +140,19 @@ public class DeployerStepExecutionHandlerTests {
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn("2");
.thenReturn("2");
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
this.handler.run();
@@ -166,19 +166,19 @@ public class DeployerStepExecutionHandlerTests {
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn("2");
.thenReturn("2");
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
doThrow(new JobInterruptedException("expected")).when(this.step).execute(workerStep);
@@ -194,19 +194,19 @@ public class DeployerStepExecutionHandlerTests {
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn(true);
.thenReturn(true);
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
.thenReturn("2");
.thenReturn("2");
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
.thenReturn("workerStep");
.thenReturn("workerStep");
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep);