Polish
This commit is contained in:
@@ -43,7 +43,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure", havingValue = "true", matchIfMissing = false)
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure", havingValue = "true")
|
||||
@EnableConfigurationProperties(TaskBatchProperties.class)
|
||||
@AutoConfigureBefore(BatchAutoConfiguration.class)
|
||||
public class TaskJobLauncherAutoConfiguration {
|
||||
@@ -51,15 +51,6 @@ public class TaskJobLauncherAutoConfiguration {
|
||||
@Autowired
|
||||
private TaskBatchProperties properties;
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(JobRepository.class)
|
||||
public JobRepository jobRepository(DataSource dataSource) throws Exception{
|
||||
JobRepositoryFactoryBean factoryBean = new JobRepositoryFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskJobLauncherCommandLineRunnerFactoryBean jobLauncherCommandLineRunner(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, List<Job> jobs, JobRegistry jobRegistry, JobRepository jobRepository) {
|
||||
|
||||
@@ -42,8 +42,6 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
|
||||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
@@ -113,7 +111,7 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
|
||||
public void run(String... args) throws JobExecutionException {
|
||||
logger.info("Running default command line with: " + Arrays.asList(args));
|
||||
launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
validateJobExecutions();
|
||||
monitorJobExecutions();
|
||||
}
|
||||
|
||||
protected void execute(Job job, JobParameters jobParameters)
|
||||
@@ -161,69 +159,72 @@ public class TaskJobLauncherCommandLineRunner extends JobLauncherCommandLineRunn
|
||||
}
|
||||
}
|
||||
|
||||
private void validateJobExecutions() {
|
||||
private void monitorJobExecutions() {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
|
||||
Date startDate = new Date();
|
||||
|
||||
template.iterate(new RepeatCallback() {
|
||||
template.iterate(context -> {
|
||||
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws InterruptedException {
|
||||
List<JobExecution> failedJobExecutions = new ArrayList<>();
|
||||
RepeatStatus repeatStatus = RepeatStatus.FINISHED;
|
||||
for (JobExecution jobExecution : jobExecutionList) {
|
||||
JobExecution currentJobExecution = taskJobExplorer.getJobExecution(jobExecution.getId());
|
||||
BatchStatus batchStatus = currentJobExecution.getStatus();
|
||||
if (batchStatus.isRunning()) {
|
||||
repeatStatus = RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
if (batchStatus.equals(BatchStatus.FAILED)) {
|
||||
failedJobExecutions.add(jobExecution);
|
||||
}
|
||||
List<JobExecution> failedJobExecutions = new ArrayList<>();
|
||||
RepeatStatus repeatStatus = RepeatStatus.FINISHED;
|
||||
for (JobExecution jobExecution : jobExecutionList) {
|
||||
JobExecution currentJobExecution = taskJobExplorer.getJobExecution(jobExecution.getId());
|
||||
BatchStatus batchStatus = currentJobExecution.getStatus();
|
||||
if (batchStatus.isRunning()) {
|
||||
repeatStatus = RepeatStatus.CONTINUABLE;
|
||||
}
|
||||
Thread.sleep(taskBatchProperties.getFailOnJobFailurePollInterval());
|
||||
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED) && failedJobExecutions.size() > 0) {
|
||||
throwJobFailedException(failedJobExecutions);
|
||||
if (batchStatus.equals(BatchStatus.FAILED)) {
|
||||
failedJobExecutions.add(jobExecution);
|
||||
}
|
||||
if (repeatStatus.isContinuable() && taskBatchProperties.getFailOnJobFailurewaitTime() != 0
|
||||
&& (new Date()).getTime() - startDate.getTime() > taskBatchProperties.getFailOnJobFailurewaitTime()) {
|
||||
throw new IllegalStateException("Not all jobs were completed " +
|
||||
"within the time specified by spring.cloud.task.batch." +
|
||||
"failOnJobFailurewaitTime.");
|
||||
}
|
||||
return repeatStatus;
|
||||
}
|
||||
Thread.sleep(taskBatchProperties.getFailOnJobFailurePollInterval());
|
||||
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED) && failedJobExecutions.size() > 0) {
|
||||
throwJobFailedException(failedJobExecutions);
|
||||
}
|
||||
if (repeatStatus.isContinuable() && taskBatchProperties.getFailOnJobFailurewaitTime() != 0
|
||||
&& (new Date()).getTime() - startDate.getTime() > taskBatchProperties.getFailOnJobFailurewaitTime()) {
|
||||
throw new IllegalStateException("Not all jobs were completed " +
|
||||
"within the time specified by spring.cloud.task.batch." +
|
||||
"failOnJobFailurewaitTime.");
|
||||
}
|
||||
return repeatStatus;
|
||||
});
|
||||
}
|
||||
|
||||
public void throwJobFailedException(List<JobExecution> failedJobExecutions) {
|
||||
String message = "The following Jobs have failed: \n";
|
||||
private void throwJobFailedException(List<JobExecution> failedJobExecutions) {
|
||||
StringBuilder message = new StringBuilder("The following Jobs have failed: \n");
|
||||
for (JobExecution failedJobExecution : failedJobExecutions) {
|
||||
message += String.format("Job %s failed during " +
|
||||
"execution for jobId %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());
|
||||
failedJobExecution.getJobId(), failedJobExecution.getId()));
|
||||
}
|
||||
|
||||
logger.error(message);
|
||||
throw new TaskException(message);
|
||||
|
||||
throw new TaskException(message.toString());
|
||||
|
||||
}
|
||||
private JobParameters removeNonIdentifying(JobParameters parameters) {
|
||||
Map<String, JobParameter> parameterMap = parameters.getParameters();
|
||||
HashMap<String, JobParameter> copy = new HashMap<>(parameterMap);
|
||||
|
||||
for (Map.Entry<String, JobParameter> parameter : copy.entrySet()) {
|
||||
if (!parameter.getValue().isIdentifying()) {
|
||||
parameterMap.remove(parameter.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
return new JobParameters(parameterMap);
|
||||
}
|
||||
|
||||
private boolean isStoppedOrFailed(JobExecution execution) {
|
||||
BatchStatus status = execution.getStatus();
|
||||
return (status == BatchStatus.STOPPED || status == BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
private JobParameters merge(JobParameters parameters, JobParameters additionals) {
|
||||
Map<String, JobParameter> merged = new HashMap<>();
|
||||
merged.putAll(parameters.getParameters());
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.task.batch.configuration.TaskBatchProperties;
|
||||
@@ -72,9 +73,6 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
@Autowired
|
||||
private JobExplorer jobExplorer;
|
||||
|
||||
@Autowired
|
||||
private BatchConfiguration batchConfigurer;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@@ -90,10 +88,9 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
batchConfigurer.clear();
|
||||
this.jobs = new JobBuilderFactory(this.jobRepository);
|
||||
this.steps = new StepBuilderFactory(this.jobRepository, this.transactionManager);
|
||||
Tasklet tasklet = (contribution, chunkContext) -> null;
|
||||
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());
|
||||
@@ -132,6 +129,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void runDifferentInstances() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
@@ -162,10 +160,8 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
|
||||
// try to re-run a failed execution
|
||||
Executable executable = () -> {
|
||||
this.runner.execute(this.job,
|
||||
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
};
|
||||
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");
|
||||
@@ -187,6 +183,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
}
|
||||
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution()
|
||||
throws Exception {
|
||||
@@ -254,10 +251,6 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
|
||||
this.jobRepository = this.jobRepositoryFactory.getObject();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.jobRepositoryFactory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobRepository getJobRepository() {
|
||||
return this.jobRepository;
|
||||
|
||||
@@ -70,7 +70,7 @@ 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 jobId 1 with jobExecutionId of 1 \n";
|
||||
"Job jobA failed during execution for job instance id 1 with jobExecutionId of 1 \n";
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@@ -146,9 +146,8 @@ public class TaskJobLauncherCommandLineRunnerTests {
|
||||
validateContext();
|
||||
assertThat(applicationContext.getBean(JobLauncherCommandLineRunner.class)).isNotNull();
|
||||
|
||||
Executable executable = () -> {
|
||||
applicationContext.getBean(TaskJobLauncherCommandLineRunner.class);
|
||||
};
|
||||
Executable executable = () -> 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");
|
||||
@@ -168,9 +167,9 @@ public class TaskJobLauncherCommandLineRunnerTests {
|
||||
}
|
||||
|
||||
private void validateForFail(String errorMessage, Class clazz, String [] enabledArgs) {
|
||||
Executable executable = () -> {
|
||||
this.applicationContext = SpringApplication
|
||||
.run(new Class[] { clazz,PropertyPlaceholderAutoConfiguration.class}, enabledArgs);};
|
||||
Executable executable = () -> this.applicationContext = SpringApplication
|
||||
.run(new Class[] { clazz,PropertyPlaceholderAutoConfiguration.class}, enabledArgs);
|
||||
|
||||
Throwable exception = assertThrows(IllegalStateException.class, executable);
|
||||
assertThat(exception.getCause().getMessage()).isEqualTo(errorMessage);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PrefixTests {
|
||||
@Test
|
||||
public void testPrefix() {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
JobConfiguration.class, new String[] { "--spring.cloud.task.tablePrefix=FOO_" });
|
||||
JobConfiguration.class, "--spring.cloud.task.tablePrefix=FOO_");
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class TaskBatchExecutionListenerTests {
|
||||
|
||||
public static final String[] ARGS = new String[] {};
|
||||
private static final String[] ARGS = new String[] {};
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@@ -89,35 +89,35 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNoAutoConfigurationEnabled() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
new String[] {"--spring.cloud.task.batch.listener.enabled=false"});
|
||||
"--spring.cloud.task.batch.listener.enabled=false");
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNoAutoConfigurationEnable() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class ,
|
||||
new String[] {"--spring.cloud.task.batch.listener.enable=false"});
|
||||
"--spring.cloud.task.batch.listener.enable=false");
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNoAutoConfigurationBothDisabled() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class ,
|
||||
new String[] {"--spring.cloud.task.batch.listener.enable=false --spring.cloud.task.batch.listener.enabled=false"});
|
||||
"--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 ,
|
||||
new String[] {"--spring.cloud.task.batch.listener.enable=true"});
|
||||
"--spring.cloud.task.batch.listener.enable=true");
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoConfigurationEnabled() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class ,
|
||||
new String[] {"--spring.cloud.task.batch.listener.enabled=true"});
|
||||
"--spring.cloud.task.batch.listener.enabled=true");
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithJobNames() {
|
||||
List jobNames = new ArrayList<String>(3);
|
||||
List<String> jobNames = new ArrayList<>(3);
|
||||
jobNames.add("job1");
|
||||
jobNames.add("job2");
|
||||
jobNames.add("TESTOBJECT");
|
||||
@@ -215,7 +215,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithEmptyJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
beanPostProcessor(Collections.<String>emptyList());
|
||||
beanPostProcessor(Collections.emptyList());
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.
|
||||
@@ -226,8 +226,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBatchExecutionListenerBeanPostProcessorNullJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor =
|
||||
beanPostProcessor(null);
|
||||
beanPostProcessor(null);
|
||||
}
|
||||
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -62,6 +61,5 @@ import org.springframework.context.annotation.Import;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ })
|
||||
public @interface EnableTask {
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.cloud.task.configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -125,7 +123,7 @@ public class SimpleTaskAutoConfiguration {
|
||||
* Determines the {@link TaskConfigurer} to use.
|
||||
*/
|
||||
@PostConstruct
|
||||
protected void initialize() throws Exception {
|
||||
protected void initialize() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +175,7 @@ public class SimpleTaskAutoConfiguration {
|
||||
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))
|
||||
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).collect(Collectors.counting());
|
||||
.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" +
|
||||
|
||||
@@ -206,7 +206,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
}
|
||||
else if (this.listenerFailed || this.applicationFailedEvent != null) {
|
||||
Throwable exception = this.listenerException;
|
||||
if (exception != null && exception instanceof TaskExecutionException) {
|
||||
if (exception instanceof TaskExecutionException) {
|
||||
TaskExecutionException taskExecutionException = (TaskExecutionException) exception;
|
||||
if (taskExecutionException.getCause() instanceof InvocationTargetException) {
|
||||
InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException
|
||||
@@ -217,7 +217,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null && exception instanceof ExitCodeGenerator) {
|
||||
if (exception instanceof ExitCodeGenerator) {
|
||||
exitCode = ((ExitCodeGenerator) exception).getExitCode();
|
||||
}
|
||||
else {
|
||||
@@ -229,46 +229,54 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
}
|
||||
|
||||
private void doTaskStart() {
|
||||
try {
|
||||
if(!this.started) {
|
||||
this.taskExecutionListeners = new ArrayList<>();
|
||||
this.taskListenerExecutorObjectFactory.getObject();
|
||||
if(!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
|
||||
this.taskExecutionListeners.addAll(this.taskExecutionListenersFromContext);
|
||||
}
|
||||
this.taskExecutionListeners.add(this.taskListenerExecutorObjectFactory.getObject());
|
||||
|
||||
if(!this.started) {
|
||||
this.taskExecutionListeners = new ArrayList<>();
|
||||
this.taskListenerExecutorObjectFactory.getObject();
|
||||
if(!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
|
||||
this.taskExecutionListeners.addAll(this.taskExecutionListenersFromContext);
|
||||
}
|
||||
this.taskExecutionListeners.add(this.taskListenerExecutorObjectFactory.getObject());
|
||||
List<String> args = new ArrayList<>(0);
|
||||
|
||||
List<String> args = new ArrayList<>(0);
|
||||
|
||||
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()));
|
||||
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(),
|
||||
this.taskNameResolver.getTaskName(), new Date(), args,
|
||||
this.taskProperties.getExternalExecutionId(),
|
||||
this.taskProperties.getParentExecutionId());
|
||||
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()));
|
||||
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(),
|
||||
this.taskNameResolver.getTaskName(), new Date(), args,
|
||||
this.taskProperties.getExternalExecutionId(),
|
||||
this.taskProperties.getParentExecutionId());
|
||||
}
|
||||
else {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(this.taskNameResolver.getTaskName());
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setArguments(args);
|
||||
taskExecution.setExternalExecutionId(this.taskProperties.getExternalExecutionId());
|
||||
taskExecution.setParentExecutionId(this.taskProperties.getParentExecutionId());
|
||||
this.taskExecution = this.taskRepository.createTaskExecution(
|
||||
taskExecution);
|
||||
}
|
||||
}
|
||||
else {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(this.taskNameResolver.getTaskName());
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setArguments(args);
|
||||
taskExecution.setExternalExecutionId(this.taskProperties.getExternalExecutionId());
|
||||
taskExecution.setParentExecutionId(this.taskProperties.getParentExecutionId());
|
||||
this.taskExecution = this.taskRepository.createTaskExecution(
|
||||
taskExecution);
|
||||
logger.error("Multiple start events have been received. The first one was " +
|
||||
"recorded.");
|
||||
}
|
||||
|
||||
setExitMessage(invokeOnTaskStartup(this.taskExecution));
|
||||
}
|
||||
else {
|
||||
logger.error("Multiple start events have been received. The first one was " +
|
||||
"recorded.");
|
||||
catch (Throwable t) {
|
||||
// This scenario will result in a context that was not startup.
|
||||
|
||||
this.doTaskEnd();
|
||||
throw t;
|
||||
}
|
||||
setExitMessage(invokeOnTaskStartup(this.taskExecution));
|
||||
}
|
||||
|
||||
private TaskExecution invokeOnTaskStartup(TaskExecution taskExecution){
|
||||
@@ -388,7 +396,6 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
this.doTaskEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,12 +30,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
|
||||
import org.springframework.aop.scope.ScopedObject;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.cloud.task.listener.TaskExecutionListener;
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
import org.springframework.cloud.task.listener.annotation.BeforeTask;
|
||||
import org.springframework.cloud.task.listener.annotation.FailedTask;
|
||||
@@ -55,7 +52,7 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory<TaskExec
|
||||
private final static Log logger = LogFactory.getLog(TaskListenerExecutor.class);
|
||||
|
||||
private final Set<Class<?>> nonAnnotatedClasses =
|
||||
Collections.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>());
|
||||
Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@@ -153,12 +150,7 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory<TaskExec
|
||||
private static class MethodGetter<T extends Annotation> {
|
||||
public Map<Method, T> getMethods(final Class<?> type, final Class<T> annotationClass){
|
||||
return MethodIntrospector.selectMethods(type,
|
||||
new MethodIntrospector.MetadataLookup<T>() {
|
||||
@Override
|
||||
public T inspect(Method method) {
|
||||
return AnnotationUtils.findAnnotation(method, annotationClass);
|
||||
}
|
||||
});
|
||||
(MethodIntrospector.MetadataLookup<T>) method -> AnnotationUtils.findAnnotation(method, annotationClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class SimpleSingleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository() throws Exception {
|
||||
public void testRepository() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -84,7 +84,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() throws Exception {
|
||||
public void testAutoConfigurationDisabled() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -102,7 +102,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() throws Exception {
|
||||
public void testRepositoryInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -115,7 +115,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() throws Exception {
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
@@ -221,12 +221,12 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource2() {
|
||||
return mock(DataSource.class);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -66,10 +66,9 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTest() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
@@ -86,10 +85,9 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation() {
|
||||
this.applicationContext = SpringApplication.run( TaskConfigurationWithAnotation.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Test results do not show create task message: " + output,
|
||||
@@ -105,10 +103,9 @@ public class TaskCoreTests {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run( TaskExceptionConfiguration.class,
|
||||
new String[] {
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false" });
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
@@ -132,12 +129,11 @@ public class TaskCoreTests {
|
||||
public void invalidExecutionId() {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
applicationContext = this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, new String[]{
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class, "--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.executionid=55"});
|
||||
"--spring.cloud.task.executionid=55");
|
||||
}
|
||||
catch (ApplicationContextException exception) {
|
||||
exceptionFired = true;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testTablesCreated() throws Exception {
|
||||
public void testTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(4);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testNoTablesCreated() throws Exception {
|
||||
public void testNoTablesCreated() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> rows= jdbcTemplate.queryForList("SHOW TABLES");
|
||||
assertThat(rows.size()).isEqualTo(0);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Date;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
@@ -53,9 +54,9 @@ public class TaskExecutionListenerTests {
|
||||
|
||||
private static final String EXCEPTION_MESSAGE = "This was expected";
|
||||
|
||||
public static boolean beforeTaskDidFireOnError = false;
|
||||
public static boolean endTaskDidFireOnError = false;
|
||||
public static boolean failedTaskDidFireOnError = false;
|
||||
private static boolean beforeTaskDidFireOnError = false;
|
||||
private static boolean endTaskDidFireOnError = false;
|
||||
private static boolean failedTaskDidFireOnError = false;
|
||||
|
||||
@BeforeTask
|
||||
public void setup() {
|
||||
@@ -81,8 +82,8 @@ public class TaskExecutionListenerTests {
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener =
|
||||
context.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, false, false, taskExecution,taskExecutionListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,8 +131,8 @@ public class TaskExecutionListenerTests {
|
||||
context.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
assertEquals(true,taskExecutionListener.isTaskStartup());
|
||||
assertEquals(true,taskExecutionListener.isTaskEnd());
|
||||
assertTrue(taskExecutionListener.isTaskStartup());
|
||||
assertTrue(taskExecutionListener.isTaskEnd());
|
||||
assertEquals(TestListener.END_MESSAGE, taskExecutionListener.getTaskExecution().getExitMessage());
|
||||
assertTrue(taskExecutionListener.getTaskExecution().getErrorMessage().contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure"));
|
||||
assertNull(taskExecutionListener.getThrowable());
|
||||
@@ -149,8 +150,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, false, taskExecution,taskExecutionListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,8 +169,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, true, taskExecution,taskExecutionListener);
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,taskExecutionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,13 +178,13 @@ public class TaskExecutionListenerTests {
|
||||
* method is called.
|
||||
*/
|
||||
@Test
|
||||
public void testAnnotationCreate() throws Exception {
|
||||
public void testAnnotationCreate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener =
|
||||
context.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, false, false, taskExecution,annotatedListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +199,8 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 0, "wombat",
|
||||
new Date(), new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, false, taskExecution,annotatedListener);
|
||||
new Date(), new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, false, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,14 +218,14 @@ public class TaskExecutionListenerTests {
|
||||
context.publishEvent(new ApplicationReadyEvent(application, new String[0], context));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", new Date(),
|
||||
new Date(), null, new ArrayList<String>(), null, null);
|
||||
verifyListenerResults(true, true, true, taskExecution,annotatedListener);
|
||||
new Date(), null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(true, true, taskExecution,annotatedListener);
|
||||
}
|
||||
|
||||
private void verifyListenerResults (boolean isTaskStartup, boolean isTaskEnd,
|
||||
boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener){
|
||||
assertEquals(isTaskStartup,actualListener.isTaskStartup());
|
||||
private void verifyListenerResults(boolean isTaskEnd,
|
||||
boolean isTaskFailed, TaskExecution taskExecution,
|
||||
TestListener actualListener){
|
||||
assertTrue(actualListener.isTaskStartup());
|
||||
assertEquals(isTaskEnd,actualListener.isTaskEnd());
|
||||
assertEquals(isTaskFailed,actualListener.isTaskFailed());
|
||||
if(isTaskFailed){
|
||||
@@ -323,6 +324,11 @@ public class TaskExecutionListenerTests {
|
||||
return new AnnotatedTaskListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner() {
|
||||
return args -> System.out.println("I was run");
|
||||
}
|
||||
|
||||
public static class AnnotatedTaskListener {
|
||||
|
||||
@BeforeTask
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.task.repository.support;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.util.TaskExecutionCreator;
|
||||
import org.springframework.cloud.task.util.TestDBUtils;
|
||||
@@ -59,9 +57,6 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private TaskExplorer taskExplorer;
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateEmptyExecution() {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultContext() throws Exception {
|
||||
public void testDefaultContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
@@ -68,7 +68,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDatabase() throws Exception {
|
||||
public void testNoDatabase() {
|
||||
this.context = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
|
||||
SimpleTaskRepository repository = new SimpleTaskRepository(new TaskExecutionDaoFactoryBean());
|
||||
assertThat(repository.getTaskExecutionDao(), instanceOf(MapTaskExecutionDao.class));
|
||||
@@ -77,7 +77,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoTaskConfiguration() throws Exception {
|
||||
public void testNoTaskConfiguration() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(EmptyConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
@@ -87,7 +87,7 @@ public class TaskDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testMultipleDataSourcesContext() throws Exception {
|
||||
public void testMultipleDataSourcesContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register( SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TestDefaultConfiguration implements InitializingBean {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskExplorer taskExplorer() throws Exception {
|
||||
public TaskExplorer taskExplorer() {
|
||||
return new SimpleTaskExplorer(this.factoryBean);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class JobConfiguration {
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt((String) item) * -1);
|
||||
return String.valueOf(Integer.parseInt(item) * -1);
|
||||
}
|
||||
})
|
||||
.writer(new ItemWriter<String>() {
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.spring.cloud;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.binder.test.junit.rabbit.RabbitTestSupport;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.batch.listener.support.JobExecutionEvent;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@@ -42,15 +40,6 @@ public class BatchEventsApplicationTests {
|
||||
// Count for two job execution events per task
|
||||
static CountDownLatch jobExecutionLatch = new CountDownLatch(2);
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
if(context != null && context.isActive()) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecution() throws Exception {
|
||||
SpringApplication.run(JobExecutionListenerBinding.class, "--spring.main.web-environment=false");
|
||||
@@ -69,7 +58,7 @@ public class BatchEventsApplicationTests {
|
||||
|
||||
@StreamListener(Sink.INPUT)
|
||||
public void receive(JobExecutionEvent execution) {
|
||||
Assert.assertEquals(String.format("Job name should be job"), "job", execution.getJobInstance().getJobName());
|
||||
Assert.assertEquals("Job name should be job", "job", execution.getJobInstance().getJobName());
|
||||
jobExecutionLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2018 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.
|
||||
*/
|
||||
package io.spring;
|
||||
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 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.
|
||||
|
||||
@@ -91,7 +91,7 @@ public class JpaApplicationTests {
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Test
|
||||
public void testBatchJobApp() throws Exception {
|
||||
public void testBatchJobApp() {
|
||||
final String INSERT_MESSAGE = "Hibernate: insert into task_run_output (";
|
||||
SpringApplication.run(JpaApplication.class, "--spring.datasource.url=" + DATASOURCE_URL,
|
||||
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
@@ -101,7 +101,7 @@ public class JpaApplicationTests {
|
||||
assertTrue("Unable to find the insert message: " + output, output.contains(INSERT_MESSAGE));
|
||||
JdbcTemplate template = new JdbcTemplate(this.dataSource);
|
||||
Map<String, Object> result = template.queryForMap("Select * from TASK_RUN_OUTPUT");
|
||||
assertThat((Long)(result.get("ID")), is(1L));
|
||||
assertThat(result.get("ID"), is(1L));
|
||||
assertThat(((String) result.get("OUTPUT")), containsString("Executed at"));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2018 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.
|
||||
*/
|
||||
package io.spring;
|
||||
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2018 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2018 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.
|
||||
|
||||
@@ -39,8 +39,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
*/
|
||||
public class TaskEventTests {
|
||||
|
||||
private static final String TASK_NAME = "taskEventTest";
|
||||
|
||||
@Test
|
||||
public void testDefaultConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
|
||||
Reference in New Issue
Block a user