Updated to files to fit the Standard.
This commit is contained in:
@@ -31,14 +31,12 @@ public class JobLaunchCondition extends AllNestedConditions {
|
||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure",
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure", havingValue = "true")
|
||||
static class FailOnJobFailureCondition {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
static class SpringBatchJobCondition {
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnBean({Job.class, TaskLifecycleListener.class})
|
||||
@ConditionalOnProperty(
|
||||
name = { "spring.cloud.task.batch.listener.enable",
|
||||
"spring.cloud.task.batch.listener.enabled" },
|
||||
@ConditionalOnBean({ Job.class, TaskLifecycleListener.class })
|
||||
@ConditionalOnProperty(name = { "spring.cloud.task.batch.listener.enable", "spring.cloud.task.batch.listener.enabled" },
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
public class TaskBatchAutoConfiguration {
|
||||
|
||||
@@ -68,15 +66,13 @@ public class TaskBatchAutoConfiguration {
|
||||
private TaskProperties taskProperties;
|
||||
|
||||
@Bean
|
||||
public TaskBatchExecutionListenerFactoryBean taskBatchExecutionListener(
|
||||
TaskExplorer taskExplorer) {
|
||||
public TaskBatchExecutionListenerFactoryBean taskBatchExecutionListener(TaskExplorer taskExplorer) {
|
||||
TaskConfigurer taskConfigurer = null;
|
||||
if (!this.context.getBeansOfType(TaskConfigurer.class).isEmpty()) {
|
||||
taskConfigurer = this.context.getBean(TaskConfigurer.class);
|
||||
}
|
||||
if (taskConfigurer != null && taskConfigurer.getTaskDataSource() != null) {
|
||||
return new TaskBatchExecutionListenerFactoryBean(
|
||||
taskConfigurer.getTaskDataSource(), taskExplorer,
|
||||
return new TaskBatchExecutionListenerFactoryBean(taskConfigurer.getTaskDataSource(), taskExplorer,
|
||||
this.taskProperties.getTablePrefix());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -43,28 +43,24 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
|
||||
private List<String> jobNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (this.jobNames.size() > 0 && !this.jobNames.contains(beanName)) {
|
||||
return bean;
|
||||
}
|
||||
int length = this.applicationContext
|
||||
.getBeanNamesForType(TaskBatchExecutionListener.class).length;
|
||||
int length = this.applicationContext.getBeanNamesForType(TaskBatchExecutionListener.class).length;
|
||||
|
||||
if (bean instanceof AbstractJob) {
|
||||
if (length != 1) {
|
||||
throw new IllegalStateException("The application context is required to "
|
||||
+ "have exactly 1 instance of the TaskBatchExecutionListener but has "
|
||||
+ length);
|
||||
+ "have exactly 1 instance of the TaskBatchExecutionListener but has " + length);
|
||||
}
|
||||
((AbstractJob) bean).registerJobExecutionListener(
|
||||
this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
((AbstractJob) bean)
|
||||
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class TaskBatchExecutionListenerFactoryBean
|
||||
implements FactoryBean<TaskBatchExecutionListener> {
|
||||
public class TaskBatchExecutionListenerFactoryBean implements FactoryBean<TaskBatchExecutionListener> {
|
||||
|
||||
private TaskBatchExecutionListener listener;
|
||||
|
||||
@@ -57,8 +56,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
* @param dataSource the dataSource to use for the TaskBatchExecutionListener.
|
||||
* @param taskExplorer the taskExplorer to use for the TaskBatchExecutionListener.
|
||||
*/
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource,
|
||||
TaskExplorer taskExplorer) {
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource, TaskExplorer taskExplorer) {
|
||||
this.dataSource = dataSource;
|
||||
this.taskExplorer = taskExplorer;
|
||||
}
|
||||
@@ -70,8 +68,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
* @param tablePrefix the prefix for the task tables accessed by the
|
||||
* TaskBatchExecutionListener.
|
||||
*/
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource,
|
||||
TaskExplorer taskExplorer, String tablePrefix) {
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource, TaskExplorer taskExplorer, String tablePrefix) {
|
||||
this(dataSource, taskExplorer);
|
||||
Assert.hasText(tablePrefix, "tablePrefix must not be null nor empty.");
|
||||
this.tablePrefix = tablePrefix;
|
||||
@@ -86,8 +83,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
this.listener = new TaskBatchExecutionListener(getMapTaskBatchDao());
|
||||
}
|
||||
else {
|
||||
this.listener = new TaskBatchExecutionListener(
|
||||
new JdbcTaskBatchDao(this.dataSource, this.tablePrefix));
|
||||
this.listener = new TaskBatchExecutionListener(new JdbcTaskBatchDao(this.dataSource, this.tablePrefix));
|
||||
}
|
||||
|
||||
return this.listener;
|
||||
@@ -104,8 +100,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
}
|
||||
|
||||
private MapTaskBatchDao getMapTaskBatchDao() throws Exception {
|
||||
Field taskExecutionDaoField = ReflectionUtils.findField(SimpleTaskExplorer.class,
|
||||
"taskExecutionDao");
|
||||
Field taskExecutionDaoField = ReflectionUtils.findField(SimpleTaskExplorer.class, "taskExecutionDao");
|
||||
taskExecutionDaoField.setAccessible(true);
|
||||
|
||||
MapTaskExecutionDao taskExecutionDao;
|
||||
@@ -114,12 +109,11 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
SimpleTaskExplorer dereferencedTaskRepository = (SimpleTaskExplorer) ((Advised) this.taskExplorer)
|
||||
.getTargetSource().getTarget();
|
||||
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils
|
||||
.getField(taskExecutionDaoField, dereferencedTaskRepository);
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField,
|
||||
dereferencedTaskRepository);
|
||||
}
|
||||
else {
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils
|
||||
.getField(taskExecutionDaoField, this.taskExplorer);
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField, this.taskExplorer);
|
||||
}
|
||||
|
||||
return new MapTaskBatchDao(taskExecutionDao.getBatchJobAssociations());
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
implements FactoryBean<TaskJobLauncherApplicationRunner> {
|
||||
public class TaskJobLauncherApplicationRunnerFactoryBean implements FactoryBean<TaskJobLauncherApplicationRunner> {
|
||||
|
||||
private JobLauncher jobLauncher;
|
||||
|
||||
@@ -54,10 +53,9 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, List<Job> jobs,
|
||||
TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry,
|
||||
JobRepository jobRepository, BatchProperties batchProperties) {
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean(JobLauncher jobLauncher, JobExplorer jobExplorer, List<Job> jobs,
|
||||
TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
BatchProperties batchProperties) {
|
||||
Assert.notNull(taskBatchProperties, "taskBatchProperties must not be null");
|
||||
Assert.notNull(batchProperties, "batchProperties must not be null");
|
||||
Assert.notEmpty(jobs, "jobs must not be null nor empty");
|
||||
@@ -85,8 +83,7 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
@Override
|
||||
public TaskJobLauncherApplicationRunner getObject() {
|
||||
TaskJobLauncherApplicationRunner taskJobLauncherApplicationRunner = new TaskJobLauncherApplicationRunner(
|
||||
this.jobLauncher, this.jobExplorer, this.jobRepository,
|
||||
this.taskBatchProperties);
|
||||
this.jobLauncher, this.jobExplorer, this.jobRepository, this.taskBatchProperties);
|
||||
taskJobLauncherApplicationRunner.setJobs(this.jobs);
|
||||
if (StringUtils.hasText(this.jobName)) {
|
||||
taskJobLauncherApplicationRunner.setJobName(this.jobName);
|
||||
|
||||
@@ -49,16 +49,13 @@ public class TaskJobLauncherAutoConfiguration {
|
||||
private TaskBatchProperties properties;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(
|
||||
name = "org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner")
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunner(
|
||||
JobLauncher jobLauncher, JobExplorer jobExplorer, List<Job> jobs,
|
||||
JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
@ConditionalOnClass(name = "org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner")
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunner(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, List<Job> jobs, JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
BatchProperties batchProperties) {
|
||||
TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunnerFactoryBean;
|
||||
taskJobLauncherApplicationRunnerFactoryBean = new TaskJobLauncherApplicationRunnerFactoryBean(
|
||||
jobLauncher, jobExplorer, jobs, this.properties, jobRegistry,
|
||||
jobRepository, batchProperties);
|
||||
taskJobLauncherApplicationRunnerFactoryBean = new TaskJobLauncherApplicationRunnerFactoryBean(jobLauncher,
|
||||
jobExplorer, jobs, this.properties, jobRegistry, jobRepository, batchProperties);
|
||||
|
||||
return taskJobLauncherApplicationRunnerFactoryBean;
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunner {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(TaskJobLauncherApplicationRunner.class);
|
||||
private static final Log logger = LogFactory.getLog(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
private JobLauncher taskJobLauncher;
|
||||
|
||||
@@ -93,9 +92,8 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
* @param taskBatchProperties the properties used to configure the
|
||||
* taskBatchProperties.
|
||||
*/
|
||||
public TaskJobLauncherApplicationRunner(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, JobRepository jobRepository,
|
||||
TaskBatchProperties taskBatchProperties) {
|
||||
public TaskJobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository, TaskBatchProperties taskBatchProperties) {
|
||||
super(jobLauncher, jobExplorer, jobRepository);
|
||||
this.taskJobLauncher = jobLauncher;
|
||||
this.taskJobExplorer = jobExplorer;
|
||||
@@ -115,18 +113,14 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
monitorJobExecutions();
|
||||
}
|
||||
|
||||
protected void execute(Job job, JobParameters jobParameters)
|
||||
throws JobExecutionAlreadyRunningException, JobRestartException,
|
||||
JobInstanceAlreadyCompleteException, JobParametersInvalidException {
|
||||
protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
|
||||
JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
|
||||
String jobName = job.getName();
|
||||
JobParameters parameters = jobParameters;
|
||||
boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName,
|
||||
parameters);
|
||||
boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName, parameters);
|
||||
if (jobInstanceExists) {
|
||||
JobExecution lastJobExecution = this.taskJobRepository
|
||||
.getLastJobExecution(jobName, jobParameters);
|
||||
if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution)
|
||||
&& job.isRestartable()) {
|
||||
JobExecution lastJobExecution = this.taskJobRepository.getLastJobExecution(jobName, jobParameters);
|
||||
if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution) && job.isRestartable()) {
|
||||
// Retry a failed or stopped execution with previous parameters
|
||||
JobParameters previousParameters = lastJobExecution.getJobParameters();
|
||||
/*
|
||||
@@ -135,8 +129,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
* they are required (or need to be modified) on a restart, they need to
|
||||
* be (re)specified.
|
||||
*/
|
||||
JobParameters previousIdentifyingParameters = removeNonIdentifying(
|
||||
previousParameters);
|
||||
JobParameters previousIdentifyingParameters = removeNonIdentifying(previousParameters);
|
||||
// merge additional parameters with previous ones (overriding those with
|
||||
// the same key)
|
||||
parameters = merge(previousIdentifyingParameters, jobParameters);
|
||||
@@ -145,15 +138,14 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
else {
|
||||
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
|
||||
if (incrementer != null) {
|
||||
JobParameters nextParameters = new JobParametersBuilder(jobParameters,
|
||||
this.taskJobExplorer).getNextJobParameters(job).toJobParameters();
|
||||
JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.taskJobExplorer)
|
||||
.getNextJobParameters(job).toJobParameters();
|
||||
parameters = merge(nextParameters, jobParameters);
|
||||
}
|
||||
}
|
||||
JobExecution execution = this.taskJobLauncher.run(job, parameters);
|
||||
if (this.taskApplicationEventPublisher != null) {
|
||||
this.taskApplicationEventPublisher
|
||||
.publishEvent(new JobExecutionEvent(execution));
|
||||
this.taskApplicationEventPublisher.publishEvent(new JobExecutionEvent(execution));
|
||||
}
|
||||
this.jobExecutionList.add(execution);
|
||||
if (execution.getStatus().equals(BatchStatus.FAILED)) {
|
||||
@@ -171,8 +163,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
List<JobExecution> failedJobExecutions = new ArrayList<>();
|
||||
RepeatStatus repeatStatus = RepeatStatus.FINISHED;
|
||||
for (JobExecution jobExecution : this.jobExecutionList) {
|
||||
JobExecution currentJobExecution = this.taskJobExplorer
|
||||
.getJobExecution(jobExecution.getId());
|
||||
JobExecution currentJobExecution = this.taskJobExplorer.getJobExecution(jobExecution.getId());
|
||||
BatchStatus batchStatus = currentJobExecution.getStatus();
|
||||
if (batchStatus.isRunning()) {
|
||||
repeatStatus = RepeatStatus.CONTINUABLE;
|
||||
@@ -183,8 +174,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
}
|
||||
Thread.sleep(this.taskBatchProperties.getFailOnJobFailurePollInterval());
|
||||
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED)
|
||||
&& failedJobExecutions.size() > 0) {
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED) && failedJobExecutions.size() > 0) {
|
||||
throwJobFailedException(failedJobExecutions);
|
||||
}
|
||||
return repeatStatus;
|
||||
@@ -194,10 +184,10 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
private void throwJobFailedException(List<JobExecution> failedJobExecutions) {
|
||||
StringBuilder message = new StringBuilder("The following Jobs have failed: \n");
|
||||
for (JobExecution failedJobExecution : failedJobExecutions) {
|
||||
message.append(String.format("Job %s failed during "
|
||||
+ "execution for job instance id %s with jobExecutionId of %s \n",
|
||||
failedJobExecution.getJobInstance().getJobName(),
|
||||
failedJobExecution.getJobId(), failedJobExecution.getId()));
|
||||
message.append(String.format(
|
||||
"Job %s failed during " + "execution for job instance id %s with jobExecutionId of %s \n",
|
||||
failedJobExecution.getJobInstance().getJobName(), failedJobExecution.getJobId(),
|
||||
failedJobExecution.getId()));
|
||||
}
|
||||
|
||||
logger.error(message);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class TaskBatchExecutionListener implements JobExecutionListener, Ordered {
|
||||
public class TaskBatchExecutionListener implements JobExecutionListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TaskBatchExecutionListener.class);
|
||||
|
||||
@@ -57,12 +57,10 @@ public class TaskBatchExecutionListener implements JobExecutionListener, Ordere
|
||||
@Override
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
if (this.taskExecution == null) {
|
||||
logger.warn(
|
||||
"This job was executed outside the scope of a task but still used the task listener.");
|
||||
logger.warn("This job was executed outside the scope of a task but still used the task listener.");
|
||||
}
|
||||
else {
|
||||
logger.info(String.format(
|
||||
"The job execution id %s was run within the task execution %s",
|
||||
logger.info(String.format("The job execution id %s was run within the task execution %s",
|
||||
jobExecution.getId(), this.taskExecution.getExecutionId()));
|
||||
this.taskBatchDao.saveRelationship(this.taskExecution, jobExecution);
|
||||
}
|
||||
@@ -72,4 +70,5 @@ public class TaskBatchExecutionListener implements JobExecutionListener, Ordere
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ public class JdbcTaskBatchDao implements TaskBatchDao {
|
||||
public void saveRelationship(TaskExecution taskExecution, JobExecution jobExecution) {
|
||||
Assert.notNull(taskExecution, "A taskExecution is required");
|
||||
Assert.notNull(jobExecution, "A jobExecution is required");
|
||||
this.jdbcTemplate.update(getQuery(INSERT_STATEMENT),
|
||||
taskExecution.getExecutionId(), jobExecution.getId());
|
||||
this.jdbcTemplate.update(getQuery(INSERT_STATEMENT), taskExecution.getExecutionId(), jobExecution.getId());
|
||||
}
|
||||
|
||||
private String getQuery(String base) {
|
||||
|
||||
@@ -48,8 +48,7 @@ public class MapTaskBatchDao implements TaskBatchDao {
|
||||
Assert.notNull(jobExecution, "A jobExecution is required");
|
||||
|
||||
if (this.relationships.containsKey(taskExecution.getExecutionId())) {
|
||||
this.relationships.get(taskExecution.getExecutionId())
|
||||
.add(jobExecution.getId());
|
||||
this.relationships.get(taskExecution.getExecutionId()).add(jobExecution.getId());
|
||||
}
|
||||
else {
|
||||
TreeSet<Long> jobExecutionIds = new TreeSet<>();
|
||||
|
||||
@@ -74,8 +74,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Michael Minella
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class DeployerPartitionHandler
|
||||
implements PartitionHandler, EnvironmentAware, InitializingBean {
|
||||
public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAware, InitializingBean {
|
||||
|
||||
/**
|
||||
* ID of Spring Cloud Task job execution.
|
||||
@@ -145,21 +144,23 @@ public class DeployerPartitionHandler
|
||||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskRepository taskRepository;
|
||||
|
||||
/**
|
||||
* Constructor initializing the DeployerPartitionHandler instance.
|
||||
* @param taskLauncher The {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute partitioned tasks.
|
||||
* @param taskLauncher The
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute
|
||||
* partitioned tasks.
|
||||
* @param jobExplorer The {@link JobExplorer} to acquire the status of the job.
|
||||
* @param resource The {@link Resource} to the app to be launched.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecutor If task launches should occur asynchronously then provide a {@link ThreadPoolTaskExecutor}. Default is null.
|
||||
* @param taskExecutor If task launches should occur asynchronously then provide a
|
||||
* {@link ThreadPoolTaskExecutor}. Default is null.
|
||||
*/
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, TaskRepository taskRepository,
|
||||
TaskExecutor taskExecutor) {
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName, TaskRepository taskRepository,
|
||||
TaskExecutor taskExecutor) {
|
||||
Assert.notNull(taskLauncher, "A taskLauncher is required");
|
||||
Assert.notNull(jobExplorer, "A jobExplorer is required");
|
||||
Assert.notNull(resource, "A resource is required");
|
||||
@@ -176,13 +177,15 @@ public class DeployerPartitionHandler
|
||||
|
||||
/**
|
||||
* Constructor initializing the DeployerPartitionHandler instance.
|
||||
* @param taskLauncher The {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute partitioned tasks.
|
||||
* @param taskLauncher The
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute
|
||||
* partitioned tasks.
|
||||
* @param jobExplorer The {@link JobExplorer} to acquire the status of the job.
|
||||
* @param resource The {@link Resource} to the app to be launched.
|
||||
* @param stepName The name of the step.
|
||||
*/
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, TaskRepository taskRepository) {
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName, TaskRepository taskRepository) {
|
||||
this(taskLauncher, jobExplorer, resource, stepName, taskRepository, new SyncTaskExecutor());
|
||||
}
|
||||
|
||||
@@ -190,8 +193,7 @@ public class DeployerPartitionHandler
|
||||
* Used to provide any environment variables to be set on each worker launched.
|
||||
* @param environmentVariablesProvider an {@link EnvironmentVariablesProvider}
|
||||
*/
|
||||
public void setEnvironmentVariablesProvider(
|
||||
EnvironmentVariablesProvider environmentVariablesProvider) {
|
||||
public void setEnvironmentVariablesProvider(EnvironmentVariablesProvider environmentVariablesProvider) {
|
||||
this.environmentVariablesProvider = environmentVariablesProvider;
|
||||
}
|
||||
|
||||
@@ -208,8 +210,7 @@ public class DeployerPartitionHandler
|
||||
* Used to provide any command line arguements to be passed to each worker launched.
|
||||
* @param commandLineArgsProvider {@link CommandLineArgsProvider}
|
||||
*/
|
||||
public void setCommandLineArgsProvider(
|
||||
CommandLineArgsProvider commandLineArgsProvider) {
|
||||
public void setCommandLineArgsProvider(CommandLineArgsProvider commandLineArgsProvider) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
}
|
||||
|
||||
@@ -250,8 +251,10 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of deployment properties to be used by the {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}.
|
||||
* @param deploymentProperties properties to be used by the {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}
|
||||
* Map of deployment properties to be used by the
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}.
|
||||
* @param deploymentProperties properties to be used by the
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}
|
||||
*/
|
||||
public void setDeploymentProperties(Map<String, String> deploymentProperties) {
|
||||
this.deploymentProperties = deploymentProperties;
|
||||
@@ -271,19 +274,17 @@ public class DeployerPartitionHandler
|
||||
this.taskExecution = taskExecution;
|
||||
|
||||
if (this.commandLineArgsProvider == null) {
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
this.commandLineArgsProvider = provider;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter,
|
||||
StepExecution stepExecution) throws Exception {
|
||||
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution)
|
||||
throws Exception {
|
||||
|
||||
final Set<StepExecution> tempCandidates = stepSplitter.split(stepExecution,
|
||||
this.gridSize);
|
||||
final Set<StepExecution> tempCandidates = stepSplitter.split(stepExecution, this.gridSize);
|
||||
|
||||
// Following two lines due to https://jira.spring.io/browse/BATCH-2490
|
||||
final Set<StepExecution> candidates = new HashSet<>(tempCandidates.size());
|
||||
@@ -306,23 +307,18 @@ public class DeployerPartitionHandler
|
||||
return pollReplies(stepExecution, executed, candidates, partitions);
|
||||
}
|
||||
|
||||
private void launchWorkers(Set<StepExecution> candidates,
|
||||
Set<StepExecution> executed) {
|
||||
private void launchWorkers(Set<StepExecution> candidates, Set<StepExecution> executed) {
|
||||
TaskLauncherHandler taskLauncherHandler = new TaskLauncherHandler(this.commandLineArgsProvider,
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars,
|
||||
this.stepName, this.taskExecution, this.environmentVariablesProvider,
|
||||
this.resource, this.deploymentProperties,
|
||||
this.taskLauncher,
|
||||
this.applicationName);
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars, this.stepName, this.taskExecution,
|
||||
this.environmentVariablesProvider, this.resource, this.deploymentProperties, this.taskLauncher,
|
||||
this.applicationName);
|
||||
for (StepExecution execution : candidates) {
|
||||
if (this.currentWorkers < this.maxWorkers || this.maxWorkers < 0) {
|
||||
if (this.taskExecutor != null) {
|
||||
TaskLauncherHandler taskLauncherThread = new TaskLauncherHandler(this.commandLineArgsProvider,
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars,
|
||||
this.stepName, this.taskExecution, this.environmentVariablesProvider,
|
||||
this.resource, this.deploymentProperties,
|
||||
this.taskLauncher,
|
||||
this.applicationName, execution);
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars, this.stepName, this.taskExecution,
|
||||
this.environmentVariablesProvider, this.resource, this.deploymentProperties,
|
||||
this.taskLauncher, this.applicationName, execution);
|
||||
this.taskExecutor.execute(taskLauncherThread);
|
||||
}
|
||||
else {
|
||||
@@ -335,8 +331,7 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
private Collection<StepExecution> pollReplies(final StepExecution masterStepExecution,
|
||||
final Set<StepExecution> executed, final Set<StepExecution> candidates,
|
||||
final int size) throws Exception {
|
||||
final Set<StepExecution> executed, final Set<StepExecution> candidates, final int size) throws Exception {
|
||||
|
||||
final Collection<StepExecution> result = new ArrayList<>(executed.size());
|
||||
|
||||
@@ -348,8 +343,7 @@ public class DeployerPartitionHandler
|
||||
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)) {
|
||||
@@ -388,8 +382,7 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
private boolean isComplete(BatchStatus status) {
|
||||
return status.equals(BatchStatus.COMPLETED)
|
||||
|| status.isGreaterThan(BatchStatus.STARTED);
|
||||
return status.equals(BatchStatus.COMPLETED) || status.isGreaterThan(BatchStatus.STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -400,9 +393,9 @@ public class DeployerPartitionHandler
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.environmentVariablesProvider == null) {
|
||||
this.environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
|
||||
this.environment);
|
||||
this.environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(this.environment);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
|
||||
private StepLocator stepLocator;
|
||||
|
||||
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository) {
|
||||
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer, JobRepository jobRepository) {
|
||||
Assert.notNull(beanFactory, "A beanFactory is required");
|
||||
Assert.notNull(jobExplorer, "A jobExplorer is required");
|
||||
Assert.notNull(jobRepository, "A jobRepository is required");
|
||||
@@ -88,26 +87,23 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
|
||||
validateRequest();
|
||||
|
||||
Long jobExecutionId = Long.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));
|
||||
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId,
|
||||
stepExecutionId);
|
||||
Long jobExecutionId = Long
|
||||
.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));
|
||||
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
|
||||
|
||||
if (stepExecution == null) {
|
||||
throw new NoSuchStepException(String.format(
|
||||
"No StepExecution could be located for step execution id %s within job execution %s",
|
||||
stepExecutionId, jobExecutionId));
|
||||
throw new NoSuchStepException(
|
||||
String.format("No StepExecution could be located for step execution id %s within job execution %s",
|
||||
stepExecutionId, jobExecutionId));
|
||||
}
|
||||
|
||||
String stepName = this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
|
||||
String stepName = this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
|
||||
Step step = this.stepLocator.getStep(stepName);
|
||||
|
||||
try {
|
||||
this.logger.debug(String.format(
|
||||
"Executing step %s with step execution id %s and job execution id %s",
|
||||
this.logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s",
|
||||
stepExecution.getStepName(), stepExecutionId, jobExecutionId));
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -124,23 +120,16 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
}
|
||||
|
||||
private void validateRequest() {
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID),
|
||||
"A job execution id is required");
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID),
|
||||
"A step execution id is required");
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME),
|
||||
"A step name is required");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class NoOpEnvironmentVariablesProvider implements EnvironmentVariablesPro
|
||||
* @return an empty {@link Map}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getEnvironmentVariables(
|
||||
ExecutionContext executionContext) {
|
||||
public Map<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,11 +71,9 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getEnvironmentVariables(
|
||||
ExecutionContext executionContext) {
|
||||
public Map<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
|
||||
|
||||
Map<String, String> environmentProperties = new HashMap<>(
|
||||
this.environmentProperties.size());
|
||||
Map<String, String> environmentProperties = new HashMap<>(this.environmentProperties.size());
|
||||
|
||||
if (this.includeCurrentEnvironment) {
|
||||
environmentProperties.putAll(getCurrentEnvironmentProperties());
|
||||
@@ -91,11 +89,9 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
|
||||
for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment)
|
||||
.getPropertySources()) {
|
||||
for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment).getPropertySources()) {
|
||||
if (propertySource instanceof MapPropertySource) {
|
||||
keys.addAll(Arrays
|
||||
.asList(((MapPropertySource) propertySource).getPropertyNames()));
|
||||
keys.addAll(Arrays.asList(((MapPropertySource) propertySource).getPropertyNames()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,26 +64,32 @@ public class TaskLauncherHandler implements Runnable {
|
||||
private Log logger = LogFactory.getLog(TaskLauncherHandler.class);
|
||||
|
||||
/**
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides command line
|
||||
* arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are used
|
||||
* internally by Spring Cloud Task and Spring Batch are passed as environment variables instead of command line arguments.
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides
|
||||
* command line arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the
|
||||
* partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are
|
||||
* used internally by Spring Cloud Task and Spring Batch are passed as environment
|
||||
* variables instead of command line arguments.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecution The {@link TaskExecution} to be associated with the partition.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that provides the environmennt variables.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that
|
||||
* provides the environmennt variables.
|
||||
* @param resource The {@link Resource} to be launched.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties for the partition.
|
||||
* @param taskLauncher {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to launch the partition.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties
|
||||
* for the partition.
|
||||
* @param taskLauncher
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to
|
||||
* launch the partition.
|
||||
* @param applicationName The name to be associated with task.
|
||||
* @param workerStepExecution The {@link StepExecution} for the paritition.
|
||||
*/
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider,
|
||||
TaskRepository taskRepository, boolean defaultArgsAsEnvironmentVars,
|
||||
String stepName, TaskExecution taskExecution, EnvironmentVariablesProvider
|
||||
environmentVariablesProvider, Resource resource, Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
String applicationName, StepExecution workerStepExecution) {
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider, TaskRepository taskRepository,
|
||||
boolean defaultArgsAsEnvironmentVars, String stepName, TaskExecution taskExecution,
|
||||
EnvironmentVariablesProvider environmentVariablesProvider, Resource resource,
|
||||
Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, String applicationName,
|
||||
StepExecution workerStepExecution) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
this.taskRepository = taskRepository;
|
||||
this.defaultArgsAsEnvironmentVars = defaultArgsAsEnvironmentVars;
|
||||
@@ -98,25 +104,30 @@ public class TaskLauncherHandler implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides command line
|
||||
* arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are used
|
||||
* internally by Spring Cloud Task and Spring Batch are passed as environment variables instead of command line arguments.
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides
|
||||
* command line arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the
|
||||
* partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are
|
||||
* used internally by Spring Cloud Task and Spring Batch are passed as environment
|
||||
* variables instead of command line arguments.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecution The {@link TaskExecution} to be associated with the partition.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that provides the environmennt variables.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that
|
||||
* provides the environmennt variables.
|
||||
* @param resource The {@link Resource} to be launched.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties for the partition.
|
||||
* @param taskLauncher {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to launch the partition.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties
|
||||
* for the partition.
|
||||
* @param taskLauncher
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to
|
||||
* launch the partition.
|
||||
* @param applicationName The name to be associated with task.
|
||||
*/
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider,
|
||||
TaskRepository taskRepository, boolean defaultArgsAsEnvironmentVars,
|
||||
String stepName, TaskExecution taskExecution, EnvironmentVariablesProvider
|
||||
environmentVariablesProvider, Resource resource, Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
String applicationName) {
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider, TaskRepository taskRepository,
|
||||
boolean defaultArgsAsEnvironmentVars, String stepName, TaskExecution taskExecution,
|
||||
EnvironmentVariablesProvider environmentVariablesProvider, Resource resource,
|
||||
Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, String applicationName) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
this.taskRepository = taskRepository;
|
||||
this.defaultArgsAsEnvironmentVars = defaultArgsAsEnvironmentVars;
|
||||
@@ -134,7 +145,6 @@ public class TaskLauncherHandler implements Runnable {
|
||||
launchWorker(this.workerStepExecution);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launches the partition for the StepExecution.
|
||||
* @param workerStepExecution The {@link StepExecution}
|
||||
@@ -142,8 +152,7 @@ public class TaskLauncherHandler implements Runnable {
|
||||
public void launchWorker(StepExecution workerStepExecution) {
|
||||
List<String> arguments = new ArrayList<>();
|
||||
|
||||
ExecutionContext copyContext = new ExecutionContext(
|
||||
workerStepExecution.getExecutionContext());
|
||||
ExecutionContext copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
|
||||
|
||||
arguments.addAll(this.commandLineArgsProvider.getCommandLineArgs(copyContext));
|
||||
|
||||
@@ -153,69 +162,61 @@ public class TaskLauncherHandler implements Runnable {
|
||||
partitionTaskExecution = this.taskRepository.createTaskExecution();
|
||||
}
|
||||
else {
|
||||
logger.warn(
|
||||
"TaskRepository was not set so external execution id will not be recorded.");
|
||||
logger.warn("TaskRepository was not set so external execution id will not be recorded.");
|
||||
}
|
||||
|
||||
if (!this.defaultArgsAsEnvironmentVars) {
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId())));
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getId())));
|
||||
String.valueOf(workerStepExecution.getId())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, this.stepName));
|
||||
arguments
|
||||
.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
String.format("%s_%s_%s", this.taskExecution.getTaskName(),
|
||||
workerStepExecution.getJobExecution().getJobInstance()
|
||||
.getJobName(),
|
||||
workerStepExecution.getStepName())));
|
||||
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
|
||||
workerStepExecution.getStepName())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
|
||||
String.valueOf(this.taskExecution.getExecutionId())));
|
||||
String.valueOf(this.taskExecution.getExecutionId())));
|
||||
|
||||
if (partitionTaskExecution != null) {
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID,
|
||||
String.valueOf(partitionTaskExecution.getExecutionId())));
|
||||
String.valueOf(partitionTaskExecution.getExecutionId())));
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId()));
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getId()));
|
||||
String.valueOf(workerStepExecution.getId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, this.stepName);
|
||||
environmentVariables
|
||||
.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
String.format("%s_%s_%s", this.taskExecution.getTaskName(),
|
||||
workerStepExecution.getJobExecution().getJobInstance()
|
||||
.getJobName(),
|
||||
workerStepExecution.getStepName()));
|
||||
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
|
||||
workerStepExecution.getStepName()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
|
||||
String.valueOf(this.taskExecution.getExecutionId()));
|
||||
String.valueOf(this.taskExecution.getExecutionId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID,
|
||||
String.valueOf(partitionTaskExecution.getExecutionId()));
|
||||
String.valueOf(partitionTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
AppDefinition definition = new AppDefinition(resolveApplicationName(),
|
||||
environmentVariables);
|
||||
AppDefinition definition = new AppDefinition(resolveApplicationName(), environmentVariables);
|
||||
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, this.resource,
|
||||
this.deploymentProperties, arguments);
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, this.resource, this.deploymentProperties,
|
||||
arguments);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Requesting the launch of the following application: " + request);
|
||||
logger.debug("Requesting the launch of the following application: " + request);
|
||||
}
|
||||
String externalExecutionId = this.taskLauncher.launch(request);
|
||||
|
||||
if (this.taskRepository != null) {
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
partitionTaskExecution.getExecutionId(), externalExecutionId);
|
||||
this.taskRepository.updateExternalExecutionId(partitionTaskExecution.getExecutionId(), externalExecutionId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,63 +37,48 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class TaskJobLauncherAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class,
|
||||
TaskJobLauncherAutoConfiguration.class))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
|
||||
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true")
|
||||
.run(context -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(TaskJobLauncherApplicationRunner.class);
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class)
|
||||
.getOrder()).isEqualTo(0);
|
||||
});
|
||||
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(TaskJobLauncherApplicationRunner.class);
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.commandLineRunnerOrder=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.commandLineRunnerOrder=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 -> {
|
||||
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 -> {
|
||||
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 {
|
||||
private void validateJobNames(AssertableApplicationContext context, String jobNames) throws Exception {
|
||||
JobLauncherApplicationRunner jobLauncherApplicationRunner = context
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner,
|
||||
"jobName");
|
||||
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner, "jobName");
|
||||
assertThat(names).isEqualTo(jobNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { TaskJobLauncherApplicationRunnerCoreTests.BatchConfiguration.class })
|
||||
@ContextConfiguration(classes = { TaskJobLauncherApplicationRunnerCoreTests.BatchConfiguration.class })
|
||||
public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
|
||||
@Autowired
|
||||
@@ -103,8 +102,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
Tasklet tasklet = (contribution, chunkContext) -> RepeatStatus.FINISHED;
|
||||
this.step = this.steps.get("step").tasklet(tasklet).build();
|
||||
this.job = this.jobs.get("job").start(this.step).build();
|
||||
this.runner = new TaskJobLauncherApplicationRunner(this.jobLauncher,
|
||||
this.jobExplorer, this.jobRepository, new TaskBatchProperties());
|
||||
this.runner = new TaskJobLauncherApplicationRunner(this.jobLauncher, this.jobExplorer, this.jobRepository,
|
||||
new TaskBatchProperties());
|
||||
|
||||
}
|
||||
|
||||
@@ -113,26 +112,23 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
public void basicExecution() throws Exception {
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
this.runner.execute(this.job,
|
||||
new JobParametersBuilder().addLong("id", 1L).toJobParameters());
|
||||
this.runner.execute(this.job, new JobParametersBuilder().addLong("id", 1L).toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
// @Test
|
||||
// @Test
|
||||
public void incrementExistingExecution() throws Exception {
|
||||
this.job = this.jobs.get("job").start(this.step)
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
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);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
// @Test
|
||||
// @Test
|
||||
public void retryFailedExecution() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
runFailedJob(new JobParameters());
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
@@ -142,16 +138,13 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void runDifferentInstances() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build()).build();
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build()).build();
|
||||
// start a job instance
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo")
|
||||
.toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
// start a different job instance
|
||||
JobParameters otherJobParameters = new JobParametersBuilder()
|
||||
.addString("name", "bar").toJobParameters();
|
||||
JobParameters otherJobParameters = new JobParametersBuilder().addString("name", "bar").toJobParameters();
|
||||
runFailedJob(otherJobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
}
|
||||
@@ -160,8 +153,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
@Test
|
||||
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
|
||||
this.job = this.jobs.get("job").preventRestart()
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build()).incrementer(new RunIdIncrementer())
|
||||
.build();
|
||||
runFailedJob(new JobParameters());
|
||||
runFailedJob(new JobParameters());
|
||||
// A failed job that is not restartable does not re-use the job params of
|
||||
@@ -171,40 +164,35 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
// try to re-run a failed execution
|
||||
Executable executable = () -> this.runner.execute(this.job,
|
||||
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
assertThatExceptionOfType(JobRestartException.class)
|
||||
.isThrownBy(executable::execute)
|
||||
assertThatExceptionOfType(JobRestartException.class).isThrownBy(executable::execute)
|
||||
.withMessage("JobInstance already exists and is not restartable");
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false).toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
runFailedJob(new JobParametersBuilder(jobParameters).addLong("run.id", 1L)
|
||||
.toJobParameters());
|
||||
runFailedJob(new JobParametersBuilder(jobParameters).addLong("run.id", 1L).toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution()
|
||||
throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution() throws Exception {
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false).toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
// try to re-run a failed execution with non identifying parameters
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L)
|
||||
.addLong("id", 2L, false).addLong("foo", 3L, false).toJobParameters());
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L).addLong("id", 2L, false).addLong("foo", 3L, false)
|
||||
.toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
JobInstance jobInstance = jobExplorer.getLastJobInstance("job");
|
||||
|
||||
@@ -212,7 +200,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
|
||||
assertThat(executions).hasSize(2);
|
||||
|
||||
JobExecution firstJobExecution = executions.get(0);
|
||||
JobExecution firstJobExecution = executions.get(0);
|
||||
JobExecution secondJobExecution = executions.get(1);
|
||||
if ((executions.get(0).getId() > executions.get(1).getId())) {
|
||||
firstJobExecution = executions.get(1);
|
||||
@@ -261,7 +249,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource;
|
||||
|
||||
public BatchConfiguration() throws Exception {
|
||||
}
|
||||
@@ -317,7 +305,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-h2.sql"));
|
||||
dataSourceInitializer.setDatabaseCleaner(databasePopulator);
|
||||
return dataSourceInitializer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,8 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFail() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class,
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE, TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class,
|
||||
enabledArgs);
|
||||
}
|
||||
|
||||
@@ -97,45 +95,37 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
*/
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFailWithAnnotation() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureAnnotatedConfiguration.class,
|
||||
enabledArgs);
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureAnnotatedConfiguration.class, enabledArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFailWithTaskExecutor() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
"--spring.cloud.task.batch.failOnJobFailurePollInterval=500" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureTaskExecutorConfiguration.class,
|
||||
enabledArgs);
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureTaskExecutorConfiguration.class, enabledArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
|
||||
assertThat(jobExplorer.getJobNames().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherPickOneJob() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"--spring.cloud.task.batch.jobNames=jobSucceed" };
|
||||
boolean isExceptionThrown = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(new Class[] {
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class },
|
||||
this.applicationContext = SpringApplication.run(
|
||||
new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class },
|
||||
enabledArgs);
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
@@ -148,19 +138,15 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
public void testApplicationRunnerSetToFalse() {
|
||||
String[] enabledArgs = new String[] {};
|
||||
this.applicationContext = SpringApplication.run(
|
||||
new Class[] {
|
||||
TaskJobLauncherApplicationRunnerTests.JobConfiguration.class },
|
||||
enabledArgs);
|
||||
this.applicationContext = SpringApplication
|
||||
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
|
||||
validateContext();
|
||||
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class))
|
||||
.isNotNull();
|
||||
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class)).isNotNull();
|
||||
|
||||
Executable executable = () -> this.applicationContext
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
Executable executable = () -> this.applicationContext.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(executable::execute).withMessage("No qualifying bean of type "
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(executable::execute)
|
||||
.withMessage("No qualifying bean of type "
|
||||
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
|
||||
validateContext();
|
||||
}
|
||||
@@ -168,24 +154,21 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
private void validateContext() {
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private void validateForFail(String errorMessage, Class clazz, String[] enabledArgs) {
|
||||
Executable executable = () -> this.applicationContext = SpringApplication.run(
|
||||
new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class },
|
||||
enabledArgs);
|
||||
Executable executable = () -> this.applicationContext = SpringApplication
|
||||
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(executable::execute).has(new Condition<Throwable>() {
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute)
|
||||
.has(new Condition<Throwable>() {
|
||||
@Override
|
||||
public boolean matches(Throwable value) {
|
||||
return errorMessage.equals(value.getCause().getMessage());
|
||||
@@ -207,23 +190,20 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
return this.jobBuilderFactory.get("job").start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableBatchProcessing
|
||||
@ImportAutoConfiguration({ PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, TaskBatchAutoConfiguration.class,
|
||||
TaskJobLauncherAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
@ImportAutoConfiguration({ PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
TaskBatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class })
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
@EnableTask
|
||||
@@ -237,24 +217,21 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Bean
|
||||
public Job jobFail() {
|
||||
return this.jobBuilderFactory.get("jobA")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}
|
||||
}).build()).build();
|
||||
return this.jobBuilderFactory.get("jobA").start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job jobFun() {
|
||||
return this.jobBuilderFactory.get("jobSucceed").start(
|
||||
this.stepBuilderFactory.get("step1Succeed").tasklet(new Tasklet() {
|
||||
return this.jobBuilderFactory.get("jobSucceed")
|
||||
.start(this.stepBuilderFactory.get("step1Succeed").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) {
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
@@ -264,8 +241,7 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
public static class JobWithFailureAnnotatedConfiguration
|
||||
extends JobWithFailureConfiguration {
|
||||
public static class JobWithFailureAnnotatedConfiguration extends JobWithFailureConfiguration {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ public class PrefixTests {
|
||||
|
||||
@Test
|
||||
public void testPrefix() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
"--spring.cloud.task.tablePrefix=FOO_");
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class, "--spring.cloud.task.tablePrefix=FOO_");
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
@@ -74,8 +73,8 @@ public class PrefixTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
return jobBuilderFactory.get("job").start(stepBuilderFactory
|
||||
.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
return jobBuilderFactory.get("job")
|
||||
.start(stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
@@ -83,8 +82,8 @@ public class PrefixTests {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,23 +133,20 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
public void testFactoryBean() {
|
||||
this.applicationContext = SpringApplication.run(JobFactoryBeanConfiguration.class,
|
||||
ARGS);
|
||||
this.applicationContext = SpringApplication.run(JobFactoryBeanConfiguration.class, ARGS);
|
||||
validateContext();
|
||||
}
|
||||
|
||||
private void validateContext() {
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@@ -158,27 +155,24 @@ 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
|
||||
public void testMultipleDataSources() {
|
||||
this.applicationContext = SpringApplication
|
||||
.run(JobConfigurationMultipleDataSources.class, ARGS);
|
||||
this.applicationContext = SpringApplication.run(JobConfigurationMultipleDataSources.class, ARGS);
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,11 +181,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(0);
|
||||
}
|
||||
@@ -202,36 +195,30 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat((long) taskExplorer
|
||||
.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
|
||||
.isEqualTo(1);
|
||||
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJobs() {
|
||||
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class,
|
||||
"--spring.batch.job.name=job1");
|
||||
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class, "--spring.batch.job.name=job1");
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
|
||||
assertThat((long) taskExplorer
|
||||
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
|
||||
.isEqualTo(1);
|
||||
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next())).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@@ -242,23 +229,19 @@ public class TaskBatchExecutionListenerTests {
|
||||
jobNames.add("job2");
|
||||
jobNames.add("TESTOBJECT");
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(
|
||||
jobNames);
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(jobNames);
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor
|
||||
.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
assertThat(bean).isEqualTo(testObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithEmptyJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(
|
||||
Collections.emptyList());
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(Collections.emptyList());
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor
|
||||
.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
assertThat(bean).isEqualTo(testObject);
|
||||
}
|
||||
|
||||
@@ -269,12 +252,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
});
|
||||
}
|
||||
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
|
||||
List<String> jobNames) {
|
||||
this.applicationContext = SpringApplication.run(new Class[] {
|
||||
JobConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class,
|
||||
TaskBatchAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(List<String> jobNames) {
|
||||
this.applicationContext = SpringApplication.run(new Class[] { JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
BatchAutoConfiguration.class, TaskBatchAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class }, ARGS);
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = this.applicationContext
|
||||
@@ -329,10 +310,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -355,8 +336,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Override
|
||||
public Job getObject() {
|
||||
return JobFactoryBeanConfiguration.this.jobBuilderFactory.get("job")
|
||||
.start(JobFactoryBeanConfiguration.this.stepBuilderFactory
|
||||
.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
.start(JobFactoryBeanConfiguration.this.stepBuilderFactory.get("step1")
|
||||
.tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build())
|
||||
@@ -383,32 +364,29 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
public static class JobConfigurationMultipleDataSources {
|
||||
|
||||
|
||||
@Bean
|
||||
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
return jobBuilderFactory.get("job")
|
||||
.start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
return jobBuilderFactory.get("job").start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource myDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2).setName("myDataSource");
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("myDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource incorrectDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2).setName("incorrectDataSource");
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("incorrectDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -438,8 +416,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Bean
|
||||
public Job job1() {
|
||||
return this.jobBuilderFactory.get("job1").start(
|
||||
this.stepBuilderFactory.get("job1step1").tasklet((contribution, chunkContext) -> {
|
||||
return this.jobBuilderFactory.get("job1")
|
||||
.start(this.stepBuilderFactory.get("job1step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job1");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
@@ -447,8 +425,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Bean
|
||||
public Job job2() {
|
||||
return this.jobBuilderFactory.get("job2").start(
|
||||
this.stepBuilderFactory.get("job2step1").tasklet((contribution, chunkContext) -> {
|
||||
return this.jobBuilderFactory.get("job2")
|
||||
.start(this.stepBuilderFactory.get("job2step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job2");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
|
||||
@@ -91,49 +91,43 @@ public class DeployerPartitionHandlerTests {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
this.environment = new MockEnvironment();
|
||||
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(),
|
||||
new Date(), "", Collections.emptyList(), null, null, null);
|
||||
Mockito.lenient().when(taskRepository.createTaskExecution())
|
||||
.thenReturn(taskExecution);
|
||||
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(), new Date(), "",
|
||||
Collections.emptyList(), null, null, null);
|
||||
Mockito.lenient().when(taskRepository.createTaskExecution()).thenReturn(taskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedConstructorValidation() {
|
||||
validateDeprecatedConstructorValidation(null, null, null, null,
|
||||
"A taskLauncher is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, null, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, null,
|
||||
null, "A resource is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, null, "A step name is required");
|
||||
validateDeprecatedConstructorValidation(null, null, null, null, "A taskLauncher is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, null, null, null, "A jobExplorer is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, null, null,
|
||||
"A resource is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null,
|
||||
"A step name is required");
|
||||
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", this.taskRepository);
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step-name",
|
||||
this.taskRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorValidation() {
|
||||
validateConstructorValidation(null, null, null, null, null,
|
||||
"A taskLauncher is required");
|
||||
validateConstructorValidation(this.taskLauncher, null, null, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null,
|
||||
null, "A resource is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
null, null, "A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
null, null, "A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", null, "A TaskRepository is required");
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", this.taskRepository);
|
||||
validateConstructorValidation(null, null, null, null, null, "A taskLauncher is required");
|
||||
validateConstructorValidation(this.taskLauncher, null, null, null, null, "A jobExplorer is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null, null, "A resource is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null, null,
|
||||
"A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null, null,
|
||||
"A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, "step-name", null,
|
||||
"A TaskRepository is required");
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step-name",
|
||||
this.taskRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPartitions() throws Exception {
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
StepExecution stepExecution = new StepExecution("step1", new JobExecution(1L));
|
||||
@@ -153,11 +147,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
@@ -167,18 +161,15 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -188,16 +179,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, "4")))
|
||||
.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();
|
||||
.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();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -212,33 +201,30 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setDefaultArgsAsEnvironmentVars(true);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null, new ArrayList<>(), null,
|
||||
null);
|
||||
taskExecution.setTaskName("partitionedJobTask");
|
||||
|
||||
Set<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -250,23 +236,17 @@ 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");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.isEqualTo("4");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.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_STEP_NAME))
|
||||
.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");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
|
||||
.isEqualTo("2");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
|
||||
.isEqualTo("2");
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -281,15 +261,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null, new ArrayList<>(), null,
|
||||
null);
|
||||
|
||||
taskExecution.setTaskName("partitionedJobTask");
|
||||
|
||||
@@ -297,8 +277,7 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
@@ -306,13 +285,11 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,19 +313,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository, threadPoolTaskExecutor);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository, threadPoolTaskExecutor);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
@@ -362,24 +339,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
Thread.sleep(5000);
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -393,19 +364,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setMaxWorkers(2);
|
||||
|
||||
@@ -420,24 +391,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -451,19 +416,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.FAILED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.FAILED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setMaxWorkers(2);
|
||||
|
||||
@@ -478,24 +443,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -524,11 +483,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
|
||||
Map<String, String> environmentParameters = new HashMap<>(2);
|
||||
environmentParameters.put("foo", "bar");
|
||||
@@ -546,17 +505,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -568,14 +524,12 @@ 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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -593,11 +547,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
Map<String, String> environmentParameters = new HashMap<>(2);
|
||||
@@ -616,17 +570,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -634,20 +585,17 @@ public class DeployerPartitionHandlerTests {
|
||||
assertThat(request.getDefinition().getProperties().size()).isEqualTo(3);
|
||||
assertThat(request.getDefinition().getProperties().get("foo")).isEqualTo("bar");
|
||||
assertThat(request.getDefinition().getProperties().get("baz")).isEqualTo("qux");
|
||||
assertThat(request.getDefinition().getProperties().get("task"))
|
||||
.isEqualTo("batch");
|
||||
assertThat(request.getDefinition().getProperties().get("task")).isEqualTo("batch");
|
||||
|
||||
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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -662,15 +610,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setPollInterval(20000L);
|
||||
@@ -684,33 +632,26 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Date startTime = new Date();
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
Date endTime = new Date();
|
||||
verify(this.taskLauncher, times(2))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(2)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allRequests, 2);
|
||||
|
||||
validateStepExecutionResults(results);
|
||||
|
||||
assertThat(endTime.getTime() - startTime.getTime() >= 19999)
|
||||
.as("Time difference was too small: "
|
||||
+ (endTime.getTime() - startTime.getTime()))
|
||||
.isTrue();
|
||||
.as("Time difference was too small: " + (endTime.getTime() - startTime.getTime())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -720,15 +661,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setPollInterval(20000L);
|
||||
@@ -743,10 +684,8 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
@@ -764,15 +703,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setGridSize(2);
|
||||
@@ -785,23 +724,18 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 2)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(2))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(2)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allRequests, 2);
|
||||
|
||||
@@ -815,11 +749,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
Map<String, String> deploymentProperties = new HashMap<>(2);
|
||||
@@ -835,17 +769,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -857,14 +788,12 @@ 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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -876,18 +805,16 @@ public class DeployerPartitionHandlerTests {
|
||||
return String.format("--%s=%s", key, value);
|
||||
}
|
||||
|
||||
private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart,
|
||||
BatchStatus status) {
|
||||
StepExecution workerStepExecutionFinish = new StepExecution(
|
||||
stepExecutionStart.getStepName(), stepExecutionStart.getJobExecution());
|
||||
private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart, BatchStatus status) {
|
||||
StepExecution workerStepExecutionFinish = new StepExecution(stepExecutionStart.getStepName(),
|
||||
stepExecutionStart.getJobExecution());
|
||||
workerStepExecutionFinish.setId(stepExecutionStart.getId());
|
||||
workerStepExecutionFinish.setStatus(status);
|
||||
return workerStepExecutionFinish;
|
||||
}
|
||||
|
||||
private StepExecution getStepExecutionStart(JobExecution jobExecution, long id) {
|
||||
StepExecution workerStepExecutionStart = new StepExecution(
|
||||
"step1:partition" + (id - 3), jobExecution);
|
||||
StepExecution workerStepExecutionStart = new StepExecution("step1:partition" + (id - 3), jobExecution);
|
||||
workerStepExecutionStart.setId(id);
|
||||
return workerStepExecutionStart;
|
||||
}
|
||||
@@ -917,8 +844,7 @@ public class DeployerPartitionHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAppDeploymentRequests(List<AppDeploymentRequest> allRequests,
|
||||
int numberOfPartitions) {
|
||||
private void validateAppDeploymentRequests(List<AppDeploymentRequest> allRequests, int numberOfPartitions) {
|
||||
Collections.sort(allRequests, new Comparator<AppDeploymentRequest>() {
|
||||
@Override
|
||||
public int compare(AppDeploymentRequest o1, AppDeploymentRequest o2) {
|
||||
@@ -926,8 +852,7 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
String o1Command = "";
|
||||
for (String commandlineArgument : commandlineArguments) {
|
||||
if (commandlineArgument.contains(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
if (commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
o1Command = commandlineArgument;
|
||||
break;
|
||||
}
|
||||
@@ -937,8 +862,7 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
String o2Command = "";
|
||||
for (String commandlineArgument : commandlineArguments) {
|
||||
if (commandlineArgument.contains(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
if (commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
o2Command = commandlineArgument;
|
||||
break;
|
||||
}
|
||||
@@ -955,39 +879,32 @@ 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")))
|
||||
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();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.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();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDeprecatedConstructorValidation(TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName,
|
||||
String expectedMessage) {
|
||||
private void validateDeprecatedConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, String expectedMessage) {
|
||||
try {
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName,
|
||||
this.taskRepository);
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName, this.taskRepository);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(expectedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConstructorValidation(TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName,
|
||||
TaskRepository taskRepository, String expectedMessage) {
|
||||
private void validateConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource,
|
||||
String stepName, TaskRepository taskRepository, String expectedMessage) {
|
||||
try {
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName,
|
||||
taskRepository);
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName, taskRepository);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(expectedMessage);
|
||||
|
||||
@@ -71,8 +71,7 @@ public class DeployerStepExecutionHandlerTests {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
|
||||
this.handler = new DeployerStepExecutionHandler(this.beanFactory,
|
||||
this.jobExplorer, this.jobRepository);
|
||||
this.handler = new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer, this.jobRepository);
|
||||
|
||||
ReflectionTestUtils.setField(this.handler, "environment", this.environment);
|
||||
}
|
||||
@@ -80,113 +79,80 @@ public class DeployerStepExecutionHandlerTests {
|
||||
@Test
|
||||
public void testConstructorValidation() {
|
||||
validateConstructorValidation(null, null, null, "A beanFactory is required");
|
||||
validateConstructorValidation(this.beanFactory, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateConstructorValidation(this.beanFactory, this.jobExplorer, null,
|
||||
"A jobRepository is required");
|
||||
validateConstructorValidation(this.beanFactory, null, null, "A jobExplorer is required");
|
||||
validateConstructorValidation(this.beanFactory, this.jobExplorer, null, "A jobRepository is required");
|
||||
|
||||
new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer,
|
||||
this.jobRepository);
|
||||
new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer, this.jobRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationOfRequestValuesExist() throws Exception {
|
||||
validateEnvironmentConfiguration("A job execution id is required", new String[0]);
|
||||
validateEnvironmentConfiguration("A step execution id is required", new String[] {
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID });
|
||||
validateEnvironmentConfiguration("A step execution id is required",
|
||||
new String[] { DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID });
|
||||
validateEnvironmentConfiguration("A step name is required",
|
||||
new String[] {
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
new String[] { DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationOfRequestStepFound() throws Exception {
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class))
|
||||
.thenReturn(new String[] { "bar", "baz" });
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "bar", "baz" });
|
||||
|
||||
try {
|
||||
this.handler.run();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(
|
||||
"The step requested cannot be found in the provided BeanFactory");
|
||||
assertThat(iae.getMessage()).isEqualTo("The step requested cannot be found in the provided BeanFactory");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingStepExecution() throws Exception {
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class))
|
||||
.thenReturn(new String[] { "foo", "bar", "baz" });
|
||||
when(this.environment.getProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "foo", "bar", "baz" });
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
|
||||
|
||||
try {
|
||||
this.handler.run();
|
||||
}
|
||||
catch (NoSuchStepException nsse) {
|
||||
assertThat(nsse.getMessage()).isEqualTo(
|
||||
"No StepExecution could be located for step execution id 2 within job execution 1");
|
||||
assertThat(nsse.getMessage())
|
||||
.isEqualTo("No StepExecution could be located for step execution id 2 within job execution 1");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunSuccessful() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
|
||||
this.handler.run();
|
||||
@@ -197,74 +163,50 @@ public class DeployerStepExecutionHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testJobInterruptedException() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new JobInterruptedException("expected")).when(this.step)
|
||||
.execute(workerStep);
|
||||
doThrow(new JobInterruptedException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
this.handler.run();
|
||||
|
||||
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
|
||||
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus())
|
||||
.isEqualTo(BatchStatus.STOPPED);
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus()).isEqualTo(BatchStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuntimeException() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
@@ -272,12 +214,10 @@ public class DeployerStepExecutionHandlerTests {
|
||||
|
||||
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
|
||||
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus())
|
||||
.isEqualTo(BatchStatus.FAILED);
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus()).isEqualTo(BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
private void validateEnvironmentConfiguration(String errorMessage,
|
||||
String[] properties) throws Exception {
|
||||
private void validateEnvironmentConfiguration(String errorMessage, String[] properties) throws Exception {
|
||||
|
||||
for (String property : properties) {
|
||||
when(this.environment.containsProperty(property)).thenReturn(true);
|
||||
@@ -291,8 +231,8 @@ public class DeployerStepExecutionHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConstructorValidation(BeanFactory beanFactory,
|
||||
JobExplorer jobExplorer, JobRepository jobRepository, String message) {
|
||||
private void validateConstructorValidation(BeanFactory beanFactory, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository, String message) {
|
||||
try {
|
||||
new DeployerStepExecutionHandler(beanFactory, jobExplorer, jobRepository);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,11 @@ public class NoOpEnvironmentVariablesProviderTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Map<String, String> environmentVariables = this.provider
|
||||
.getEnvironmentVariables(null);
|
||||
Map<String, String> environmentVariables = this.provider.getEnvironmentVariables(null);
|
||||
assertThat(environmentVariables).isNotNull();
|
||||
assertThat(environmentVariables.isEmpty()).isTrue();
|
||||
|
||||
Map<String, String> environmentVariables2 = this.provider
|
||||
.getEnvironmentVariables(null);
|
||||
Map<String, String> environmentVariables2 = this.provider.getEnvironmentVariables(null);
|
||||
assertThat(environmentVariables == environmentVariables2).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
|
||||
@@ -56,8 +55,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
provider.setAppendedArgs(appendedValues);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
@@ -76,8 +74,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
provider.setAppendedArgs(null);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
|
||||
Reference in New Issue
Block a user