Skip to content

Commit 4f0b68b

Browse files
committed
Identified depracations and updated the code
1 parent afc1b2e commit 4f0b68b

File tree

8 files changed

+41
-62
lines changed

8 files changed

+41
-62
lines changed

spring-cloud-starter-single-step-batch-job/src/main/java/org/springframework/cloud/task/batch/autoconfigure/SingleStepJobAutoConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ private void validateProperties(SingleStepJobProperties properties) {
8080
public Job job(ItemReader<Map<String, Object>> itemReader, ItemWriter<Map<String, Object>> itemWriter) {
8181

8282
SimpleStepBuilder<Map<String, Object>, Map<String, Object>> stepBuilder = new StepBuilder(
83-
this.properties.getStepName()).repository(this.jobRepository)
84-
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize())
83+
this.properties.getStepName(), this.jobRepository)
84+
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize(),
85+
this.transactionManager)
8586
.reader(itemReader);
8687

8788
stepBuilder.processor(this.itemProcessor);
8889

89-
Step step = stepBuilder.writer(itemWriter).transactionManager(this.transactionManager).build();
90+
Step step = stepBuilder.writer(itemWriter).build();
9091

91-
return new JobBuilder(this.properties.getJobName()).repository(this.jobRepository).start(step).build();
92+
return new JobBuilder(this.properties.getJobName(), this.jobRepository).start(step).build();
9293
}
9394

9495
}

spring-cloud-starter-single-step-batch-job/src/test/java/org/springframework/cloud/task/batch/autoconfigure/flatfile/FlatFileItemWriterAutoConfigurationTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import java.io.File;
2020
import java.io.InputStreamReader;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.ArrayList;
2223
import java.util.Collections;
2324
import java.util.List;
2425
import java.util.Map;
2526

27+
import org.assertj.core.api.Assertions;
2628
import org.junit.jupiter.api.AfterEach;
2729
import org.junit.jupiter.api.BeforeEach;
2830
import org.junit.jupiter.api.Test;
@@ -40,7 +42,6 @@
4042
import org.springframework.batch.item.file.transform.PassThroughLineAggregator;
4143
import org.springframework.batch.item.support.ListItemReader;
4244
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
43-
import org.springframework.batch.test.AssertFile;
4445
import org.springframework.boot.autoconfigure.AutoConfigurations;
4546
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
4647
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -166,9 +167,9 @@ public void testDelimitedFileGeneration() {
166167

167168
FlatFileItemWriter writer = context.getBean(FlatFileItemWriter.class);
168169

169-
AssertFile.assertLineCount(3, this.outputFile);
170-
AssertFile.assertFileEquals(new ClassPathResource("writerTestUTF16.txt"),
171-
new FileSystemResource(this.outputFile));
170+
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_16).size()).isEqualTo(3);
171+
assertThat(Assertions.contentOf((new ClassPathResource("writerTestUTF16.txt")).getFile())
172+
.equals(new FileSystemResource(this.outputFile)));
172173

173174
assertThat((Boolean) ReflectionTestUtils.getField(writer, "saveState")).isFalse();
174175
assertThat((Boolean) ReflectionTestUtils.getField(writer, "append")).isTrue();
@@ -209,7 +210,7 @@ public void testFormattedFileGeneration() {
209210
Thread.sleep(1000);
210211
}
211212

212-
AssertFile.assertLineCount(2, this.outputFile);
213+
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(2);
213214

214215
String results = FileCopyUtils
215216
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
@@ -246,7 +247,7 @@ public void testFormattedFieldExtractorFileGeneration() {
246247
Thread.sleep(1000);
247248
}
248249

249-
AssertFile.assertLineCount(3, this.outputFile);
250+
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(3);
250251

251252
String results = FileCopyUtils
252253
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
@@ -281,7 +282,7 @@ public void testFieldExtractorFileGeneration() {
281282
Thread.sleep(1000);
282283
}
283284

284-
AssertFile.assertLineCount(3, this.outputFile);
285+
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
285286

286287
String results = FileCopyUtils
287288
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
@@ -315,7 +316,7 @@ public void testCustomLineAggregatorFileGeneration() {
315316
Thread.sleep(1000);
316317
}
317318

318-
AssertFile.assertLineCount(3, this.outputFile);
319+
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
319320

320321
String results = FileCopyUtils
321322
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
@@ -351,7 +352,7 @@ public void testHeaderFooterFileGeneration() {
351352
Thread.sleep(1000);
352353
}
353354

354-
AssertFile.assertLineCount(5, this.outputFile);
355+
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(5);
355356

