Updated to files to fit the Standard.
This commit is contained in:
@@ -60,43 +60,39 @@ public class BatchEventsApplication {
|
||||
|
||||
@Bean
|
||||
public Step step1() {
|
||||
return this.stepBuilderFactory.get("step1")
|
||||
.tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Tasklet has run");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build();
|
||||
return this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Tasklet has run");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return this.stepBuilderFactory.get("step2")
|
||||
.<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(List<? extends String> items) throws Exception {
|
||||
for (String item : items) {
|
||||
System.out.println(">> " + item);
|
||||
return this.stepBuilderFactory.get("step2").<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);
|
||||
}
|
||||
}
|
||||
}).build();
|
||||
}).writer(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
for (String item : items) {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job")
|
||||
.start(step1())
|
||||
.next(step2())
|
||||
.build();
|
||||
return this.jobBuilderFactory.get("job").start(step1()).next(step2()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Tag("DockerRequired")
|
||||
public class BatchEventsApplicationTests {
|
||||
|
||||
private static final String TASK_NAME = "taskEventTest";
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
@@ -64,33 +65,25 @@ public class BatchEventsApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testExecution() throws Exception {
|
||||
List<Message<byte[]>> result = testListener(
|
||||
taskEventProperties.getJobExecutionEventBindingName(), 1);
|
||||
List<Message<byte[]>> result = testListener(taskEventProperties.getJobExecutionEventBindingName(), 1);
|
||||
JobExecutionEvent jobExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(),
|
||||
JobExecutionEvent.class);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.isEqualTo("job").as("Job name should be job");
|
||||
JobExecutionEvent.class);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName()).isEqualTo("job").as("Job name should be job");
|
||||
}
|
||||
|
||||
private String[] getCommandLineParams(boolean enableFailJobConfig) {
|
||||
String jobConfig = enableFailJobConfig ?
|
||||
"--spring.cloud.task.test.enable-job-configuration=true" :
|
||||
"--spring.cloud.task.test.enable-fail-job-configuration=true";
|
||||
return new String[]{"--spring.cloud.task.closecontext_enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.stream.defaultBinder=rabbit",
|
||||
"--spring.cloud.stream.bindings.task-events.destination=test",
|
||||
jobConfig,
|
||||
"foo=" + UUID.randomUUID()};
|
||||
String jobConfig = enableFailJobConfig ? "--spring.cloud.task.test.enable-job-configuration=true"
|
||||
: "--spring.cloud.task.test.enable-fail-job-configuration=true";
|
||||
return new String[] { "--spring.cloud.task.closecontext_enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false", "--spring.cloud.stream.defaultBinder=rabbit",
|
||||
"--spring.cloud.stream.bindings.task-events.destination=test", jobConfig, "foo=" + UUID.randomUUID() };
|
||||
}
|
||||
|
||||
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));
|
||||
@@ -99,8 +92,9 @@ public class BatchEventsApplicationTests {
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@Import({BatchEventsApplication.class})
|
||||
@Import({ BatchEventsApplication.class })
|
||||
public static class BatchEventsTestApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user