Identified depracations and updated the code
This commit is contained in:
@@ -80,15 +80,16 @@ public class SingleStepJobAutoConfiguration {
|
||||
public Job job(ItemReader<Map<String, Object>> itemReader, ItemWriter<Map<String, Object>> itemWriter) {
|
||||
|
||||
SimpleStepBuilder<Map<String, Object>, Map<String, Object>> stepBuilder = new StepBuilder(
|
||||
this.properties.getStepName()).repository(this.jobRepository)
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize())
|
||||
this.properties.getStepName(), this.jobRepository)
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize(),
|
||||
this.transactionManager)
|
||||
.reader(itemReader);
|
||||
|
||||
stepBuilder.processor(this.itemProcessor);
|
||||
|
||||
Step step = stepBuilder.writer(itemWriter).transactionManager(this.transactionManager).build();
|
||||
Step step = stepBuilder.writer(itemWriter).build();
|
||||
|
||||
return new JobBuilder(this.properties.getJobName()).repository(this.jobRepository).start(step).build();
|
||||
return new JobBuilder(this.properties.getJobName(), this.jobRepository).start(step).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,13 @@ package org.springframework.cloud.task.batch.autoconfigure.flatfile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -40,7 +42,6 @@ import org.springframework.batch.item.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.file.transform.PassThroughLineAggregator;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.batch.test.AssertFile;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -166,9 +167,9 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
FlatFileItemWriter writer = context.getBean(FlatFileItemWriter.class);
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
AssertFile.assertFileEquals(new ClassPathResource("writerTestUTF16.txt"),
|
||||
new FileSystemResource(this.outputFile));
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_16).size()).isEqualTo(3);
|
||||
assertThat(Assertions.contentOf((new ClassPathResource("writerTestUTF16.txt")).getFile())
|
||||
.equals(new FileSystemResource(this.outputFile)));
|
||||
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "saveState")).isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "append")).isTrue();
|
||||
@@ -209,7 +210,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
AssertFile.assertLineCount(2, this.outputFile);
|
||||
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(2);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
@@ -246,7 +247,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
@@ -281,7 +282,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
@@ -315,7 +316,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
@@ -351,7 +352,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
AssertFile.assertLineCount(5, this.outputFile);
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(5);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
|
||||
@@ -278,27 +278,6 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
@Configuration
|
||||
public static class JobWithFailureTaskExecutorConfiguration {
|
||||
|
||||
// @Bean
|
||||
// public BatchConfigurer batchConfigurer(DataSource dataSource) {
|
||||
// return new TestBatchConfigurer(dataSource);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// private static class TestBatchConfigurer extends DefaultBatchConfigurer {
|
||||
//
|
||||
// TestBatchConfigurer(DataSource dataSource) {
|
||||
// super(dataSource);
|
||||
// }
|
||||
//
|
||||
// protected JobLauncher createJobLauncher() throws Exception {
|
||||
// TaskExecutorJobLauncher jobLauncher = new TaskExecutorJobLauncher();
|
||||
// jobLauncher.setJobRepository(getJobRepository());
|
||||
// jobLauncher.setTaskExecutor(new ConcurrentTaskExecutor());
|
||||
// jobLauncher.afterPropertiesSet();
|
||||
// return jobLauncher;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -54,23 +54,24 @@ public class JobConfiguration {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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("Executed");
|
||||
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, transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
@@ -84,7 +85,7 @@ public class JobConfiguration {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}
|
||||
}).transactionManager(transactionManager).build();
|
||||
}).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,30 +47,30 @@ public class JobSkipConfiguration {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).transactionManager(transactionManager).build();
|
||||
}, transactionManager).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return new StepBuilder("step2").repository(this.jobRepository).chunk(3).faultTolerant()
|
||||
return new StepBuilder("step2", this.jobRepository).chunk(3, transactionManager).faultTolerant()
|
||||
.skip(IllegalStateException.class).skipLimit(100).reader(new SkipItemReader())
|
||||
.processor(new ItemProcessor<Object, Object>() {
|
||||
@Override
|
||||
public String process(Object item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt((String) item) * -1);
|
||||
}
|
||||
}).writer(new SkipItemWriter()).transactionManager(transactionManager).build();
|
||||
}).writer(new SkipItemWriter()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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