Identified depracations and updated the code
This commit is contained in:
@@ -60,19 +60,19 @@ public class BatchEventsApplication {
|
||||
|
||||
@Bean
|
||||
public Step step1() {
|
||||
return new StepBuilder("step1").repository(this.jobRepository).tasklet(new Tasklet() {
|
||||
return new StepBuilder("step1", this.jobRepository).tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Tasklet has run");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(transactionManager).build();
|
||||
}, transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return new StepBuilder("step2").repository(this.jobRepository)
|
||||
.<String, String>chunk(DEFAULT_CHUNK_COUNT)
|
||||
return new StepBuilder("step2", this.jobRepository)
|
||||
.<String, String>chunk(DEFAULT_CHUNK_COUNT, this.transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
@@ -88,13 +88,12 @@ public class BatchEventsApplication {
|
||||
}
|
||||
}
|
||||
})
|
||||
.transactionManager(transactionManager)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return new JobBuilder("job").repository(this.jobRepository).start(step1()).next(step2()).build();
|
||||
return new JobBuilder("job", this.jobRepository).start(step1()).next(step2()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -160,8 +160,7 @@ public class JobConfiguration {
|
||||
|
||||
@Bean
|
||||
public Step step1(PartitionHandler partitionHandler) throws Exception {
|
||||
return new StepBuilder("step1").repository(this.jobRepository)
|
||||
.partitioner(workerStep().getName(), partitioner())
|
||||
return new StepBuilder("step1", this.jobRepository).partitioner(workerStep().getName(), partitioner())
|
||||
.step(workerStep())
|
||||
.partitionHandler(partitionHandler)
|
||||
.build();
|
||||
@@ -169,9 +168,8 @@ public class JobConfiguration {
|
||||
|
||||
@Bean
|
||||
public Step workerStep() {
|
||||
return new StepBuilder("workerStep").repository(this.jobRepository)
|
||||
.tasklet(workerTasklet(null))
|
||||
.transactionManager(this.transactionManager)
|
||||
return new StepBuilder("workerStep", this.jobRepository).repository(this.jobRepository)
|
||||
.tasklet(workerTasklet(null), this.transactionManager)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -179,8 +177,7 @@ public class JobConfiguration {
|
||||
@Profile("!worker")
|
||||
public Job partitionedJob(PartitionHandler partitionHandler) throws Exception {
|
||||
Random random = new Random();
|
||||
return new JobBuilder("partitionedJob" + random.nextInt()).repository(this.jobRepository)
|
||||
.start(step1(partitionHandler))
|
||||
return new JobBuilder("partitionedJob" + random.nextInt(), this.jobRepository).start(step1(partitionHandler))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package io.spring;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.SQLException;
|
||||
@@ -26,16 +27,16 @@ import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.h2.tools.Server;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
//import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
//import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
@@ -145,9 +146,9 @@ public class BatchJobApplicationTests {
|
||||
}
|
||||
|
||||
private void validateFileResult() throws Exception {
|
||||
// AssertFile.assertLineCount(6, new FileSystemResource("./result.txt"));
|
||||
// AssertFile.assertFileEquals(new ClassPathResource("testresult.txt"),
|
||||
// new FileSystemResource(this.outputFile));
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_16).size()).isEqualTo(6);
|
||||
assertThat(Assertions.contentOf((new ClassPathResource("testresult.txt")).getFile())
|
||||
.equals(new FileSystemResource(this.outputFile)));
|
||||
}
|
||||
|
||||
private void validateDBResult() {
|
||||
|
||||
Reference in New Issue
Block a user