Added ability to cofigure CommandLineRunner order

This commit adds the ability to configure the order for the
TaskJobLauncherCommandLineRunner.  It also provides minor polish on a
few other code review related items.
This commit is contained in:
Michael Minella
2018-02-12 17:00:22 -06:00
parent cd4dbe6a93
commit 1ae7930d09
7 changed files with 66 additions and 13 deletions

View File

@@ -43,10 +43,25 @@ public class TaskJobLauncherAutoConfigurationTests {
@Test
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
this.contextRunner.
withPropertyValues("spring.cloud.task.batch.commandLineRunnerEnabled=true").
withPropertyValues("spring.cloud.task.batch.failOnJobFailure=true").
run(context -> {
assertThat(context).hasSingleBean(TaskJobLauncherCommandLineRunner.class);
assertThat(context).doesNotHaveBean(JobLauncherCommandLineRunner.class);
assertThat(context.getBean(TaskJobLauncherCommandLineRunner.class)
.getOrder())
.isEqualTo(0);
});
}
@Test
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
this.contextRunner.
withPropertyValues("spring.cloud.task.batch.failOnJobFailure=true",
"spring.cloud.task.batch.commandLineRunnerOrder=100").
run(context -> {
assertThat(context.getBean(TaskJobLauncherCommandLineRunner.class)
.getOrder())
.isEqualTo(100);
});
}
@@ -58,3 +73,4 @@ public class TaskJobLauncherAutoConfigurationTests {
});
}
}

View File

@@ -65,7 +65,7 @@ public class TaskJobLauncherCommandLineRunnerCoreTests {
private JobExplorer jobExplorer;
@Autowired
PlatformTransactionManager transactionManager;
private PlatformTransactionManager transactionManager;
private TaskJobLauncherCommandLineRunner runner;

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.task.batch.handler;
import java.util.Set;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Test;
@@ -37,13 +36,11 @@ import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
import org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration;
import org.springframework.cloud.task.batch.configuration.TaskJobLauncherAutoConfiguration;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.cloud.task.repository.TaskExecution;
import org.springframework.cloud.task.repository.TaskExplorer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -68,7 +65,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Test
public void testTaskJobLauncherCLRSuccessFail() {
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.commandLineRunnerEnabled=true" };
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
boolean isExceptionThrown = false;
try {
this.applicationContext = SpringApplication
@@ -88,7 +85,7 @@ public class TaskJobLauncherCommandLineRunnerTests {
@Test
public void testTaskJobLauncherPickOneJob() {
String[] enabledArgs = new String[] {
"--spring.cloud.task.batch.commandLineRunnerEnabled=true",
"--spring.cloud.task.batch.failOnJobFailure=true",
"--spring.cloud.task.batch.jobNames=jobSucceed" };
boolean isExceptionThrown = false;
try {