356357
String results = FileCopyUtils
357358
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherApplicationRunnerTests.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,6 @@ public static class JobWithFailureAnnotatedConfiguration extends JobWithFailureC
278278
@Configuration
279279
public static class JobWithFailureTaskExecutorConfiguration {
280280

281-
// @Bean
282-
// public BatchConfigurer batchConfigurer(DataSource dataSource) {
283-
// return new TestBatchConfigurer(dataSource);
284-
// }
285-
286281
}
287282

288-
// private static class TestBatchConfigurer extends DefaultBatchConfigurer {
289-
//
290-
// TestBatchConfigurer(DataSource dataSource) {
291-
// super(dataSource);
292-
// }
293-
//
294-
// protected JobLauncher createJobLauncher() throws Exception {
295-
// TaskExecutorJobLauncher jobLauncher = new TaskExecutorJobLauncher();
296-
// jobLauncher.setJobRepository(getJobRepository());
297-
// jobLauncher.setTaskExecutor(new ConcurrentTaskExecutor());
298-
// jobLauncher.afterPropertiesSet();
299-
// return jobLauncher;
300-
// }
301-
//
302-
// }
303-
304283
}

spring-cloud-task-integration-tests/src/test/java/configuration/JobConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,24 @@ public class JobConfiguration {
5454

5555
@Bean
5656
public Job job() {
57-
return new JobBuilder("job").repository(this.jobRepository).start(step1()).next(step2()).build();
57+
return new JobBuilder("job", this.jobRepository).start(step1()).next(step2()).build();
5858
}
5959

6060
@Bean
6161
public Step step1() {
62-
return new StepBuilder("step1").repository(this.jobRepository).tasklet(new Tasklet() {
62+
return new StepBuilder("step1", this.jobRepository).tasklet(new Tasklet() {
6363
@Override
6464
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
6565
System.out.println("Executed");
6666
return RepeatStatus.FINISHED;
6767
}
68-
}).transactionManager(transactionManager).build();
68+
}, transactionManager).build();
6969
}
7070

7171
@Bean
7272
public Step step2() {
73-
return new StepBuilder("step2").repository(this.jobRepository).<String, String>chunk(DEFAULT_CHUNK_COUNT)
73+
return new StepBuilder("step2", this.jobRepository)
74+
.<String, String>chunk(DEFAULT_CHUNK_COUNT, transactionManager)
7475
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
7576
.processor(new ItemProcessor<String, String>() {
7677
@Override
@@ -84,7 +85,7 @@ public void write(Chunk<? extends String> items) throws Exception {
8485
System.out.println(">> " + item);
8586
}
8687
}
87-
}).transactionManager(transactionManager).build();
88+
}).build();
8889
}
8990

9091
}

spring-cloud-task-integration-tests/src/test/java/configuration/JobSkipConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,30 @@ public class JobSkipConfiguration {
4747

4848
@Bean
4949
public Job job() {
50-
return new JobBuilder("job").repository(this.jobRepository).start(step1()).next(step2()).build();
50+
return new JobBuilder("job", this.jobRepository).start(step1()).next(step2()).build();
5151
}
5252

5353
@Bean
5454
public Step step1() {
55-
return new StepBuilder("step1").repository(this.jobRepository).tasklet(new Tasklet() {
55+
return new StepBuilder("step1", this.jobRepository).tasklet(new Tasklet() {
5656
@Override
5757
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
5858
System.out.println("Executed");
5959
return RepeatStatus.FINISHED;
6060
}
61-
}).transactionManager(transactionManager).build();
61+
}, transactionManager).build();
6262
}
6363

6464
@Bean
6565
public Step step2() {
66-
return new StepBuilder("step2").repository(this.jobRepository).chunk(3).faultTolerant()
66+
return new StepBuilder("step2", this.jobRepository).chunk(3, transactionManager).faultTolerant()
6767
.skip(IllegalStateException.class).skipLimit(100).reader(new SkipItemReader())
6868
.processor(new ItemProcessor<Object, Object>() {
6969
@Override
7070
public String process(Object item) throws Exception {
7171
return String.valueOf(Integer.parseInt((String) item) * -1);
7272
}
73-
}).writer(new SkipItemWriter()).transactionManager(transactionManager).build();
73+
}).writer(new SkipItemWriter()).build();
7474
}
7575

7676
}

spring-cloud-task-samples/batch-events/src/main/java/io/spring/cloud/BatchEventsApplication.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ public static class JobConfiguration {
6060

6161
@Bean
6262
public Step step1() {
63-
return new StepBuilder("step1").repository(this.jobRepository).tasklet(new Tasklet() {
63+
return new StepBuilder("step1", this.jobRepository).tasklet(new Tasklet() {
6464
@Override
6565
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
6666
System.out.println("Tasklet has run");
6767
return RepeatStatus.FINISHED;
6868
}
69-
}).transactionManager(transactionManager).build();
69+
}, transactionManager).build();
7070
}
7171

