Upgrade spring-javaformat maven plugin to version 0.0.39

This commit is contained in:
Mahmoud Ben Hassine
2023-06-05 11:11:48 +02:00
parent bb5598e569
commit c25cd55901
264 changed files with 2551 additions and 1397 deletions

View File

@@ -31,10 +31,13 @@ class DefaultJobKeyGeneratorTests {
@Test
void testMixedParameters() {
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar")
.addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters2 = new JobParametersBuilder().addString("foo", "bar", true)
.addString("bar", "foo", true).addString("ignoreMe", "irrelevant", false).toJobParameters();
.addString("bar", "foo", true)
.addString("ignoreMe", "irrelevant", false)
.toJobParameters();
String key1 = jobKeyGenerator.generateKey(jobParameters1);
String key2 = jobKeyGenerator.generateKey(jobParameters2);
assertEquals(key1, key2);
@@ -42,19 +45,22 @@ class DefaultJobKeyGeneratorTests {
@Test
void testCreateJobKey() {
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar")
.addString("bar", "foo")
.toJobParameters();
String key = jobKeyGenerator.generateKey(jobParameters);
assertEquals(32, key.length());
}
@Test
void testCreateJobKeyOrdering() {
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters1 = new JobParametersBuilder().addString("foo", "bar")
.addString("bar", "foo")
.toJobParameters();
String key1 = jobKeyGenerator.generateKey(jobParameters1);
JobParameters jobParameters2 = new JobParametersBuilder().addString("bar", "foo").addString("foo", "bar")
.toJobParameters();
JobParameters jobParameters2 = new JobParametersBuilder().addString("bar", "foo")
.addString("foo", "bar")
.toJobParameters();
String key2 = jobKeyGenerator.generateKey(jobParameters2);
assertEquals(key1, key2);
}

View File

@@ -69,13 +69,16 @@ class JobParametersBuilderTests {
@Test
void testAddingExistingJobParameters() {
JobParameters params1 = new JobParametersBuilder().addString("foo", "bar").addString("bar", "baz")
.toJobParameters();
JobParameters params1 = new JobParametersBuilder().addString("foo", "bar")
.addString("bar", "baz")
.toJobParameters();
JobParameters params2 = new JobParametersBuilder().addString("foo", "baz").toJobParameters();
JobParameters finalParams = new JobParametersBuilder().addString("baz", "quix").addJobParameters(params1)
.addJobParameters(params2).toJobParameters();
JobParameters finalParams = new JobParametersBuilder().addString("baz", "quix")
.addJobParameters(params1)
.addJobParameters(params2)
.toJobParameters();
assertEquals(finalParams.getString("foo"), "baz");
assertEquals(finalParams.getString("bar"), "baz");

View File

@@ -64,8 +64,11 @@ public class SpringBatchVersionTests {
assertNotNull(jobExecution);
assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
assertTrue(jobExecution.getExecutionContext().containsKey(SpringBatchVersion.BATCH_VERSION_KEY));
assertTrue(jobExecution.getStepExecutions().iterator().next().getExecutionContext()
.containsKey(SpringBatchVersion.BATCH_VERSION_KEY));
assertTrue(jobExecution.getStepExecutions()
.iterator()
.next()
.getExecutionContext()
.containsKey(SpringBatchVersion.BATCH_VERSION_KEY));
}
@Configuration
@@ -75,7 +78,9 @@ public class SpringBatchVersionTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -86,9 +91,10 @@ public class SpringBatchVersionTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -112,7 +112,7 @@ class BatchRegistrarTests {
Assertions.assertEquals(context.getBean(DataSource.class), dataSource);
JdbcExecutionContextDao executionContextDao = (JdbcExecutionContextDao) ReflectionTestUtils
.getField(jobRepository, "ecDao");
.getField(jobRepository, "ecDao");
jdbcTemplate = (JdbcTemplate) ReflectionTestUtils.getField(executionContextDao, "jdbcTemplate");
dataSource = (DataSource) ReflectionTestUtils.getField(jdbcTemplate, "dataSource");
Assertions.assertEquals(context.getBean(DataSource.class), dataSource);
@@ -147,7 +147,7 @@ class BatchRegistrarTests {
Assertions.assertEquals(context.getBean(DataSource.class), dataSource);
JdbcExecutionContextDao executionContextDao = (JdbcExecutionContextDao) ReflectionTestUtils
.getField(jobRepository, "ecDao");
.getField(jobRepository, "ecDao");
jdbcTemplate = (JdbcTemplate) ReflectionTestUtils.getField(executionContextDao, "jdbcTemplate");
dataSource = (DataSource) ReflectionTestUtils.getField(jdbcTemplate, "dataSource");
Assertions.assertEquals(context.getBean(DataSource.class), dataSource);
@@ -231,7 +231,9 @@ class BatchRegistrarTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -248,7 +250,9 @@ class BatchRegistrarTests {
@Bean
public DataSource batchDataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -29,8 +29,10 @@ public class DataSourceConfiguration {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -61,17 +61,20 @@ class InlineDataSourceDefinitionTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("hello world");
return RepeatStatus.FINISHED;
}, transactionManager).build()).build();
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
System.out.println("hello world");
return RepeatStatus.FINISHED;
}, transactionManager).build())
.build();
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-drop-h2.sql")
.addScript("/org/springframework/batch/core/schema-h2.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-h2.sql")
.addScript("/org/springframework/batch/core/schema-h2.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -87,8 +87,9 @@ public class JobBuilderConfigurationTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(jobName, Job.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("run.id", (long) (Math.random() * Long.MAX_VALUE)).toJobParameters());
JobExecution execution = jobLauncher.run(job,
new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
.toJobParameters());
assertEquals(status, execution.getStatus());
assertEquals(stepExecutionCount, execution.getStepExecutions().size());
context.close();
@@ -196,7 +197,9 @@ public class JobBuilderConfigurationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -74,8 +74,9 @@ class JobLoaderConfigurationTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
Job job = jobName == null ? context.getBean(Job.class) : context.getBean(JobLocator.class).getJob(jobName);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder()
.addLong("run.id", (long) (Math.random() * Long.MAX_VALUE)).toJobParameters());
JobExecution execution = jobLauncher.run(job,
new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
.toJobParameters());
assertEquals(status, execution.getStatus());
assertEquals(stepExecutionCount, execution.getStepExecutions().size());
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
@@ -128,20 +129,20 @@ class JobLoaderConfigurationTests {
@Bean
public Job testJob(JobRepository jobRepository) throws Exception {
SimpleJobBuilder builder = new JobBuilder("test", jobRepository).start(step1(jobRepository))
.next(step2(jobRepository));
.next(step2(jobRepository));
return builder.build();
}
@Bean
protected Step step1(JobRepository jobRepository) throws Exception {
return new StepBuilder("step1", jobRepository).tasklet(tasklet(), new ResourcelessTransactionManager())
.build();
.build();
}
@Bean
protected Step step2(JobRepository jobRepository) throws Exception {
return new StepBuilder("step2", jobRepository).tasklet(tasklet(), new ResourcelessTransactionManager())
.build();
.build();
}
@Bean

View File

@@ -61,8 +61,9 @@ abstract class TransactionManagerConfigurationTests {
static DataSource createDataSource() {
return new EmbeddedDatabaseBuilder().generateUniqueName(true)
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.build();
}
}

View File

@@ -146,7 +146,9 @@ class DefaultBatchConfigurationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -172,7 +172,7 @@ class GenericApplicationContextFactoryTests {
assertNotNull(context.getBean("concrete-job", JobSupport.class).getStep("step32"));
boolean autowiredFound = false;
for (BeanPostProcessor postProcessor : ((AbstractBeanFactory) context.getBeanFactory())
.getBeanPostProcessors()) {
.getBeanPostProcessors()) {
if (postProcessor instanceof AutowiredAnnotationBeanPostProcessor) {
autowiredFound = true;
}

View File

@@ -32,7 +32,7 @@ class DuplicateTransitionJobParserTests {
@Test
void testNextAttributeWithNestedElement() {
assertThrows(BeanDefinitionStoreException.class, () -> new ClassPathXmlApplicationContext(ClassUtils
.addResourcePathToPackagePath(getClass(), "NextAttributeMultipleFinalJobParserTests-context.xml")));
.addResourcePathToPackagePath(getClass(), "NextAttributeMultipleFinalJobParserTests-context.xml")));
}
@Test

View File

@@ -104,7 +104,7 @@ class StepListenerInStepParserTests {
try {
compositeListener = ReflectionTestUtils.getField(
ReflectionTestUtils.getField(ReflectionTestUtils
.getField(ReflectionTestUtils.getField(step, "tasklet"), "chunkProvider"), "listener"),
.getField(ReflectionTestUtils.getField(step, "tasklet"), "chunkProvider"), "listener"),
"itemReadListener");
composite = ReflectionTestUtils.getField(compositeListener, "listeners");
proxiedListeners = (List<StepListener>) ReflectionTestUtils.getField(composite, "list");

View File

@@ -55,7 +55,7 @@ class StepListenerMethodAttributeParserTests {
Object compositeListener = ReflectionTestUtils.getField(step, "stepExecutionListener");
Object composite = ReflectionTestUtils.getField(compositeListener, "list");
List<StepExecutionListener> proxiedListeners = (List<StepExecutionListener>) ReflectionTestUtils
.getField(composite, "list");
.getField(composite, "list");
List<Object> r = new ArrayList<>();
for (Object listener : proxiedListeners) {
while (listener instanceof Advised) {

View File

@@ -144,7 +144,7 @@ class StepListenerParserTests {
try {
compositeListener = ReflectionTestUtils.getField(
ReflectionTestUtils.getField(ReflectionTestUtils
.getField(ReflectionTestUtils.getField(step, "tasklet"), "chunkProvider"), "listener"),
.getField(ReflectionTestUtils.getField(step, "tasklet"), "chunkProvider"), "listener"),
"itemReadListener");
composite = ReflectionTestUtils.getField(compositeListener, "listeners");
proxiedListeners = (List<StepListener>) ReflectionTestUtils.getField(composite, "list");

View File

@@ -499,7 +499,7 @@ public class StepParserTests {
ApplicationContext ctx = stepParserParentAttributeTestsCtx;
StepParserStepFactoryBean<?, ?> fb = (StepParserStepFactoryBean<?, ?>) ctx
.getBean("&stepWithListsOverrideWithEmpty");
.getBean("&stepWithListsOverrideWithEmpty");
assertEquals(1, getExceptionMap(fb, "skippableExceptionClasses").size());
assertEquals(1, getExceptionMap(fb, "retryableExceptionClasses").size());

View File

@@ -191,8 +191,11 @@ class DefaultJobParametersConverterTests {
void testGetProperties() throws Exception {
LocalDate date = LocalDate.of(2008, 1, 23);
JobParameters parameters = new JobParametersBuilder()
.addJobParameter("schedule.date", date, LocalDate.class, true).addString("job.key", "myKey")
.addLong("vendor.id", 33243243L).addDouble("double.key", 1.23).toJobParameters();
.addJobParameter("schedule.date", date, LocalDate.class, true)
.addString("job.key", "myKey")
.addLong("vendor.id", 33243243L)
.addDouble("double.key", 1.23)
.toJobParameters();
Properties props = factory.getProperties(parameters);
assertNotNull(props);

View File

@@ -115,7 +115,7 @@ class SimpleJobExplorerIntegrationTests {
List<StateTransition> transitions = new ArrayList<>();
transitions.add(StateTransition.createStateTransition(new StepState(dummyStep()), "end0"));
transitions
.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
simpleFlow.setStateTransitions(transitions);
return simpleFlow;
}
@@ -219,7 +219,9 @@ class SimpleJobExplorerIntegrationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-h2.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-h2.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -237,10 +239,12 @@ class SimpleJobExplorerIntegrationTests {
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
Job job = context.getBean(Job.class);
long id = 1L;
JobParameters jobParameters1 = new JobParametersBuilder().addLong("id", id).addString("name", "foo", false)
.toJobParameters();
JobParameters jobParameters2 = new JobParametersBuilder().addLong("id", id).addString("name", "bar", false)
.toJobParameters();
JobParameters jobParameters1 = new JobParametersBuilder().addLong("id", id)
.addString("name", "foo", false)
.toJobParameters();
JobParameters jobParameters2 = new JobParametersBuilder().addLong("id", id)
.addString("name", "bar", false)
.toJobParameters();
// when
JobExecution jobExecution1 = jobLauncher.run(job, jobParameters1);

View File

@@ -40,7 +40,7 @@ class DefaultJobParametersValidatorTests {
void testValidateRequiredValues() throws Exception {
validator.setRequiredKeys(new String[] { "name", "value" });
validator
.validate(new JobParametersBuilder().addString("name", "foo").addLong("value", 111L).toJobParameters());
.validate(new JobParametersBuilder().addString("name", "foo").addLong("value", 111L).toJobParameters());
}
@Test

View File

@@ -57,8 +57,9 @@ class ExtendedAbstractJobTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -52,8 +52,9 @@ class SimpleJobFailureTests {
@BeforeEach
void init() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -98,8 +98,10 @@ class SimpleJobTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);
@@ -116,7 +118,7 @@ class SimpleJobTests {
ObservationRegistry observationRegistry = ObservationRegistry.create();
observationRegistry.observationConfig()
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
job.setObservationRegistry(observationRegistry);
step1 = new StubStep("TestStep1", jobRepository);
@@ -226,9 +228,10 @@ class SimpleJobTests {
assertFalse(step2.passedInJobContext.isEmpty());
// Observability
MeterRegistryAssert.assertThat(Metrics.globalRegistry).hasTimerWithNameAndTags(
BatchJobObservation.BATCH_JOB_OBSERVATION.getName(), Tags.of(Tag.of("error", "none"),
Tag.of("spring.batch.job.name", "testJob"), Tag.of("spring.batch.job.status", "COMPLETED")));
MeterRegistryAssert.assertThat(Metrics.globalRegistry)
.hasTimerWithNameAndTags(BatchJobObservation.BATCH_JOB_OBSERVATION.getName(),
Tags.of(Tag.of("error", "none"), Tag.of("spring.batch.job.name", "testJob"),
Tag.of("spring.batch.job.status", "COMPLETED")));
}
@AfterEach
@@ -500,7 +503,7 @@ class SimpleJobTests {
job.setSteps(Arrays.asList(new Step[] { failStep }));
JobParameters firstJobParameters = new JobParametersBuilder().addString("JobExecutionParameter", "first", false)
.toJobParameters();
.toJobParameters();
JobExecution jobexecution = jobRepository.createJobExecution(job.getName(), firstJobParameters);
job.execute(jobexecution);
@@ -510,7 +513,8 @@ class SimpleJobTests {
assertEquals(jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"), "first");
JobParameters secondJobParameters = new JobParametersBuilder()
.addString("JobExecutionParameter", "second", false).toJobParameters();
.addString("JobExecutionParameter", "second", false)
.toJobParameters();
jobexecution = jobRepository.createJobExecution(job.getName(), secondJobParameters);
job.execute(jobexecution);

View File

@@ -50,8 +50,9 @@ class SimpleStepHandlerTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -84,8 +84,14 @@ class FlowBuilderTests {
}
};
FlowExecution flowExecution = builder.start(stepA).on("*").to(stepB).from(stepA).on("FAILED").to(stepC).end()
.start(new JobFlowExecutor(jobRepository, new SimpleStepHandler(jobRepository), execution));
FlowExecution flowExecution = builder.start(stepA)
.on("*")
.to(stepB)
.from(stepA)
.on("FAILED")
.to(stepC)
.end()
.start(new JobFlowExecutor(jobRepository, new SimpleStepHandler(jobRepository), execution));
Iterator<StepExecution> stepExecutions = execution.getStepExecutions().iterator();
StepExecution stepExecutionA = stepExecutions.next();

View File

@@ -110,8 +110,9 @@ class FlowJobBuilderTests {
@BeforeEach
void init() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
@@ -122,8 +123,11 @@ class FlowJobBuilderTests {
@Test
void testBuildOnOneLine() {
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1).on("COMPLETED").to(step2).end()
.preventRestart();
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(step1)
.on("COMPLETED")
.to(step2)
.end()
.preventRestart();
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(2, execution.getStepExecutions().size());
@@ -171,8 +175,10 @@ class FlowJobBuilderTests {
void testBuildSplitUsingStartAndAdd_BATCH_2346() {
Flow subflow1 = new FlowBuilder<Flow>("subflow1").from(step2).end();
Flow subflow2 = new FlowBuilder<Flow>("subflow2").from(step3).end();
Flow splitflow = new FlowBuilder<Flow>("splitflow").start(subflow1).split(new SimpleAsyncTaskExecutor())
.add(subflow2).build();
Flow splitflow = new FlowBuilder<Flow>("splitflow").start(subflow1)
.split(new SimpleAsyncTaskExecutor())
.add(subflow2)
.build();
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitflow).end();
builder.preventRestart().build().execute(execution);
@@ -184,8 +190,9 @@ class FlowJobBuilderTests {
void testBuildSplit_BATCH_2282() {
Flow flow1 = new FlowBuilder<Flow>("subflow1").from(step1).end();
Flow flow2 = new FlowBuilder<Flow>("subflow2").from(step2).end();
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor()).add(flow1, flow2)
.build();
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor())
.add(flow1, flow2)
.build();
FlowJobBuilder builder = new JobBuilder("flow", jobRepository).start(splitFlow).end();
builder.preventRestart().build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -291,8 +298,10 @@ class FlowJobBuilderTests {
public Step step(JobRepository jobRepository, PlatformTransactionManager transactionManager,
@Value("#{jobParameters['chunkSize']}") Integer chunkSize) {
return new StepBuilder("step", jobRepository).<Integer, Integer>chunk(chunkSize, transactionManager)
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4))).writer(items -> {
}).build();
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4)))
.writer(items -> {
})
.build();
}
@Bean
@@ -304,7 +313,9 @@ class FlowJobBuilderTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -72,16 +72,19 @@ class JobBuilderTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository).listener(new InterfaceBasedJobExecutionListener())
.listener(new AnnotationBasedJobExecutionListener())
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.listener(new AnnotationBasedJobExecutionListener())
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -57,8 +57,9 @@ class FlowJobFailureTests {
@BeforeEach
void init() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -74,8 +74,9 @@ public class FlowJobTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
@@ -129,8 +130,8 @@ public class FlowJobTests {
void testFailedStep() throws Exception {
SimpleFlow flow = new SimpleFlow("job");
List<StateTransition> transitions = new ArrayList<>();
transitions.add(
StateTransition.createStateTransition(new StateSupport("step1", FlowExecutionStatus.FAILED), "step2"));
transitions
.add(StateTransition.createStateTransition(new StateSupport("step1", FlowExecutionStatus.FAILED), "step2"));
StepState step2 = new StepState(new StubStep("step2"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.FAILED.getExitCode(), "end0"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.COMPLETED.getExitCode(), "end1"));
@@ -192,7 +193,7 @@ public class FlowJobTests {
transitions.add(StateTransition.createStateTransition(state2, ExitStatus.FAILED.getExitCode(), "end0"));
transitions.add(StateTransition.createStateTransition(state2, ExitStatus.COMPLETED.getExitCode(), "end1"));
transitions
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end0"), "step3"));
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end0"), "step3"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end1")));
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step3")), "end2"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end2")));
@@ -280,7 +281,7 @@ public class FlowJobTests {
transitions = new ArrayList<>();
transitions.add(StateTransition
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end0"));
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end0"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
flow.setStateTransitions(transitions);
flow.afterPropertiesSet();
@@ -341,7 +342,7 @@ public class FlowJobTests {
transitions = new ArrayList<>();
transitions.add(StateTransition
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end0"));
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end0"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0")));
flow.setStateTransitions(transitions);
flow.afterPropertiesSet();
@@ -361,7 +362,7 @@ public class FlowJobTests {
List<StateTransition> transitions = new ArrayList<>();
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "end"));
transitions
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end"), "step2"));
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end"), "step2"));
StepState step2 = new StepState(new StubStep("step2"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.FAILED.getExitCode(), "end0"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.COMPLETED.getExitCode(), "end1"));
@@ -380,7 +381,7 @@ public class FlowJobTests {
List<StateTransition> transitions = new ArrayList<>();
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "end"));
transitions
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.FAILED, "end"), "step2"));
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.FAILED, "end"), "step2"));
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")),
ExitStatus.FAILED.getExitCode(), "end0"));
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step2")),
@@ -401,7 +402,7 @@ public class FlowJobTests {
List<StateTransition> transitions = new ArrayList<>();
transitions.add(StateTransition.createStateTransition(new StepState(new StubStep("step1")), "end"));
transitions
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end"), "step2"));
.add(StateTransition.createStateTransition(new EndState(FlowExecutionStatus.STOPPED, "end"), "step2"));
StepState step2 = new StepState(new StubStep("step2"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.COMPLETED.getExitCode(), "end0"));
transitions.add(StateTransition.createStateTransition(step2, ExitStatus.FAILED.getExitCode(), "end1"));
@@ -675,7 +676,7 @@ public class FlowJobTests {
transitions = new ArrayList<>();
transitions.add(StateTransition
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end2"));
.createStateTransition(new SplitState(Arrays.<Flow>asList(flow1, flow2), "split"), "end2"));
transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end2")));
flow.setStateTransitions(transitions);
flow.afterPropertiesSet();

View File

@@ -55,8 +55,9 @@ class FlowStepTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setDataSource(embeddedDatabase);
jobRepositoryFactoryBean.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -112,9 +112,9 @@ class TaskExecutorJobLauncherTests {
testRun();
when(jobRepository.getLastJobExecution(job.getName(), jobParameters))
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
when(jobRepository.createJobExecution(job.getName(), jobParameters))
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
jobLauncher.run(job, jobParameters);
}
@@ -139,7 +139,7 @@ class TaskExecutorJobLauncherTests {
testRun();
when(jobRepository.getLastJobExecution(job.getName(), jobParameters))
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
.thenReturn(new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
assertThrows(JobRestartException.class, () -> jobLauncher.run(job, jobParameters));
}
@@ -275,7 +275,7 @@ class TaskExecutorJobLauncherTests {
String jobName = "test_job";
JobRepository jobRepository = mock(JobRepository.class);
JobParameters parameters = new JobParametersBuilder().addLong("runtime", System.currentTimeMillis())
.toJobParameters();
.toJobParameters();
JobExecution jobExecution = mock(JobExecution.class);
Job job = mock(Job.class);
JobParametersValidator validator = mock(JobParametersValidator.class);

View File

@@ -350,8 +350,9 @@ class CommandLineJobRunnerTests {
@Test
void testNext() throws Throwable {
String[] args = new String[] { jobPath, "-next", jobName, "bar=foo" };
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
.toJobParameters();
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar")
.addString("bar", "foo")
.toJobParameters();
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobName));
CommandLineJobRunner.main(args);
assertEquals(0, StubSystemExiter.status);

View File

@@ -161,7 +161,7 @@ class SimpleJobOperatorTests {
JobInstance jobInstance = new JobInstance(321L, "foo");
when(jobExplorer.getJobInstances("foo", 0, 1)).thenReturn(Collections.singletonList(jobInstance));
when(jobExplorer.getJobExecutions(jobInstance))
.thenReturn(Collections.singletonList(new JobExecution(jobInstance, new JobParameters())));
.thenReturn(Collections.singletonList(new JobExecution(jobInstance, new JobParameters())));
Long value = jobOperator.startNextInstance("foo");
assertEquals(999, value.longValue());
}
@@ -191,7 +191,7 @@ class SimpleJobOperatorTests {
void testResumeSunnyDay() throws Exception {
jobParameters = new JobParameters();
when(jobExplorer.getJobExecution(111L))
.thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
.thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
jobExplorer.getJobExecution(111L);
Long value = jobOperator.restart(111L);
assertEquals(999, value.longValue());
@@ -255,7 +255,7 @@ class SimpleJobOperatorTests {
void testGetJobParametersSunnyDay() throws Exception {
final JobParameters jobParameters = new JobParameters();
when(jobExplorer.getJobExecution(111L))
.thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
.thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
String value = jobOperator.getParameters(111L);
assertEquals("a=b", value);
}

View File

@@ -68,7 +68,7 @@ class CompositeItemProcessListenerTests {
@Test
void testSetListeners() {
compositeListener
.setListeners(Collections.<ItemProcessListener<? super Object, ? super Object>>singletonList(listener));
.setListeners(Collections.<ItemProcessListener<? super Object, ? super Object>>singletonList(listener));
listener.beforeProcess(null);
compositeListener.beforeProcess(null);
}

View File

@@ -142,14 +142,22 @@ class ItemListenerErrorTests {
ItemWriter<String> fakeItemWriter, ItemProcessListener<String, String> itemProcessListener) {
return new StepBuilder("testStep", jobRepository).<String, String>chunk(10, transactionManager)
.reader(fakeItemReader).processor(fakeProcessor).writer(fakeItemWriter)
.listener(itemProcessListener).faultTolerant().skipLimit(50).skip(RuntimeException.class).build();
.reader(fakeItemReader)
.processor(fakeProcessor)
.writer(fakeItemWriter)
.listener(itemProcessListener)
.faultTolerant()
.skipLimit(50)
.skip(RuntimeException.class)
.build();
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -64,8 +64,10 @@ class BatchMetricsTests {
@Test
void testCalculateDuration() {
LocalDateTime startTime = LocalDateTime.now();
LocalDateTime endTime = startTime.plus(2, ChronoUnit.HOURS).plus(31, ChronoUnit.MINUTES)
.plus(12, ChronoUnit.SECONDS).plus(42, ChronoUnit.MILLIS);
LocalDateTime endTime = startTime.plus(2, ChronoUnit.HOURS)
.plus(31, ChronoUnit.MINUTES)
.plus(12, ChronoUnit.SECONDS)
.plus(42, ChronoUnit.MILLIS);
Duration duration = BatchMetrics.calculateDuration(startTime, endTime);
Duration expectedDuration = Duration.ofMillis(42).plusSeconds(12).plusMinutes(31).plusHours(2);
@@ -152,67 +154,95 @@ class BatchMetricsTests {
"There should be a meter of type COUNTER named spring.batch.job.launch.count registered in the global registry");
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.job").tag("spring.batch.job.name", "job")
.tag("spring.batch.job.status", "COMPLETED").timer(),
() -> Metrics.globalRegistry.get("spring.batch.job")
.tag("spring.batch.job.name", "job")
.tag("spring.batch.job.status", "COMPLETED")
.timer(),
"There should be a meter of type TIMER named spring.batch.job registered in the global registry");
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.job.active").tag("spring.batch.job.active.name", "job")
.longTaskTimer(),
() -> Metrics.globalRegistry.get("spring.batch.job.active")
.tag("spring.batch.job.active.name", "job")
.longTaskTimer(),
"There should be a meter of type LONG_TASK_TIMER named spring.batch.job.active"
+ " registered in the global registry");
// Step 1 (tasklet) metrics
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.step").tag("spring.batch.step.name", "step1")
.tag("spring.batch.step.job.name", "job").tag("spring.batch.step.status", "COMPLETED").timer(),
() -> Metrics.globalRegistry.get("spring.batch.step")
.tag("spring.batch.step.name", "step1")
.tag("spring.batch.step.job.name", "job")
.tag("spring.batch.step.status", "COMPLETED")
.timer(),
"There should be a meter of type TIMER named spring.batch.step registered in the global registry");
// Step 2 (simple chunk-oriented) metrics
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.step").tag("spring.batch.step.name", "step2")
.tag("spring.batch.step.job.name", "job").tag("spring.batch.step.status", "COMPLETED").timer(),
() -> Metrics.globalRegistry.get("spring.batch.step")
.tag("spring.batch.step.name", "step2")
.tag("spring.batch.step.job.name", "job")
.tag("spring.batch.step.status", "COMPLETED")
.timer(),
"There should be a meter of type TIMER named spring.batch.step registered in the global registry");
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.item.read").tag("spring.batch.item.read.job.name", "job")
.tag("spring.batch.item.read.step.name", "step2")
.tag("spring.batch.item.read.status", "SUCCESS").timer(),
() -> Metrics.globalRegistry.get("spring.batch.item.read")
.tag("spring.batch.item.read.job.name", "job")
.tag("spring.batch.item.read.step.name", "step2")
.tag("spring.batch.item.read.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.item.read registered in the global registry");
assertDoesNotThrow(() -> Metrics.globalRegistry.get("spring.batch.item.process")
.tag("spring.batch.item.process.job.name", "job").tag("spring.batch.item.process.step.name", "step2")
.tag("spring.batch.item.process.status", "SUCCESS").timer(),
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.item.process")
.tag("spring.batch.item.process.job.name", "job")
.tag("spring.batch.item.process.step.name", "step2")
.tag("spring.batch.item.process.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.item.process registered in the global registry");
assertDoesNotThrow(() -> Metrics.globalRegistry.get("spring.batch.chunk.write")
.tag("spring.batch.chunk.write.job.name", "job").tag("spring.batch.chunk.write.step.name", "step2")
.tag("spring.batch.chunk.write.status", "SUCCESS").timer(),
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.chunk.write")
.tag("spring.batch.chunk.write.job.name", "job")
.tag("spring.batch.chunk.write.step.name", "step2")
.tag("spring.batch.chunk.write.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.chunk.write registered in the global registry");
// Step 3 (fault-tolerant chunk-oriented) metrics
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.step").tag("spring.batch.step.name", "step3")
.tag("spring.batch.step.job.name", "job").tag("spring.batch.step.status", "COMPLETED").timer(),
() -> Metrics.globalRegistry.get("spring.batch.step")
.tag("spring.batch.step.name", "step3")
.tag("spring.batch.step.job.name", "job")
.tag("spring.batch.step.status", "COMPLETED")
.timer(),
"There should be a meter of type TIMER named spring.batch.step registered in the global registry");
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.item.read").tag("spring.batch.item.read.job.name", "job")
.tag("spring.batch.item.read.step.name", "step3")
.tag("spring.batch.item.read.status", "SUCCESS").timer(),
() -> Metrics.globalRegistry.get("spring.batch.item.read")
.tag("spring.batch.item.read.job.name", "job")
.tag("spring.batch.item.read.step.name", "step3")
.tag("spring.batch.item.read.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.item.read registered in the global registry");
assertDoesNotThrow(() -> Metrics.globalRegistry.get("spring.batch.item.process")
.tag("spring.batch.item.process.job.name", "job").tag("spring.batch.item.process.step.name", "step3")
.tag("spring.batch.item.process.status", "SUCCESS").timer(),
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.item.process")
.tag("spring.batch.item.process.job.name", "job")
.tag("spring.batch.item.process.step.name", "step3")
.tag("spring.batch.item.process.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.item.process registered in the global registry");
assertDoesNotThrow(() -> Metrics.globalRegistry.get("spring.batch.chunk.write")
.tag("spring.batch.chunk.write.job.name", "job").tag("spring.batch.chunk.write.step.name", "step3")
.tag("spring.batch.chunk.write.status", "SUCCESS").timer(),
assertDoesNotThrow(
() -> Metrics.globalRegistry.get("spring.batch.chunk.write")
.tag("spring.batch.chunk.write.job.name", "job")
.tag("spring.batch.chunk.write.step.name", "step3")
.tag("spring.batch.chunk.write.status", "SUCCESS")
.timer(),
"There should be a meter of type TIMER named spring.batch.chunk.write registered in the global registry");
}
@@ -223,43 +253,51 @@ class BatchMetricsTests {
@Bean
public Step step1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("step1", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build();
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build();
}
@Bean
public Step step2(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("step2", jobRepository).<Integer, Integer>chunk(2, transactionManager)
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5)))
.writer(items -> items.forEach(System.out::println)).build();
.reader(new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5)))
.writer(items -> items.forEach(System.out::println))
.build();
}
@Bean
public Step step3(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("step3", jobRepository).<Integer, Integer>chunk(2, transactionManager)
.reader(new ListItemReader<>(Arrays.asList(6, 7, 8, 9, 10)))
.writer(items -> items.forEach(System.out::println)).faultTolerant().skip(Exception.class)
.skipLimit(3).build();
.reader(new ListItemReader<>(Arrays.asList(6, 7, 8, 9, 10)))
.writer(items -> items.forEach(System.out::println))
.faultTolerant()
.skip(Exception.class)
.skipLimit(3)
.build();
}
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository).start(step1(jobRepository, transactionManager))
.next(step2(jobRepository, transactionManager)).next(step3(jobRepository, transactionManager))
.build();
.next(step2(jobRepository, transactionManager))
.next(step3(jobRepository, transactionManager))
.build();
}
@Bean
public ObservationRegistry observationRegistry() {
ObservationRegistry observationRegistry = ObservationRegistry.create();
observationRegistry.observationConfig()
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
return observationRegistry;
}
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean

View File

@@ -53,8 +53,9 @@ class PartitionStepTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -51,8 +51,9 @@ class RemoteStepExecutionAggregatorTests {
@BeforeEach
void init() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);

View File

@@ -56,8 +56,9 @@ class SimpleStepExecutionSplitterTests {
void setUp() throws Exception {
step = new TaskletStep("step");
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -52,7 +52,9 @@ public abstract class AbstractJobDaoTests {
protected JobExecutionDao jobExecutionDao;
protected JobParameters jobParameters = new JobParametersBuilder().addString("job.key", "jobKey")
.addLong("long", (long) 1).addDouble("double", 7.7).toJobParameters();
.addLong("long", (long) 1)
.addDouble("double", 7.7)
.toJobParameters();
protected JobInstance jobInstance;
@@ -211,7 +213,7 @@ public abstract class AbstractJobDaoTests {
jobInstance = jobInstanceDao.createJobInstance(testJob, jobParameters);
List<Map<String, Object>> jobs = jdbcTemplate
.queryForList("SELECT * FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", jobInstance.getId());
.queryForList("SELECT * FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?", jobInstance.getId());
assertEquals(1, jobs.size());
assertEquals("test", jobs.get(0).get("JOB_NAME"));

View File

@@ -242,8 +242,10 @@ public abstract class AbstractJobExecutionDaoTests {
assertEquals(3, values.size());
Long jobExecutionId = exec.getId();
JobExecution value = values.stream().filter(jobExecution -> jobExecutionId.equals(jobExecution.getId()))
.findFirst().orElseThrow();
JobExecution value = values.stream()
.filter(jobExecution -> jobExecutionId.equals(jobExecution.getId()))
.findFirst()
.orElseThrow();
assertEquals(now.plus(3, ChronoUnit.SECONDS), value.getLastUpdated());
}

View File

@@ -41,8 +41,10 @@ public abstract class AbstractJobInstanceDaoTests {
private final String fooJob = "foo";
private final JobParameters fooParams = new JobParametersBuilder().addString("stringKey", "stringValue")
.addLong("longKey", Long.MAX_VALUE).addDouble("doubleKey", Double.MAX_VALUE)
.addDate("dateKey", new Date(DATE)).toJobParameters();
.addLong("longKey", Long.MAX_VALUE)
.addDouble("doubleKey", Double.MAX_VALUE)
.addDate("dateKey", new Date(DATE))
.toJobParameters();
protected abstract JobInstanceDao getJobInstanceDao();

View File

@@ -48,7 +48,7 @@ public class JdbcJobDaoTests extends AbstractJobDaoTests {
jobExecutionDao.updateJobExecution(jobExecution);
List<Map<String, Object>> executions = jdbcTemplate
.queryForList("SELECT * FROM BATCH_JOB_EXECUTION where JOB_INSTANCE_ID=?", jobInstance.getId());
.queryForList("SELECT * FROM BATCH_JOB_EXECUTION where JOB_INSTANCE_ID=?", jobInstance.getId());
assertEquals(1, executions.size());
assertEquals(LONG_STRING.substring(0, 250), executions.get(0).get("EXIT_MESSAGE"));
}

View File

@@ -119,9 +119,13 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
long longParameter = 1L;
double doubleParameter = 2D;
JobParameters jobParameters = new JobParametersBuilder().addString("string", stringParameter)
.addLong("long", longParameter).addDouble("double", doubleParameter).addDate("date", dateParameter)
.addLocalDate("localDate", localDateParameter).addLocalTime("localTime", localTimeParameter)
.addLocalDateTime("localDateTime", localDateTimeParameter).toJobParameters();
.addLong("long", longParameter)
.addDouble("double", doubleParameter)
.addDate("date", dateParameter)
.addLocalDate("localDate", localDateParameter)
.addLocalTime("localTime", localTimeParameter)
.addLocalDateTime("localDateTime", localDateTimeParameter)
.toJobParameters();
JobExecution execution = new JobExecution(jobInstance, jobParameters);
// when

View File

@@ -64,14 +64,16 @@ class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, stepExecution.getId());
assertTrue(retrievedAfterSave.getExitStatus().getExitDescription().length() < stepExecution.getExitStatus()
.getExitDescription().length(), "Exit description should be truncated");
.getExitDescription()
.length(), "Exit description should be truncated");
dao.updateStepExecution(stepExecution);
StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, stepExecution.getId());
assertTrue(retrievedAfterUpdate.getExitStatus().getExitDescription().length() < stepExecution.getExitStatus()
.getExitDescription().length(), "Exit description should be truncated");
.getExitDescription()
.length(), "Exit description should be truncated");
}
@Transactional

View File

@@ -101,9 +101,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.afterPropertiesSet();
factory.getObject();
@@ -119,9 +119,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
factory.afterPropertiesSet();
@@ -139,9 +139,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
LobHandler lobHandler = new DefaultLobHandler();
@@ -162,14 +162,14 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
factory.afterPropertiesSet();
Serializer<Map<String, Object>> serializer = (Serializer<Map<String, Object>>) ReflectionTestUtils
.getField(factory, "serializer");
.getField(factory, "serializer");
assertTrue(serializer instanceof DefaultExecutionContextSerializer);
}
@@ -182,9 +182,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
ExecutionContextSerializer customSerializer = new DefaultExecutionContextSerializer();
@@ -203,9 +203,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
factory.afterPropertiesSet();
@@ -223,9 +223,9 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("ORACLE")).thenReturn(true);
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.setIncrementerFactory(incrementerFactory);
JdbcOperations customJdbcOperations = mock(JdbcOperations.class);
@@ -281,11 +281,11 @@ class JobRepositoryFactoryBeanTests {
when(incrementerFactory.isSupportedIncrementerType("HSQL")).thenReturn(true);
when(incrementerFactory.getSupportedIncrementerTypes()).thenReturn(new String[0]);
when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
when(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ"))
.thenReturn(new StubIncrementer());
.thenReturn(new StubIncrementer());
factory.afterPropertiesSet();
factory.getObject();

View File

@@ -235,7 +235,7 @@ class SimpleJobRepositoryIntegrationTests {
@Test
public void testReExecuteWithSameJobParametersWhenRunning() throws Exception {
JobParameters jobParameters = new JobParametersBuilder().addString("stringKey", "stringValue")
.toJobParameters();
.toJobParameters();
// jobExecution with status STARTING
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);

View File

@@ -373,7 +373,7 @@ class SimpleJobRepositoryTests {
JobExecution jobExecution2 = mock(JobExecution.class);
JobInstance jobInstance = mock(JobInstance.class);
when(this.jobExecutionDao.findJobExecutions(jobInstance))
.thenReturn(Arrays.asList(jobExecution1, jobExecution2));
.thenReturn(Arrays.asList(jobExecution1, jobExecution2));
// when
this.jobRepository.deleteJobInstance(jobInstance);

View File

@@ -37,7 +37,7 @@ class ChunkContextTests {
private final ChunkContext context = new ChunkContext(new StepContext(new JobExecution(new JobInstance(0L, "job"),
1L, new JobParameters(Collections.singletonMap("foo", new JobParameter("bar", String.class))))
.createStepExecution("foo")));
.createStepExecution("foo")));
@Test
void testGetStepContext() {

View File

@@ -195,7 +195,7 @@ class NonAbstractStepTests {
ObservationRegistry observationRegistry = ObservationRegistry.create();
observationRegistry.observationConfig()
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
.observationHandler(new DefaultMeterObservationHandler(Metrics.globalRegistry));
tested.setObservationRegistry(observationRegistry);
tested.execute(execution);
@@ -218,11 +218,11 @@ class NonAbstractStepTests {
"Execution context modifications made by listener should be persisted");
// Observability
MeterRegistryAssert.assertThat(Metrics.globalRegistry).hasTimerWithNameAndTags(
BatchStepObservation.BATCH_STEP_OBSERVATION.getName(),
Tags.of(Tag.of("error", "none"), Tag.of("spring.batch.step.job.name", "jobName"),
Tag.of("spring.batch.step.name", "eventTrackingStep"),
Tag.of("spring.batch.step.status", "COMPLETED")));
MeterRegistryAssert.assertThat(Metrics.globalRegistry)
.hasTimerWithNameAndTags(BatchStepObservation.BATCH_STEP_OBSERVATION.getName(),
Tags.of(Tag.of("error", "none"), Tag.of("spring.batch.step.job.name", "jobName"),
Tag.of("spring.batch.step.name", "eventTrackingStep"),
Tag.of("spring.batch.step.status", "COMPLETED")));
}
@AfterEach

View File

@@ -39,9 +39,12 @@ class FaultTolerantStepBuilderTests {
void testAnnotationBasedStepExecutionListenerRegistration() {
// given
FaultTolerantStepBuilder<Object, Object> faultTolerantStepBuilder = new StepBuilder("myStep",
new DummyJobRepository()).<Object, Object>chunk(5, new ResourcelessTransactionManager())
.reader(new DummyItemReader()).writer(new DummyItemWriter()).faultTolerant()
.listener(new StepBuilderTests.AnnotationBasedStepExecutionListener());
new DummyJobRepository())
.<Object, Object>chunk(5, new ResourcelessTransactionManager())
.reader(new DummyItemReader())
.writer(new DummyItemWriter())
.faultTolerant()
.listener(new StepBuilderTests.AnnotationBasedStepExecutionListener());
// when
Step step = faultTolerantStepBuilder.build();

View File

@@ -121,8 +121,8 @@ class RegisterMultiListenerTests {
private void bootstrap(Class<?> configurationClass) {
context = new AnnotationConfigApplicationContext(configurationClass);
context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
context.getAutowireCapableBeanFactory()
.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
}
public static abstract class MultiListenerTestConfigurationSupport {
@@ -190,9 +190,11 @@ class RegisterMultiListenerTests {
@Bean
public DataSource dataSource() {
return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder()
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.setType(EmbeddedDatabaseType.HSQL).generateUniqueName(true).build());
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.setType(EmbeddedDatabaseType.HSQL)
.generateUniqueName(true)
.build());
}
@Bean
@@ -204,10 +206,15 @@ class RegisterMultiListenerTests {
@Bean
public Step step(JobRepository jobRepository) {
return new StepBuilder("step", jobRepository).listener(listener())
.<String, String>chunk(2, transactionManager(dataSource())).reader(reader()).writer(writer())
.faultTolerant().skipLimit(1).skip(MySkippableException.class)
// ChunkListener registered twice for checking BATCH-2149
.listener((ChunkListener) listener()).build();
.<String, String>chunk(2, transactionManager(dataSource()))
.reader(reader())
.writer(writer())
.faultTolerant()
.skipLimit(1)
.skip(MySkippableException.class)
// ChunkListener registered twice for checking BATCH-2149
.listener((ChunkListener) listener())
.build();
}
}
@@ -219,9 +226,11 @@ class RegisterMultiListenerTests {
@Bean
public DataSource dataSource() {
return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder()
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.setType(EmbeddedDatabaseType.HSQL).generateUniqueName(true).build());
.addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql")
.setType(EmbeddedDatabaseType.HSQL)
.generateUniqueName(true)
.build());
}
@Bean
@@ -233,8 +242,10 @@ class RegisterMultiListenerTests {
@Bean
public Step step(JobRepository jobRepository) {
return new StepBuilder("step", jobRepository).listener(listener())
.<String, String>chunk(2, transactionManager(dataSource())).reader(reader()).writer(writer())
.build();
.<String, String>chunk(2, transactionManager(dataSource()))
.reader(reader())
.writer(writer())
.build();
}
}

View File

@@ -79,8 +79,9 @@ class StepBuilderTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
@@ -95,7 +96,7 @@ class StepBuilderTests {
@Test
void test() throws Exception {
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> null, transactionManager);
.tasklet((contribution, chunkContext) -> null, transactionManager);
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
}
@@ -103,9 +104,9 @@ class StepBuilderTests {
@Test
void testListeners() throws Exception {
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
.listener(new InterfaceBasedStepExecutionListener())
.listener(new AnnotationBasedStepExecutionListener())
.tasklet((contribution, chunkContext) -> null, transactionManager);
.listener(new InterfaceBasedStepExecutionListener())
.listener(new AnnotationBasedStepExecutionListener())
.tasklet((contribution, chunkContext) -> null, transactionManager);
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(1, InterfaceBasedStepExecutionListener.beforeStepCount);
@@ -119,8 +120,8 @@ class StepBuilderTests {
@Test
void testAnnotationBasedChunkListenerForTaskletStep() throws Exception {
TaskletStepBuilder builder = new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> null, transactionManager)
.listener(new AnnotationBasedChunkListener());
.tasklet((contribution, chunkContext) -> null, transactionManager)
.listener(new AnnotationBasedChunkListener());
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount);
@@ -130,8 +131,9 @@ class StepBuilderTests {
@Test
void testAnnotationBasedChunkListenerForSimpleTaskletStep() throws Exception {
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step", jobRepository).chunk(5, transactionManager)
.reader(new DummyItemReader()).writer(new DummyItemWriter())
.listener(new AnnotationBasedChunkListener());
.reader(new DummyItemReader())
.writer(new DummyItemWriter())
.listener(new AnnotationBasedChunkListener());
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount);
@@ -141,12 +143,14 @@ class StepBuilderTests {
@Test
void testAnnotationBasedChunkListenerForFaultTolerantTaskletStep() throws Exception {
SimpleStepBuilder<Object, Object> builder = new StepBuilder("step", jobRepository).chunk(5, transactionManager)
.reader(new DummyItemReader()).writer(new DummyItemWriter()).faultTolerant()
.listener(new AnnotationBasedChunkListener()); // TODO//
// should
// this
// return
// FaultTolerantStepBuilder?
.reader(new DummyItemReader())
.writer(new DummyItemWriter())
.faultTolerant()
.listener(new AnnotationBasedChunkListener()); // TODO//
// should
// this
// return
// FaultTolerantStepBuilder?
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(1, AnnotationBasedChunkListener.beforeChunkCount);
@@ -158,7 +162,7 @@ class StepBuilderTests {
SimpleJob job = new SimpleJob("job");
job.setJobRepository(jobRepository);
JobStepBuilder builder = new StepBuilder("step", jobRepository).job(job)
.listener(new AnnotationBasedChunkListener());
.listener(new AnnotationBasedChunkListener());
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -175,8 +179,11 @@ class StepBuilderTests {
ItemReader<String> reader = new ListItemReader<>(items);
SimpleStepBuilder<String, String> builder = new StepBuilder("step", jobRepository)
.<String, String>chunk(3, transactionManager).reader(reader).processor(new PassThroughItemProcessor<>())
.writer(new DummyItemWriter()).listener(new AnnotationBasedStepExecutionListener());
.<String, String>chunk(3, transactionManager)
.reader(reader)
.processor(new PassThroughItemProcessor<>())
.writer(new DummyItemWriter())
.listener(new AnnotationBasedStepExecutionListener());
builder.build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
@@ -209,8 +216,11 @@ class StepBuilderTests {
ListItemWriter<String> itemWriter = new ListItemWriter<>();
SimpleStepBuilder<Object, String> builder = new StepBuilder("step", jobRepository)
.<Object, String>chunk(3, transactionManager).reader(reader).processor(Object::toString)
.writer(itemWriter).listener(new AnnotationBasedStepExecutionListener());
.<Object, String>chunk(3, transactionManager)
.reader(reader)
.processor(Object::toString)
.writer(itemWriter)
.listener(new AnnotationBasedStepExecutionListener());
if (faultTolerantStep) {
builder = builder.faultTolerant();
@@ -291,7 +301,9 @@ class StepBuilderTests {
ItemReader<String> reader = new ListItemReader<>(items);
SimpleStepBuilder<String, String> builder = new StepBuilder("step", jobRepository)
.<String, String>chunk(3, transactionManager).reader(reader).writer(new DummyItemWriter());
.<String, String>chunk(3, transactionManager)
.reader(reader)
.writer(new DummyItemWriter());
configurer.apply(builder).listener(new InterfaceBasedItemReadListenerListener()).build().execute(execution);
assertEquals(BatchStatus.COMPLETED, execution.getStatus());

View File

@@ -61,7 +61,8 @@ class FaultTolerantChunkProcessorTests {
private FaultTolerantChunkProcessor<String, String> processor;
private final StepContribution contribution = new StepExecution("foo",
new JobExecution(new JobInstance(0L, "job"), new JobParameters())).createStepContribution();
new JobExecution(new JobInstance(0L, "job"), new JobParameters()))
.createStepContribution();
@BeforeEach
void setUp() {
@@ -266,8 +267,8 @@ class FaultTolerantChunkProcessorTests {
}
});
processor.setProcessSkipPolicy(new AlwaysSkipItemSkipPolicy());
processor.setRollbackClassifier(
new BinaryExceptionClassifier(Set.of(DataIntegrityViolationException.class), false));
processor
.setRollbackClassifier(new BinaryExceptionClassifier(Set.of(DataIntegrityViolationException.class), false));
Chunk<String> inputs = new Chunk<>(Arrays.asList("1", "2"));
processor.process(contribution, inputs);
assertEquals(1, list.size());

View File

@@ -102,8 +102,10 @@ class FaultTolerantStepFactoryBeanRetryTests {
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);
@@ -124,7 +126,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));
JobParameters jobParameters = new JobParametersBuilder().addString("statefulTest", "make_this_unique")
.toJobParameters();
.toJobParameters();
jobExecution = repository.createJobExecution("job", jobParameters);
jobExecution.setEndTime(LocalDateTime.now());
@@ -145,7 +147,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
void testProcessAllItemsWhenErrorInWriterTransformationWhenReaderTransactional() throws Exception {
final int RETRY_LIMIT = 3;
final List<String> ITEM_LIST = TransactionAwareProxyFactory
.createTransactionalList(Arrays.asList("1", "2", "3"));
.createTransactionalList(Arrays.asList("1", "2", "3"));
FaultTolerantStepFactoryBean<String, Integer> factory = new FaultTolerantStepFactoryBean<>();
factory.setBeanName("step");

View File

@@ -110,8 +110,9 @@ class FaultTolerantStepFactoryBeanRollbackTests {
factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean repositoryFactory = new JobRepositoryFactoryBean();
repositoryFactory.setDataSource(embeddedDatabase);
repositoryFactory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -111,8 +111,9 @@ public class FaultTolerantStepFactoryBeanTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().generateUniqueName(true)
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb-extended.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb-extended.sql")
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
factory = new FaultTolerantStepFactoryBean<>();
@@ -131,8 +132,8 @@ public class FaultTolerantStepFactoryBeanTests {
factory.setSkipLimit(2);
factory.setSkippableExceptionClasses(
getExceptionMap(SkippableException.class, SkippableRuntimeException.class));
factory
.setSkippableExceptionClasses(getExceptionMap(SkippableException.class, SkippableRuntimeException.class));
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);

View File

@@ -85,8 +85,10 @@ class SimpleStepFactoryBeanTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);

View File

@@ -56,8 +56,9 @@ class JobStepTests {
void setUp() throws Exception {
step.setName("step");
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));

View File

@@ -142,12 +142,12 @@ class AsyncChunkOrientedStepIntegrationTests {
// Need a transaction so one connection is enough to get job execution and its
// parameters
StepExecution lastStepExecution = new TransactionTemplate(transactionManager)
.execute(new TransactionCallback<StepExecution>() {
@Override
public StepExecution doInTransaction(TransactionStatus status) {
return jobRepository.getLastStepExecution(jobExecution.getJobInstance(), step.getName());
}
});
.execute(new TransactionCallback<StepExecution>() {
@Override
public StepExecution doInTransaction(TransactionStatus status) {
return jobRepository.getLastStepExecution(jobExecution.getJobInstance(), step.getName());
}
});
assertEquals(lastStepExecution, stepExecution);
assertNotSame(lastStepExecution, stepExecution);
}

View File

@@ -119,7 +119,7 @@ class AsyncTaskletStepTests {
void testStepExecutionUpdates() throws Exception {
items = new ArrayList<>(Arrays.asList(StringUtils
.commaDelimitedListToStringArray("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25")));
.commaDelimitedListToStringArray("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25")));
setUp();

View File

@@ -67,8 +67,10 @@ class StepExecutorInterruptionTests {
@BeforeEach
void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
this.transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);

View File

@@ -226,8 +226,9 @@ class TaskletStepTests {
@Test
void testRepository() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.build();
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);

View File

@@ -100,22 +100,23 @@ class ConcurrentTransactionTests {
@Bean
public Flow flow(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new FlowBuilder<Flow>("flow")
.start(new StepBuilder("flow.step1", jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
return RepeatStatus.FINISHED;
}
}, transactionManager).build())
.next(new StepBuilder("flow.step2", jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
return RepeatStatus.FINISHED;
}
}, transactionManager).build()).build();
.start(new StepBuilder("flow.step1", jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
return RepeatStatus.FINISHED;
}
}, transactionManager).build())
.next(new StepBuilder("flow.step2", jobRepository).tasklet(new Tasklet() {
@Nullable
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
return RepeatStatus.FINISHED;
}
}, transactionManager).build())
.build();
}
@Bean
@@ -146,15 +147,16 @@ class ConcurrentTransactionTests {
public Job concurrentJob(JobRepository jobRepository, PlatformTransactionManager transactionManager,
TaskExecutor taskExecutor) {
Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(taskExecutor)
.add(flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager))
.build();
.add(flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager), flow(jobRepository, transactionManager),
flow(jobRepository, transactionManager))
.build();
return new JobBuilder("concurrentJob", jobRepository).start(firstStep(jobRepository, transactionManager))
.next(new StepBuilder("splitFlowStep", jobRepository).flow(splitFlow).build())
.next(lastStep(jobRepository, transactionManager)).build();
.next(new StepBuilder("splitFlowStep", jobRepository).flow(splitFlow).build())
.next(lastStep(jobRepository, transactionManager))
.build();
}
@Bean
@@ -219,7 +221,7 @@ class ConcurrentTransactionTests {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(defaultResourceLoader
.getResource("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"));
.getResource("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"));
databasePopulator.addScript(
defaultResourceLoader.getResource("classpath:org/springframework/batch/core/schema-hsqldb.sql"));
embeddedDatabaseFactory.setDatabasePopulator(databasePopulator);

View File

@@ -84,8 +84,10 @@ public class FootballJobSkipIntegrationTests extends AbstractIntegrationTests {
// They all skip on the second execution because of a primary key
// violation
long retryLimit = 2L;
execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 100000L)
.addLong("retry.limit", retryLimit).toJobParameters());
execution = jobLauncher.run(job,
new JobParametersBuilder().addLong("skip.limit", 100000L)
.addLong("retry.limit", retryLimit)
.toJobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
for (StepExecution stepExecution : execution.getStepExecutions()) {
logger.info("Processed: " + stepExecution);

View File

@@ -31,9 +31,10 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
@Override
protected void initDao() throws Exception {
super.initDao();
insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES").usingColumns("player_id", "year_no",
"team", "week", "opponent", " completes", "attempts", "passing_yards", "passing_td", "interceptions",
"rushes", "rush_yards", "receptions", "receptions_yards", "total_td");
insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES")
.usingColumns("player_id", "year_no", "team", "week", "opponent", " completes", "attempts", "passing_yards",
"passing_td", "interceptions", "rushes", "rush_yards", "receptions", "receptions_yards",
"total_td");
}
@Override
@@ -42,13 +43,20 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter<Game> {
for (Game game : games) {
SqlParameterSource values = new MapSqlParameterSource().addValue("player_id", game.getId())
.addValue("year_no", game.getYear()).addValue("team", game.getTeam())
.addValue("week", game.getWeek()).addValue("opponent", game.getOpponent())
.addValue("completes", game.getCompletes()).addValue("attempts", game.getAttempts())
.addValue("passing_yards", game.getPassingYards()).addValue("passing_td", game.getPassingTd())
.addValue("interceptions", game.getInterceptions()).addValue("rushes", game.getRushes())
.addValue("rush_yards", game.getRushYards()).addValue("receptions", game.getReceptions())
.addValue("receptions_yards", game.getReceptionYards()).addValue("total_td", game.getTotalTd());
.addValue("year_no", game.getYear())
.addValue("team", game.getTeam())
.addValue("week", game.getWeek())
.addValue("opponent", game.getOpponent())
.addValue("completes", game.getCompletes())
.addValue("attempts", game.getAttempts())
.addValue("passing_yards", game.getPassingYards())
.addValue("passing_td", game.getPassingTd())
.addValue("interceptions", game.getInterceptions())
.addValue("rushes", game.getRushes())
.addValue("rush_yards", game.getRushYards())
.addValue("receptions", game.getReceptions())
.addValue("receptions_yards", game.getReceptionYards())
.addValue("total_td", game.getTotalTd());
this.insertGame.execute(values);
}

View File

@@ -39,12 +39,17 @@ public class JdbcPlayerSummaryDao implements ItemWriter<PlayerSummary> {
for (PlayerSummary summary : summaries) {
MapSqlParameterSource args = new MapSqlParameterSource().addValue("id", summary.getId())
.addValue("year", summary.getYear()).addValue("completes", summary.getCompletes())
.addValue("attempts", summary.getAttempts()).addValue("passingYards", summary.getPassingYards())
.addValue("passingTd", summary.getPassingTd()).addValue("interceptions", summary.getInterceptions())
.addValue("rushes", summary.getRushes()).addValue("rushYards", summary.getRushYards())
.addValue("receptions", summary.getReceptions())
.addValue("receptionYards", summary.getReceptionYards()).addValue("totalTd", summary.getTotalTd());
.addValue("year", summary.getYear())
.addValue("completes", summary.getCompletes())
.addValue("attempts", summary.getAttempts())
.addValue("passingYards", summary.getPassingYards())
.addValue("passingTd", summary.getPassingTd())
.addValue("interceptions", summary.getInterceptions())
.addValue("rushes", summary.getRushes())
.addValue("rushYards", summary.getRushYards())
.addValue("receptions", summary.getReceptions())
.addValue("receptionYards", summary.getReceptionYards())
.addValue("totalTd", summary.getTotalTd());
namedParameterJdbcTemplate.update(INSERT_SUMMARY, args);
}

View File

@@ -58,8 +58,10 @@ class LdifReaderBuilderTests {
@Test
void testSkipRecord() throws Exception {
this.ldifReader = new LdifReaderBuilder().recordsToSkip(1).resource(context.getResource("classpath:/test.ldif"))
.name("foo").build();
this.ldifReader = new LdifReaderBuilder().recordsToSkip(1)
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com", ldapAttributes.getName().toString(),
"The attribute name for the second record did not match expected result");
@@ -67,8 +69,9 @@ class LdifReaderBuilderTests {
@Test
void testBasicRead() throws Exception {
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/test.ldif")).name("foo")
.build();
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com",
ldapAttributes.getName().toString(),
@@ -78,7 +81,9 @@ class LdifReaderBuilderTests {
@Test
void testCurrentItemCount() throws Exception {
this.ldifReader = new LdifReaderBuilder().currentItemCount(3)
.resource(context.getResource("classpath:/test.ldif")).name("foo").build();
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com", ldapAttributes.getName().toString(),
"The attribute name for the third record did not match expected result");
@@ -86,8 +91,10 @@ class LdifReaderBuilderTests {
@Test
void testMaxItemCount() throws Exception {
this.ldifReader = new LdifReaderBuilder().maxItemCount(1).resource(context.getResource("classpath:/test.ldif"))
.name("foo").build();
this.ldifReader = new LdifReaderBuilder().maxItemCount(1)
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com",
ldapAttributes.getName().toString(),
@@ -98,8 +105,11 @@ class LdifReaderBuilderTests {
@Test
void testSkipRecordCallback() throws Exception {
this.ldifReader = new LdifReaderBuilder().recordsToSkip(1).skippedRecordsCallback(new TestCallBackHandler())
.resource(context.getResource("classpath:/test.ldif")).name("foo").build();
this.ldifReader = new LdifReaderBuilder().recordsToSkip(1)
.skippedRecordsCallback(new TestCallBackHandler())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", this.callbackAttributeName,
"The attribute name from the callback handler did not match the expected result");
@@ -107,8 +117,9 @@ class LdifReaderBuilderTests {
@Test
void testSaveState() throws Exception {
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/test.ldif")).name("foo")
.build();
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
ExecutionContext executionContext = new ExecutionContext();
firstRead(executionContext);
this.ldifReader.update(executionContext);
@@ -117,8 +128,9 @@ class LdifReaderBuilderTests {
@Test
void testSaveStateDisabled() throws Exception {
this.ldifReader = new LdifReaderBuilder().saveState(false).resource(context.getResource("classpath:/test.ldif"))
.build();
this.ldifReader = new LdifReaderBuilder().saveState(false)
.resource(context.getResource("classpath:/test.ldif"))
.build();
ExecutionContext executionContext = new ExecutionContext();
firstRead(executionContext);
this.ldifReader.update(executionContext);
@@ -128,15 +140,18 @@ class LdifReaderBuilderTests {
@Test
void testStrict() {
// Test that strict when enabled will throw an exception.
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/teadsfst.ldif")).name("foo")
.build();
this.ldifReader = new LdifReaderBuilder().resource(context.getResource("classpath:/teadsfst.ldif"))
.name("foo")
.build();
Exception exception = assertThrows(ItemStreamException.class,
() -> this.ldifReader.open(new ExecutionContext()));
assertEquals("Failed to initialize the reader", exception.getMessage(),
"IllegalStateException message did not match the expected result.");
// Test that strict when disabled will still allow the ldap resource to be opened.
this.ldifReader = new LdifReaderBuilder().strict(false)
.resource(context.getResource("classpath:/teadsfst.ldif")).name("foo").build();
.resource(context.getResource("classpath:/teadsfst.ldif"))
.name("foo")
.build();
this.ldifReader.open(new ExecutionContext());
}

View File

@@ -61,8 +61,10 @@ class MappingLdifReaderBuilderTests {
@Test
void testSkipRecord() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().recordsToSkip(1)
.recordMapper(new TestMapper()).resource(context.getResource("classpath:/test.ldif")).name("foo")
.build();
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com", ldapAttributes.getName().toString(),
"The attribute name for the second record did not match expected result");
@@ -71,7 +73,9 @@ class MappingLdifReaderBuilderTests {
@Test
void testBasicRead() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif")).name("foo").build();
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com",
ldapAttributes.getName().toString(),
@@ -81,8 +85,10 @@ class MappingLdifReaderBuilderTests {
@Test
void testCurrentItemCount() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().currentItemCount(3)
.recordMapper(new TestMapper()).resource(context.getResource("classpath:/test.ldif")).name("foo")
.build();
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com", ldapAttributes.getName().toString(),
"The attribute name for the third record did not match expected result");
@@ -91,8 +97,10 @@ class MappingLdifReaderBuilderTests {
@Test
void testMaxItemCount() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().maxItemCount(1)
.recordMapper(new TestMapper()).resource(context.getResource("classpath:/test.ldif")).name("foo")
.build();
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
LdapAttributes ldapAttributes = firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com",
ldapAttributes.getName().toString(),
@@ -104,8 +112,11 @@ class MappingLdifReaderBuilderTests {
@Test
void testSkipRecordCallback() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().recordsToSkip(1)
.recordMapper(new TestMapper()).skippedRecordsCallback(new TestCallBackHandler())
.resource(context.getResource("classpath:/test.ldif")).name("foo").build();
.recordMapper(new TestMapper())
.skippedRecordsCallback(new TestCallBackHandler())
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
firstRead();
assertEquals("cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com", this.callbackAttributeName,
"The attribute name from the callback handler did not match the expected result");
@@ -114,7 +125,9 @@ class MappingLdifReaderBuilderTests {
@Test
void testSaveState() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif")).name("foo").build();
.resource(context.getResource("classpath:/test.ldif"))
.name("foo")
.build();
ExecutionContext executionContext = new ExecutionContext();
firstRead(executionContext);
this.mappingLdifReader.update(executionContext);
@@ -124,7 +137,9 @@ class MappingLdifReaderBuilderTests {
@Test
void testSaveStateDisabled() throws Exception {
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().saveState(false)
.recordMapper(new TestMapper()).resource(context.getResource("classpath:/test.ldif")).build();
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/test.ldif"))
.build();
ExecutionContext executionContext = new ExecutionContext();
firstRead(executionContext);
this.mappingLdifReader.update(executionContext);
@@ -135,14 +150,19 @@ class MappingLdifReaderBuilderTests {
void testStrict() {
// Test that strict when enabled will throw an exception.
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().recordMapper(new TestMapper())
.resource(context.getResource("classpath:/teadsfst.ldif")).name("foo").build();
.resource(context.getResource("classpath:/teadsfst.ldif"))
.name("foo")
.build();
Exception exception = assertThrows(ItemStreamException.class,
() -> this.mappingLdifReader.open(new ExecutionContext()));
assertEquals("Failed to initialize the reader", exception.getMessage(),
"IllegalStateException message did not match the expected result.");
// Test that strict when disabled will still allow the ldap resource to be opened.
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().strict(false).name("foo")
.recordMapper(new TestMapper()).resource(context.getResource("classpath:/teadsfst.ldif")).build();
this.mappingLdifReader = new MappingLdifReaderBuilder<LdapAttributes>().strict(false)
.name("foo")
.recordMapper(new TestMapper())
.resource(context.getResource("classpath:/teadsfst.ldif"))
.build();
this.mappingLdifReader.open(new ExecutionContext());
}
@@ -150,7 +170,8 @@ class MappingLdifReaderBuilderTests {
void testNullRecordMapper() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> new MappingLdifReaderBuilder<LdapAttributes>()
.resource(context.getResource("classpath:/teadsfst.ldif")).build());
.resource(context.getResource("classpath:/teadsfst.ldif"))
.build());
assertEquals("RecordMapper is required.", exception.getMessage(),
"IllegalArgumentException message did not match the expected result.");
}

View File

@@ -116,9 +116,10 @@ class Db2JobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -74,7 +74,9 @@ class DerbyJobRepositoryIntegrationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
.addScript("/org/springframework/batch/core/schema-derby.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-derby.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -85,9 +87,10 @@ class DerbyJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -94,9 +94,10 @@ class H2CompatibilityModeJobRepositoryIntegrationTests {
@Bean
Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -74,7 +74,9 @@ class H2JobRepositoryIntegrationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-h2.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-h2.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -85,9 +87,10 @@ class H2JobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -76,7 +76,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
class HANAJobRepositoryIntegrationTests {
private static final DockerImageName HANA_IMAGE = DockerImageName
.parse("store/saplabs/hanaexpress:2.00.057.00.20211207.1");
.parse("store/saplabs/hanaexpress:2.00.057.00.20211207.1");
@Container
public static HANAContainer<?> hana = new HANAContainer<>(HANA_IMAGE).acceptLicense();
@@ -131,9 +131,10 @@ class HANAJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}
@@ -171,8 +172,9 @@ class HANAJobRepositoryIntegrationTests {
this.withCommand("--master-password " + SYSTEM_USER_PASSWORD + " --agree-to-sap-license");
// Determine if container is ready.
this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*Startup finished!*\\s").withTimes(1)
.withStartupTimeout(Duration.of(600, ChronoUnit.SECONDS));
this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*Startup finished!*\\s")
.withTimes(1)
.withStartupTimeout(Duration.of(600, ChronoUnit.SECONDS));
}
@Override

View File

@@ -74,7 +74,9 @@ class HSQLDBJobRepositoryIntegrationTests {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
.generateUniqueName(true)
.build();
}
@Bean
@@ -85,9 +87,10 @@ class HSQLDBJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -112,9 +112,10 @@ class MariaDBJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -146,9 +146,10 @@ class MySQLJdbcJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
throw new Exception("expected failure");
}, transactionManager).build()).build();
.start(new StepBuilder("step", jobRepository).tasklet((contribution, chunkContext) -> {
throw new Exception("expected failure");
}, transactionManager).build())
.build();
}
@Bean

View File

@@ -113,9 +113,10 @@ class MySQLJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -121,9 +121,10 @@ class OracleJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -112,9 +112,10 @@ class PostgreSQLJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -58,7 +58,7 @@ class SQLServerJobRepositoryIntegrationTests {
// TODO find the best way to externalize and manage image versions
private static final DockerImageName SQLSERVER_IMAGE = DockerImageName
.parse("mcr.microsoft.com/mssql/server:2019-CU11-ubuntu-20.04");
.parse("mcr.microsoft.com/mssql/server:2019-CU11-ubuntu-20.04");
@Container
public static MSSQLServerContainer<?> sqlserver = new MSSQLServerContainer<>(SQLSERVER_IMAGE).acceptLicense();
@@ -113,9 +113,10 @@ class SQLServerJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -78,7 +78,7 @@ class SQLiteJobRepositoryIntegrationTests {
dataSource.setUrl("jdbc:sqlite:target/spring-batch.sqlite");
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator
.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-sqlite.sql"));
.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-sqlite.sql"));
databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-sqlite.sql"));
databasePopulator.execute(dataSource);
return dataSource;
@@ -92,9 +92,10 @@ class SQLiteJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -114,9 +114,10 @@ class SybaseJobRepositoryIntegrationTests {
@Bean
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new JobBuilder("job", jobRepository)
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager).build())
.build();
.start(new StepBuilder("step", jobRepository)
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED, transactionManager)
.build())
.build();
}
}

View File

@@ -78,7 +78,10 @@ class FaultTolerantStepIntegrationTests {
};
skipPolicy = new SkipIllegalArgumentExceptionSkipPolicy();
stepBuilder = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(CHUNK_SIZE, transactionManager)
.reader(itemReader).processor(item -> item > 20 ? null : item).writer(itemWriter).faultTolerant();
.reader(itemReader)
.processor(item -> item > 20 ? null : item)
.writer(itemWriter)
.faultTolerant();
}
@Test
@@ -130,8 +133,11 @@ class FaultTolerantStepIntegrationTests {
@Test
void testFilterCountOnRetryWithNonTransactionalProcessorWhenSkipInWrite() throws Exception {
// Given
Step step = stepBuilder.retry(IllegalArgumentException.class).retryLimit(2).skipPolicy(skipPolicy)
.processorNonTransactional().build();
Step step = stepBuilder.retry(IllegalArgumentException.class)
.retryLimit(2)
.skipPolicy(skipPolicy)
.processorNonTransactional()
.build();
// When
StepExecution stepExecution = execute(step);
@@ -178,8 +184,13 @@ class FaultTolerantStepIntegrationTests {
};
Step step = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(5, transactionManager)
.reader(itemReader).processor(itemProcessor).writer(itemWriter).faultTolerant().skip(Exception.class)
.skipLimit(3).build();
.reader(itemReader)
.processor(itemProcessor)
.writer(itemWriter)
.faultTolerant()
.skip(Exception.class)
.skipLimit(3)
.build();
// When
StepExecution stepExecution = execute(step);
@@ -218,8 +229,12 @@ class FaultTolerantStepIntegrationTests {
};
Step step = new StepBuilder("step", jobRepository).<Integer, Integer>chunk(5, transactionManager)
.reader(itemReader).processor(itemProcessor).writer(itemWriter).faultTolerant()
.skipPolicy(new AlwaysSkipItemSkipPolicy()).build();
.reader(itemReader)
.processor(itemProcessor)
.writer(itemWriter)
.faultTolerant()
.skipPolicy(new AlwaysSkipItemSkipPolicy())
.build();
// When
StepExecution stepExecution = execute(step);