Merged MapTaskExecutionTests into TaskExecutionDaoTests
Removes duplicated code. Resolves #427
This commit is contained in:
@@ -71,21 +71,25 @@ public class BatchEventsApplication {
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return new StepBuilder("step2").repository(this.jobRepository).<String, String>chunk(DEFAULT_CHUNK_COUNT)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt(item) * -1);
|
||||
return new StepBuilder("step2").repository(this.jobRepository)
|
||||
.<String, String>chunk(DEFAULT_CHUNK_COUNT)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt(item) * -1);
|
||||
}
|
||||
})
|
||||
.writer(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
for (String item : items) {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}).writer(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
for (String item : items) {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}
|
||||
}).transactionManager(transactionManager).build();
|
||||
}
|
||||
})
|
||||
.transactionManager(transactionManager)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -84,8 +84,10 @@ public class BatchEventsApplicationTests {
|
||||
private List<Message<byte[]>> testListener(String bindingName, int numberToRead) {
|
||||
List<Message<byte[]>> results = new ArrayList<>();
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsTestApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run(getCommandLineParams(true));
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsTestApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(getCommandLineParams(true));
|
||||
OutputDestination target = this.applicationContext.getBean(OutputDestination.class);
|
||||
for (int i = 0; i < numberToRead; i++) {
|
||||
results.add(target.receive(10000, bindingName));
|
||||
|
||||
@@ -57,22 +57,24 @@ public class JobConfiguration {
|
||||
@Bean
|
||||
public Job job1() {
|
||||
return new JobBuilder("job1", this.jobRepository)
|
||||
.start(new StepBuilder("job1step1", this.jobRepository).tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
|
||||
throws Exception {
|
||||
logger.info("Job1 was run");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("job1step1", this.jobRepository).tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
logger.info("Job1 was run");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
static class RuntimeHint implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.proxies().registerJdkProxy(builder -> builder
|
||||
.proxiedInterfaces(TypeReference.of("org.springframework.batch.core.launch.JobOperator"))
|
||||
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
|
||||
hints.proxies()
|
||||
.registerJdkProxy(builder -> builder
|
||||
.proxiedInterfaces(TypeReference.of("org.springframework.batch.core.launch.JobOperator"))
|
||||
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ public class JpaApplicationTests {
|
||||
this.dataSource = dataSource;
|
||||
try {
|
||||
this.server = Server
|
||||
.createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
.createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -55,17 +55,23 @@ public class ExternalDataSourceConfiguration {
|
||||
@Primary
|
||||
public DataSource dataSource(
|
||||
@Qualifier("springDataSourceProperties") DataSourceProperties springDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(springDataSourceProperties.getDriverClassName())
|
||||
.url(springDataSourceProperties.getUrl()).password(springDataSourceProperties.getPassword())
|
||||
.username(springDataSourceProperties.getUsername()).build();
|
||||
return DataSourceBuilder.create()
|
||||
.driverClassName(springDataSourceProperties.getDriverClassName())
|
||||
.url(springDataSourceProperties.getUrl())
|
||||
.password(springDataSourceProperties.getPassword())
|
||||
.username(springDataSourceProperties.getUsername())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource secondDataSource(
|
||||
@Qualifier("secondDataSourceProperties") DataSourceProperties secondDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(secondDataSourceProperties.getDriverClassName())
|
||||
.url(secondDataSourceProperties.getUrl()).password(secondDataSourceProperties.getPassword())
|
||||
.username(secondDataSourceProperties.getUsername()).build();
|
||||
return DataSourceBuilder.create()
|
||||
.driverClassName(secondDataSourceProperties.getDriverClassName())
|
||||
.url(secondDataSourceProperties.getUrl())
|
||||
.password(secondDataSourceProperties.getPassword())
|
||||
.username(secondDataSourceProperties.getUsername())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@ public class MultiDataSourcesApplicationTests {
|
||||
String output = capturedOutput.toString();
|
||||
|
||||
assertThat(output.contains("There are 2 DataSources within this application"))
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
.as("Unable to find CommandLineRunner output: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{")).as("Unable to find start task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution")).as("Unable to find update task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,11 +78,12 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
String output = capturedOutput.toString();
|
||||
|
||||
assertThat(output.contains("There are 2 DataSources within this application"))
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
.as("Unable to find CommandLineRunner output: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{")).as("Unable to find start task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution")).as("Unable to find update task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -97,8 +98,10 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (defaultServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort))
|
||||
.start();
|
||||
defaultServer = server;
|
||||
}
|
||||
}
|
||||
@@ -113,8 +116,10 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (secondServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(secondRandomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(secondRandomPort))
|
||||
.start();
|
||||
secondServer = server;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class JobConfiguration {
|
||||
TaskRepository taskRepository, @Autowired(required = false) ThreadPoolTaskExecutor executor)
|
||||
throws Exception {
|
||||
Resource resource = this.resourceLoader
|
||||
.getResource("maven://io.spring.cloud:partitioned-batch-job:3.0.0-SNAPSHOT");
|
||||
.getResource("maven://io.spring.cloud:partitioned-batch-job:3.0.0-SNAPSHOT");
|
||||
|
||||
DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource,
|
||||
"workerStep", taskRepository, executor);
|
||||
@@ -161,14 +161,18 @@ public class JobConfiguration {
|
||||
@Bean
|
||||
public Step step1(PartitionHandler partitionHandler) throws Exception {
|
||||
return new StepBuilder("step1").repository(this.jobRepository)
|
||||
.partitioner(workerStep().getName(), partitioner()).step(workerStep())
|
||||
.partitionHandler(partitionHandler).build();
|
||||
.partitioner(workerStep().getName(), partitioner())
|
||||
.step(workerStep())
|
||||
.partitionHandler(partitionHandler)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step workerStep() {
|
||||
return new StepBuilder("workerStep").repository(this.jobRepository).tasklet(workerTasklet(null))
|
||||
.transactionManager(this.transactionManager).build();
|
||||
return new StepBuilder("workerStep").repository(this.jobRepository)
|
||||
.tasklet(workerTasklet(null))
|
||||
.transactionManager(this.transactionManager)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -176,7 +180,8 @@ public class JobConfiguration {
|
||||
public Job partitionedJob(PartitionHandler partitionHandler) throws Exception {
|
||||
Random random = new Random();
|
||||
return new JobBuilder("partitionedJob" + random.nextInt()).repository(this.jobRepository)
|
||||
.start(step1(partitionHandler)).build();
|
||||
.start(step1(partitionHandler))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,7 +117,8 @@ public class TaskPartitionerTests {
|
||||
Page<TaskExecution> taskExecutions = this.taskExplorer.findAll(PageRequest.of(0, 10));
|
||||
assertThat(taskExecutions.getTotalElements()).as("Five rows are expected").isEqualTo(5);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName("PartitionedBatchJobTask"))
|
||||
.as("Only One master is expected").isEqualTo(1);
|
||||
.as("Only One master is expected")
|
||||
.isEqualTo(1);
|
||||
for (TaskExecution taskExecution : taskExecutions) {
|
||||
assertThat(taskExecution.getExitCode().intValue()).as("return code should be 0").isEqualTo(0);
|
||||
}
|
||||
@@ -130,8 +131,9 @@ public class TaskPartitionerTests {
|
||||
public org.h2.tools.Server initH2TCPServer() {
|
||||
Server server;
|
||||
try {
|
||||
server = Server.createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -128,8 +128,8 @@ public class BatchJobApplicationTests {
|
||||
|
||||
if (defaultServer == null) {
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
defaultServer = server;
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
|
||||
|
||||
@@ -83,8 +83,9 @@ public class TaskProcessorApplicationTests {
|
||||
private List<Message<byte[]>> testListener(String bindingName, int numberToRead) {
|
||||
List<Message<byte[]>> results = new ArrayList<>();
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(TaskProcessorTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run();
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(TaskProcessorTestApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
|
||||
InputDestination input = this.applicationContext.getBean(InputDestination.class);
|
||||
OutputDestination target = this.applicationContext.getBean(OutputDestination.class);
|
||||
|
||||
@@ -71,8 +71,9 @@ public class TaskSinkApplicationTests {
|
||||
|
||||
assertThat(actualRequest.getCommandlineArguments().isEmpty()).isTrue();
|
||||
assertThat(actualRequest.getDefinition().getProperties().get("server.port")).isEqualTo("0");
|
||||
assertThat(actualRequest.getResource().toString()
|
||||
.contains("org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE")).isTrue();
|
||||
assertThat(actualRequest.getResource()
|
||||
.toString()
|
||||
.contains("org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public class TaskApplicationTests {
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(TEST_DATE_DOTS)).as("Unable to find the timestamp: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output).isTrue();
|
||||
|
||||
String taskTitle = "Demo Timestamp Task";
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TimestampTaskPropertiesTests {
|
||||
context.refresh();
|
||||
TimestampTaskProperties properties = context.getBean(TimestampTaskProperties.class);
|
||||
assertThat(properties.getFormat()).as("result does not match default format.")
|
||||
.isEqualTo("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
.isEqualTo("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user