This commit is contained in:
Michael Minella
2018-10-31 22:11:01 -05:00
parent d2bc2530cc
commit 90c88c52e6
29 changed files with 197 additions and 205 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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(