7272
@Bean
7373
public Step step2() {
74-
return new StepBuilder("step2").repository(this.jobRepository)
75-
.<String, String>chunk(DEFAULT_CHUNK_COUNT)
74+
return new StepBuilder("step2", this.jobRepository)
75+
.<String, String>chunk(DEFAULT_CHUNK_COUNT, this.transactionManager)
7676
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
7777
.processor(new ItemProcessor<String, String>() {
7878
@Override
@@ -88,13 +88,12 @@ public void write(Chunk<? extends String> items) throws Exception {
8888
}
8989
}
9090
})
91-
.transactionManager(transactionManager)
9291
.build();
9392
}
9493

9594
@Bean
9695
public Job job() {
97-
return new JobBuilder("job").repository(this.jobRepository).start(step1()).next(step2()).build();
96+
return new JobBuilder("job", this.jobRepository).start(step1()).next(step2()).build();
9897
}
9998

10099
}

spring-cloud-task-samples/partitioned-batch-job/src/main/java/io/spring/JobConfiguration.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,24 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
160160

161161
@Bean
162162
public Step step1(PartitionHandler partitionHandler) throws Exception {
163-
return new StepBuilder("step1").repository(this.jobRepository)
164-
.partitioner(workerStep().getName(), partitioner())
163+
return new StepBuilder("step1", this.jobRepository).partitioner(workerStep().getName(), partitioner())
165164
.step(workerStep())
166165
.partitionHandler(partitionHandler)
167166
.build();
168167
}
169168

170169
@Bean
171170
public Step workerStep() {
172-
return new StepBuilder("workerStep").repository(this.jobRepository)
173-
.tasklet(workerTasklet(null))
174-
.transactionManager(this.transactionManager)
171+
return new StepBuilder("workerStep", this.jobRepository).repository(this.jobRepository)
172+
.tasklet(workerTasklet(null), this.transactionManager)
175173
.build();
176174
}
177175

178176
@Bean
179177
@Profile("!worker")
180178
public Job partitionedJob(PartitionHandler partitionHandler) throws Exception {
181179
Random random = new Random();
182-
return new JobBuilder("partitionedJob" + random.nextInt()).repository(this.jobRepository)
183-
.start(step1(partitionHandler))
180+
return new JobBuilder("partitionedJob" + random.nextInt(), this.jobRepository).start(step1(partitionHandler))
184181
.build();
185182
}
186183

spring-cloud-task-samples/single-step-batch-job/src/test/java/io/spring/BatchJobApplicationTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.spring;
1818

1919
import java.io.File;
20+
import java.nio.charset.StandardCharsets;
2021
import java.nio.file.Files;
2122
import java.nio.file.Paths;
2223
import java.sql.SQLException;
@@ -26,16 +27,16 @@
2627

2728
import javax.sql.DataSource;
2829

30+
import org.assertj.core.api.Assertions;
2931
import org.h2.tools.Server;
3032
import org.junit.jupiter.api.AfterEach;
3133
import org.junit.jupiter.api.BeforeEach;
3234
import org.junit.jupiter.api.Test;
3335

34-
//import org.springframework.batch.test.AssertFile;
3536
import org.springframework.boot.SpringApplication;
3637
import org.springframework.boot.jdbc.DataSourceBuilder;
3738
import org.springframework.core.io.ClassPathResource;
38-
//import org.springframework.core.io.FileSystemResource;
39+
import org.springframework.core.io.FileSystemResource;
3940
import org.springframework.jdbc.core.JdbcTemplate;
4041
import org.springframework.jdbc.datasource.DriverManagerDataSource;
4142
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
@@ -145,9 +146,9 @@ public Server initH2TCPServer() throws SQLException {
145146
}
146147

147148
private void validateFileResult() throws Exception {
148-
// AssertFile.assertLineCount(6, new FileSystemResource("./result.txt"));
149-
// AssertFile.assertFileEquals(new ClassPathResource("testresult.txt"),
150-
// new FileSystemResource(this.outputFile));
149+
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_16).size()).isEqualTo(6);
150+
assertThat(Assertions.contentOf((new ClassPathResource("testresult.txt")).getFile())
151+
.equals(new FileSystemResource(this.outputFile)));
151152
}
152153

153154
private void validateDBResult() {

0 commit comments

Comments
 (0)