diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..0679d88a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,14 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+[*]
+indent_style = tab
+indent_size = 4
+end_of_line = lf
+insert_final_newline = true
+
+[*.yml]
+indent_style = space
+indent_size = 2
diff --git a/.settings.xml b/.settings.xml
index 8c8fdc70..d9004c57 100644
--- a/.settings.xml
+++ b/.settings.xml
@@ -1,7 +1,7 @@
spring
- true
+
+ true
+
spring-snapshots
diff --git a/.springformat b/.springformat
new file mode 100644
index 00000000..e69de29b
diff --git a/pom.xml b/pom.xml
index bdf5a886..a5df1e39 100755
--- a/pom.xml
+++ b/pom.xml
@@ -1,12 +1,14 @@
-
+
4.0.0
org.springframework.cloud
spring-cloud-build
- 2.1.1.RELEASE
-
+ 2.1.3.BUILD-SNAPSHOT
+
org.springframework.cloud
@@ -126,15 +128,24 @@
2.1.0.RELEASE
2.0.0.RELEASE
- 2.0.0.RELEASE
- 2.1.0.RELEASE
+ 2.0.0.RELEASE
+
+ 2.1.0.RELEASE
+
4.1.1.RELEASE
1.1
8.0
5.3.1
UTF-8
- ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
+ ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
+ true
+ true
+
+ true
+
@@ -211,7 +222,9 @@
- ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
+ ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
- ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
+ ${project.build.directory}/coverage-reports/jacoco-ut.exec
+
- ${project.reporting.outputDirectory}/jacoco-ut
+
+ ${project.reporting.outputDirectory}/jacoco-ut
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+
+
spring
diff --git a/spring-cloud-starter-task/pom.xml b/spring-cloud-starter-task/pom.xml
index 9a99b465..f7d29288 100644
--- a/spring-cloud-starter-task/pom.xml
+++ b/spring-cloud-starter-task/pom.xml
@@ -1,5 +1,7 @@
-
+
4.0.0
diff --git a/spring-cloud-task-batch/pom.xml b/spring-cloud-task-batch/pom.xml
index 5232f24e..b8c80ca2 100644
--- a/spring-cloud-task-batch/pom.xml
+++ b/spring-cloud-task-batch/pom.xml
@@ -1,5 +1,7 @@
-
+
4.0.0
@@ -12,7 +14,8 @@
spring-cloud-task-batch
jar
Spring Cloud Task Batch
- Module for use when combining Spring Cloud Task with Spring Batch
+ Module for use when combining Spring Cloud Task with Spring Batch
+
@@ -79,7 +82,7 @@
org.assertj
assertj-core
test
-
+
org.junit.jupiter
junit-jupiter-api
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchAutoConfiguration.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchAutoConfiguration.java
index 8167f30e..f2f672a5 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchAutoConfiguration.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.configuration;
import org.springframework.batch.core.Job;
@@ -38,8 +39,9 @@ import org.springframework.context.annotation.Configuration;
* @author Michael Minella
*/
@Configuration
-@ConditionalOnBean({Job.class})
-@ConditionalOnProperty(name = {"spring.cloud.task.batch.listener.enable", "spring.cloud.task.batch.listener.enabled"}, havingValue = "true", matchIfMissing = true)
+@ConditionalOnBean({ Job.class })
+@ConditionalOnProperty(name = { "spring.cloud.task.batch.listener.enable",
+ "spring.cloud.task.batch.listener.enabled" }, havingValue = "true", matchIfMissing = true)
public class TaskBatchAutoConfiguration {
@Bean
@@ -48,6 +50,9 @@ public class TaskBatchAutoConfiguration {
return new TaskBatchExecutionListenerBeanPostProcessor();
}
+ /**
+ * Auto configuration for Task Batch Execution Listener.
+ */
@Configuration
@ConditionalOnMissingBean(name = "taskBatchExecutionListener")
@EnableConfigurationProperties(TaskProperties.class)
@@ -60,20 +65,23 @@ 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()) {
+ if (!this.context.getBeansOfType(TaskConfigurer.class).isEmpty()) {
taskConfigurer = this.context.getBean(TaskConfigurer.class);
}
- if(taskConfigurer != null && taskConfigurer.getTaskDataSource() != null) {
+ if (taskConfigurer != null && taskConfigurer.getTaskDataSource() != null) {
return new TaskBatchExecutionListenerFactoryBean(
- taskConfigurer.getTaskDataSource(),
- taskExplorer, taskProperties.getTablePrefix());
+ taskConfigurer.getTaskDataSource(), taskExplorer,
+ this.taskProperties.getTablePrefix());
}
else {
- return new TaskBatchExecutionListenerFactoryBean(null,
- taskExplorer, taskProperties.getTablePrefix());
+ return new TaskBatchExecutionListenerFactoryBean(null, taskExplorer,
+ this.taskProperties.getTablePrefix());
}
}
+
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerBeanPostProcessor.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerBeanPostProcessor.java
index 556bd038..384b499c 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerBeanPostProcessor.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerBeanPostProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.configuration;
import java.util.ArrayList;
@@ -28,7 +29,7 @@ import org.springframework.util.Assert;
/**
* Injects a configured {@link TaskBatchExecutionListener} into any batch jobs (beans
- * assignable to {@link AbstractJob}) that are executed within the scope of a task. The
+ * assignable to {@link AbstractJob}) that are executed within the scope of a task. The
* context this is used within is expected to have only one bean of type
* {@link TaskBatchExecutionListener}.
*
@@ -50,17 +51,17 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
- if(jobNames.size() > 0 && !jobNames.contains(beanName)) {
- return bean;
+ if (this.jobNames.size() > 0 && !this.jobNames.contains(beanName)) {
+ return bean;
}
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);
+ 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);
}
((AbstractJob) bean).registerJobExecutionListener(
this.applicationContext.getBean(TaskBatchExecutionListener.class));
@@ -73,4 +74,5 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
this.jobNames = jobNames;
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerFactoryBean.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerFactoryBean.java
index 15ed62be..d8397b80 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerFactoryBean.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskBatchExecutionListenerFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.configuration;
import java.lang.reflect.Field;
+
import javax.sql.DataSource;
import org.springframework.aop.framework.Advised;
@@ -32,13 +34,14 @@ import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
- * {@link FactoryBean} for a {@link TaskBatchExecutionListener}. Provides a jdbc based
- * listener if there is a {@link DataSource} available. Otherwise, builds a listener that
+ * {@link FactoryBean} for a {@link TaskBatchExecutionListener}. Provides a jdbc based
+ * listener if there is a {@link DataSource} available. Otherwise, builds a listener that
* uses the map based implementation.
*
* @author Michael Minella
*/
-public class TaskBatchExecutionListenerFactoryBean implements FactoryBean {
+public class TaskBatchExecutionListenerFactoryBean
+ implements FactoryBean {
private TaskBatchExecutionListener listener;
@@ -49,45 +52,45 @@ public class TaskBatchExecutionListenerFactoryBean implements FactoryBean jobs, JobRegistry jobRegistry, JobRepository jobRepository) {
- TaskJobLauncherCommandLineRunnerFactoryBean taskJobLauncherCommandLineRunnerFactoryBean =
- new TaskJobLauncherCommandLineRunnerFactoryBean(jobLauncher,
- jobExplorer,
- jobs,
- this.properties,
- jobRegistry,
- jobRepository);
+ public TaskJobLauncherCommandLineRunnerFactoryBean jobLauncherCommandLineRunner(
+ JobLauncher jobLauncher, JobExplorer jobExplorer, List jobs,
+ JobRegistry jobRegistry, JobRepository jobRepository) {
+ TaskJobLauncherCommandLineRunnerFactoryBean taskJobLauncherCommandLineRunnerFactoryBean;
+ taskJobLauncherCommandLineRunnerFactoryBean = new TaskJobLauncherCommandLineRunnerFactoryBean(
+ jobLauncher, jobExplorer, jobs, this.properties, jobRegistry,
+ jobRepository);
return taskJobLauncherCommandLineRunnerFactoryBean;
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherCommandLineRunnerFactoryBean.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherCommandLineRunnerFactoryBean.java
index 1a658d52..eb0c439a 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherCommandLineRunnerFactoryBean.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherCommandLineRunnerFactoryBean.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.configuration;
@@ -33,7 +33,8 @@ import org.springframework.util.StringUtils;
*
* @author Glenn Renfro
*/
-public class TaskJobLauncherCommandLineRunnerFactoryBean implements FactoryBean {
+public class TaskJobLauncherCommandLineRunnerFactoryBean
+ implements FactoryBean {
private JobLauncher jobLauncher;
@@ -52,8 +53,9 @@ public class TaskJobLauncherCommandLineRunnerFactoryBean implements FactoryBean<
private JobRepository jobRepository;
public TaskJobLauncherCommandLineRunnerFactoryBean(JobLauncher jobLauncher,
- JobExplorer jobExplorer, List jobs, TaskBatchProperties taskBatchProperties,
- JobRegistry jobRegistry, JobRepository jobRepository) {
+ JobExplorer jobExplorer, List jobs,
+ TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry,
+ JobRepository jobRepository) {
Assert.notNull(taskBatchProperties, "properties must not be null");
this.jobLauncher = jobLauncher;
this.jobExplorer = jobExplorer;
@@ -72,15 +74,16 @@ public class TaskJobLauncherCommandLineRunnerFactoryBean implements FactoryBean<
@Override
public TaskJobLauncherCommandLineRunner getObject() {
- TaskJobLauncherCommandLineRunner taskJobLauncherCommandLineRunner =
- new TaskJobLauncherCommandLineRunner(this.jobLauncher, this.jobExplorer, this.jobRepository, this.taskBatchProperties);
+ TaskJobLauncherCommandLineRunner taskJobLauncherCommandLineRunner = new TaskJobLauncherCommandLineRunner(
+ this.jobLauncher, this.jobExplorer, this.jobRepository,
+ this.taskBatchProperties);
taskJobLauncherCommandLineRunner.setJobs(this.jobs);
- if(StringUtils.hasText(this.jobNames)) {
+ if (StringUtils.hasText(this.jobNames)) {
taskJobLauncherCommandLineRunner.setJobNames(this.jobNames);
}
taskJobLauncherCommandLineRunner.setJobRegistry(this.jobRegistry);
- if(this.order != null) {
+ if (this.order != null) {
taskJobLauncherCommandLineRunner.setOrder(this.order);
}
return taskJobLauncherCommandLineRunner;
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunner.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunner.java
index 9690ce13..c18f1bf4 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunner.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunner.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.handler;
@@ -57,11 +57,11 @@ import org.springframework.util.StringUtils;
* {@link CommandLineRunner} to {@link JobLauncher launch} Spring Batch jobs. Runs all
* jobs in the surrounding context by default and throws an exception upon the first job
* that returns an {@link BatchStatus} of FAILED if a {@link TaskExecutor} in the
- * {@link JobLauncher} is not specified. If a {@link TaskExecutor} is specified
- * in the {@link JobLauncher} then all Jobs are launched and an
- * exception is thrown if one or more of the jobs has an {@link BatchStatus} of FAILED.
- * TaskJobLauncherCommandLineRunner can also be used to launch a specific job by
- * providing a jobName. The TaskJobLaunchercommandLineRunner takes the place of the
+ * {@link JobLauncher} is not specified. If a {@link TaskExecutor} is specified in the
+ * {@link JobLauncher} then all Jobs are launched and an exception is thrown if one or
+ * more of the jobs has an {@link BatchStatus} of FAILED. TaskJobLauncherCommandLineRunner
+ * can also be used to launch a specific job by providing a jobName. The
+ * TaskJobLaunchercommandLineRunner takes the place of the
* {@link org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner} when
* it is in use.
*
@@ -70,15 +70,15 @@ import org.springframework.util.StringUtils;
*/
public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunner {
+ private static final Log logger = LogFactory
+ .getLog(TaskJobLauncherCommandLineRunner.class);
+
private JobLauncher taskJobLauncher;
private JobExplorer taskJobExplorer;
private JobRepository taskJobRepository;
- private static final Log logger = LogFactory
- .getLog(TaskJobLauncherCommandLineRunner.class);
-
private List jobExecutionList = new ArrayList<>();
private ApplicationEventPublisher taskApplicationEventPublisher;
@@ -91,10 +91,12 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
* @param jobExplorer to check the job repository for previous executions
* @param jobRepository to check if a job instance exists with the given parameters
* when running a job
- * @param taskBatchProperties the properties used to configure the taskBatchProperties.
+ * @param taskBatchProperties the properties used to configure the
+ * taskBatchProperties.
*/
- public TaskJobLauncherCommandLineRunner(JobLauncher jobLauncher, JobExplorer jobExplorer,
- JobRepository jobRepository, TaskBatchProperties taskBatchProperties) {
+ public TaskJobLauncherCommandLineRunner(JobLauncher jobLauncher,
+ JobExplorer jobExplorer, JobRepository jobRepository,
+ TaskBatchProperties taskBatchProperties) {
super(jobLauncher, jobExplorer, jobRepository);
this.taskJobLauncher = jobLauncher;
this.taskJobExplorer = jobExplorer;
@@ -151,7 +153,8 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
}
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)) {
@@ -168,8 +171,9 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
List failedJobExecutions = new ArrayList<>();
RepeatStatus repeatStatus = RepeatStatus.FINISHED;
- for (JobExecution jobExecution : jobExecutionList) {
- JobExecution currentJobExecution = taskJobExplorer.getJobExecution(jobExecution.getId());
+ for (JobExecution jobExecution : this.jobExecutionList) {
+ JobExecution currentJobExecution = this.taskJobExplorer
+ .getJobExecution(jobExecution.getId());
BatchStatus batchStatus = currentJobExecution.getStatus();
if (batchStatus.isRunning()) {
repeatStatus = RepeatStatus.CONTINUABLE;
@@ -178,9 +182,10 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
failedJobExecutions.add(jobExecution);
}
}
- Thread.sleep(taskBatchProperties.getFailOnJobFailurePollInterval());
+ 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;
@@ -190,8 +195,8 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
private void throwJobFailedException(List 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",
+ 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()));
}
@@ -201,6 +206,7 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
throw new TaskException(message.toString());
}
+
private JobParameters removeNonIdentifying(JobParameters parameters) {
Map parameterMap = parameters.getParameters();
HashMap copy = new HashMap<>(parameterMap);
@@ -225,4 +231,5 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
merged.putAll(additionals.getParameters());
return new JobParameters(merged);
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchDao.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchDao.java
index 940793f0..90e1b70d 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchDao.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.listener;
import org.springframework.batch.core.JobExecution;
@@ -28,9 +29,9 @@ public interface TaskBatchDao {
/**
* Saves the relationship between a task execution and a job execution.
- *
* @param taskExecution task execution
* @param jobExecution job execution
*/
void saveRelationship(TaskExecution taskExecution, JobExecution jobExecution);
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListener.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListener.java
index 0296476f..0e595d72 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListener.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.listener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.cloud.task.listener.annotation.BeforeTask;
@@ -31,14 +33,14 @@ import org.springframework.util.Assert;
*/
public class TaskBatchExecutionListener extends JobExecutionListenerSupport {
+ private static final Log logger = LogFactory.getLog(TaskBatchExecutionListener.class);
+
private TaskExecution taskExecution;
private TaskBatchDao taskBatchDao;
- private static final Log logger = LogFactory.getLog(TaskBatchExecutionListener.class);
-
/**
- * @param taskBatchDao dao used to persist the relationship. Must not be null
+ * @param taskBatchDao dao used to persist the relationship. Must not be null
*/
public TaskBatchExecutionListener(TaskBatchDao taskBatchDao) {
Assert.notNull(taskBatchDao, "A TaskBatchDao is required");
@@ -53,14 +55,16 @@ public class TaskBatchExecutionListener extends JobExecutionListenerSupport {
@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.");
+ if (this.taskExecution == null) {
+ 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",
- jobExecution.getId(),
- this.taskExecution.getExecutionId()));
- taskBatchDao.saveRelationship(taskExecution, jobExecution);
+ 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);
}
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/JdbcTaskBatchDao.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/JdbcTaskBatchDao.java
index c058d378..8725af7a 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/JdbcTaskBatchDao.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/JdbcTaskBatchDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.listener.support;
import javax.sql.DataSource;
@@ -27,7 +28,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
- * JDBC based implementation of the {@link TaskBatchDao}. Intended to be used in
+ * JDBC based implementation of the {@link TaskBatchDao}. Intended to be used in
* conjunction with the JDBC based
* {@link org.springframework.cloud.task.repository.TaskRepository}
*
@@ -36,10 +37,10 @@ import org.springframework.util.StringUtils;
*/
public class JdbcTaskBatchDao implements TaskBatchDao {
- private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX;
-
private static final String INSERT_STATEMENT = "INSERT INTO %PREFIX%TASK_BATCH VALUES(?, ?)";
+ private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX;
+
private JdbcOperations jdbcTemplate;
/**
@@ -68,10 +69,12 @@ 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");
- jdbcTemplate.update(getQuery(INSERT_STATEMENT), taskExecution.getExecutionId(), jobExecution.getId());
+ this.jdbcTemplate.update(getQuery(INSERT_STATEMENT),
+ taskExecution.getExecutionId(), jobExecution.getId());
}
private String getQuery(String base) {
- return StringUtils.replace(base, "%PREFIX%", tablePrefix);
+ return StringUtils.replace(base, "%PREFIX%", this.tablePrefix);
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/MapTaskBatchDao.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/MapTaskBatchDao.java
index 35ed7102..81e17eeb 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/MapTaskBatchDao.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/listener/support/MapTaskBatchDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.listener.support;
import java.util.Map;
@@ -25,8 +26,10 @@ import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.util.Assert;
/**
- * Map implementation of the {@link TaskBatchDao}. This is intended for
- * testing purposes only!
+ * Map implementation of the {@link TaskBatchDao}.
+ *
+ * This is intended for testing purposes only!
+ *
*
* @author Michael Minella
*/
@@ -44,8 +47,9 @@ public class MapTaskBatchDao implements TaskBatchDao {
Assert.notNull(taskExecution, "A taskExecution is required");
Assert.notNull(jobExecution, "A jobExecution is required");
- if(this.relationships.containsKey(taskExecution.getExecutionId())) {
- this.relationships.get(taskExecution.getExecutionId()).add(jobExecution.getId());
+ if (this.relationships.containsKey(taskExecution.getExecutionId())) {
+ this.relationships.get(taskExecution.getExecutionId())
+ .add(jobExecution.getId());
}
else {
TreeSet jobExecutionIds = new TreeSet<>();
@@ -54,4 +58,5 @@ public class MapTaskBatchDao implements TaskBatchDao {
this.relationships.put(taskExecution.getExecutionId(), jobExecutionIds);
}
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/CommandLineArgsProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/CommandLineArgsProvider.java
index 37635142..93eb54e8 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/CommandLineArgsProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/CommandLineArgsProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.List;
@@ -33,10 +34,10 @@ public interface CommandLineArgsProvider {
* worker for the specified {@link ExecutionContext}.
*
* Note: This method is called once per partition.
- *
* @param executionContext the unique state for the step to be executed.
* @return a list of formatted command line arguments to be passed to the worker (the
- * list will be joined via spaces).
+ * list will be joined via spaces).
*/
List getCommandLineArgs(ExecutionContext executionContext);
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java
index f23c8c46..91946cf6 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.ArrayList;
@@ -51,39 +52,57 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
- * A {@link PartitionHandler} implementation that delegates to a {@link TaskLauncher} for
- * each of the workers. The id of the worker's StepExecution is passed as an environment
- * variable to the worker. The worker, bootstrapped by the
+ *
+ * A {@link PartitionHandler} implementation that delegates to a {@link TaskLauncher} for
+ * each of the workers. The id of the worker's StepExecution is passed as an environment
+ * variable to the worker. The worker, bootstrapped by the
* {@link DeployerStepExecutionHandler}, looks up the StepExecution in the JobRepository
- * and executes it. This PartitionHandler polls the JobRepository for the results.
+ * and executes it. This PartitionHandler polls the JobRepository for the results.
+ *
*
- * If the job fails, the partitions will be re-executed per normal batch rules (steps that
+ *
+ * If the job fails, the partitions will be re-executed per normal batch rules (steps that
* are complete should do nothing, failed steps should restart based on their
- * configurations).
+ * configurations).
+ *
*
- * This PartitionHandler and all of the worker processes must share the same JobRepository
- * data store (aka point the same database).
+ *
+ * This PartitionHandler and all of the worker processes must share the same JobRepository
+ * data store (aka point the same database).
+ *
*
* @author Michael Minella
*/
-public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAware, InitializingBean {
+public class DeployerPartitionHandler
+ implements PartitionHandler, EnvironmentAware, InitializingBean {
+
+ /**
+ * ID of Spring Cloud Task job execution.
+ */
+ public static final String SPRING_CLOUD_TASK_JOB_EXECUTION_ID = "spring.cloud.task.job-execution-id";
+
+ /**
+ * ID of Spring Cloud Task step execution.
+ */
+ public static final String SPRING_CLOUD_TASK_STEP_EXECUTION_ID = "spring.cloud.task.step-execution-id";
+
+ /**
+ * Name of Spring Cloud Task step.
+ */
+ public static final String SPRING_CLOUD_TASK_STEP_NAME = "spring.cloud.task.step-name";
+
+ /**
+ * ID of Spring Cloud Task parent execution.
+ */
+ public static final String SPRING_CLOUD_TASK_PARENT_EXECUTION_ID = "spring.cloud.task.parentExecutionId";
+
+ /**
+ * Spring Cloud Task property name.
+ */
+ public static final String SPRING_CLOUD_TASK_NAME = "spring.cloud.task.name";
private static final long DEFAULT_POLL_INTERVAL = 10000;
- public static final String SPRING_CLOUD_TASK_JOB_EXECUTION_ID =
- "spring.cloud.task.job-execution-id";
-
- public static final String SPRING_CLOUD_TASK_STEP_EXECUTION_ID =
- "spring.cloud.task.step-execution-id";
-
- public static final String SPRING_CLOUD_TASK_STEP_NAME =
- "spring.cloud.task.step-name";
-
- public static final String SPRING_CLOUD_TASK_PARENT_EXECUTION_ID =
- "spring.cloud.task.parentExecutionId";
-
- public static final String SPRING_CLOUD_TASK_NAME = "spring.cloud.task.name";
-
private int maxWorkers = -1;
private int gridSize = 1;
@@ -118,10 +137,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
private boolean defaultArgsAsEnvironmentVars = false;
- public DeployerPartitionHandler(TaskLauncher taskLauncher,
- JobExplorer jobExplorer,
- Resource resource,
- String stepName) {
+ public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer,
+ Resource resource, String stepName) {
Assert.notNull(taskLauncher, "A taskLauncher is required");
Assert.notNull(jobExplorer, "A jobExplorer is required");
Assert.notNull(resource, "A resource is required");
@@ -135,17 +152,16 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
/**
* 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;
}
/**
* 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 defaultArgsAsEnvironmentVars defaults to false
*/
public void setDefaultArgsAsEnvironmentVars(boolean defaultArgsAsEnvironmentVars) {
@@ -154,17 +170,16 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
/**
* 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;
}
/**
* The maximum number of workers to be executing at once.
- *
- * @param maxWorkers number of workers. Defaults to -1 (unlimited)
+ * @param maxWorkers number of workers. Defaults to -1 (unlimited)
*/
public void setMaxWorkers(int maxWorkers) {
Assert.isTrue(maxWorkers != 0, "maxWorkers cannot be 0");
@@ -172,11 +187,11 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
}
/**
- * Approximate size of the pool of worker JVMs available. May be used by the
+ * Approximate size of the pool of worker JVMs available. May be used by the
* {@link StepExecutionSplitter} to determine how many partitions to create (at the
- * discretion of the {@link org.springframework.batch.core.partition.support.Partitioner}).
- *
- * @param gridSize size of grid. Defaults to 1
+ * discretion of the
+ * {@link org.springframework.batch.core.partition.support.Partitioner}).
+ * @param gridSize size of grid. Defaults to 1
*/
public void setGridSize(int gridSize) {
this.gridSize = gridSize;
@@ -184,25 +199,22 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
/**
* The interval to check the job repository for completed steps.
- *
- * @param pollInterval interval. Defaults to 10 seconds
+ * @param pollInterval interval. Defaults to 10 seconds
*/
public void setPollInterval(long pollInterval) {
this.pollInterval = pollInterval;
}
/**
- * Timeout for the master step. This is a timeout for all workers to complete.
- *
- * @param timeout timeout. Defaults to none (-1).
+ * Timeout for the master step. This is a timeout for all workers to complete.
+ * @param timeout timeout. Defaults to none (-1).
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
}
/**
- * Map of deployment properties to be used by the {@link TaskLauncher}
- *
+ * Map of deployment properties to be used by the {@link TaskLauncher}.
* @param deploymentProperties properties to be used by the {@link TaskLauncher}
*/
public void setDeploymentProperties(Map deploymentProperties) {
@@ -210,9 +222,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
}
/**
- * The name of the application to be launched. Useful in environments where
+ * The name of the application to be launched. Useful in environments where
* application deployments are reused (such as CloudFoundry).
- *
* @param applicationName The name of the application to be launched
*/
public void setApplicationName(String applicationName) {
@@ -223,9 +234,9 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
public void beforeTask(TaskExecution taskExecution) {
this.taskExecution = taskExecution;
- if(this.commandLineArgsProvider == null) {
- SimpleCommandLineArgsProvider provider = new
- SimpleCommandLineArgsProvider(taskExecution);
+ if (this.commandLineArgsProvider == null) {
+ SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
+ taskExecution);
this.commandLineArgsProvider = provider;
}
@@ -235,8 +246,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
public Collection handle(StepExecutionSplitter stepSplitter,
StepExecution stepExecution) throws Exception {
- final Set tempCandidates =
- stepSplitter.split(stepExecution, this.gridSize);
+ final Set tempCandidates = stepSplitter.split(stepExecution,
+ this.gridSize);
// Following two lines due to https://jira.spring.io/browse/BATCH-2490
final Set candidates = new HashSet<>(tempCandidates.size());
@@ -244,7 +255,7 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
int partitions = candidates.size();
- logger.debug(String.format("%s partitions were returned", partitions));
+ this.logger.debug(String.format("%s partitions were returned", partitions));
final Set executed = new HashSet<>(candidates.size());
@@ -259,7 +270,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
return pollReplies(stepExecution, executed, candidates, partitions);
}
- private void launchWorkers(Set candidates, Set executed) {
+ private void launchWorkers(Set candidates,
+ Set executed) {
for (StepExecution execution : candidates) {
if (this.currentWorkers < this.maxWorkers || this.maxWorkers < 0) {
launchWorker(execution);
@@ -273,59 +285,59 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
private void launchWorker(StepExecution workerStepExecution) {
List arguments = new ArrayList<>();
- ExecutionContext copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
+ ExecutionContext copyContext = new ExecutionContext(
+ workerStepExecution.getExecutionContext());
- arguments.addAll(
- this.commandLineArgsProvider
- .getCommandLineArgs(copyContext));
+ arguments.addAll(this.commandLineArgsProvider.getCommandLineArgs(copyContext));
- if(!this.defaultArgsAsEnvironmentVars) {
+ if (!this.defaultArgsAsEnvironmentVars) {
arguments.add(formatArgument(SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
String.valueOf(workerStepExecution.getJobExecution().getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
String.valueOf(workerStepExecution.getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_NAME, this.stepName));
- arguments.add(formatArgument(SPRING_CLOUD_TASK_NAME, String.format("%s_%s_%s",
- taskExecution.getTaskName(),
- workerStepExecution.getJobExecution().getJobInstance().getJobName(),
- workerStepExecution.getStepName())));
+ arguments
+ .add(formatArgument(SPRING_CLOUD_TASK_NAME,
+ String.format("%s_%s_%s", this.taskExecution.getTaskName(),
+ workerStepExecution.getJobExecution().getJobInstance()
+ .getJobName(),
+ workerStepExecution.getStepName())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
- String.valueOf(taskExecution.getExecutionId())));
+ String.valueOf(this.taskExecution.getExecutionId())));
}
copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
- Map environmentVariables = this.environmentVariablesProvider.getEnvironmentVariables(copyContext);
+ Map environmentVariables = this.environmentVariablesProvider
+ .getEnvironmentVariables(copyContext);
- if(this.defaultArgsAsEnvironmentVars) {
+ if (this.defaultArgsAsEnvironmentVars) {
environmentVariables.put(SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
String.valueOf(workerStepExecution.getJobExecution().getId()));
environmentVariables.put(SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
String.valueOf(workerStepExecution.getId()));
environmentVariables.put(SPRING_CLOUD_TASK_STEP_NAME, this.stepName);
- environmentVariables.put(SPRING_CLOUD_TASK_NAME, String.format("%s_%s_%s",
- taskExecution.getTaskName(),
- workerStepExecution.getJobExecution().getJobInstance().getJobName(),
- workerStepExecution.getStepName()));
+ environmentVariables
+ .put(SPRING_CLOUD_TASK_NAME,
+ String.format("%s_%s_%s", this.taskExecution.getTaskName(),
+ workerStepExecution.getJobExecution().getJobInstance()
+ .getJobName(),
+ workerStepExecution.getStepName()));
environmentVariables.put(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
- String.valueOf(taskExecution.getExecutionId()));
+ String.valueOf(this.taskExecution.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);
- taskLauncher.launch(request);
+ this.taskLauncher.launch(request);
}
private String resolveApplicationName() {
- if(StringUtils.hasText(this.applicationName)) {
+ if (StringUtils.hasText(this.applicationName)) {
return this.applicationName;
}
else {
@@ -338,8 +350,7 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
}
private Collection pollReplies(final StepExecution masterStepExecution,
- final Set executed,
- final Set candidates,
+ final Set executed, final Set candidates,
final int size) throws Exception {
final Collection result = new ArrayList<>(executed.size());
@@ -351,13 +362,14 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
for (StepExecution curStepExecution : executed) {
if (!result.contains(curStepExecution)) {
- StepExecution partitionStepExecution =
- jobExplorer.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId());
+ StepExecution partitionStepExecution = DeployerPartitionHandler.this.jobExplorer
+ .getStepExecution(masterStepExecution.getJobExecutionId(),
+ curStepExecution.getId());
BatchStatus batchStatus = partitionStepExecution.getStatus();
if (batchStatus != null && isComplete(batchStatus)) {
result.add(partitionStepExecution);
- currentWorkers--;
+ DeployerPartitionHandler.this.currentWorkers--;
if (!candidates.isEmpty()) {
@@ -382,8 +394,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
Poller> poller = new DirectPoller<>(this.pollInterval);
Future> resultsFuture = poller.poll(callback);
- if (timeout >= 0) {
- return resultsFuture.get(timeout, TimeUnit.MILLISECONDS);
+ if (this.timeout >= 0) {
+ return resultsFuture.get(this.timeout, TimeUnit.MILLISECONDS);
}
else {
return resultsFuture.get();
@@ -391,7 +403,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
}
private boolean isComplete(BatchStatus status) {
- return status.equals(BatchStatus.COMPLETED) || status.isGreaterThan(BatchStatus.STARTED);
+ return status.equals(BatchStatus.COMPLETED)
+ || status.isGreaterThan(BatchStatus.STARTED);
}
@Override
@@ -401,10 +414,11 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
@Override
public void afterPropertiesSet() throws Exception {
- if(this.environmentVariablesProvider == null) {
- this.environmentVariablesProvider =
- new SimpleEnvironmentVariablesProvider(this.environment);
+ if (this.environmentVariablesProvider == null) {
+ this.environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
+ this.environment);
}
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandler.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandler.java
index 20f652c5..d2a8b178 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandler.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import org.apache.commons.logging.Log;
@@ -34,20 +35,24 @@ import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
/**
- * A {@link CommandLineRunner} used to execute a {@link Step}. No result is provided
+ *
+ * A {@link CommandLineRunner} used to execute a {@link Step}. No result is provided
* directly to the associated {@link DeployerPartitionHandler} as it will obtain the step
- * results directly from the shared job repository.
+ * results directly from the shared job repository.
+ *
*
- * The {@link StepExecution} is rehydrated based on the environment variables provided.
- * Specifically, the following variables are required:
+ *
+ * The {@link StepExecution} is rehydrated based on the environment variables provided.
+ * Specifically, the following variables are required:
+ *
*
- * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_JOB_EXECUTION_ID}: The id of
- * the JobExecution.
- * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_STEP_EXECUTION_ID}: The id of
- * the StepExecution.
- * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_STEP_NAME}: The id of the
- * bean definition for the Step to execute. The id must be found within the provided
- * {@link BeanFactory}
+ * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_JOB_EXECUTION_ID}: The id of the
+ * JobExecution.
+ * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_STEP_EXECUTION_ID}: The id of the
+ * StepExecution.
+ * - {@link DeployerPartitionHandler#SPRING_CLOUD_TASK_STEP_NAME}: The id of the bean
+ * definition for the Step to execute. The id must be found within the provided
+ * {@link BeanFactory}
*
*
* @author Michael Minella
@@ -65,7 +70,8 @@ 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");
@@ -82,38 +88,60 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
validateRequest();
- Long jobExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
- Long stepExecutionId = Long.parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
- StepExecution stepExecution = 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 = environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
- Step step = stepLocator.getStep(stepName);
+ String stepName = this.environment
+ .getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
+ Step step = this.stepLocator.getStep(stepName);
try {
- logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s", stepExecution.getStepName(), stepExecutionId, jobExecutionId));
+ 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);
}
catch (JobInterruptedException e) {
stepExecution.setStatus(BatchStatus.STOPPED);
- jobRepository.update(stepExecution);
+ this.jobRepository.update(stepExecution);
}
catch (Throwable e) {
stepExecution.addFailureException(e);
stepExecution.setStatus(BatchStatus.FAILED);
- jobRepository.update(stepExecution);
+ this.jobRepository.update(stepExecution);
}
}
private void validateRequest() {
- Assert.isTrue(environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID), "A job execution id is required");
- Assert.isTrue(environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID), "A step execution id is required");
- Assert.isTrue(environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME), "A step name is required");
+ 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),
+ "A step execution id is required");
+ Assert.isTrue(
+ this.environment.containsProperty(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME),
+ "A step name is required");
- Assert.isTrue(this.stepLocator.getStepNames().contains(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)), "The step requested cannot be found in the provided BeanFactory");
+ Assert.isTrue(
+ this.stepLocator.getStepNames()
+ .contains(this.environment.getProperty(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)),
+ "The step requested cannot be found in the provided BeanFactory");
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/EnvironmentVariablesProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/EnvironmentVariablesProvider.java
index 7a7fb428..6910d661 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/EnvironmentVariablesProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/EnvironmentVariablesProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.Map;
@@ -24,19 +25,18 @@ import org.springframework.batch.item.ExecutionContext;
* each worker in a partitioned job.
*
* @author Michael Minella
- *
* @since 1.0.2
*/
public interface EnvironmentVariablesProvider {
/**
- * Provides a {@link Map} of Strings to be used as environment variables. This method
- * will be called for each worker step. For example, if there are 5 partitions, this
+ * Provides a {@link Map} of Strings to be used as environment variables. This method
+ * will be called for each worker step. For example, if there are 5 partitions, this
* method will be called 5 times.
- *
* @param executionContext the {@link ExecutionContext} associated with the worker's
- * step
+ * step
* @return A {@link Map} of values to be used as environment variables
*/
Map getEnvironmentVariables(ExecutionContext executionContext);
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProvider.java
index 02b49f63..5de4770f 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.Collections;
@@ -21,23 +22,23 @@ import java.util.Map;
import org.springframework.batch.item.ExecutionContext;
/**
- * A simple no-op implementation of the {@link EnvironmentVariablesProvider}. It returns
+ * A simple no-op implementation of the {@link EnvironmentVariablesProvider}. It returns
* an empty {@link Map}.
*
* @author Michael Minella
- *
* @since 1.0.2
*/
public class NoOpEnvironmentVariablesProvider implements EnvironmentVariablesProvider {
/**
- *
* @param executionContext the {@link ExecutionContext} associated with the worker's
- * step
+ * step
* @return an empty {@link Map}
*/
@Override
- public Map getEnvironmentVariables(ExecutionContext executionContext) {
+ public Map getEnvironmentVariables(
+ ExecutionContext executionContext) {
return Collections.emptyMap();
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProvider.java
index e2ef58d4..c7bbb338 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.List;
@@ -38,6 +39,7 @@ public class PassThroughCommandLineArgsProvider implements CommandLineArgsProvid
@Override
public List getCommandLineArgs(ExecutionContext executionContext) {
- return commandLineArgs;
+ return this.commandLineArgs;
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java
index e19cfd9b..4afbacb9 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.ArrayList;
@@ -31,7 +32,8 @@ import org.springframework.util.Assert;
* @author Glenn Renfro
* @since 1.1.0
*/
-public class SimpleCommandLineArgsProvider extends TaskExecutionListenerSupport implements CommandLineArgsProvider {
+public class SimpleCommandLineArgsProvider extends TaskExecutionListenerSupport
+ implements CommandLineArgsProvider {
private TaskExecution taskExecution;
@@ -56,7 +58,6 @@ public class SimpleCommandLineArgsProvider extends TaskExecutionListenerSupport
/**
* Additional command line args to be appended.
- *
* @param appendedArgs list of arguments
* @since 1.2
*/
@@ -67,17 +68,18 @@ public class SimpleCommandLineArgsProvider extends TaskExecutionListenerSupport
@Override
public List getCommandLineArgs(ExecutionContext executionContext) {
- int listSize = this.taskExecution.getArguments().size() +
- (this.appendedArgs != null ? this.appendedArgs.size() : 0);
+ int listSize = this.taskExecution.getArguments().size()
+ + (this.appendedArgs != null ? this.appendedArgs.size() : 0);
List args = new ArrayList<>(listSize);
args.addAll(this.taskExecution.getArguments());
- if(this.appendedArgs != null) {
+ if (this.appendedArgs != null) {
args.addAll(this.appendedArgs);
}
return args;
}
+
}
diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleEnvironmentVariablesProvider.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleEnvironmentVariablesProvider.java
index c75b33a4..576daaf0 100644
--- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleEnvironmentVariablesProvider.java
+++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/SimpleEnvironmentVariablesProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.Arrays;
@@ -29,12 +30,11 @@ import org.springframework.core.env.PropertySource;
/**
* Copies all existing environment variables as made available in the {@link Environment}
- * only if includeCurrentEnvironment is set to true (default).
- * The environmentProperties option provides the ability to override any
- * specific values on an as needed basis.
+ * only if includeCurrentEnvironment is set to true (default). The
+ * environmentProperties option provides the ability to override any specific
+ * values on an as needed basis.
*
* @author Michael Minella
- *
* @since 1.0.2
*/
public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesProvider {
@@ -53,28 +53,31 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
}
/**
- * @param environmentProperties a {@link Map} of properties used to override any values
- * configured in the current {@link Environment}
+ * @param environmentProperties a {@link Map} of properties used to override any
+ * values configured in the current {@link Environment}
*/
public void setEnvironmentProperties(Map environmentProperties) {
this.environmentProperties = environmentProperties;
}
/**
- * Establishes if current environment variables will be included as a part of the provider.
- * @param includeCurrentEnvironment true(default) include local environment properties. False do not include
- * current environment properties.
+ * Establishes if current environment variables will be included as a part of the
+ * provider.
+ * @param includeCurrentEnvironment true(default) include local environment
+ * properties. False do not include current environment properties.
*/
public void setIncludeCurrentEnvironment(boolean includeCurrentEnvironment) {
this.includeCurrentEnvironment = includeCurrentEnvironment;
}
@Override
- public Map getEnvironmentVariables(ExecutionContext executionContext) {
+ public Map getEnvironmentVariables(
+ ExecutionContext executionContext) {
- Map environmentProperties = new HashMap<>(this.environmentProperties.size());
+ Map environmentProperties = new HashMap<>(
+ this.environmentProperties.size());
- if(includeCurrentEnvironment) {
+ if (this.includeCurrentEnvironment) {
environmentProperties.putAll(getCurrentEnvironmentProperties());
}
@@ -88,9 +91,11 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
Set 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()));
}
}
@@ -100,4 +105,5 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
return currentEnvironment;
}
+
}
diff --git a/spring-cloud-task-batch/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-task-batch/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index cca0a097..246cffc2 100644
--- a/spring-cloud-task-batch/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/spring-cloud-task-batch/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -1,64 +1,64 @@
{
- "properties": [
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.listener.enabled",
- "description": "This property is used to determine if a task will be linked to the batch jobs that are run.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": false,
- "name": "spring.cloud.task.batch.fail-on-job-failure",
- "description": "This property is used to determine if a task app should return with a non zero exit code if a batch job fails.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.enabled",
- "description": "This property is used to determine if a task should listen for batch events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.chunk.enabled",
- "description": "This property is used to determine if a task should listen for batch chunk events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.item-process.enabled",
- "description": "This property is used to determine if a task should listen for batch item processed events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.item-read.enabled",
- "description": "This property is used to determine if a task should listen for batch item read events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.item-write.enabled",
- "description": "This property is used to determine if a task should listen for batch item write events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.job-execution.enabled",
- "description": "This property is used to determine if a task should listen for batch job execution events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.skip.enabled",
- "description": "This property is used to determine if a task should listen for batch skip events.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.task.batch.events.step-execution.enabled",
- "description": "This property is used to determine if a task should listen for batch step execution events.",
- "type": "java.lang.Boolean"
- }
- ]
+ "properties": [
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.listener.enabled",
+ "description": "This property is used to determine if a task will be linked to the batch jobs that are run.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": false,
+ "name": "spring.cloud.task.batch.fail-on-job-failure",
+ "description": "This property is used to determine if a task app should return with a non zero exit code if a batch job fails.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.enabled",
+ "description": "This property is used to determine if a task should listen for batch events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.chunk.enabled",
+ "description": "This property is used to determine if a task should listen for batch chunk events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.item-process.enabled",
+ "description": "This property is used to determine if a task should listen for batch item processed events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.item-read.enabled",
+ "description": "This property is used to determine if a task should listen for batch item read events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.item-write.enabled",
+ "description": "This property is used to determine if a task should listen for batch item write events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.job-execution.enabled",
+ "description": "This property is used to determine if a task should listen for batch job execution events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.skip.enabled",
+ "description": "This property is used to determine if a task should listen for batch skip events.",
+ "type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": true,
+ "name": "spring.cloud.task.batch.events.step-execution.enabled",
+ "description": "This property is used to determine if a task should listen for batch step execution events.",
+ "type": "java.lang.Boolean"
+ }
+ ]
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskBatchTest.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskBatchTest.java
index e5797cb0..9e43e6be 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskBatchTest.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskBatchTest.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.configuration;
@@ -35,4 +35,5 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@Documented
@ImportAutoConfiguration
public @interface TaskBatchTest {
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java
index 9d7ecd2f..16b45e76 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/configuration/TaskJobLauncherAutoConfigurationTests.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.configuration;
@@ -33,33 +33,33 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class TaskJobLauncherAutoConfigurationTests {
- private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().
- withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
- EmbeddedDataSourceConfiguration.class,
- BatchAutoConfiguration.class,
+ EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class,
TaskJobLauncherAutoConfiguration.class);
@Test
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
- this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true").run(context -> {
- assertThat(context).hasSingleBean(TaskJobLauncherCommandLineRunner.class);
- assertThat(context.getBean(TaskJobLauncherCommandLineRunner.class)
- .getOrder())
- .isEqualTo(0);
- });
+ this.contextRunner
+ .withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true")
+ .run(context -> {
+ assertThat(context)
+ .hasSingleBean(TaskJobLauncherCommandLineRunner.class);
+ assertThat(context.getBean(TaskJobLauncherCommandLineRunner.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 -> {
+ this.contextRunner
+ .withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
+ "spring.cloud.task.batch.commandLineRunnerOrder=100")
+ .run(context -> {
assertThat(context.getBean(TaskJobLauncherCommandLineRunner.class)
- .getOrder())
- .isEqualTo(100);
- });
+ .getOrder()).isEqualTo(100);
+ });
}
@Test
@@ -69,5 +69,5 @@ public class TaskJobLauncherAutoConfigurationTests {
assertThat(context).doesNotHaveBean(TaskJobLauncherCommandLineRunner.class);
});
}
-}
+}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java
index 07672de2..f25890e5 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerCoreTests.java
@@ -1,23 +1,21 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.handler;
-
-import org.assertj.core.api.AssertionsForClassTypes;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
@@ -55,13 +53,14 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.PlatformTransactionManager;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author Glenn Renfro
*/
@RunWith(SpringRunner.class)
-@ContextConfiguration(classes = {TaskJobLauncherCommandLineRunnerCoreTests.BatchConfiguration.class})
+@ContextConfiguration(classes = {
+ TaskJobLauncherCommandLineRunnerCoreTests.BatchConfiguration.class })
public class TaskJobLauncherCommandLineRunnerCoreTests {
@Autowired
@@ -93,11 +92,11 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
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 TaskJobLauncherCommandLineRunner(this.jobLauncher, this.jobExplorer, jobRepository, new TaskBatchProperties());
+ this.runner = new TaskJobLauncherCommandLineRunner(this.jobLauncher,
+ this.jobExplorer, this.jobRepository, new TaskBatchProperties());
}
-
@DirtiesContext
@Test
public void basicExecution() throws Exception {
@@ -146,7 +145,6 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
-
@DirtiesContext
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
@@ -162,9 +160,9 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
// try to re-run a failed execution
Executable executable = () -> this.runner.execute(this.job,
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
- Throwable exception = assertThrows(JobRestartException.class, executable);
- AssertionsForClassTypes.assertThat(exception.getMessage())
- .isEqualTo("JobInstance already exists and is not restartable");
+ assertThatExceptionOfType(JobRestartException.class)
+ .isThrownBy(executable::execute)
+ .withMessage("JobInstance already exists and is not restartable");
}
@DirtiesContext
@@ -177,12 +175,11 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
.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()
@@ -195,7 +192,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
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)
+ 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 = this.jobExplorer.getJobInstance(0L);
@@ -216,7 +213,6 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
assertThat(parameters.getLong("foo")).isEqualTo(3L);
}
-
private Tasklet throwingTasklet() {
return (contribution, chunkContext) -> {
throw new RuntimeException("Planned");
@@ -238,13 +234,11 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
@EnableBatchProcessing
protected static class BatchConfiguration implements BatchConfigurer {
- private ResourcelessTransactionManager transactionManager =
- new ResourcelessTransactionManager();
+ private ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
private JobRepository jobRepository;
- private MapJobRepositoryFactoryBean jobRepositoryFactory =
- new MapJobRepositoryFactoryBean(
+ private MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(
this.transactionManager);
public BatchConfiguration() throws Exception {
@@ -275,4 +269,5 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
}
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java
index 0c4a8478..c47f19b2 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.handler;
@@ -20,6 +20,7 @@ import java.util.Set;
import javax.sql.DataSource;
+import org.assertj.core.api.Condition;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
@@ -59,18 +60,18 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
-import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
-import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author Glenn Renfro
*/
public class TaskJobLauncherCommandLineRunnerTests {
- private ConfigurableApplicationContext applicationContext;
+ private static final String DEFAULT_ERROR_MESSAGE = "The following Jobs have failed: \n"
+ + "Job jobA failed during execution for job instance id 1 with jobExecutionId of 1 \n";
- private static final String DEFAULT_ERROR_MESSAGE = "The following Jobs have failed: \n" +
- "Job jobA failed during execution for job instance id 1 with jobExecutionId of 1 \n";
+ private ConfigurableApplicationContext applicationContext;
@After
public void tearDown() {
@@ -82,20 +83,22 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Test
public void testTaskJobLauncherCLRSuccessFail() {
String[] enabledArgs = new String[] {
- "--spring.cloud.task.batch.failOnJobFailure=true"};
- validateForFail(DEFAULT_ERROR_MESSAGE, TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class,
+ "--spring.cloud.task.batch.failOnJobFailure=true" };
+ validateForFail(DEFAULT_ERROR_MESSAGE,
+ TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class,
enabledArgs);
}
/**
- * Verifies that the task will return an exit code other than zero if the
- * job fails with the deprecated EnableTask annotation.
+ * Verifies that the task will return an exit code other than zero if the job fails
+ * with the deprecated EnableTask annotation.
*/
@Test
public void testTaskJobLauncherCLRSuccessFailWithAnnotation() {
String[] enabledArgs = new String[] {
- "--spring.cloud.task.batch.failOnJobFailure=true"};
- validateForFail(DEFAULT_ERROR_MESSAGE, TaskJobLauncherCommandLineRunnerTests.JobWithFailureAnnotatedConfiguration.class,
+ "--spring.cloud.task.batch.failOnJobFailure=true" };
+ validateForFail(DEFAULT_ERROR_MESSAGE,
+ TaskJobLauncherCommandLineRunnerTests.JobWithFailureAnnotatedConfiguration.class,
enabledArgs);
}
@@ -103,8 +106,9 @@ public class TaskJobLauncherCommandLineRunnerTests {
public void testTaskJobLauncherCLRSuccessFailWithTaskExecutor() {
String[] enabledArgs = new String[] {
"--spring.cloud.task.batch.failOnJobFailure=true",
- "--spring.cloud.task.batch.failOnJobFailurePollInterval=500"};
- validateForFail(DEFAULT_ERROR_MESSAGE, TaskJobLauncherCommandLineRunnerTests.JobWithFailureTaskExecutorConfiguration.class,
+ "--spring.cloud.task.batch.failOnJobFailurePollInterval=500" };
+ validateForFail(DEFAULT_ERROR_MESSAGE,
+ TaskJobLauncherCommandLineRunnerTests.JobWithFailureTaskExecutorConfiguration.class,
enabledArgs);
}
@@ -112,11 +116,12 @@ public class TaskJobLauncherCommandLineRunnerTests {
public void testTaskJobLauncherPickOneJob() {
String[] enabledArgs = new String[] {
"--spring.cloud.task.batch.fail-on-job-failure=true",
- "--spring.cloud.task.batch.jobNames=jobSucceed"};
+ "--spring.cloud.task.batch.jobNames=jobSucceed" };
boolean isExceptionThrown = false;
try {
- this.applicationContext = SpringApplication
- .run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
+ this.applicationContext = SpringApplication.run(new Class[] {
+ TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class },
+ enabledArgs);
}
catch (IllegalStateException exception) {
isExceptionThrown = true;
@@ -128,40 +133,51 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Test
public void testCommandLineRunnerSetToFalse() {
String[] enabledArgs = new String[] {};
- this.applicationContext = SpringApplication
- .run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobConfiguration.class }, enabledArgs);
+ this.applicationContext = SpringApplication.run(
+ new Class[] {
+ TaskJobLauncherCommandLineRunnerTests.JobConfiguration.class },
+ enabledArgs);
validateContext();
- assertThat(applicationContext.getBean(JobLauncherCommandLineRunner.class)).isNotNull();
+ assertThat(this.applicationContext.getBean(JobLauncherCommandLineRunner.class))
+ .isNotNull();
- Executable executable = () -> applicationContext.getBean(TaskJobLauncherCommandLineRunner.class);
+ Executable executable = () -> this.applicationContext
+ .getBean(TaskJobLauncherCommandLineRunner.class);
- Throwable exception = assertThrows(NoSuchBeanDefinitionException.class, executable);
- assertThat(exception.getMessage()).isEqualTo("No qualifying bean of type " +
- "'org.springframework.cloud.task.batch.handler.TaskJobLauncherCommandLineRunner' available");
+ assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
+ .isThrownBy(executable::execute).withMessage("No qualifying bean of type "
+ + "'org.springframework.cloud.task.batch.handler.TaskJobLauncherCommandLineRunner' available");
validateContext();
}
private void validateContext() {
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
- Page page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer
- .getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set 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);
+ private void validateForFail(String errorMessage, Class clazz, String[] enabledArgs) {
+ Executable executable = () -> this.applicationContext = SpringApplication.run(
+ new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class },
+ enabledArgs);
- Throwable exception = assertThrows(IllegalStateException.class, executable);
- assertThat(exception.getCause().getMessage()).isEqualTo(errorMessage);
+ assertThatExceptionOfType(IllegalStateException.class)
+ .isThrownBy(executable::execute).has(new Condition() {
+ @Override
+ public boolean matches(Throwable value) {
+ return errorMessage.equals(value.getCause().getMessage());
+ }
+ });
}
-
@EnableBatchProcessing
@TaskBatchTest
@Import(EmbeddedDataSourceConfiguration.class)
@@ -176,25 +192,23 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Bean
public Job job() {
- return jobBuilderFactory.get("job")
- .start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("job")
+ .start(this.stepBuilderFactory.get("step1").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;
}
- }).build())
- .build();
+ }).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
@@ -208,50 +222,54 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Bean
public Job jobFail() {
- return jobBuilderFactory.get("jobA")
- .start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("jobA")
+ .start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution,
- ChunkContext chunkContext)
- throws Exception {
+ ChunkContext chunkContext) throws Exception {
System.out.println("Executed");
- throw new IllegalStateException("WHOOPS");
+ throw new IllegalStateException("WHOOPS");
}
- }).build())
- .build();
+ }).build()).build();
}
@Bean
public Job jobFun() {
- return jobBuilderFactory.get("jobSucceed")
- .start(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) {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}
- }).build())
- .build();
+ }).build()).build();
}
+
}
@EnableTask
- public static class JobWithFailureAnnotatedConfiguration extends JobWithFailureConfiguration{
+ public static class JobWithFailureAnnotatedConfiguration
+ extends JobWithFailureConfiguration {
}
- public static class JobWithFailureTaskExecutorConfiguration extends JobWithFailureConfiguration{
+ public static class JobWithFailureTaskExecutorConfiguration
+ extends JobWithFailureConfiguration {
+
@Bean
public BatchConfigurer batchConfigurer(DataSource dataSource) {
return new TestBatchConfigurer(dataSource);
}
+
}
- private static class TestBatchConfigurer extends DefaultBatchConfigurer{
- public TestBatchConfigurer(DataSource dataSource) {
+ private static class TestBatchConfigurer extends DefaultBatchConfigurer {
+
+ TestBatchConfigurer(DataSource dataSource) {
super(dataSource);
}
+
protected JobLauncher createJobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(getJobRepository());
@@ -259,5 +277,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
+
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java
index a4bd7daf..ac6c00ce 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java
@@ -1,22 +1,23 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.batch.listener;
import java.util.Set;
+
import javax.sql.DataSource;
import org.junit.After;
@@ -56,8 +57,8 @@ 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);
@@ -80,22 +81,19 @@ public class PrefixTests {
@Bean
public Job job() {
- return jobBuilderFactory.get("job")
- .start(stepBuilderFactory.get("step1")
- .tasklet((contribution, chunkContext) -> {
+ return this.jobBuilderFactory.get("job").start(this.stepBuilderFactory
+ .get("step1").tasklet((contribution, chunkContext) -> {
System.out.println("Executed");
return RepeatStatus.FINISHED;
- }).build())
- .build();
+ }).build()).build();
}
@Bean
public DataSource dataSource() {
- return new EmbeddedDatabaseBuilder()
- .addScript("classpath:schema-h2.sql")
- .setType(EmbeddedDatabaseType.H2)
- .build();
+ return new EmbeddedDatabaseBuilder().addScript("classpath:schema-h2.sql")
+ .setType(EmbeddedDatabaseType.H2).build();
}
+
}
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java
index 1bebcf9a..5e916ffb 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/TaskBatchExecutionListenerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.listener;
import java.util.ArrayList;
@@ -61,7 +62,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael Minella
@@ -75,15 +76,14 @@ public class TaskBatchExecutionListenerTests {
@After
public void tearDown() {
- if(this.applicationContext != null && this.applicationContext.isActive()) {
+ if (this.applicationContext != null && this.applicationContext.isActive()) {
this.applicationContext.close();
}
}
@Test
public void testAutobuiltDataSource() {
- this.applicationContext = SpringApplication.run(JobConfiguration.class ,
- ARGS);
+ this.applicationContext = SpringApplication.run(JobConfiguration.class, ARGS);
validateContext();
}
@@ -96,28 +96,28 @@ public class TaskBatchExecutionListenerTests {
@Test(expected = AssertionError.class)
public void testNoAutoConfigurationEnable() {
- this.applicationContext = SpringApplication.run(JobConfiguration.class ,
+ this.applicationContext = SpringApplication.run(JobConfiguration.class,
"--spring.cloud.task.batch.listener.enable=false");
validateContext();
}
@Test(expected = AssertionError.class)
public void testNoAutoConfigurationBothDisabled() {
- this.applicationContext = SpringApplication.run(JobConfiguration.class ,
+ this.applicationContext = SpringApplication.run(JobConfiguration.class,
"--spring.cloud.task.batch.listener.enable=false --spring.cloud.task.batch.listener.enabled=false");
validateContext();
}
@Test
public void testAutoConfigurationEnable() {
- this.applicationContext = SpringApplication.run(JobConfiguration.class ,
+ this.applicationContext = SpringApplication.run(JobConfiguration.class,
"--spring.cloud.task.batch.listener.enable=true");
validateContext();
}
@Test
public void testAutoConfigurationEnabled() {
- this.applicationContext = SpringApplication.run(JobConfiguration.class ,
+ this.applicationContext = SpringApplication.run(JobConfiguration.class,
"--spring.cloud.task.batch.listener.enabled=true");
validateContext();
}
@@ -132,26 +132,34 @@ public class TaskBatchExecutionListenerTests {
private void validateContext() {
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
- Page page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
+ page.iterator().next().getExecutionId());
- assertEquals(1, jobExecutionIds.size());
- assertEquals(1, taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId());
+ assertThat(jobExecutionIds.size()).isEqualTo(1);
+ assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
+ .getExecutionId()).isEqualTo(1);
}
+
@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 page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
+ page.iterator().next().getExecutionId());
- assertEquals(1, jobExecutionIds.size());
- assertEquals(1, taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId());
+ assertThat(jobExecutionIds.size()).isEqualTo(1);
+ assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
+ .getExecutionId()).isEqualTo(1);
}
@Test
@@ -160,11 +168,13 @@ public class TaskBatchExecutionListenerTests {
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
- Page page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
+ page.iterator().next().getExecutionId());
- assertEquals(0, jobExecutionIds.size());
+ assertThat(jobExecutionIds.size()).isEqualTo(0);
}
@Test
@@ -173,28 +183,39 @@ public class TaskBatchExecutionListenerTests {
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
- Page page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
+ page.iterator().next().getExecutionId());
- assertEquals(1, jobExecutionIds.size());
- assertEquals(1, (long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()));
+ assertThat(jobExecutionIds.size()).isEqualTo(1);
+ assertThat((long) taskExplorer
+ .getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
+ .isEqualTo(1);
}
@Test
public void testMultipleJobs() {
- this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class, ARGS);
+ this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class,
+ ARGS);
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
- Page page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
+ Page page = taskExplorer.findTaskExecutionsByName("application",
+ PageRequest.of(0, 1));
- Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
+ Set jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
+ page.iterator().next().getExecutionId());
- assertEquals(2, jobExecutionIds.size());
+ assertThat(jobExecutionIds.size()).isEqualTo(2);
Iterator jobExecutionIdsIterator = jobExecutionIds.iterator();
- assertEquals(1, (long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()));
- assertEquals(1, (long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()));
+ assertThat((long) taskExplorer
+ .getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
+ .isEqualTo(1);
+ assertThat((long) taskExplorer
+ .getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
+ .isEqualTo(1);
}
@Test
@@ -204,27 +225,26 @@ 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");
- assertEquals(testObject,bean);
+ 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");
- assertEquals(testObject,bean);
+ SimpleJob bean = (SimpleJob) beanPostProcessor
+ .postProcessBeforeInitialization(testObject, "TESTOBJECT");
+ assertThat(bean).isEqualTo(testObject);
}
-
@Test(expected = IllegalArgumentException.class)
public void testBatchExecutionListenerBeanPostProcessorNullJobNames() {
beanPostProcessor(null);
@@ -232,16 +252,14 @@ public class TaskBatchExecutionListenerTests {
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
List jobNames) {
- this.applicationContext = SpringApplication.run(new Class[] {JobConfiguration.class,
- PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
- BatchAutoConfiguration.class,
- TaskBatchAutoConfiguration.class,
- SimpleTaskAutoConfiguration.class,
+ 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.getBean(
- TaskBatchExecutionListenerBeanPostProcessor.class);
+ TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = this.applicationContext
+ .getBean(TaskBatchExecutionListenerBeanPostProcessor.class);
beanPostProcessor.setJobNames(jobNames);
return beanPostProcessor;
@@ -269,16 +287,17 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job() {
- return jobBuilderFactory.get("job")
- .start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("job")
+ .start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
@Override
- public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
+ public RepeatStatus execute(StepContribution contribution,
+ ChunkContext chunkContext) throws Exception {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}
- }).build())
- .build();
+ }).build()).build();
}
+
}
@EnableBatchProcessing
@@ -298,14 +317,18 @@ public class TaskBatchExecutionListenerTests {
return new FactoryBean() {
@Override
public Job getObject() throws Exception {
- 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())
+ return JobFactoryBeanConfiguration.this.jobBuilderFactory.get("job")
+ .start(JobFactoryBeanConfiguration.this.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();
}
@@ -320,6 +343,7 @@ public class TaskBatchExecutionListenerTests {
}
};
}
+
}
@EnableBatchProcessing
@@ -336,34 +360,31 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job() {
- return jobBuilderFactory.get("job")
- .start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("job")
+ .start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
@Override
- public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
+ public RepeatStatus execute(StepContribution contribution,
+ ChunkContext chunkContext) throws Exception {
System.out.println("Executed");
return RepeatStatus.FINISHED;
}
- }).build())
- .build();
+ }).build()).build();
}
@Bean
@Primary
public DataSource myDataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
- .setType(EmbeddedDatabaseType.H2)
- .setName("myDataSource");
+ .setType(EmbeddedDatabaseType.H2).setName("myDataSource");
return builder.build();
}
@Bean
public DataSource incorrectDataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
- .setType(EmbeddedDatabaseType.H2)
- .setName("incorrectDataSource");
+ .setType(EmbeddedDatabaseType.H2).setName("incorrectDataSource");
return builder.build();
}
-
@Bean
public TaskConfigurer taskConfigurer() {
@@ -374,6 +395,7 @@ public class TaskBatchExecutionListenerTests {
public DefaultBatchConfigurer batchConfigurer() {
return new DefaultBatchConfigurer(myDataSource());
}
+
}
@EnableBatchProcessing
@@ -390,28 +412,30 @@ public class TaskBatchExecutionListenerTests {
@Bean
public Job job1() {
- return jobBuilderFactory.get("job1")
- .start(stepBuilderFactory.get("job1step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("job1").start(
+ this.stepBuilderFactory.get("job1step1").tasklet(new Tasklet() {
@Override
- public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
+ public RepeatStatus execute(StepContribution contribution,
+ ChunkContext chunkContext) throws Exception {
System.out.println("Executed job1");
return RepeatStatus.FINISHED;
}
- }).build())
- .build();
+ }).build()).build();
}
@Bean
public Job job2() {
- return jobBuilderFactory.get("job2")
- .start(stepBuilderFactory.get("job2step1").tasklet(new Tasklet() {
+ return this.jobBuilderFactory.get("job2").start(
+ this.stepBuilderFactory.get("job2step1").tasklet(new Tasklet() {
@Override
- public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
+ public RepeatStatus execute(StepContribution contribution,
+ ChunkContext chunkContext) throws Exception {
System.out.println("Executed job2");
return RepeatStatus.FINISHED;
}
- }).build())
- .build();
+ }).build()).build();
}
+
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java
index 298e3821..6a047eef 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2017 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.ArrayList;
@@ -50,9 +51,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.mock.env.MockEnvironment;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -64,6 +63,9 @@ import static org.mockito.Mockito.when;
*/
public class DeployerPartitionHandlerTests {
+ @Captor
+ ArgumentCaptor appDeploymentRequestArgumentCaptor;
+
@Mock
private TaskLauncher taskLauncher;
@@ -81,8 +83,6 @@ public class DeployerPartitionHandlerTests {
private Environment environment;
- @Captor ArgumentCaptor appDeploymentRequestArgumentCaptor;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -91,27 +91,33 @@ public class DeployerPartitionHandlerTests {
@Test
public void testConstructorValidation() {
- validateConstructorValidation(null, null, null, null, "A taskLauncher is required");
- validateConstructorValidation(this.taskLauncher, null, null, null, "A jobExplorer is required");
- validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null, "A resource is required");
- validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null, "A step name is required");
+ validateConstructorValidation(null, null, null, null,
+ "A taskLauncher is required");
+ validateConstructorValidation(this.taskLauncher, null, null, null,
+ "A jobExplorer is required");
+ validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null,
+ "A resource is required");
+ validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
+ null, "A step name is required");
- new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step-name");
+ new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
+ "step-name");
}
@Test
public void testNoPartitions() throws Exception {
- DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step1");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
StepExecution stepExecution = new StepExecution("step1", new JobExecution(1L));
- when(this.splitter.split(stepExecution, 1)).thenReturn(new HashSet());
+ when(this.splitter.split(stepExecution, 1)).thenReturn(new HashSet<>());
Collection results = handler.handle(this.splitter, stepExecution);
verify(this.taskLauncher, never()).launch((AppDeploymentRequest) any());
- assertTrue(results.isEmpty());
+ assertThat(results.isEmpty()).isTrue();
}
@Test
@@ -121,9 +127,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
TaskExecution taskExecution = new TaskExecution();
@@ -133,32 +141,40 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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();
- assertEquals(this.resource, request.getResource());
- assertEquals(0, request.getDeploymentProperties().size());
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ assertThat(request.getDeploymentProperties().size()).isEqualTo(0);
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
+ 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();
- assertEquals(1, results.size());
+ assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
- assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus());
- assertEquals("step1:partition1", resultStepExecution.getStepName());
+ assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
+ assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
@Test
@@ -168,49 +184,64 @@ 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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
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 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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();
- assertEquals(this.resource, request.getResource());
- assertEquals(0, request.getDeploymentProperties().size());
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ assertThat(request.getDeploymentProperties().size()).isEqualTo(0);
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().isEmpty());
- assertEquals("1", request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
- assertEquals("4", request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
- assertEquals("step1", request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME));
- assertEquals("partitionedJobTask_partitionedJob_step1:partition1", request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME));
- assertEquals("55", request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID));
+ assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
+ assertThat(request.getCommandlineArguments().isEmpty()).isTrue();
+ assertThat(request.getDefinition().getProperties()
+ .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
+ .isEqualTo("1");
+ assertThat(request.getDefinition().getProperties()
+ .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
+ .isEqualTo("4");
+ assertThat(request.getDefinition().getProperties()
+ .get(DeployerPartitionHandler.SPRING_CLOUD_TASK_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");
- assertEquals(1, results.size());
+ assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
- assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus());
- assertEquals("step1:partition1", resultStepExecution.getStepName());
+ assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
+ assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
@Test
@@ -220,13 +251,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
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");
@@ -234,7 +267,8 @@ 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();
@@ -242,10 +276,13 @@ 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();
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55")));
+ assertThat(request.getCommandlineArguments().contains(formatArgs(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55")))
+ .isTrue();
}
@Test
@@ -255,15 +292,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
TaskExecution taskExecution = new TaskExecution();
@@ -277,18 +318,24 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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 allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
+ List allValues = this.appDeploymentRequestArgumentCaptor
+ .getAllValues();
validateAppDeploymentRequests(allValues, 3);
@@ -302,15 +349,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
handler.setMaxWorkers(2);
@@ -325,18 +376,24 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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 allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
+ List allValues = this.appDeploymentRequestArgumentCaptor
+ .getAllValues();
validateAppDeploymentRequests(allValues, 3);
@@ -350,15 +407,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
handler.setMaxWorkers(2);
@@ -373,18 +434,24 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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 allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
+ List allValues = this.appDeploymentRequestArgumentCaptor
+ .getAllValues();
validateAppDeploymentRequests(allValues, 3);
@@ -395,13 +462,13 @@ public class DeployerPartitionHandlerTests {
StepExecution curResult = resultsIterator.next();
if (curResult.getStepName().equals("step1:partition2")) {
- assertEquals(BatchStatus.FAILED, curResult.getStatus());
+ assertThat(curResult.getStatus()).isEqualTo(BatchStatus.FAILED);
}
else {
- assertEquals(BatchStatus.COMPLETED, curResult.getStatus());
+ assertThat(curResult.getStatus()).isEqualTo(BatchStatus.COMPLETED);
}
- assertTrue(!names.contains(curResult.getStepName()));
+ assertThat(!names.contains(curResult.getStepName())).isTrue();
names.add(curResult.getStepName());
}
}
@@ -413,15 +480,18 @@ 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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
Map environmentParameters = new HashMap<>(2);
environmentParameters.put("foo", "bar");
environmentParameters.put("baz", "qux");
- SimpleEnvironmentVariablesProvider environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(this.environment);
+ SimpleEnvironmentVariablesProvider environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
+ this.environment);
environmentVariablesProvider.setEnvironmentProperties(environmentParameters);
handler.setEnvironmentVariablesProvider(environmentVariablesProvider);
@@ -432,33 +502,41 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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();
- assertEquals(this.resource, request.getResource());
- assertEquals(2, request.getDefinition().getProperties().size());
- assertEquals("bar", request.getDefinition().getProperties().get("foo"));
- assertEquals("qux", request.getDefinition().getProperties().get("baz"));
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ assertThat(request.getDefinition().getProperties().size()).isEqualTo(2);
+ assertThat(request.getDefinition().getProperties().get("foo")).isEqualTo("bar");
+ assertThat(request.getDefinition().getProperties().get("baz")).isEqualTo("qux");
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
+ 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();
- assertEquals(1, results.size());
+ assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
- assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus());
- assertEquals("step1:partition1", resultStepExecution.getStepName());
+ assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
+ assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
@Test
@@ -471,16 +549,19 @@ 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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
Map environmentParameters = new HashMap<>(2);
environmentParameters.put("foo", "bar");
environmentParameters.put("baz", "qux");
- SimpleEnvironmentVariablesProvider environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(this.environment);
+ SimpleEnvironmentVariablesProvider environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
+ this.environment);
environmentVariablesProvider.setEnvironmentProperties(environmentParameters);
handler.setEnvironmentVariablesProvider(environmentVariablesProvider);
@@ -491,34 +572,43 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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();
- assertEquals(this.resource, request.getResource());
- assertEquals(3, request.getDefinition().getProperties().size());
- assertEquals("bar", request.getDefinition().getProperties().get("foo"));
- assertEquals("qux", request.getDefinition().getProperties().get("baz"));
- assertEquals("batch", request.getDefinition().getProperties().get("task"));
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ 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");
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
+ 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();
- assertEquals(1, results.size());
+ assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
- assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus());
- assertEquals("step1:partition1", resultStepExecution.getStepName());
+ assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
+ assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
@Test
@@ -528,12 +618,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
handler.setPollInterval(20000L);
@@ -547,26 +640,33 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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 allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
+ List allRequests = this.appDeploymentRequestArgumentCaptor
+ .getAllValues();
validateAppDeploymentRequests(allRequests, 2);
validateStepExecutionResults(results);
- assertTrue("Time difference was too small: " + (endTime.getTime() - startTime.getTime()),
- endTime.getTime() - startTime.getTime() >= 19999);
+ assertThat(endTime.getTime() - startTime.getTime() >= 19999)
+ .as("Time difference was too small: "
+ + (endTime.getTime() - startTime.getTime()))
+ .isTrue();
}
@Test(expected = TimeoutException.class)
@@ -576,12 +676,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
handler.setPollInterval(20000L);
@@ -596,8 +699,10 @@ 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();
@@ -613,12 +718,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
handler.setGridSize(2);
@@ -631,18 +739,23 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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 allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
+ List allRequests = this.appDeploymentRequestArgumentCaptor
+ .getAllValues();
validateAppDeploymentRequests(allRequests, 2);
@@ -656,9 +769,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");
+ DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
+ this.jobExplorer, this.resource, "step1");
handler.setEnvironment(this.environment);
Map deploymentProperties = new HashMap<>(2);
@@ -674,48 +789,59 @@ 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 results = handler.handle(this.splitter, masterStepExecution);
+ Collection 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();
- assertEquals(this.resource, request.getResource());
- assertEquals(2, request.getDeploymentProperties().size());
- assertEquals("bar", request.getDeploymentProperties().get("foo"));
- assertEquals("qux", request.getDeploymentProperties().get("baz"));
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ assertThat(request.getDeploymentProperties().size()).isEqualTo(2);
+ assertThat(request.getDeploymentProperties().get("foo")).isEqualTo("bar");
+ assertThat(request.getDeploymentProperties().get("baz")).isEqualTo("qux");
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
+ 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();
- assertEquals(1, results.size());
+ assertThat(results.size()).isEqualTo(1);
StepExecution resultStepExecution = results.iterator().next();
- assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus());
- assertEquals("step1:partition1", resultStepExecution.getStepName());
+ assertThat(resultStepExecution.getStatus()).isEqualTo(BatchStatus.COMPLETED);
+ assertThat(resultStepExecution.getStepName()).isEqualTo("step1:partition1");
}
private String formatArgs(String key, String value) {
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;
}
@@ -738,14 +864,15 @@ public class DeployerPartitionHandlerTests {
while (resultsIterator.hasNext()) {
StepExecution curResult = resultsIterator.next();
- assertEquals(BatchStatus.COMPLETED, curResult.getStatus());
+ assertThat(curResult.getStatus()).isEqualTo(BatchStatus.COMPLETED);
- assertTrue(!names.contains(curResult.getStepName()));
+ assertThat(!names.contains(curResult.getStepName())).isTrue();
names.add(curResult.getStepName());
}
}
- private void validateAppDeploymentRequests(List allRequests, int numberOfPartitions) {
+ private void validateAppDeploymentRequests(List allRequests,
+ int numberOfPartitions) {
Collections.sort(allRequests, new Comparator() {
@Override
public int compare(AppDeploymentRequest o1, AppDeploymentRequest o2) {
@@ -753,7 +880,8 @@ 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;
}
@@ -763,7 +891,8 @@ 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;
}
@@ -775,23 +904,33 @@ public class DeployerPartitionHandlerTests {
for (int i = 4; i < (numberOfPartitions + 4); i++) {
AppDeploymentRequest request = allRequests.get(i - 4);
- assertEquals(this.resource, request.getResource());
- assertEquals(0, request.getDeploymentProperties().size());
+ assertThat(request.getResource()).isEqualTo(this.resource);
+ assertThat(request.getDeploymentProperties().size()).isEqualTo(0);
AppDefinition appDefinition = request.getDefinition();
- assertEquals("partitionedJobTask", appDefinition.getName());
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))));
- assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")));
+ assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
+ assertThat(request.getCommandlineArguments().contains(formatArgs(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1")))
+ .isTrue();
+ assertThat(request.getCommandlineArguments()
+ .contains(formatArgs(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
+ String.valueOf(i)))).isTrue();
+ assertThat(request.getCommandlineArguments().contains(formatArgs(
+ DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1")))
+ .isTrue();
}
}
- private void validateConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource, String stepName, String expectedMessage) {
+ private void validateConstructorValidation(TaskLauncher taskLauncher,
+ JobExplorer jobExplorer, Resource resource, String stepName,
+ String expectedMessage) {
try {
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName);
}
catch (IllegalArgumentException iae) {
- assertEquals(expectedMessage, iae.getMessage());
+ assertThat(iae.getMessage()).isEqualTo(expectedMessage);
}
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java
index 41fd97a6..15e5a170 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerStepExecutionHandlerTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import org.junit.Before;
@@ -35,7 +36,7 @@ import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.core.env.Environment;
import org.springframework.test.util.ReflectionTestUtils;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -70,7 +71,8 @@ public class DeployerStepExecutionHandlerTests {
public void setUp() {
MockitoAnnotations.initMocks(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);
}
@@ -78,69 +80,116 @@ 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 name is required", new String[] {DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_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,
+ 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) {
- assertEquals("The step requested cannot be found in the provided BeanFactory", iae.getMessage());
+ 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) {
- assertEquals("No StepExecution could be located for step execution id 2 within job execution 1", nsse.getMessage());
+ 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);
- handler.run();
+ this.handler.run();
verify(this.step).execute(workerStep);
verifyZeroInteractions(this.jobRepository);
@@ -148,51 +197,87 @@ 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);
- handler.run();
+ this.handler.run();
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
- assertEquals(BatchStatus.STOPPED, this.stepExecutionArgumentCaptor.getValue().getStatus());
+ 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);
- handler.run();
+ this.handler.run();
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
- assertEquals(BatchStatus.FAILED, this.stepExecutionArgumentCaptor.getValue().getStatus());
+ 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);
@@ -202,17 +287,18 @@ public class DeployerStepExecutionHandlerTests {
this.handler.run();
}
catch (IllegalArgumentException iae) {
- assertEquals(errorMessage, iae.getMessage());
+ assertThat(iae.getMessage()).isEqualTo(errorMessage);
}
}
-
- 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);
}
catch (IllegalArgumentException iae) {
- assertEquals(message, iae.getMessage());
+ assertThat(iae.getMessage()).isEqualTo(message);
}
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java
index 65e695db..27020d96 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/NoOpEnvironmentVariablesProviderTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael Minella
@@ -35,11 +37,14 @@ public class NoOpEnvironmentVariablesProviderTests {
@Test
public void test() {
- Map environmentVariables = this.provider.getEnvironmentVariables(null);
- assertNotNull(environmentVariables);
- assertTrue(environmentVariables.isEmpty());
+ Map environmentVariables = this.provider
+ .getEnvironmentVariables(null);
+ assertThat(environmentVariables).isNotNull();
+ assertThat(environmentVariables.isEmpty()).isTrue();
- Map environmentVariables2 = this.provider.getEnvironmentVariables(null);
- assertTrue(environmentVariables == environmentVariables2);
+ Map environmentVariables2 = this.provider
+ .getEnvironmentVariables(null);
+ assertThat(environmentVariables == environmentVariables2).isTrue();
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java
index aeb38b9f..a5e53e8e 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/PassThroughCommandLineArgsProviderTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,13 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
-import static org.junit.Assert.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael Minella
@@ -39,8 +41,9 @@ public class PassThroughCommandLineArgsProviderTests {
List commandLineArgs = provider.getCommandLineArgs(null);
- assertEquals("foo", commandLineArgs.get(0));
- assertEquals("bar", commandLineArgs.get(1));
- assertEquals("baz", commandLineArgs.get(2));
+ assertThat(commandLineArgs.get(0)).isEqualTo("foo");
+ assertThat(commandLineArgs.get(1)).isEqualTo("bar");
+ assertThat(commandLineArgs.get(2)).isEqualTo("baz");
}
+
}
diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java
index 4855db57..738fa1dd 100644
--- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java
+++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/SimpleCommandLineArgsProviderTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.batch.partition;
import java.util.ArrayList;
@@ -23,7 +24,7 @@ import org.junit.Test;
import org.springframework.cloud.task.repository.TaskExecution;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michael Minella
@@ -35,13 +36,14 @@ 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 commandLineArgs = provider.getCommandLineArgs(null);
- assertEquals("foo", commandLineArgs.get(0));
- assertEquals("bar", commandLineArgs.get(1));
- assertEquals("baz", commandLineArgs.get(2));
+ assertThat(commandLineArgs.get(0)).isEqualTo("foo");
+ assertThat(commandLineArgs.get(1)).isEqualTo("bar");
+ assertThat(commandLineArgs.get(2)).isEqualTo("baz");
}
@Test
@@ -54,17 +56,18 @@ 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 commandLineArgs = provider.getCommandLineArgs(null);
- assertEquals("foo", commandLineArgs.get(0));
- assertEquals("bar", commandLineArgs.get(1));
- assertEquals("baz", commandLineArgs.get(2));
- assertEquals("one", commandLineArgs.get(3));
- assertEquals("two", commandLineArgs.get(4));
- assertEquals("three", commandLineArgs.get(5));
+ assertThat(commandLineArgs.get(0)).isEqualTo("foo");
+ assertThat(commandLineArgs.get(1)).isEqualTo("bar");
+ assertThat(commandLineArgs.get(2)).isEqualTo("baz");
+ assertThat(commandLineArgs.get(3)).isEqualTo("one");
+ assertThat(commandLineArgs.get(4)).isEqualTo("two");
+ assertThat(commandLineArgs.get(5)).isEqualTo("three");
}
@Test
@@ -73,14 +76,16 @@ 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 commandLineArgs = provider.getCommandLineArgs(null);
- assertEquals(3, commandLineArgs.size());
- assertEquals("foo", commandLineArgs.get(0));
- assertEquals("bar", commandLineArgs.get(1));
- assertEquals("baz", commandLineArgs.get(2));
+ assertThat(commandLineArgs.size()).isEqualTo(3);
+ assertThat(commandLineArgs.get(0)).isEqualTo("foo");
+ assertThat(commandLineArgs.get(1)).isEqualTo("bar");
+ assertThat(commandLineArgs.get(2)).isEqualTo("baz");
}
+
}
diff --git a/spring-cloud-task-core/pom.xml b/spring-cloud-task-core/pom.xml
index 8b40b38e..803e8629 100755
--- a/spring-cloud-task-core/pom.xml
+++ b/spring-cloud-task-core/pom.xml
@@ -1,5 +1,7 @@
-
+
4.0.0
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurer.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurer.java
index f95465b3..65e2d62a 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurer.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/DefaultTaskConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,13 +36,14 @@ import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
/**
- * Default implementation of the TaskConfigurer interface. If no {@link TaskConfigurer}
- * implementation is present, then this configuration will be used.
- * The following defaults will be used:
+ * Default implementation of the TaskConfigurer interface. If no {@link TaskConfigurer}
+ * implementation is present, then this configuration will be used. The following defaults
+ * will be used:
*
- * - {@link SimpleTaskRepository} is the default {@link TaskRepository} returned.
- * If a data source is present then a data will be stored in the database {@link JdbcTaskExecutionDao} else it will
- * be stored in a map {@link MapTaskExecutionDao}.
+ *
- {@link SimpleTaskRepository} is the default {@link TaskRepository} returned. If a
+ * data source is present then a data will be stored in the database
+ * {@link JdbcTaskExecutionDao} else it will be stored in a map
+ * {@link MapTaskExecutionDao}.
*
*
* @author Glenn Renfro
@@ -67,12 +68,11 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
}
/**
- * Initializes the DefaultTaskConfigurer and sets the default table prefix
- * to {@link TaskProperties#DEFAULT_TABLE_PREFIX}.
- *
+ * Initializes the DefaultTaskConfigurer and sets the default table prefix to
+ * {@link TaskProperties#DEFAULT_TABLE_PREFIX}.
* @param dataSource references the {@link DataSource} to be used as the Task
- * repository. If none is provided, a Map will be used (not recommended for
- * production use.
+ * repository. If none is provided, a Map will be used (not recommended for production
+ * use.
*/
public DefaultTaskConfigurer(DataSource dataSource) {
this(dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, null);
@@ -80,9 +80,8 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
/**
* Initializes the DefaultTaskConfigurer.
- *
- * @param tablePrefix the prefix to apply to the task table names used by
- * task infrastructure.
+ * @param tablePrefix the prefix to apply to the task table names used by task
+ * infrastructure.
*/
public DefaultTaskConfigurer(String tablePrefix) {
this(null, tablePrefix, null);
@@ -90,23 +89,23 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
/**
* Initializes the DefaultTaskConfigurer.
- *
* @param dataSource references the {@link DataSource} to be used as the Task
- * repository. If none is provided, a Map will be used (not recommended for
- * production use.
- * @param tablePrefix the prefix to apply to the task table names used by
- * task infrastructure.
+ * repository. If none is provided, a Map will be used (not recommended for production
+ * use.
+ * @param tablePrefix the prefix to apply to the task table names used by task
+ * infrastructure.
* @param context the context to be used.
*/
- public DefaultTaskConfigurer(DataSource dataSource, String tablePrefix, ApplicationContext context) {
+ public DefaultTaskConfigurer(DataSource dataSource, String tablePrefix,
+ ApplicationContext context) {
this.dataSource = dataSource;
this.context = context;
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean;
- if(this.dataSource != null) {
- taskExecutionDaoFactoryBean = new
- TaskExecutionDaoFactoryBean(this.dataSource, tablePrefix);
+ if (this.dataSource != null) {
+ taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(this.dataSource,
+ tablePrefix);
}
else {
taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean();
@@ -137,22 +136,27 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
if (isDataSourceAvailable()) {
try {
Class.forName("javax.persistence.EntityManager");
- if (this.context != null && this.context.getBeanNamesForType(EntityManager.class).length > 0) {
- logger.debug("EntityManager was found, using JpaTransactionManager");
+ if (this.context != null && this.context
+ .getBeanNamesForType(EntityManager.class).length > 0) {
+ logger.debug(
+ "EntityManager was found, using JpaTransactionManager");
this.transactionManager = new JpaTransactionManager();
}
}
catch (ClassNotFoundException ignore) {
- logger.debug("No EntityManager was found, using DataSourceTransactionManager");
+ logger.debug(
+ "No EntityManager was found, using DataSourceTransactionManager");
}
finally {
if (this.transactionManager == null) {
- this.transactionManager = new DataSourceTransactionManager(this.dataSource);
+ this.transactionManager = new DataSourceTransactionManager(
+ this.dataSource);
}
}
}
else {
- logger.debug("No DataSource was found, using ResourcelessTransactionManager");
+ logger.debug(
+ "No DataSource was found, using ResourcelessTransactionManager");
this.transactionManager = new ResourcelessTransactionManager();
}
}
@@ -163,4 +167,5 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
private boolean isDataSourceAvailable() {
return this.dataSource != null;
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/EnableTask.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/EnableTask.java
index 11e43db6..75478835 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/EnableTask.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/EnableTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,13 +23,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.springframework.cloud.task.repository.TaskRepository;
import org.springframework.context.annotation.Import;
/**
*
- * Enables the {@link org.springframework.cloud.task.listener.TaskLifecycleListener}
- * so that the features of Spring Cloud Task will be applied.
+ * Enables the {@link org.springframework.cloud.task.listener.TaskLifecycleListener} so
+ * that the features of Spring Cloud Task will be applied.
*
*
* @Configuration
@@ -39,13 +38,14 @@ import org.springframework.context.annotation.Import;
* @Bean
* public MyCommandLineRunner myCommandLineRunner() {
* return new MyCommandLineRunner()
- * }
+ * }
* }
*
*
- * Note that only one of your configuration classes needs to have the @EnableTask
- * annotation. Once you have an @EnableTask class in your configuration
- * the task will have the Spring Cloud Task features available.
+ * Note that only one of your configuration classes needs to have the
+ * @EnableTask annotation. Once you have an
+ * @EnableTask class in your configuration the task will have the Spring
+ * Cloud Task features available.
*
* @author Glenn Renfro
*
@@ -56,4 +56,5 @@ import org.springframework.context.annotation.Import;
@Inherited
@Import(TaskLifecycleConfiguration.class)
public @interface EnableTask {
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SimpleTaskAutoConfiguration.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SimpleTaskAutoConfiguration.java
index fdf4c945..c4fe1fc6 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SimpleTaskAutoConfiguration.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SimpleTaskAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,10 +54,13 @@ import org.springframework.util.CollectionUtils;
@Configuration
@EnableTransactionManagement
@EnableConfigurationProperties(TaskProperties.class)
+// @checkstyle:off
@ConditionalOnProperty(prefix = "spring.cloud.task.autoconfiguration", name = "enabled", havingValue = "true", matchIfMissing = true)
+// @checkstyle:on
public class SimpleTaskAutoConfiguration {
- protected static final Log logger = LogFactory.getLog(SimpleTaskAutoConfiguration.class);
+ protected static final Log logger = LogFactory
+ .getLog(SimpleTaskAutoConfiguration.class);
@Autowired(required = false)
private Collection dataSources;
@@ -80,7 +83,7 @@ public class SimpleTaskAutoConfiguration {
private TaskExplorer taskExplorer;
@Bean
- public TaskRepository taskRepository(){
+ public TaskRepository taskRepository() {
return this.taskRepository;
}
@@ -104,7 +107,7 @@ public class SimpleTaskAutoConfiguration {
public TaskRepositoryInitializer taskRepositoryInitializer() {
TaskRepositoryInitializer taskRepositoryInitializer = new TaskRepositoryInitializer();
DataSource initializerDataSource = getDefaultConfigurer().getTaskDataSource();
- if(initializerDataSource != null) {
+ if (initializerDataSource != null) {
taskRepositoryInitializer.setDataSource(initializerDataSource);
}
@@ -116,7 +119,7 @@ public class SimpleTaskAutoConfiguration {
*/
@PostConstruct
protected void initialize() {
- if (initialized) {
+ if (this.initialized) {
return;
}
@@ -128,7 +131,7 @@ public class SimpleTaskAutoConfiguration {
this.taskRepository = taskConfigurer.getTaskRepository();
this.platformTransactionManager = taskConfigurer.getTransactionManager();
this.taskExplorer = taskConfigurer.getTaskExplorer();
- initialized = true;
+ this.initialized = true;
}
private TaskConfigurer getDefaultConfigurer() {
@@ -138,36 +141,44 @@ public class SimpleTaskAutoConfiguration {
if (configurers < 1) {
TaskConfigurer taskConfigurer;
- if(!CollectionUtils.isEmpty(this.dataSources) && this.dataSources.size() == 1) {
+ if (!CollectionUtils.isEmpty(this.dataSources)
+ && this.dataSources.size() == 1) {
taskConfigurer = new DefaultTaskConfigurer(
this.dataSources.iterator().next(),
- taskProperties.getTablePrefix(), context);
+ this.taskProperties.getTablePrefix(), this.context);
}
else {
- taskConfigurer = new DefaultTaskConfigurer(taskProperties.getTablePrefix());
+ taskConfigurer = new DefaultTaskConfigurer(
+ this.taskProperties.getTablePrefix());
}
- this.context.getBeanFactory().registerSingleton("taskConfigurer", taskConfigurer);
+ this.context.getBeanFactory().registerSingleton("taskConfigurer",
+ taskConfigurer);
return taskConfigurer;
}
else {
- if(configurers == 1) {
+ if (configurers == 1) {
return this.context.getBean(TaskConfigurer.class);
}
else {
- throw new IllegalStateException("Expected one TaskConfigurer but found " + configurers);
+ throw new IllegalStateException(
+ "Expected one TaskConfigurer but found " + configurers);
}
}
}
private void verifyEnvironment() {
int configurers = this.context.getBeanNamesForType(TaskConfigurer.class).length;
- // retrieve the count of dataSources (without instantiating them) excluding DataSource proxy beans
- long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
+ // retrieve the count of dataSources (without instantiating them) excluding
+ // DataSource proxy beans
+ long dataSources = Arrays
+ .stream(this.context.getBeanNamesForType(DataSource.class))
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).count();
- if(configurers == 0 && dataSources > 1) {
- throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than" +
- " one DataSource, found " + dataSources);
+ if (configurers == 0 && dataSources > 1) {
+ throw new IllegalStateException(
+ "To use the default TaskConfigurer the context must contain no more than"
+ + " one DataSource, found " + dataSources);
}
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SingleInstanceTaskListener.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SingleInstanceTaskListener.java
index b2b155d3..23e1afa4 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SingleInstanceTaskListener.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/SingleInstanceTaskListener.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.configuration;
@@ -39,10 +39,10 @@ import org.springframework.integration.support.leader.LockRegistryLeaderInitiato
import org.springframework.integration.support.locks.LockRegistry;
/**
- * When spring.cloud.task.single-instance-enabled is set to true this listener will create a lock for the task
- * based on the spring.cloud.task.name. If a lock already exists this Listener will throw
- * a TaskExecutionException. If this listener is added manually, then it should
- * be added as the first listener in the chain.
+ * When spring.cloud.task.single-instance-enabled is set to true this listener will create
+ * a lock for the task based on the spring.cloud.task.name. If a lock already exists this
+ * Listener will throw a TaskExecutionException. If this listener is added manually, then
+ * it should be added as the first listener in the chain.
*
* @author Glenn Renfro
* @since 2.0.0
@@ -68,19 +68,18 @@ public class SingleInstanceTaskListener implements ApplicationListenerTaskConfigurer directly unless they are using it to supply the implementations
- * for Spring Beans.
+ * Provides a strategy interface for providing configuration customization to the task
+ * system. Users should not directly use getter methods from a TaskConfigurer
+ * directly unless they are using it to supply the implementations for Spring Beans.
*
* @author Glenn Renfro
*/
@@ -34,7 +33,6 @@ public interface TaskConfigurer {
/**
* Create a {@link TaskRepository} for the Task.
- *
* @return A TaskRepository
*/
TaskRepository getTaskRepository();
@@ -42,23 +40,22 @@ public interface TaskConfigurer {
/**
* Create a {@link PlatformTransactionManager} for use with the
* TaskRepository.
- *
* @return A PlatformTransactionManager
*/
PlatformTransactionManager getTransactionManager();
/**
* Create a {@link TaskExplorer} for the task.
- *
* @return a TaskExplorer
*/
TaskExplorer getTaskExplorer();
/**
- * Retrieves the {@link DataSource} that will be used for task operations. If a
- * DataSource is not being used for the implemented TaskConfigurer this
- * method will return null.
+ * Retrieves the {@link DataSource} that will be used for task operations. If a
+ * DataSource is not being used for the implemented TaskConfigurer this method will
+ * return null.
* @return {@link DataSource} that will be used for task operations.
*/
DataSource getTaskDataSource();
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskLifecycleConfiguration.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskLifecycleConfiguration.java
index df49c67c..e6cdcfd2 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskLifecycleConfiguration.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskLifecycleConfiguration.java
@@ -1,17 +1,17 @@
/*
- * Copyright 2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.configuration;
@@ -43,7 +43,8 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class TaskLifecycleConfiguration {
- protected static final Log logger = LogFactory.getLog(TaskLifecycleConfiguration.class);
+ protected static final Log logger = LogFactory
+ .getLog(TaskLifecycleConfiguration.class);
private TaskProperties taskProperties;
@@ -63,10 +64,8 @@ public class TaskLifecycleConfiguration {
@Autowired
public TaskLifecycleConfiguration(TaskProperties taskProperties,
- ConfigurableApplicationContext context,
- TaskRepository taskRepository,
- TaskExplorer taskExplorer,
- TaskNameResolver taskNameResolver,
+ ConfigurableApplicationContext context, TaskRepository taskRepository,
+ TaskExplorer taskExplorer, TaskNameResolver taskNameResolver,
ObjectProvider applicationArguments) {
this.taskProperties = taskProperties;
@@ -88,15 +87,13 @@ public class TaskLifecycleConfiguration {
@PostConstruct
protected void initialize() {
if (!this.initialized) {
- this.taskLifecycleListener =
- new TaskLifecycleListener(this.taskRepository,
- this.taskNameResolver,
- this.applicationArguments,
- this.taskExplorer,
- this.taskProperties,
- new TaskListenerExecutorObjectFactory(context));
+ this.taskLifecycleListener = new TaskLifecycleListener(this.taskRepository,
+ this.taskNameResolver, this.applicationArguments, this.taskExplorer,
+ this.taskProperties,
+ new TaskListenerExecutorObjectFactory(this.context));
this.initialized = true;
}
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskProperties.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskProperties.java
index efd7d4ce..e956f31f 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskProperties.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/TaskProperties.java
@@ -1,22 +1,21 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.springframework.cloud.task.configuration;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,11 +31,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.cloud.task")
public class TaskProperties {
+ /**
+ * Default table prefix for Spring Cloud Task.
+ */
+ public static final String DEFAULT_TABLE_PREFIX = "TASK_";
+
private static final int DEFAULT_CHECK_INTERVAL = 500;
private static final Log logger = LogFactory.getLog(TaskProperties.class);
-
- public static final String DEFAULT_TABLE_PREFIX = "TASK_";
/**
* An id that can be associated with a task.
@@ -49,8 +51,8 @@ public class TaskProperties {
private Long executionid;
/**
- * The id of the parent task execution id that launched this task execution.
- * Defaults to null if task execution had no parent.
+ * The id of the parent task execution id that launched this task execution. Defaults
+ * to null if task execution had no parent.
*/
private Long parentExecutionId;
@@ -60,35 +62,34 @@ public class TaskProperties {
private String tablePrefix = DEFAULT_TABLE_PREFIX;
/**
- * When set to true the context is closed at the end of the task. Else
- * the context remains open.
+ * When set to true the context is closed at the end of the task. Else the context
+ * remains open.
*/
private Boolean closecontextEnabled = false;
/**
- * When set to true it
- * will check to see if a task execution with the same task name is already
- * running. If a task is still running then it will throw a
- * {@link org.springframework.cloud.task.listener.TaskExecutionException}.
- * When task execution ends the lock is released.
+ * When set to true it will check to see if a task execution with the same task name
+ * is already running. If a task is still running then it will throw a
+ * {@link org.springframework.cloud.task.listener.TaskExecutionException}. When task
+ * execution ends the lock is released.
*/
private boolean singleInstanceEnabled = false;
/**
- * Declares the maximum amount of time (in millis) that a task execution can
- * hold a lock to prevent another task from executing with a specific task
- * name when the single-instance-enabled is set to true. Default time is: Integer.MAX_VALUE.
+ * Declares the maximum amount of time (in millis) that a task execution can hold a
+ * lock to prevent another task from executing with a specific task name when the
+ * single-instance-enabled is set to true. Default time is: Integer.MAX_VALUE.
*/
private int singleInstanceLockTtl = Integer.MAX_VALUE;
/**
- * Declares the time (in millis) that a task execution will wait between
- * checks. Default time is: 500 millis.
+ * Declares the time (in millis) that a task execution will wait between checks.
+ * Default time is: 500 millis.
*/
private int singleInstanceLockCheckInterval = DEFAULT_CHECK_INTERVAL;
public String getExternalExecutionId() {
- return externalExecutionId;
+ return this.externalExecutionId;
}
public void setExternalExecutionId(String externalExecutionId) {
@@ -96,7 +97,7 @@ public class TaskProperties {
}
public Long getExecutionid() {
- return executionid;
+ return this.executionid;
}
public void setExecutionid(Long executionid) {
@@ -104,7 +105,7 @@ public class TaskProperties {
}
public Boolean getClosecontextEnabled() {
- return closecontextEnabled;
+ return this.closecontextEnabled;
}
public void setClosecontextEnabled(Boolean closecontextEnabled) {
@@ -112,7 +113,7 @@ public class TaskProperties {
}
public String getTablePrefix() {
- return tablePrefix;
+ return this.tablePrefix;
}
public void setTablePrefix(String tablePrefix) {
@@ -120,7 +121,7 @@ public class TaskProperties {
}
public Long getParentExecutionId() {
- return parentExecutionId;
+ return this.parentExecutionId;
}
public void setParentExecutionId(Long parentExecutionId) {
@@ -128,7 +129,7 @@ public class TaskProperties {
}
public boolean getSingleInstanceEnabled() {
- return singleInstanceEnabled;
+ return this.singleInstanceEnabled;
}
public void setSingleInstanceEnabled(boolean singleInstanceEnabled) {
@@ -136,7 +137,7 @@ public class TaskProperties {
}
public int getSingleInstanceLockTtl() {
- return singleInstanceLockTtl;
+ return this.singleInstanceLockTtl;
}
public void setSingleInstanceLockTtl(int singleInstanceLockTtl) {
@@ -144,10 +145,11 @@ public class TaskProperties {
}
public int getSingleInstanceLockCheckInterval() {
- return singleInstanceLockCheckInterval;
+ return this.singleInstanceLockCheckInterval;
}
public void setSingleInstanceLockCheckInterval(int singleInstanceLockCheckInterval) {
this.singleInstanceLockCheckInterval = singleInstanceLockCheckInterval;
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/package-info.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/package-info.java
index 8bbdd330..cb39e626 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/package-info.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/package-info.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2015-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/**
* Interfaces for configuring Spring Cloud Task and a default implementations.
*/
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskException.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskException.java
index e83e5284..8db88097 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskException.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,15 +18,16 @@ package org.springframework.cloud.task.listener;
/**
* Base Exception for any Task issues.
+ *
* @author Glenn Renfro
*/
public class TaskException extends RuntimeException {
- public TaskException(String message, Throwable e){
+ public TaskException(String message, Throwable e) {
super(message, e);
}
- public TaskException(String message){
+ public TaskException(String message) {
super(message);
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionException.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionException.java
index c4737986..82f5410c 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionException.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,11 +23,12 @@ package org.springframework.cloud.task.listener;
*/
public class TaskExecutionException extends TaskException {
- public TaskExecutionException(String message){
+ public TaskExecutionException(String message) {
super(message);
}
- public TaskExecutionException(String message, Throwable throwable){
+ public TaskExecutionException(String message, Throwable throwable) {
super(message, throwable);
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListener.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListener.java
index 637a9be6..79148d31 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListener.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,29 +21,32 @@ import org.springframework.cloud.task.repository.TaskRepository;
/**
* The listener interface for receiving task execution events.
+ *
* @author Glenn Renfro
*/
public interface TaskExecutionListener {
/**
- * Invoked after the {@link TaskExecution} has been stored in the {@link TaskRepository}.
+ * Invoked after the {@link TaskExecution} has been stored in the
+ * {@link TaskRepository}.
* @param taskExecution instance containing the information about the current task.
*/
void onTaskStartup(TaskExecution taskExecution);
/**
- * Invoked before the {@link TaskExecution} has been updated in the {@link TaskRepository}
- * upon task end.
+ * Invoked before the {@link TaskExecution} has been updated in the
+ * {@link TaskRepository} upon task end.
* @param taskExecution instance containing the information about the current task.
*/
void onTaskEnd(TaskExecution taskExecution);
/**
- * Invoked if an uncaught exception occurs during a task execution. This invocation
- * will occur before the {@link TaskExecution} has been updated in the {@link TaskRepository}
- * and before the onTaskEnd is called.
+ * Invoked if an uncaught exception occurs during a task execution. This invocation
+ * will occur before the {@link TaskExecution} has been updated in the
+ * {@link TaskRepository} and before the onTaskEnd is called.
* @param taskExecution instance containing the information about the current task.
* @param throwable the uncaught exception that was thrown during task execution.
*/
void onTaskFailed(TaskExecution taskExecution, Throwable throwable);
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java
index 16dabcd1..e5cfd9cb 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskExecutionListenerSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.listener;
import org.springframework.cloud.task.repository.TaskExecution;
@@ -25,6 +26,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
* @since 1.2
*/
public class TaskExecutionListenerSupport implements TaskExecutionListener {
+
@Override
public void onTaskStartup(TaskExecution taskExecution) {
@@ -39,4 +41,5 @@ public class TaskExecutionListenerSupport implements TaskExecutionListener {
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java
index 5578555e..6f12eff1 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/TaskLifecycleListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.listener;
import java.io.PrintWriter;
@@ -49,33 +50,42 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
- * Monitors the lifecycle of a task. This listener will record both the start and end of
- * a task in the registered {@link TaskRepository}.
+ * Monitors the lifecycle of a task. This listener will record both the start and end of a
+ * task in the registered {@link TaskRepository}.
*
* The following events are used to identify the start and end of a task:
*
*
- * - {@link SmartLifecycle#start()} - Used to identify the start of a task. A task
- * is expected to contain a single application context.
- * - {@link ApplicationReadyEvent} - Used to identify the successful end of a task.
- * - {@link ApplicationFailedEvent} - Used to identify the failure of a task.
- * - {@link SmartLifecycle#stop()} - Used to identify the end of a task,
- * if the {@link ApplicationReadyEvent} or {@link ApplicationFailedEvent}
- * is not emitted. This can occur if an error occurs while executing a BeforeTask.
- *
+ * - {@link SmartLifecycle#start()} - Used to identify the start of a task. A task is
+ * expected to contain a single application context.
+ * - {@link ApplicationReadyEvent} - Used to identify the successful end of a task.
+ * - {@link ApplicationFailedEvent} - Used to identify the failure of a task.
+ * - {@link SmartLifecycle#stop()} - Used to identify the end of a task, if the
+ * {@link ApplicationReadyEvent} or {@link ApplicationFailedEvent} is not emitted. This
+ * can occur if an error occurs while executing a BeforeTask.
*
*
- * Note: By default, the context will close at the completion of the task unless other non-daemon
- * threads keep it running. Programatic closing of the context can be configured via the
- * property spring.cloud.task.closecontext.enabled (defaults to false).
- * If the spring.cloud.task.closecontext.enabled is set to true,
- * then the context will be closed upon task completion regardless if non-daemon threads are still running.
- * Also if the context did not start, the FailedTask and TaskEnd may not have all the dependencies met.
+ * Note: By default, the context will close at the completion of the task unless
+ * other non-daemon threads keep it running. Programatic closing of the context can be
+ * configured via the property spring.cloud.task.closecontext.enabled
+ * (defaults to false). If the spring.cloud.task.closecontext.enabled is set
+ * to true, then the context will be closed upon task completion regardless if non-daemon
+ * threads are still running. Also if the context did not start, the FailedTask and
+ * TaskEnd may not have all the dependencies met.
*
* @author Michael Minella
* @author Glenn Renfro
*/
-public class TaskLifecycleListener implements ApplicationListener, SmartLifecycle, DisposableBean {
+public class TaskLifecycleListener
+ implements ApplicationListener, SmartLifecycle, DisposableBean {
+
+ private static final Log logger = LogFactory.getLog(TaskLifecycleListener.class);
+
+ private final TaskRepository taskRepository;
+
+ private final TaskExplorer taskExplorer;
+
+ private final TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory;
@Autowired
private ConfigurableApplicationContext context;
@@ -85,14 +95,6 @@ public class TaskLifecycleListener implements ApplicationListener taskExecutionListeners;
- private static final Log logger = LogFactory.getLog(TaskLifecycleListener.class);
-
- private final TaskRepository taskRepository;
-
- private final TaskExplorer taskExplorer;
-
- private final TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory;
-
private TaskExecution taskExecution;
private TaskProperties taskProperties;
@@ -115,22 +117,25 @@ public class TaskLifecycleListener implements ApplicationListener
- * {@link ApplicationReadyEvent} - Successful end of a task
- * {@link ApplicationFailedEvent} - Failure of a task
+ * {@link ApplicationReadyEvent} - Successful end of a task
+ * {@link ApplicationFailedEvent} - Failure of a task
*
- *
* @param applicationEvent The application being listened for.
*/
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
- if(applicationEvent instanceof ApplicationFailedEvent) {
- this.applicationFailedException = ((ApplicationFailedEvent) applicationEvent).getException();
+ if (applicationEvent instanceof ApplicationFailedEvent) {
+ this.applicationFailedException = ((ApplicationFailedEvent) applicationEvent)
+ .getException();
doTaskEnd();
}
- else if(applicationEvent instanceof ExitCodeEvent){
+ else if (applicationEvent instanceof ExitCodeEvent) {
this.exitCodeEvent = (ExitCodeEvent) applicationEvent;
}
- else if(applicationEvent instanceof ApplicationReadyEvent) {
+ else if (applicationEvent instanceof ApplicationReadyEvent) {
doTaskEnd();
}
}
@@ -174,37 +179,41 @@ public class TaskLifecycleListener implements ApplicationListener();
this.taskListenerExecutorObjectFactory.getObject();
- if(!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
- this.taskExecutionListeners.addAll(this.taskExecutionListenersFromContext);
+ if (!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
+ this.taskExecutionListeners
+ .addAll(this.taskExecutionListenersFromContext);
}
- this.taskExecutionListeners.add(this.taskListenerExecutorObjectFactory.getObject());
+ this.taskExecutionListeners
+ .add(this.taskListenerExecutorObjectFactory.getObject());
List args = new ArrayList<>(0);
- if(this.applicationArguments != null) {
+ if (this.applicationArguments != null) {
args = Arrays.asList(this.applicationArguments.getSourceArgs());
}
- if(this.taskProperties.getExecutionid() != null) {
- TaskExecution taskExecution = this.taskExplorer.getTaskExecution(this.taskProperties.getExecutionid());
- Assert.notNull(taskExecution, String.format("Invalid TaskExecution, ID %s not found", this.taskProperties.getExecutionid()));
+ if (this.taskProperties.getExecutionid() != null) {
+ TaskExecution taskExecution = this.taskExplorer
+ .getTaskExecution(this.taskProperties.getExecutionid());
+ Assert.notNull(taskExecution,
+ String.format("Invalid TaskExecution, ID %s not found",
+ this.taskProperties.getExecutionid()));
Assert.isNull(taskExecution.getEndTime(), String.format(
- "Invalid TaskExecution, ID %s task is already complete", this.taskProperties.getExecutionid()));
- this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(),
+ "Invalid TaskExecution, ID %s task is already complete",
+ this.taskProperties.getExecutionid()));
+ this.taskExecution = this.taskRepository.startTaskExecution(
+ this.taskProperties.getExecutionid(),
this.taskNameResolver.getTaskName(), new Date(), args,
this.taskProperties.getExternalExecutionId(),
this.taskProperties.getParentExecutionId());
@@ -268,15 +286,18 @@ public class TaskLifecycleListener implements ApplicationListener startupListenerList = new ArrayList<>(this.taskExecutionListeners);
+ List startupListenerList = new ArrayList<>(
+ this.taskExecutionListeners);
if (!CollectionUtils.isEmpty(startupListenerList)) {
try {
Collections.reverse(startupListenerList);
@@ -310,7 +332,7 @@ public class TaskLifecycleListener implements ApplicationListener {
+public class TaskListenerExecutorObjectFactory
+ implements ObjectFactory {
private static final Log logger = LogFactory.getLog(TaskListenerExecutor.class);
- private final Set> nonAnnotatedClasses =
- Collections.newSetFromMap(new ConcurrentHashMap<>());
+ private final Set> nonAnnotatedClasses = Collections
+ .newSetFromMap(new ConcurrentHashMap<>());
private ConfigurableApplicationContext context;
@@ -62,7 +63,7 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory failedTaskInstances;
- public TaskListenerExecutorObjectFactory(ConfigurableApplicationContext context){
+ public TaskListenerExecutorObjectFactory(ConfigurableApplicationContext context) {
this.context = context;
}
@@ -72,12 +73,13 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory();
this.failedTaskInstances = new HashMap<>();
initializeExecutor();
- return new TaskListenerExecutor(beforeTaskInstances, afterTaskInstances, failedTaskInstances);
+ return new TaskListenerExecutor(this.beforeTaskInstances, this.afterTaskInstances,
+ this.failedTaskInstances);
}
- private void initializeExecutor( ) {
- ConfigurableListableBeanFactory factory = context.getBeanFactory();
- for( String beanName : context.getBeanDefinitionNames()) {
+ private void initializeExecutor() {
+ ConfigurableListableBeanFactory factory = this.context.getBeanFactory();
+ for (String beanName : this.context.getBeanDefinitionNames()) {
if (!ScopedProxyUtils.isScopedTarget(beanName)) {
Class> type = null;
@@ -85,9 +87,11 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory type){
+ private void processBean(String beanName, final Class> type) {
if (!this.nonAnnotatedClasses.contains(type)) {
- Map beforeTaskMethods =
- (new MethodGetter()).getMethods(type, BeforeTask.class);
- Map afterTaskMethods =
- (new MethodGetter()).getMethods(type, AfterTask.class);
- Map failedTaskMethods =
- (new MethodGetter()).getMethods(type, FailedTask.class);
+ Map beforeTaskMethods = (new MethodGetter())
+ .getMethods(type, BeforeTask.class);
+ Map afterTaskMethods = (new MethodGetter())
+ .getMethods(type, AfterTask.class);
+ Map failedTaskMethods = (new MethodGetter())
+ .getMethods(type, FailedTask.class);
if (beforeTaskMethods.isEmpty() && afterTaskMethods.isEmpty()) {
this.nonAnnotatedClasses.add(type);
return;
}
- if(!beforeTaskMethods.isEmpty()) {
- for(Method beforeTaskMethod : beforeTaskMethods.keySet()) {
- this.beforeTaskInstances.put(beforeTaskMethod, context.getBean(beanName));
+ if (!beforeTaskMethods.isEmpty()) {
+ for (Method beforeTaskMethod : beforeTaskMethods.keySet()) {
+ this.beforeTaskInstances.put(beforeTaskMethod,
+ this.context.getBean(beanName));
}
}
- if(!afterTaskMethods.isEmpty()){
- for(Method afterTaskMethod : afterTaskMethods.keySet()) {
- this.afterTaskInstances.put(afterTaskMethod, context.getBean(beanName));
+ if (!afterTaskMethods.isEmpty()) {
+ for (Method afterTaskMethod : afterTaskMethods.keySet()) {
+ this.afterTaskInstances.put(afterTaskMethod,
+ this.context.getBean(beanName));
}
}
- if(!failedTaskMethods.isEmpty()){
- for(Method failedTaskMethod : failedTaskMethods.keySet()) {
- this.failedTaskInstances.put(failedTaskMethod, context.getBean(beanName));
+ if (!failedTaskMethods.isEmpty()) {
+ for (Method failedTaskMethod : failedTaskMethods.keySet()) {
+ this.failedTaskInstances.put(failedTaskMethod,
+ this.context.getBean(beanName));
}
}
}
}
private static class MethodGetter {
- public Map getMethods(final Class> type, final Class annotationClass){
+
+ public Map getMethods(final Class> type,
+ final Class annotationClass) {
return MethodIntrospector.selectMethods(type,
- (MethodIntrospector.MetadataLookup) method -> AnnotationUtils.findAnnotation(method, annotationClass));
+ (MethodIntrospector.MetadataLookup) method -> AnnotationUtils
+ .findAnnotation(method, annotationClass));
}
+
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/AfterTask.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/AfterTask.java
index 546cd7f6..7d623092 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/AfterTask.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/AfterTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,22 +27,22 @@ import org.springframework.cloud.task.repository.TaskExecution;
/**
*
- * {@link TaskExecutionListener#onTaskEnd(TaskExecution)}
+ * {@link TaskExecutionListener#onTaskEnd(TaskExecution)}.
*
*
*
* public class MyListener {
-
* @AfterTask
* public void doSomething(TaskExecution taskExecution) {
- * }
+ * }
* }
*
*
* @author Glenn Renfro
*/
-@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
+@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface AfterTask {
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/BeforeTask.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/BeforeTask.java
index 3180ded2..3a11fb58 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/BeforeTask.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/BeforeTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,22 +27,22 @@ import org.springframework.cloud.task.repository.TaskExecution;
/**
*
- * {@link TaskExecutionListener#onTaskStartup(TaskExecution)}
+ * {@link TaskExecutionListener#onTaskStartup(TaskExecution)}.
*
*
*
* public class MyListener {
-
* @BeforeTask
* public void doSomething(TaskExecution taskExecution) {
- * }
+ * }
* }
*
*
* @author Glenn Renfro
*/
-@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
+@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BeforeTask {
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/FailedTask.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/FailedTask.java
index 62b7534f..75cc86f9 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/FailedTask.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/FailedTask.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,22 +27,22 @@ import org.springframework.cloud.task.repository.TaskExecution;
/**
*
- * {@link TaskExecutionListener#onTaskFailed(TaskExecution, Throwable)}
+ * {@link TaskExecutionListener#onTaskFailed(TaskExecution, Throwable)}.
*
*
*
* public class MyListener {
-
* @FailedTask
* public void doSomething(TaskExecution taskExecution, Throwable throwable) {
- * }
+ * }
* }
*
*
* @author Glenn Renfro
*/
-@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
+@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FailedTask {
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/TaskListenerExecutor.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/TaskListenerExecutor.java
index 4cec5ce5..cee9db8b 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/TaskListenerExecutor.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/listener/annotation/TaskListenerExecutor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
*
* @author Glenn Renfro
*/
-public class TaskListenerExecutor implements TaskExecutionListener{
+public class TaskListenerExecutor implements TaskExecutionListener {
private Map beforeTaskInstances;
@@ -42,7 +42,7 @@ public class TaskListenerExecutor implements TaskExecutionListener{
public TaskListenerExecutor(Map beforeTaskInstances,
Map afterTaskInstances,
- Map failedTaskInstances){
+ Map failedTaskInstances) {
this.beforeTaskInstances = beforeTaskInstances;
this.afterTaskInstances = afterTaskInstances;
@@ -50,66 +50,77 @@ public class TaskListenerExecutor implements TaskExecutionListener{
}
/**
- * Executes all the methods that have been annotated with @BeforeTask.
+ * Executes all the methods that have been annotated with @BeforeTask.
* @param taskExecution associated with the event.
*/
@Override
public void onTaskStartup(TaskExecution taskExecution) {
- executeTaskListener(taskExecution, beforeTaskInstances.keySet(), beforeTaskInstances);
+ executeTaskListener(taskExecution, this.beforeTaskInstances.keySet(),
+ this.beforeTaskInstances);
}
/**
- * Executes all the methods that have been annotated with @AfterTask.
+ * Executes all the methods that have been annotated with @AfterTask.
* @param taskExecution associated with the event.
*/
@Override
public void onTaskEnd(TaskExecution taskExecution) {
- executeTaskListener(taskExecution, afterTaskInstances.keySet(), afterTaskInstances);
+ executeTaskListener(taskExecution, this.afterTaskInstances.keySet(),
+ this.afterTaskInstances);
}
/**
- * Executes all the methods that have been annotated with @FailedTask.
+ * Executes all the methods that have been annotated with @FailedTask.
* @param throwable that was not caught for the task execution.
* @param taskExecution associated with the event.
*/
@Override
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
executeTaskListenerWithThrowable(taskExecution, throwable,
- failedTaskInstances.keySet(),failedTaskInstances);
+ this.failedTaskInstances.keySet(), this.failedTaskInstances);
}
- private void executeTaskListener(TaskExecution taskExecution, Set methods, Map instances){
+ private void executeTaskListener(TaskExecution taskExecution, Set methods,
+ Map instances) {
for (Method method : methods) {
try {
- method.invoke(instances.get(method),taskExecution);
+ method.invoke(instances.get(method), taskExecution);
}
catch (IllegalAccessException e) {
- throw new TaskExecutionException("@BeforeTask and @AfterTask annotated methods must be public.", e);
+ throw new TaskExecutionException(
+ "@BeforeTask and @AfterTask annotated methods must be public.",
+ e);
}
catch (InvocationTargetException e) {
- throw new TaskExecutionException(String.format("Failed to process @BeforeTask or @AfterTask" +
- " annotation because: %s", e.getTargetException().getMessage()), e);
+ throw new TaskExecutionException(String.format(
+ "Failed to process @BeforeTask or @AfterTask"
+ + " annotation because: %s",
+ e.getTargetException().getMessage()), e);
}
- catch (IllegalArgumentException e){
- throw new TaskExecutionException("taskExecution parameter is required for @BeforeTask and @AfterTask annotated methods", e);
+ catch (IllegalArgumentException e) {
+ throw new TaskExecutionException("taskExecution parameter "
+ + "is required for @BeforeTask and @AfterTask annotated methods",
+ e);
}
}
}
private void executeTaskListenerWithThrowable(TaskExecution taskExecution,
- Throwable throwable, Set methods, Map instances){
+ Throwable throwable, Set methods, Map instances) {
for (Method method : methods) {
try {
- method.invoke(instances.get(method),taskExecution, throwable);
+ method.invoke(instances.get(method), taskExecution, throwable);
}
catch (IllegalAccessException e) {
- throw new TaskExecutionException("@FailedTask annotated methods must be public.", e);
+ throw new TaskExecutionException(
+ "@FailedTask annotated methods must be public.", e);
}
catch (InvocationTargetException e) {
- throw new TaskExecutionException(String.format("Failed to process @FailedTask " +
- "annotation because: %s", e.getTargetException().getMessage()), e);
+ throw new TaskExecutionException(String.format(
+ "Failed to process @FailedTask " + "annotation because: %s",
+ e.getTargetException().getMessage()), e);
}
- catch (IllegalArgumentException e){
+ catch (IllegalArgumentException e) {
throw new TaskExecutionException("taskExecution and throwable parameters "
+ "are required for @FailedTask annotated methods", e);
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/package-info.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/package-info.java
index 235956ad..55d679f7 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/package-info.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/package-info.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2015-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/**
* Base package for spring cloud task.
*/
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExecution.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExecution.java
index 97a35de1..69e1f129 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExecution.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExecution.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ import org.springframework.util.Assert;
public class TaskExecution {
/**
- * The unique id associated with the task execution.
+ * The unique id associated with the task execution.
*/
private long executionId;
@@ -75,7 +75,7 @@ public class TaskExecution {
private String externalExecutionId;
/**
- * Error information available upon the failure of a task
+ * Error information available upon the failure of a task.
*
* @since 1.1.0
*/
@@ -87,14 +87,12 @@ public class TaskExecution {
private List arguments;
public TaskExecution() {
- arguments = new ArrayList<>();
+ this.arguments = new ArrayList<>();
}
public TaskExecution(long executionId, Integer exitCode, String taskName,
- Date startTime, Date endTime,
- String exitMessage, List arguments,
- String errorMessage, String externalExecutionId,
- Long parentExecutionId) {
+ Date startTime, Date endTime, String exitMessage, List arguments,
+ String errorMessage, String externalExecutionId, Long parentExecutionId) {
Assert.notNull(arguments, "arguments must not be null");
this.executionId = executionId;
@@ -102,24 +100,23 @@ public class TaskExecution {
this.taskName = taskName;
this.exitMessage = exitMessage;
this.arguments = new ArrayList<>(arguments);
- this.startTime = (startTime != null) ? (Date)startTime.clone() : null;
- this.endTime = (endTime != null) ? (Date)endTime.clone() : null;
+ this.startTime = (startTime != null) ? (Date) startTime.clone() : null;
+ this.endTime = (endTime != null) ? (Date) endTime.clone() : null;
this.errorMessage = errorMessage;
this.externalExecutionId = externalExecutionId;
this.parentExecutionId = parentExecutionId;
}
public TaskExecution(long executionId, Integer exitCode, String taskName,
- Date startTime, Date endTime,
- String exitMessage, List arguments,
+ Date startTime, Date endTime, String exitMessage, List arguments,
String errorMessage, String externalExecutionId) {
- this(executionId, exitCode, taskName, startTime, endTime, exitMessage,
- arguments, errorMessage,externalExecutionId, null);
+ this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments,
+ errorMessage, externalExecutionId, null);
}
public long getExecutionId() {
- return executionId;
+ return this.executionId;
}
public Integer getExitCode() {
@@ -131,7 +128,7 @@ public class TaskExecution {
}
public String getTaskName() {
- return taskName;
+ return this.taskName;
}
public void setTaskName(String taskName) {
@@ -139,23 +136,23 @@ public class TaskExecution {
}
public Date getStartTime() {
- return (startTime != null) ? (Date)startTime.clone() : null;
+ return (this.startTime != null) ? (Date) this.startTime.clone() : null;
}
public void setStartTime(Date startTime) {
- this.startTime = (startTime != null) ? (Date)startTime.clone() : null;
+ this.startTime = (startTime != null) ? (Date) startTime.clone() : null;
}
public Date getEndTime() {
- return (endTime != null) ? (Date)endTime.clone() : null;
+ return (this.endTime != null) ? (Date) this.endTime.clone() : null;
}
public void setEndTime(Date endTime) {
- this.endTime = (endTime != null) ? (Date)endTime.clone() : null;
+ this.endTime = (endTime != null) ? (Date) endTime.clone() : null;
}
public String getExitMessage() {
- return exitMessage;
+ return this.exitMessage;
}
public void setExitMessage(String exitMessage) {
@@ -163,15 +160,15 @@ public class TaskExecution {
}
public List getArguments() {
- return arguments;
+ return this.arguments;
}
public void setArguments(List arguments) {
- this.arguments = new ArrayList<> (arguments);
+ this.arguments = new ArrayList<>(arguments);
}
public String getErrorMessage() {
- return errorMessage;
+ return this.errorMessage;
}
public void setErrorMessage(String errorMessage) {
@@ -179,7 +176,7 @@ public class TaskExecution {
}
public String getExternalExecutionId() {
- return externalExecutionId;
+ return this.externalExecutionId;
}
public void setExternalExecutionId(String externalExecutionId) {
@@ -187,7 +184,7 @@ public class TaskExecution {
}
public Long getParentExecutionId() {
- return parentExecutionId;
+ return this.parentExecutionId;
}
public void setParentExecutionId(Long parentExecutionId) {
@@ -196,17 +193,13 @@ public class TaskExecution {
@Override
public String toString() {
- return "TaskExecution{" +
- "executionId=" + executionId +
- ", parentExecutionId=" + parentExecutionId +
- ", exitCode=" + exitCode +
- ", taskName='" + taskName + '\'' +
- ", startTime=" + startTime +
- ", endTime=" + endTime +
- ", exitMessage='" + exitMessage + '\'' +
- ", externalExecutionId='" + externalExecutionId + '\'' +
- ", errorMessage='" + errorMessage + '\'' +
- ", arguments=" + arguments +
- '}';
+ return "TaskExecution{" + "executionId=" + this.executionId
+ + ", parentExecutionId=" + this.parentExecutionId + ", exitCode="
+ + this.exitCode + ", taskName='" + this.taskName + '\'' + ", startTime="
+ + this.startTime + ", endTime=" + this.endTime + ", exitMessage='"
+ + this.exitMessage + '\'' + ", externalExecutionId='"
+ + this.externalExecutionId + '\'' + ", errorMessage='" + this.errorMessage
+ + '\'' + ", arguments=" + this.arguments + '}';
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExplorer.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExplorer.java
index 3fa4ef82..8f0d3319 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExplorer.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskExplorer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,16 +33,13 @@ public interface TaskExplorer {
/**
* Retrieve a {@link TaskExecution} by its id.
- *
* @param executionId the task execution id
* @return the {@link TaskExecution} with this id, or null if not found
*/
TaskExecution getTaskExecution(long executionId);
-
/**
* Retrieve a collection of taskExecutions that have the task name provided.
- *
* @param taskName the name of the task
* @param pageable the constraints for the search
* @return the set of running executions for tasks with the specified name
@@ -51,14 +48,12 @@ public interface TaskExplorer {
/**
* Retrieve a list of available task names.
- *
* @return the set of task names that have been executed
*/
List getTaskNames();
/**
* Get number of executions for a taskName.
- *
* @param taskName the name of the task to be searched
* @return the number of running tasks that have the taskname specified
*/
@@ -66,21 +61,18 @@ public interface TaskExplorer {
/**
* Retrieves current number of task executions.
- *
* @return current number of task executions.
*/
long getTaskExecutionCount();
/**
* Retrieves current number of running task executions.
- *
* @return current number of running task executions.
*/
long getRunningTaskExecutionCount();
/**
- * Get a collection/page of executions
- *
+ * Get a collection/page of executions.
* @param taskName the name of the task to be searched
* @param pageable the constraints for the search
* @return list of task executions
@@ -88,9 +80,8 @@ public interface TaskExplorer {
Page findTaskExecutionsByName(String taskName, Pageable pageable);
/**
- * Retrieves all the task executions within the pageable constraints sorted by
- * start date descending, taskExecution id descending.
- *
+ * Retrieves all the task executions within the pageable constraints sorted by start
+ * date descending, taskExecution id descending.
* @param pageable the constraints for the search
* @return page containing the results from the search
*/
@@ -98,8 +89,7 @@ public interface TaskExplorer {
/**
* Returns the id of the TaskExecution that the requested Spring Batch job execution
- * was executed within the context of. Returns null if none were found.
- *
+ * was executed within the context of. Returns null if none were found.
* @param jobExecutionId the id of the JobExecution
* @return the id of the {@link TaskExecution}
*/
@@ -108,39 +98,39 @@ public interface TaskExplorer {
/**
* Returns a Set of JobExecution ids for the jobs that were executed within the scope
* of the requested task.
- *
* @param taskExecutionId id of the {@link TaskExecution}
- * @return a Set of the ids of the job executions executed within the task.
+ * @return a Set of the ids of the job executions executed within the
+ * task.
*/
Set getJobExecutionIdsByTaskExecutionId(long taskExecutionId);
/**
- * Returns a {@link List} of the latest {@link TaskExecution} for 1 or more task names.
+ * Returns a {@link List} of the latest {@link TaskExecution} for 1 or more task
+ * names.
*
- * Latest is defined by the most recent start time. A {@link TaskExecution} does not have to be finished
- * (The results may including pending {@link TaskExecution}s).
+ * Latest is defined by the most recent start time. A {@link TaskExecution} does not
+ * have to be finished (The results may including pending {@link TaskExecution}s).
*
- * It is theoretically possible that a {@link TaskExecution} with the same name to have more than 1
- * {@link TaskExecution} for the exact same start time. In that case the {@link TaskExecution} with the
- * highest Task Execution ID is returned.
- *
- * This method will not consider end times in its calculations. Thus, when a task execution {@code A} starts
- * after task execution {@code B} but finishes BEFORE task execution {@code A}, then task execution {@code B}
- * is being returned.
+ * It is theoretically possible that a {@link TaskExecution} with the same name to
+ * have more than 1 {@link TaskExecution} for the exact same start time. In that case
+ * the {@link TaskExecution} with the highest Task Execution ID is returned.
*
+ * This method will not consider end times in its calculations. Thus, when a task
+ * execution {@code A} starts after task execution {@code B} but finishes BEFORE task
+ * execution {@code A}, then task execution {@code B} is being returned.
* @param taskNames At least 1 task name must be provided
* @return List of TaskExecutions. May be empty but never null.
*/
List getLatestTaskExecutionsByTaskNames(String... taskNames);
-
/**
- * Returns the latest task execution for a given task name. Will ultimately apply the same algorithm underneath
- * as {@link #getLatestTaskExecutionsByTaskNames(String...)} but will only return a single result.
- *
+ * Returns the latest task execution for a given task name. Will ultimately apply the
+ * same algorithm underneath as {@link #getLatestTaskExecutionsByTaskNames(String...)}
+ * but will only return a single result.
* @param taskName Must not be null or empty
* @return The latest Task Execution or null
* @see #getLatestTaskExecutionsByTaskNames(String...)
*/
TaskExecution getLatestTaskExecutionForTaskName(String taskName);
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskNameResolver.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskNameResolver.java
index 5f92d0e7..752216fa 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskNameResolver.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskNameResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.cloud.task.repository;
/**
@@ -26,4 +27,5 @@ public interface TaskNameResolver {
* @return the name of the task being executed within this context.
*/
String getTaskName();
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskRepository.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskRepository.java
index de47572b..721c797b 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskRepository.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/TaskRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@ public interface TaskRepository {
/**
* Notifies the repository that a taskExecution has completed.
- *
* @param executionId to the task execution to be updated.
* @param exitCode to be stored for this task.
* @param endTime designated when the task completed.
@@ -40,11 +39,10 @@ public interface TaskRepository {
*/
@Transactional
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
- String exitMessage);
+ String exitMessage);
/**
* Notifies the repository that a taskExecution has completed.
- *
* @param executionId to the task execution to be updated.
* @param exitCode to be stored for this task execution.
* @param endTime designated when the task completed.
@@ -55,30 +53,26 @@ public interface TaskRepository {
*/
@Transactional
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
- String exitMessage, String errorMessage);
+ String exitMessage, String errorMessage);
/**
* Notifies the repository that a taskExecution needs to be created.
- *
- * @param taskExecution a TaskExecution instance containing the startTime,
- * arguments and externalExecutionId that will be stored in the repository.
- * Only the values enumerated above will be stored for this
+ * @param taskExecution a TaskExecution instance containing the startTime, arguments
+ * and externalExecutionId that will be stored in the repository. Only the values
+ * enumerated above will be stored for this TaskExecution.
+ * @return the {@link TaskExecution} that was stored in the repository. The
+ * TaskExecution's taskExecutionId will also contain the id that was used to store the
* TaskExecution.
- * @return the {@link TaskExecution} that was stored in the repository. The
- * TaskExecution's taskExecutionId will also contain the id that was used
- * to store the TaskExecution.
*/
@Transactional
TaskExecution createTaskExecution(TaskExecution taskExecution);
/**
- * Creates an empty TaskExecution with just an id and name provided. This is intended to be
- * utilized in systems where the request of launching a task is separate from the
- * actual start of a task (the underlying system may need to deploy the task prior to
- * launching, etc).
- *
+ * Creates an empty TaskExecution with just an id and name provided. This is intended
+ * to be utilized in systems where the request of launching a task is separate from
+ * the actual start of a task (the underlying system may need to deploy the task prior
+ * to launching, etc).
* @param name task name to be associated with the task execution.
- *
* @return the initial {@link TaskExecution}
*/
@Transactional
@@ -89,7 +83,6 @@ public interface TaskRepository {
* utilized in systems where the request of launching a task is separate from the
* actual start of a task (the underlying system may need to deploy the task prior to
* launching, etc).
- *
* @return the initial {@link TaskExecution}
*/
@Transactional
@@ -97,43 +90,38 @@ public interface TaskRepository {
/**
* Notifies the repository that a taskExecution has has started.
- *
- * @param executionid to the task execution to be updated.
- * @param taskName the name that associated with the task execution.
- * @param startTime the time task began.
- * @param arguments list of key/value pairs that configure the task.
+ * @param executionid to the task execution to be updated.
+ * @param taskName the name that associated with the task execution.
+ * @param startTime the time task began.
+ * @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform.
* @return TaskExecution created based on the parameters.
*/
@Transactional
- TaskExecution startTaskExecution(long executionid, String taskName,
- Date startTime,List arguments, String externalExecutionId);
+ TaskExecution startTaskExecution(long executionid, String taskName, Date startTime,
+ List arguments, String externalExecutionId);
/**
* Notifies the repository to update the taskExecution's externalExecutionId.
- *
- * @param executionid to the task execution to be updated.
+ * @param executionid to the task execution to be updated.
* @param externalExecutionId id assigned to the task by the platform.
*/
@Transactional
- void updateExternalExecutionId(long executionid,
- String externalExecutionId);
+ void updateExternalExecutionId(long executionid, String externalExecutionId);
/**
* Notifies the repository that a taskExecution has has started.
- * @param executionid to the task execution to be updated.
+ * @param executionid to the task execution to be updated.
* @param taskName the name that associated with the task execution.
* @param startTime the time task began.
* @param arguments list of key/value pairs that configure the task.
* @param externalExecutionId id assigned to the task by the platform.
* @param parentExecutionId the parent task execution id.
-
- * @return A TaskExecution that contains the information available at the
- * beginning of a TaskExecution.
+ * @return A TaskExecution that contains the information available at the beginning of
+ * a TaskExecution.
*/
@Transactional
- TaskExecution startTaskExecution(long executionid, String taskName,
- Date startTime,List arguments, String externalExecutionId,
- Long parentExecutionId);
+ TaskExecution startTaskExecution(long executionid, String taskName, Date startTime,
+ List arguments, String externalExecutionId, Long parentExecutionId);
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java
index 672aef21..f099c43f 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/JdbcTaskExecutionDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,22 +61,33 @@ import org.springframework.util.StringUtils;
*/
public class JdbcTaskExecutionDao implements TaskExecutionDao {
-
+ /**
+ * SELECT clause for task execution.
+ */
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, "
+ "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID ";
+ /**
+ * FROM clause for task execution.
+ */
public static final String FROM_CLAUSE = "%PREFIX%EXECUTION";
- public static final String RUNNING_TASK_WHERE_CLAUSE =
- "where TASK_NAME = :taskName AND END_TIME IS NULL ";
+ /**
+ * WHERE clause for running task.
+ */
+ public static final String RUNNING_TASK_WHERE_CLAUSE = "where TASK_NAME = :taskName AND END_TIME IS NULL ";
+ /**
+ * WHERE clause for task name.
+ */
public static final String TASK_NAME_WHERE_CLAUSE = "where TASK_NAME = :taskName ";
private static final String SAVE_TASK_EXECUTION = "INSERT into %PREFIX%EXECUTION"
+ "(TASK_EXECUTION_ID, EXIT_CODE, START_TIME, TASK_NAME, LAST_UPDATED, EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID)"
- + "values (:taskExecutionId, :exitCode, :startTime, :taskName, :lastUpdated, :externalExecutionId, :parentExecutionId)";
+ + "values (:taskExecutionId, :exitCode, :startTime, "
+ + ":taskName, :lastUpdated, :externalExecutionId, :parentExecutionId)";
private static final String CREATE_TASK_ARGUMENT = "INSERT into "
+ "%PREFIX%EXECUTION_PARAMS(TASK_EXECUTION_ID, TASK_PARAM ) values (:taskExecutionId, :taskParam)";
@@ -85,9 +96,11 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
+ "START_TIME = :startTime, TASK_NAME = :taskName, LAST_UPDATED = :lastUpdated";
private static final String START_TASK_EXECUTION_EXTERNAL_ID_SUFFIX = ", "
- + "EXTERNAL_EXECUTION_ID = :externalExecutionId, PARENT_EXECUTION_ID = :parentExecutionId where TASK_EXECUTION_ID = :taskExecutionId";
+ + "EXTERNAL_EXECUTION_ID = :externalExecutionId, PARENT_EXECUTION_ID = :parentExecutionId "
+ + "where TASK_EXECUTION_ID = :taskExecutionId";
- private static final String START_TASK_EXECUTION_SUFFIX = ", PARENT_EXECUTION_ID = :parentExecutionId where TASK_EXECUTION_ID = :taskExecutionId";
+ private static final String START_TASK_EXECUTION_SUFFIX = ", PARENT_EXECUTION_ID = :parentExecutionId "
+ + "where TASK_EXECUTION_ID = :taskExecutionId";
private static final String CHECK_TASK_EXECUTION_EXISTS = "SELECT COUNT(*) FROM "
+ "%PREFIX%EXECUTION WHERE TASK_EXECUTION_ID = :taskExecutionId";
@@ -99,8 +112,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
private static final String UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID = "UPDATE %PREFIX%EXECUTION set "
+ "EXTERNAL_EXECUTION_ID = :externalExecutionId where TASK_EXECUTION_ID = :taskExecutionId";
- private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, " +
- "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
+ private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, "
+ + "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, "
+ "PARENT_EXECUTION_ID "
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = :taskExecutionId";
@@ -108,41 +121,40 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
private static final String FIND_ARGUMENT_FROM_ID = "SELECT TASK_EXECUTION_ID, "
+ "TASK_PARAM from %PREFIX%EXECUTION_PARAMS where TASK_EXECUTION_ID = :taskExecutionId";
- private static final String TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM " +
- "%PREFIX%EXECUTION ";
+ private static final String TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM "
+ + "%PREFIX%EXECUTION ";
- private static final String TASK_EXECUTION_COUNT_BY_NAME = "SELECT COUNT(*) FROM " +
- "%PREFIX%EXECUTION where TASK_NAME = :taskName";
+ private static final String TASK_EXECUTION_COUNT_BY_NAME = "SELECT COUNT(*) FROM "
+ + "%PREFIX%EXECUTION where TASK_NAME = :taskName";
- private static final String RUNNING_TASK_EXECUTION_COUNT_BY_NAME = "SELECT COUNT(*) FROM " +
- "%PREFIX%EXECUTION where TASK_NAME = :taskName AND END_TIME IS NULL ";
+ private static final String RUNNING_TASK_EXECUTION_COUNT_BY_NAME = "SELECT COUNT(*) FROM "
+ + "%PREFIX%EXECUTION where TASK_NAME = :taskName AND END_TIME IS NULL ";
- private static final String RUNNING_TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM " +
- "%PREFIX%EXECUTION where END_TIME IS NULL ";
+ private static final String RUNNING_TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM "
+ + "%PREFIX%EXECUTION where END_TIME IS NULL ";
- private static final String LAST_TASK_EXECUTIONS_BY_TASK_NAMES =
- "select TE2.* from (" +
- "select MAX(TE.TASK_EXECUTION_ID) as TASK_EXECUTION_ID, TE.TASK_NAME, TE.START_TIME from (" +
- "select TASK_NAME, MAX(START_TIME) as START_TIME" +
- " FROM %PREFIX%EXECUTION where TASK_NAME in (:taskNames)" +
- " GROUP BY TASK_NAME" +
- ") TE_MAX " +
- "inner join %PREFIX%EXECUTION TE ON TE.TASK_NAME = TE_MAX.TASK_NAME AND TE.START_TIME = TE_MAX.START_TIME " +
- "group by TE.TASK_NAME, TE.START_TIME" +
- ") TE1 " +
- "inner join %PREFIX%EXECUTION TE2 ON TE1.TASK_EXECUTION_ID = TE2.TASK_EXECUTION_ID " +
- "order by TE2.START_TIME DESC, TE2.TASK_EXECUTION_ID DESC";
+ private static final String LAST_TASK_EXECUTIONS_BY_TASK_NAMES = "select TE2.* from ("
+ + "select MAX(TE.TASK_EXECUTION_ID) as TASK_EXECUTION_ID, TE.TASK_NAME, TE.START_TIME from ("
+ + "select TASK_NAME, MAX(START_TIME) as START_TIME"
+ + " FROM %PREFIX%EXECUTION where TASK_NAME in (:taskNames)"
+ + " GROUP BY TASK_NAME" + ") TE_MAX "
+ + "inner join %PREFIX%EXECUTION TE ON TE.TASK_NAME = TE_MAX.TASK_NAME AND TE.START_TIME = TE_MAX.START_TIME "
+ + "group by TE.TASK_NAME, TE.START_TIME" + ") TE1 "
+ + "inner join %PREFIX%EXECUTION TE2 ON TE1.TASK_EXECUTION_ID = TE2.TASK_EXECUTION_ID "
+ + "order by TE2.START_TIME DESC, TE2.TASK_EXECUTION_ID DESC";
private static final String FIND_TASK_NAMES = "SELECT distinct TASK_NAME from %PREFIX%EXECUTION order by TASK_NAME";
- private static final String FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID = "SELECT TASK_EXECUTION_ID FROM %PREFIX%TASK_BATCH WHERE JOB_EXECUTION_ID = :jobExecutionId";
+ private static final String FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID = "SELECT TASK_EXECUTION_ID FROM "
+ + "%PREFIX%TASK_BATCH WHERE JOB_EXECUTION_ID = :jobExecutionId";
- private static final String FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID = "SELECT JOB_EXECUTION_ID FROM %PREFIX%TASK_BATCH WHERE TASK_EXECUTION_ID = :taskExecutionId";
-
- private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX;
+ private static final String FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID = "SELECT JOB_EXECUTION_ID "
+ + "FROM %PREFIX%TASK_BATCH WHERE TASK_EXECUTION_ID = :taskExecutionId";
private final NamedParameterJdbcTemplate jdbcTemplate;
+ private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX;
+
private DataSource dataSource;
private LinkedHashMap orderMap;
@@ -169,120 +181,119 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
Assert.notNull(dataSource, "The dataSource must not be null.");
this.jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
this.dataSource = dataSource;
- orderMap = new LinkedHashMap<>();
- orderMap.put("START_TIME", Order.DESCENDING);
- orderMap.put("TASK_EXECUTION_ID", Order.DESCENDING);
- }
-
- @Override
- public TaskExecution createTaskExecution(String taskName,
- Date startTime, List arguments, String externalExecutionId) {
- return createTaskExecution(taskName, startTime, arguments,
- externalExecutionId, null);
+ this.orderMap = new LinkedHashMap<>();
+ this.orderMap.put("START_TIME", Order.DESCENDING);
+ this.orderMap.put("TASK_EXECUTION_ID", Order.DESCENDING);
}
@Override
public TaskExecution createTaskExecution(String taskName, Date startTime,
- List arguments, String externalExecutionId,
- Long parentExecutionId) {
+ List arguments, String externalExecutionId) {
+ return createTaskExecution(taskName, startTime, arguments, externalExecutionId,
+ null);
+ }
+
+ @Override
+ public TaskExecution createTaskExecution(String taskName, Date startTime,
+ List arguments, String externalExecutionId, Long parentExecutionId) {
long nextExecutionId = getNextExecutionId();
TaskExecution taskExecution = new TaskExecution(nextExecutionId, null, taskName,
startTime, null, null, arguments, null, externalExecutionId);
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskExecutionId", nextExecutionId, Types.BIGINT)
- .addValue("exitCode", null, Types.INTEGER)
- .addValue("startTime", startTime, Types.TIMESTAMP)
- .addValue("taskName", taskName, Types.VARCHAR)
- .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
- .addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
- .addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
+ .addValue("taskExecutionId", nextExecutionId, Types.BIGINT)
+ .addValue("exitCode", null, Types.INTEGER)
+ .addValue("startTime", startTime, Types.TIMESTAMP)
+ .addValue("taskName", taskName, Types.VARCHAR)
+ .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
+ .addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
+ .addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
- jdbcTemplate.update(
- getQuery(SAVE_TASK_EXECUTION),
- queryParameters);
+ this.jdbcTemplate.update(getQuery(SAVE_TASK_EXECUTION), queryParameters);
insertTaskArguments(nextExecutionId, arguments);
return taskExecution;
}
@Override
public TaskExecution startTaskExecution(long executionId, String taskName,
- Date startTime, List arguments,
- String externalExecutionId) {
+ Date startTime, List arguments, String externalExecutionId) {
return startTaskExecution(executionId, taskName, startTime, arguments,
externalExecutionId, null);
}
@Override
public TaskExecution startTaskExecution(long executionId, String taskName,
- Date startTime, List arguments,
- String externalExecutionId, Long parentExecutionId) {
+ Date startTime, List arguments, String externalExecutionId,
+ Long parentExecutionId) {
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
- startTime, null, null, arguments,null, externalExecutionId, parentExecutionId);
+ startTime, null, null, arguments, null, externalExecutionId,
+ parentExecutionId);
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("startTime", startTime, Types.TIMESTAMP)
- .addValue("exitCode", null, Types.INTEGER)
- .addValue("taskName", taskName, Types.VARCHAR)
- .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
- .addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
- .addValue("taskExecutionId", executionId, Types.BIGINT);
+ .addValue("startTime", startTime, Types.TIMESTAMP)
+ .addValue("exitCode", null, Types.INTEGER)
+ .addValue("taskName", taskName, Types.VARCHAR)
+ .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
+ .addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
+ .addValue("taskExecutionId", executionId, Types.BIGINT);
String updateString = START_TASK_EXECUTION_PREFIX;
- if(externalExecutionId == null) {
+ if (externalExecutionId == null) {
updateString += START_TASK_EXECUTION_SUFFIX;
}
else {
updateString += START_TASK_EXECUTION_EXTERNAL_ID_SUFFIX;
- queryParameters.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR);
+ queryParameters.addValue("externalExecutionId", externalExecutionId,
+ Types.VARCHAR);
}
- jdbcTemplate.update(getQuery(updateString), queryParameters);
+ this.jdbcTemplate.update(getQuery(updateString), queryParameters);
insertTaskArguments(executionId, arguments);
return taskExecution;
}
@Override
- public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime,
- String exitMessage, String errorMessage) {
+ public void completeTaskExecution(long taskExecutionId, Integer exitCode,
+ Date endTime, String exitMessage, String errorMessage) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
+ .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
// Check if given TaskExecution's Id already exists, if none is found
// it is invalid and an exception should be thrown.
- if (jdbcTemplate.queryForObject(getQuery(CHECK_TASK_EXECUTION_EXISTS), queryParameters, Integer.class) != 1) {
- throw new IllegalStateException("Invalid TaskExecution, ID " + taskExecutionId + " not found.");
+ if (this.jdbcTemplate.queryForObject(getQuery(CHECK_TASK_EXECUTION_EXISTS),
+ queryParameters, Integer.class) != 1) {
+ throw new IllegalStateException(
+ "Invalid TaskExecution, ID " + taskExecutionId + " not found.");
}
final MapSqlParameterSource parameters = new MapSqlParameterSource()
- .addValue("endTime", endTime, Types.TIMESTAMP)
- .addValue("exitCode", exitCode, Types.INTEGER)
- .addValue("exitMessage", exitMessage, Types.VARCHAR)
- .addValue("errorMessage", errorMessage, Types.VARCHAR)
- .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
- .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
+ .addValue("endTime", endTime, Types.TIMESTAMP)
+ .addValue("exitCode", exitCode, Types.INTEGER)
+ .addValue("exitMessage", exitMessage, Types.VARCHAR)
+ .addValue("errorMessage", errorMessage, Types.VARCHAR)
+ .addValue("lastUpdated", new Date(), Types.TIMESTAMP)
+ .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
- jdbcTemplate.update(
- getQuery(UPDATE_TASK_EXECUTION),
- parameters);
+ this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION), parameters);
}
@Override
- public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime,
- String exitMessage) {
+ public void completeTaskExecution(long taskExecutionId, Integer exitCode,
+ Date endTime, String exitMessage) {
completeTaskExecution(taskExecutionId, exitCode, endTime, exitMessage, null);
}
@Override
public TaskExecution getTaskExecution(long executionId) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskExecutionId", executionId, Types.BIGINT);
+ .addValue("taskExecutionId", executionId, Types.BIGINT);
try {
- TaskExecution taskExecution = jdbcTemplate.queryForObject(getQuery(GET_EXECUTION_BY_ID),
- queryParameters, new TaskExecutionRowMapper());
+ TaskExecution taskExecution = this.jdbcTemplate.queryForObject(
+ getQuery(GET_EXECUTION_BY_ID), queryParameters,
+ new TaskExecutionRowMapper());
taskExecution.setArguments(getTaskArguments(executionId));
return taskExecution;
}
@@ -295,11 +306,11 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
public long getTaskExecutionCountByTaskName(String taskName) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskName", taskName, Types.VARCHAR);
+ .addValue("taskName", taskName, Types.VARCHAR);
try {
- return jdbcTemplate.queryForObject(
- getQuery(TASK_EXECUTION_COUNT_BY_NAME), queryParameters, Long.class);
+ return this.jdbcTemplate.queryForObject(
+ getQuery(TASK_EXECUTION_COUNT_BY_NAME), queryParameters, Long.class);
}
catch (EmptyResultDataAccessException e) {
return 0;
@@ -309,11 +320,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public long getRunningTaskExecutionCountByTaskName(String taskName) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskName", taskName, Types.VARCHAR);
+ .addValue("taskName", taskName, Types.VARCHAR);
try {
- return jdbcTemplate.queryForObject(
- getQuery(RUNNING_TASK_EXECUTION_COUNT_BY_NAME), queryParameters, Long.class);
+ return this.jdbcTemplate.queryForObject(
+ getQuery(RUNNING_TASK_EXECUTION_COUNT_BY_NAME), queryParameters,
+ Long.class);
}
catch (EmptyResultDataAccessException e) {
return 0;
@@ -325,8 +337,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
try {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource();
- return jdbcTemplate.queryForObject(
- getQuery(RUNNING_TASK_EXECUTION_COUNT), queryParameters, Long.class);
+ return this.jdbcTemplate.queryForObject(
+ getQuery(RUNNING_TASK_EXECUTION_COUNT), queryParameters, Long.class);
}
catch (EmptyResultDataAccessException e) {
return 0;
@@ -345,14 +357,15 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
}
}
- Assert.isTrue(taskNamesAsList.size() == taskNames.length,
- String.format("Task names must not contain any empty elements but %s of %s were empty or null.",
- taskNames.length - taskNamesAsList.size(), taskNames.length));
+ Assert.isTrue(taskNamesAsList.size() == taskNames.length, String.format(
+ "Task names must not contain any empty elements but %s of %s were empty or null.",
+ taskNames.length - taskNamesAsList.size(), taskNames.length));
try {
- final Map> paramMap = Collections.singletonMap("taskNames", taskNamesAsList);
- return this.jdbcTemplate.query(
- getQuery(LAST_TASK_EXECUTIONS_BY_TASK_NAMES), paramMap, new TaskExecutionRowMapper());
+ final Map> paramMap = Collections
+ .singletonMap("taskNames", taskNamesAsList);
+ return this.jdbcTemplate.query(getQuery(LAST_TASK_EXECUTIONS_BY_TASK_NAMES),
+ paramMap, new TaskExecutionRowMapper());
}
catch (EmptyResultDataAccessException e) {
return Collections.emptyList();
@@ -362,7 +375,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public TaskExecution getLatestTaskExecutionForTaskName(String taskName) {
Assert.hasText(taskName, "The task name must not be empty.");
- final List taskExecutions = this.getLatestTaskExecutionsByTaskNames(taskName);
+ final List taskExecutions = this
+ .getLatestTaskExecutionsByTaskNames(taskName);
if (taskExecutions.isEmpty()) {
return null;
}
@@ -370,7 +384,9 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
return taskExecutions.get(0);
}
else {
- throw new IllegalStateException("Only expected a single TaskExecution but received " + taskExecutions.size());
+ throw new IllegalStateException(
+ "Only expected a single TaskExecution but received "
+ + taskExecutions.size());
}
}
@@ -378,8 +394,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
public long getTaskExecutionCount() {
try {
- return jdbcTemplate.queryForObject(
- getQuery(TASK_EXECUTION_COUNT), new MapSqlParameterSource(), Long.class);
+ return this.jdbcTemplate.queryForObject(getQuery(TASK_EXECUTION_COUNT),
+ new MapSqlParameterSource(), Long.class);
}
catch (EmptyResultDataAccessException e) {
return 0;
@@ -387,14 +403,17 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
}
@Override
- public Page findRunningTaskExecutions(String taskName, Pageable pageable) {
+ public Page findRunningTaskExecutions(String taskName,
+ Pageable pageable) {
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
- RUNNING_TASK_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName),
+ RUNNING_TASK_WHERE_CLAUSE,
+ new MapSqlParameterSource("taskName", taskName),
getRunningTaskExecutionCountByTaskName(taskName));
}
@Override
- public Page findTaskExecutionsByName(String taskName, Pageable pageable) {
+ public Page findTaskExecutionsByName(String taskName,
+ Pageable pageable) {
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
TASK_NAME_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName),
getTaskExecutionCountByTaskName(taskName));
@@ -402,7 +421,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public List getTaskNames() {
- return jdbcTemplate.queryForList(getQuery(FIND_TASK_NAMES), new MapSqlParameterSource(), String.class);
+ return this.jdbcTemplate.queryForList(getQuery(FIND_TASK_NAMES),
+ new MapSqlParameterSource(), String.class);
}
@Override
@@ -415,19 +435,18 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
this.taskIncrementer = taskIncrementer;
}
- public long getNextExecutionId(){
- return taskIncrementer.nextLongValue();
+ public long getNextExecutionId() {
+ return this.taskIncrementer.nextLongValue();
}
@Override
public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("jobExecutionId", jobExecutionId, Types.BIGINT);
+ .addValue("jobExecutionId", jobExecutionId, Types.BIGINT);
try {
- return jdbcTemplate.queryForObject(
- getQuery(FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID),
- queryParameters,
+ return this.jdbcTemplate.queryForObject(
+ getQuery(FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID), queryParameters,
Long.class);
}
catch (EmptyResultDataAccessException e) {
@@ -438,19 +457,20 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public Set getJobExecutionIdsByTaskExecutionId(long taskExecutionId) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
+ .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
try {
- return jdbcTemplate.query(
- getQuery(FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID),
- queryParameters,
+ return this.jdbcTemplate.query(
+ getQuery(FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID), queryParameters,
new ResultSetExtractor>() {
@Override
- public Set extractData(ResultSet resultSet) throws SQLException, DataAccessException {
+ public Set extractData(ResultSet resultSet)
+ throws SQLException, DataAccessException {
Set jobExecutionIds = new TreeSet<>();
- while(resultSet.next()) {
- jobExecutionIds.add(resultSet.getLong("JOB_EXECUTION_ID"));
+ while (resultSet.next()) {
+ jobExecutionIds
+ .add(resultSet.getLong("JOB_EXECUTION_ID"));
}
return jobExecutionIds;
@@ -463,29 +483,27 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
}
@Override
- public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
+ public void updateExternalExecutionId(long taskExecutionId,
+ String externalExecutionId) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
- .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
+ .addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
+ .addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
- if (jdbcTemplate.update(
+ if (this.jdbcTemplate.update(
getQuery(UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID),
queryParameters) != 1) {
- throw new IllegalStateException("Invalid TaskExecution, ID "
- + taskExecutionId + " not found.");
+ throw new IllegalStateException(
+ "Invalid TaskExecution, ID " + taskExecutionId + " not found.");
}
}
private Page queryForPageableResults(Pageable pageable,
- String selectClause,
- String fromClause,
- String whereClause,
- MapSqlParameterSource queryParameters,
- long totalCount){
+ String selectClause, String fromClause, String whereClause,
+ MapSqlParameterSource queryParameters, long totalCount) {
SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
factoryBean.setSelectClause(selectClause);
factoryBean.setFromClause(fromClause);
- if(StringUtils.hasText(whereClause)){
+ if (StringUtils.hasText(whereClause)) {
factoryBean.setWhereClause(whereClause);
}
final Sort sort = pageable.getSort();
@@ -493,7 +511,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
if (sort != null) {
for (Sort.Order sortOrder : sort) {
- sortOrderMap.put(sortOrder.getProperty(), sortOrder.isAscending() ? Order.ASCENDING : Order.DESCENDING);
+ sortOrderMap.put(sortOrder.getProperty(),
+ sortOrder.isAscending() ? Order.ASCENDING : Order.DESCENDING);
}
}
@@ -508,29 +527,25 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
PagingQueryProvider pagingQueryProvider;
try {
pagingQueryProvider = factoryBean.getObject();
- pagingQueryProvider.init(dataSource);
+ pagingQueryProvider.init(this.dataSource);
}
catch (Exception e) {
throw new IllegalStateException(e);
}
String query = pagingQueryProvider.getPageQuery(pageable);
- List resultList = jdbcTemplate.query(
- getQuery(query),
- queryParameters,
- new TaskExecutionRowMapper());
+ List resultList = this.jdbcTemplate.query(getQuery(query),
+ queryParameters, new TaskExecutionRowMapper());
return new PageImpl<>(resultList, pageable, totalCount);
}
private String getQuery(String base) {
- return StringUtils.replace(base, "%PREFIX%", tablePrefix);
+ return StringUtils.replace(base, "%PREFIX%", this.tablePrefix);
}
/**
- * Convenience method that inserts all arguments from the provided
- * task arguments.
- *
- * @param executionId The executionId to which the arguments are associated.
- * @param taskArguments The arguments to be stored.
+ * Convenience method that inserts all arguments from the provided task arguments.
+ * @param executionId The executionId to which the arguments are associated.
+ * @param taskArguments The arguments to be stored.
*/
private void insertTaskArguments(long executionId, List taskArguments) {
for (String args : taskArguments) {
@@ -541,26 +556,29 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
/**
* Convenience method that inserts an individual records into the
* TASK_EXECUTION_PARAMS table.
+ * @param taskExecutionId id of a task execution
+ * @param taskParam task parameters
*/
private void insertArgument(long taskExecutionId, String taskParam) {
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
- .addValue("taskExecutionId", taskExecutionId, Types.BIGINT)
- .addValue("taskParam", taskParam, Types.VARCHAR);
- jdbcTemplate.update(getQuery(CREATE_TASK_ARGUMENT), queryParameters);
+ .addValue("taskExecutionId", taskExecutionId, Types.BIGINT)
+ .addValue("taskParam", taskParam, Types.VARCHAR);
+ this.jdbcTemplate.update(getQuery(CREATE_TASK_ARGUMENT), queryParameters);
}
- private List getTaskArguments(long taskExecutionId){
- final List params= new ArrayList<>();
+ private List getTaskArguments(long taskExecutionId) {
+ final List params = new ArrayList<>();
RowCallbackHandler handler = new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
params.add(rs.getString(2));
}
};
- jdbcTemplate.query(getQuery(FIND_ARGUMENT_FROM_ID), new MapSqlParameterSource("taskExecutionId", taskExecutionId),
- handler);
+ this.jdbcTemplate.query(getQuery(FIND_ARGUMENT_FROM_ID),
+ new MapSqlParameterSource("taskExecutionId", taskExecutionId), handler);
return params;
}
+
/**
* Re-usable mapper for {@link TaskExecution} instances.
*
@@ -572,26 +590,23 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
@Override
public TaskExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
- long id = rs.getLong("TASK_EXECUTION_ID");
+ long id = rs.getLong("TASK_EXECUTION_ID");
Long parentExecutionId = rs.getLong("PARENT_EXECUTION_ID");
- if(rs.wasNull()) {
+ if (rs.wasNull()) {
parentExecutionId = null;
}
- return new TaskExecution(id,
- getNullableExitCode(rs),
- rs.getString("TASK_NAME"),
- rs.getTimestamp("START_TIME"),
- rs.getTimestamp("END_TIME"),
- rs.getString("EXIT_MESSAGE"),
- getTaskArguments(id),
- rs.getString("ERROR_MESSAGE"),
- rs.getString("EXTERNAL_EXECUTION_ID"),
- parentExecutionId);
+ return new TaskExecution(id, getNullableExitCode(rs),
+ rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"),
+ rs.getTimestamp("END_TIME"), rs.getString("EXIT_MESSAGE"),
+ getTaskArguments(id), rs.getString("ERROR_MESSAGE"),
+ rs.getString("EXTERNAL_EXECUTION_ID"), parentExecutionId);
}
private Integer getNullableExitCode(ResultSet rs) throws SQLException {
int exitCode = rs.getInt("EXIT_CODE");
return !rs.wasNull() ? exitCode : null;
}
+
}
+
}
diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDao.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDao.java
index e4f28b8d..3cd7b0bb 100644
--- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDao.java
+++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/dao/MapTaskExecutionDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 the original author or authors.
+ * Copyright 2015-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,36 +46,38 @@ import org.springframework.util.StringUtils;
*/
public class MapTaskExecutionDao implements TaskExecutionDao {
+ private final AtomicLong currentId = new AtomicLong(0L);
+
private ConcurrentMap taskExecutions;
private ConcurrentMap> batchJobAssociations;
- private final AtomicLong currentId = new AtomicLong(0L);
-
public MapTaskExecutionDao() {
- taskExecutions = new ConcurrentHashMap<>();
- batchJobAssociations = new ConcurrentHashMap<>();
+ this.taskExecutions = new ConcurrentHashMap<>();
+ this.batchJobAssociations = new ConcurrentHashMap<>();
}
@Override
- public TaskExecution createTaskExecution(String taskName,
- Date startTime, List arguments, String externalExecutionId) {
- return createTaskExecution(taskName, startTime, arguments,
- externalExecutionId, null);
+ public TaskExecution createTaskExecution(String taskName, Date startTime,
+ List arguments, String externalExecutionId) {
+ return createTaskExecution(taskName, startTime, arguments, externalExecutionId,
+ null);
}
@Override
- public TaskExecution createTaskExecution(String taskName, Date startTime, List arguments, String externalExecutionId, Long parentExecutionId) {
+ public TaskExecution createTaskExecution(String taskName, Date startTime,
+ List arguments, String externalExecutionId, Long parentExecutionId) {
long taskExecutionId = getNextExecutionId();
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
- startTime, null, null, arguments, null, externalExecutionId, parentExecutionId);
- taskExecutions.put(taskExecutionId, taskExecution);
+ startTime, null, null, arguments, null, externalExecutionId,
+ parentExecutionId);
+ this.taskExecutions.put(taskExecutionId, taskExecution);
return taskExecution;
}
@Override
- public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List arguments,
- String externalExecutionid) {
+ public TaskExecution startTaskExecution(long executionId, String taskName,
+ Date startTime, List arguments, String externalExecutionid) {
return startTaskExecution(executionId, taskName, startTime, arguments,
externalExecutionid, null);
}
@@ -84,24 +86,26 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
public TaskExecution startTaskExecution(long executionId, String taskName,
Date startTime, List arguments, String externalExecutionid,
Long parentExecutionId) {
- TaskExecution taskExecution= taskExecutions.get(executionId);
+ TaskExecution taskExecution = this.taskExecutions.get(executionId);
taskExecution.setTaskName(taskName);
taskExecution.setStartTime(startTime);
taskExecution.setArguments(arguments);
taskExecution.setParentExecutionId(parentExecutionId);
- if(externalExecutionid != null) {
+ if (externalExecutionid != null) {
taskExecution.setExternalExecutionId(externalExecutionid);
}
return taskExecution;
}
@Override
- public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage, String errorMessage) {
- if(!this.taskExecutions.containsKey(executionId)) {
- throw new IllegalStateException("Invalid TaskExecution, ID " + executionId + " not found.");
+ public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
+ String exitMessage, String errorMessage) {
+ if (!this.taskExecutions.containsKey(executionId)) {
+ throw new IllegalStateException(
+ "Invalid TaskExecution, ID " + executionId + " not found.");
}
- TaskExecution taskExecution= taskExecutions.get(executionId);
+ TaskExecution taskExecution = this.taskExecutions.get(executionId);
taskExecution.setEndTime(endTime);
taskExecution.setExitCode(exitCode);
taskExecution.setExitMessage(exitMessage);
@@ -109,19 +113,20 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
}
@Override
- public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
+ public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
+ String exitMessage) {
completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
}
@Override
public TaskExecution getTaskExecution(long executionId) {
- return taskExecutions.get(executionId);
+ return this.taskExecutions.get(executionId);
}
@Override
public long getTaskExecutionCountByTaskName(String taskName) {
int count = 0;
- for (Map.Entry entry : taskExecutions.entrySet()) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
if (entry.getValue().getTaskName().equals(taskName)) {
count++;
}
@@ -132,9 +137,9 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public long getRunningTaskExecutionCountByTaskName(String taskName) {
int count = 0;
- for (Map.Entry entry : taskExecutions.entrySet()) {
- if (entry.getValue().getTaskName().equals(taskName) &&
- entry.getValue().getEndTime() == null) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
+ if (entry.getValue().getTaskName().equals(taskName)
+ && entry.getValue().getEndTime() == null) {
count++;
}
}
@@ -144,8 +149,8 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public long getRunningTaskExecutionCount() {
long count = 0;
- for (Map.Entry entry : taskExecutions.entrySet()) {
- if ( entry.getValue().getEndTime() == null) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
+ if (entry.getValue().getEndTime() == null) {
count++;
}
}
@@ -154,15 +159,16 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public long getTaskExecutionCount() {
- return taskExecutions.size();
+ return this.taskExecutions.size();
}
@Override
- public Page findRunningTaskExecutions(String taskName, Pageable pageable) {
+ public Page findRunningTaskExecutions(String taskName,
+ Pageable pageable) {
Set result = getTaskExecutionTreeSet();
- for (Map.Entry entry : taskExecutions.entrySet()) {
- if (entry.getValue().getTaskName().equals(taskName) &&
- entry.getValue().getEndTime() == null) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
+ if (entry.getValue().getTaskName().equals(taskName)
+ && entry.getValue().getEndTime() == null) {
result.add(entry.getValue());
}
}
@@ -171,9 +177,10 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
}
@Override
- public Page findTaskExecutionsByName(String taskName, Pageable pageable) {
+ public Page findTaskExecutionsByName(String taskName,
+ Pageable pageable) {
Set filteredSet = getTaskExecutionTreeSet();
- for (Map.Entry entry : taskExecutions.entrySet()) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
if (entry.getValue().getTaskName().equals(taskName)) {
filteredSet.add(entry.getValue());
}
@@ -185,7 +192,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public List getTaskNames() {
Set result = new TreeSet<>();
- for (Map.Entry entry : taskExecutions.entrySet()) {
+ for (Map.Entry entry : this.taskExecutions.entrySet()) {
result.add(entry.getValue().getTaskName());
}
return new ArrayList<>(result);
@@ -194,17 +201,17 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public Page findAll(Pageable pageable) {
TreeSet sortedSet = getTaskExecutionTreeSet();
- sortedSet.addAll(taskExecutions.values());
+ sortedSet.addAll(this.taskExecutions.values());
List result = new ArrayList<>(sortedSet.descendingSet());
return getPageFromList(result, pageable, getTaskExecutionCount());
}
public Map getTaskExecutions() {
- return Collections.unmodifiableMap(taskExecutions);
+ return Collections.unmodifiableMap(this.taskExecutions);
}
- public long getNextExecutionId(){
- return currentId.getAndIncrement();
+ public long getNextExecutionId() {
+ return this.currentId.getAndIncrement();
}
@Override
@@ -213,9 +220,10 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
found:
- for (Map.Entry> association : batchJobAssociations.entrySet()) {
+ for (Map.Entry> association : this.batchJobAssociations
+ .entrySet()) {
for (Long curJobExecutionId : association.getValue()) {
- if(curJobExecutionId.equals(jobExecutionId)) {
+ if (curJobExecutionId.equals(jobExecutionId)) {
taskId = association.getKey();
break found;
}
@@ -227,8 +235,9 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public Set getJobExecutionIdsByTaskExecutionId(long taskExecutionId) {
- if(batchJobAssociations.containsKey(taskExecutionId)) {
- return Collections.unmodifiableSet(batchJobAssociations.get(taskExecutionId));
+ if (this.batchJobAssociations.containsKey(taskExecutionId)) {
+ return Collections
+ .unmodifiableSet(this.batchJobAssociations.get(taskExecutionId));
}
else {
return new TreeSet<>();
@@ -236,15 +245,16 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
}
@Override
- public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
- TaskExecution taskExecution = taskExecutions.get(taskExecutionId);
- Assert.notNull(taskExecution, "Invalid TaskExecution, ID "
- + taskExecutionId + " not found.");
+ public void updateExternalExecutionId(long taskExecutionId,
+ String externalExecutionId) {
+ TaskExecution taskExecution = this.taskExecutions.get(taskExecutionId);
+ Assert.notNull(taskExecution,
+ "Invalid TaskExecution, ID " + taskExecutionId + " not found.");
taskExecution.setExternalExecutionId(externalExecutionId);
}
public ConcurrentMap> getBatchJobAssociations() {
- return batchJobAssociations;
+ return this.batchJobAssociations;
}
private TreeSet getTaskExecutionTreeSet() {
@@ -252,19 +262,22 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
@Override
public int compare(TaskExecution e1, TaskExecution e2) {
int result = e1.getStartTime().compareTo(e2.getStartTime());
- if (result == 0){
- result = Long.valueOf(e1.getExecutionId()).compareTo(e2.getExecutionId());
+ if (result == 0) {
+ result = Long.valueOf(e1.getExecutionId())
+ .compareTo(e2.getExecutionId());
}
return result;
}
});
}
- private Page getPageFromList(List executionList, Pageable pageable, long maxSize){
- long toIndex = (pageable.getOffset() + pageable.getPageSize() > executionList.size()) ?
- executionList.size() : pageable.getOffset() + pageable.getPageSize();
+ private Page getPageFromList(List executionList, Pageable pageable,
+ long maxSize) {
+ long toIndex = (pageable.getOffset() + pageable.getPageSize() > executionList
+ .size()) ? executionList.size()
+ : pageable.getOffset() + pageable.getPageSize();
return new PageImpl<>(
- executionList.subList((int)pageable.getOffset(), (int)toIndex),
+ executionList.subList((int) pageable.getOffset(), (int) toIndex),
pageable, maxSize);
}
@@ -281,29 +294,34 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
}
}
- Assert.isTrue(taskNamesAsList.size() == taskNames.length,
- String.format("Task names must not contain any empty elements but %s of %s were empty or null.",
- taskNames.length - taskNamesAsList.size(), taskNames.length));
+ Assert.isTrue(taskNamesAsList.size() == taskNames.length, String.format(
+ "Task names must not contain any empty elements but %s of %s were empty or null.",
+ taskNames.length - taskNamesAsList.size(), taskNames.length));
final Map tempTaskExecutions = new HashMap<>();
- for (Map.Entry taskExecutionMapEntry : this.taskExecutions.entrySet()) {
- if (!taskNamesAsList.contains(taskExecutionMapEntry.getValue().getTaskName())) {
+ for (Map.Entry taskExecutionMapEntry : this.taskExecutions
+ .entrySet()) {
+ if (!taskNamesAsList
+ .contains(taskExecutionMapEntry.getValue().getTaskName())) {
continue;
}
- final TaskExecution tempTaskExecution = tempTaskExecutions.get(taskExecutionMapEntry.getValue().getTaskName());
+ final TaskExecution tempTaskExecution = tempTaskExecutions
+ .get(taskExecutionMapEntry.getValue().getTaskName());
if (tempTaskExecution == null
- || tempTaskExecution.getStartTime().before(taskExecutionMapEntry.getValue().getStartTime())
- || (
- tempTaskExecution.getStartTime().equals(taskExecutionMapEntry.getValue().getStartTime())
- && tempTaskExecution.getExecutionId() < taskExecutionMapEntry.getValue().getExecutionId()
- )
- ) {
- tempTaskExecutions.put(taskExecutionMapEntry.getValue().getTaskName(), taskExecutionMapEntry.getValue());
+ || tempTaskExecution.getStartTime()
+ .before(taskExecutionMapEntry.getValue().getStartTime())
+ || (tempTaskExecution.getStartTime()
+ .equals(taskExecutionMapEntry.getValue().getStartTime())
+ && tempTaskExecution.getExecutionId() < taskExecutionMapEntry
+ .getValue().getExecutionId())) {
+ tempTaskExecutions.put(taskExecutionMapEntry.getValue().getTaskName(),
+ taskExecutionMapEntry.getValue());
}
}
- final List