Update versions and update code format
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -110,8 +110,8 @@
|
||||
<properties>
|
||||
|
||||
<spring-cloud-stream.version>4.1.0-SNAPSHOT</spring-cloud-stream.version>
|
||||
<spring-cloud-deployer.version>2.8.3</spring-cloud-deployer.version>
|
||||
<spring-cloud-deployer-local.version>2.8.3
|
||||
<spring-cloud-deployer.version>2.9.0</spring-cloud-deployer.version>
|
||||
<spring-cloud-deployer-local.version>2.9.0
|
||||
</spring-cloud-deployer-local.version>
|
||||
<spring-cloud-stream-binder-rabbit.version>${spring-cloud-stream.version}
|
||||
</spring-cloud-stream-binder-rabbit.version>
|
||||
@@ -127,7 +127,7 @@
|
||||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||||
</maven-checkstyle-plugin.includeTestSourceDirectory>
|
||||
<java.version>17</java.version>
|
||||
<spring-javaformat-maven-plugin.version>0.0.34</spring-javaformat-maven-plugin.version>
|
||||
<spring-javaformat-maven-plugin.version>0.0.39</spring-javaformat-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RangeConverter implements Converter<String, Range> {
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(String
|
||||
.format("%s is in an illegal format. Ranges must be specified as startIndex-endIndex", source));
|
||||
.format("%s is in an illegal format. Ranges must be specified as startIndex-endIndex", source));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,9 +81,8 @@ public class SingleStepJobAutoConfiguration {
|
||||
|
||||
SimpleStepBuilder<Map<String, Object>, Map<String, Object>> stepBuilder = new StepBuilder(
|
||||
this.properties.getStepName(), this.jobRepository)
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize(),
|
||||
this.transactionManager)
|
||||
.reader(itemReader);
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize(), this.transactionManager)
|
||||
.reader(itemReader);
|
||||
|
||||
stepBuilder.processor(this.itemProcessor);
|
||||
|
||||
|
||||
@@ -67,11 +67,15 @@ public class FlatFileItemReaderAutoConfiguration {
|
||||
@Autowired(required = false) LineCallbackHandler skippedLinesCallback,
|
||||
@Autowired(required = false) RecordSeparatorPolicy recordSeparatorPolicy) {
|
||||
FlatFileItemReaderBuilder<Map<String, Object>> mapFlatFileItemReaderBuilder = new FlatFileItemReaderBuilder<Map<String, Object>>()
|
||||
.name(this.properties.getName()).resource(this.properties.getResource())
|
||||
.saveState(this.properties.isSaveState()).maxItemCount(this.properties.getMaxItemCount())
|
||||
.currentItemCount(this.properties.getCurrentItemCount()).strict(this.properties.isStrict())
|
||||
.encoding(this.properties.getEncoding()).linesToSkip(this.properties.getLinesToSkip())
|
||||
.comments(this.properties.getComments().toArray(new String[this.properties.getComments().size()]));
|
||||
.name(this.properties.getName())
|
||||
.resource(this.properties.getResource())
|
||||
.saveState(this.properties.isSaveState())
|
||||
.maxItemCount(this.properties.getMaxItemCount())
|
||||
.currentItemCount(this.properties.getCurrentItemCount())
|
||||
.strict(this.properties.isStrict())
|
||||
.encoding(this.properties.getEncoding())
|
||||
.linesToSkip(this.properties.getLinesToSkip())
|
||||
.comments(this.properties.getComments().toArray(new String[this.properties.getComments().size()]));
|
||||
|
||||
mapFlatFileItemReaderBuilder.lineTokenizer(lineTokenizer);
|
||||
if (recordSeparatorPolicy != null) {
|
||||
@@ -82,19 +86,23 @@ public class FlatFileItemReaderAutoConfiguration {
|
||||
mapFlatFileItemReaderBuilder.skippedLinesCallback(skippedLinesCallback);
|
||||
|
||||
if (this.properties.isDelimited()) {
|
||||
mapFlatFileItemReaderBuilder.delimited().quoteCharacter(this.properties.getQuoteCharacter())
|
||||
.delimiter(this.properties.getDelimiter())
|
||||
.includedFields(this.properties.getIncludedFields().toArray(new Integer[0]))
|
||||
.names(this.properties.getNames()).beanMapperStrict(this.properties.isParsingStrict())
|
||||
.fieldSetMapper(new MapFieldSetMapper());
|
||||
mapFlatFileItemReaderBuilder.delimited()
|
||||
.quoteCharacter(this.properties.getQuoteCharacter())
|
||||
.delimiter(this.properties.getDelimiter())
|
||||
.includedFields(this.properties.getIncludedFields().toArray(new Integer[0]))
|
||||
.names(this.properties.getNames())
|
||||
.beanMapperStrict(this.properties.isParsingStrict())
|
||||
.fieldSetMapper(new MapFieldSetMapper());
|
||||
}
|
||||
else if (this.properties.isFixedLength()) {
|
||||
RangeConverter rangeConverter = new RangeConverter();
|
||||
List<Range> ranges = new ArrayList<>();
|
||||
this.properties.getRanges().forEach(range -> ranges.add(rangeConverter.convert(range)));
|
||||
mapFlatFileItemReaderBuilder.fixedLength().columns(ranges.toArray(new Range[0]))
|
||||
.names(this.properties.getNames()).fieldSetMapper(new MapFieldSetMapper())
|
||||
.beanMapperStrict(this.properties.isParsingStrict());
|
||||
mapFlatFileItemReaderBuilder.fixedLength()
|
||||
.columns(ranges.toArray(new Range[0]))
|
||||
.names(this.properties.getNames())
|
||||
.fieldSetMapper(new MapFieldSetMapper())
|
||||
.beanMapperStrict(this.properties.isParsingStrict());
|
||||
}
|
||||
|
||||
return mapFlatFileItemReaderBuilder.build();
|
||||
|
||||
@@ -80,17 +80,22 @@ public class FlatFileItemWriterAutoConfiguration {
|
||||
}
|
||||
|
||||
FlatFileItemWriterBuilder<Map<String, Object>> builder = new FlatFileItemWriterBuilder<Map<String, Object>>()
|
||||
.name(this.properties.getName()).resource((WritableResource) this.properties.getResource())
|
||||
.append(this.properties.isAppend()).encoding(this.properties.getEncoding())
|
||||
.forceSync(this.properties.isForceSync()).lineSeparator(this.properties.getLineSeparator())
|
||||
.saveState(this.properties.isSaveState()).shouldDeleteIfEmpty(this.properties.isShouldDeleteIfEmpty())
|
||||
.shouldDeleteIfExists(this.properties.isShouldDeleteIfExists())
|
||||
.transactional(this.properties.isTransactional()).headerCallback(this.headerCallback)
|
||||
.footerCallback(this.footerCallback);
|
||||
.name(this.properties.getName())
|
||||
.resource((WritableResource) this.properties.getResource())
|
||||
.append(this.properties.isAppend())
|
||||
.encoding(this.properties.getEncoding())
|
||||
.forceSync(this.properties.isForceSync())
|
||||
.lineSeparator(this.properties.getLineSeparator())
|
||||
.saveState(this.properties.isSaveState())
|
||||
.shouldDeleteIfEmpty(this.properties.isShouldDeleteIfEmpty())
|
||||
.shouldDeleteIfExists(this.properties.isShouldDeleteIfExists())
|
||||
.transactional(this.properties.isTransactional())
|
||||
.headerCallback(this.headerCallback)
|
||||
.footerCallback(this.footerCallback);
|
||||
|
||||
if (this.properties.isDelimited()) {
|
||||
FlatFileItemWriterBuilder.DelimitedBuilder<Map<String, Object>> delimitedBuilder = builder.delimited()
|
||||
.delimiter(this.properties.getDelimiter());
|
||||
.delimiter(this.properties.getDelimiter());
|
||||
|
||||
if (this.fieldExtractor != null) {
|
||||
delimitedBuilder.fieldExtractor(this.fieldExtractor);
|
||||
@@ -101,9 +106,10 @@ public class FlatFileItemWriterAutoConfiguration {
|
||||
}
|
||||
else if (this.properties.isFormatted()) {
|
||||
FlatFileItemWriterBuilder.FormattedBuilder<Map<String, Object>> formattedBuilder = builder.formatted()
|
||||
.format(this.properties.getFormat()).locale(this.properties.getLocale())
|
||||
.maximumLength(this.properties.getMaximumLength())
|
||||
.minimumLength(this.properties.getMinimumLength());
|
||||
.format(this.properties.getFormat())
|
||||
.locale(this.properties.getLocale())
|
||||
.maximumLength(this.properties.getMaximumLength())
|
||||
.minimumLength(this.properties.getMinimumLength());
|
||||
|
||||
if (this.fieldExtractor != null) {
|
||||
formattedBuilder.fieldExtractor(this.fieldExtractor);
|
||||
|
||||
@@ -87,7 +87,8 @@ public class JdbcBatchItemWriterAutoConfiguration {
|
||||
}
|
||||
|
||||
JdbcBatchItemWriterBuilder<Map<String, Object>> jdbcBatchItemWriterBuilder = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.dataSource(writerDataSource).sql(this.properties.getSql());
|
||||
.dataSource(writerDataSource)
|
||||
.sql(this.properties.getSql());
|
||||
if (this.itemPreparedStatementSetter != null) {
|
||||
jdbcBatchItemWriterBuilder.itemPreparedStatementSetter(this.itemPreparedStatementSetter);
|
||||
}
|
||||
|
||||
@@ -85,14 +85,21 @@ public class JdbcCursorItemReaderAutoConfiguration {
|
||||
|
||||
}
|
||||
return new JdbcCursorItemReaderBuilder<Map<String, Object>>().name(this.properties.getName())
|
||||
.currentItemCount(this.properties.getCurrentItemCount()).dataSource(readerDataSource)
|
||||
.driverSupportsAbsolute(this.properties.isDriverSupportsAbsolute())
|
||||
.fetchSize(this.properties.getFetchSize()).ignoreWarnings(this.properties.isIgnoreWarnings())
|
||||
.maxItemCount(this.properties.getMaxItemCount()).maxRows(this.properties.getMaxRows())
|
||||
.queryTimeout(this.properties.getQueryTimeout()).saveState(this.properties.isSaveState())
|
||||
.sql(this.properties.getSql()).rowMapper(rowMapper).preparedStatementSetter(preparedStatementSetter)
|
||||
.verifyCursorPosition(this.properties.isVerifyCursorPosition())
|
||||
.useSharedExtendedConnection(this.properties.isUseSharedExtendedConnection()).build();
|
||||
.currentItemCount(this.properties.getCurrentItemCount())
|
||||
.dataSource(readerDataSource)
|
||||
.driverSupportsAbsolute(this.properties.isDriverSupportsAbsolute())
|
||||
.fetchSize(this.properties.getFetchSize())
|
||||
.ignoreWarnings(this.properties.isIgnoreWarnings())
|
||||
.maxItemCount(this.properties.getMaxItemCount())
|
||||
.maxRows(this.properties.getMaxRows())
|
||||
.queryTimeout(this.properties.getQueryTimeout())
|
||||
.saveState(this.properties.isSaveState())
|
||||
.sql(this.properties.getSql())
|
||||
.rowMapper(rowMapper)
|
||||
.preparedStatementSetter(preparedStatementSetter)
|
||||
.verifyCursorPosition(this.properties.isVerifyCursorPosition())
|
||||
.useSharedExtendedConnection(this.properties.isUseSharedExtendedConnection())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -64,10 +64,13 @@ public class KafkaItemReaderAutoConfiguration {
|
||||
kafkaItemReaderProperties.getPartitions().add(0);
|
||||
}
|
||||
return new KafkaItemReaderBuilder<Object, Map<String, Object>>()
|
||||
.partitions(kafkaItemReaderProperties.getPartitions()).consumerProperties(consumerProperties)
|
||||
.name(kafkaItemReaderProperties.getName())
|
||||
.pollTimeout(Duration.ofSeconds(kafkaItemReaderProperties.getPollTimeOutInSeconds()))
|
||||
.saveState(kafkaItemReaderProperties.isSaveState()).topic(kafkaItemReaderProperties.getTopic()).build();
|
||||
.partitions(kafkaItemReaderProperties.getPartitions())
|
||||
.consumerProperties(consumerProperties)
|
||||
.name(kafkaItemReaderProperties.getName())
|
||||
.pollTimeout(Duration.ofSeconds(kafkaItemReaderProperties.getPollTimeOutInSeconds()))
|
||||
.saveState(kafkaItemReaderProperties.isSaveState())
|
||||
.topic(kafkaItemReaderProperties.getTopic())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void validateProperties(KafkaItemReaderProperties kafkaItemReaderProperties) {
|
||||
|
||||
@@ -66,7 +66,9 @@ public class KafkaItemWriterAutoConfiguration {
|
||||
KafkaTemplate template = new KafkaTemplate(producerFactory);
|
||||
template.setDefaultTopic(kafkaItemWriterProperties.getTopic());
|
||||
return new KafkaItemWriterBuilder<Object, Map<String, Object>>().delete(kafkaItemWriterProperties.isDelete())
|
||||
.kafkaTemplate(template).itemKeyMapper(itemKeyMapper).build();
|
||||
.kafkaTemplate(template)
|
||||
.itemKeyMapper(itemKeyMapper)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -57,7 +57,7 @@ public class AmqpItemReaderAutoConfiguration {
|
||||
public AmqpItemReader<Map<String, Object>> amqpItemReader(AmqpTemplate amqpTemplate,
|
||||
@Autowired(required = false) Class itemType) {
|
||||
AmqpItemReaderBuilder<Map<String, Object>> builder = new AmqpItemReaderBuilder<Map<String, Object>>()
|
||||
.amqpTemplate(amqpTemplate);
|
||||
.amqpTemplate(amqpTemplate);
|
||||
if (itemType != null) {
|
||||
builder.itemType(itemType);
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ public class SingleStepJobAutoConfigurationTests {
|
||||
@Test
|
||||
public void testSimpleConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(SimpleConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5");
|
||||
.withUserConfiguration(SimpleConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5");
|
||||
|
||||
validateConfiguration(applicationContextRunner);
|
||||
}
|
||||
@@ -117,12 +117,12 @@ public class SingleStepJobAutoConfigurationTests {
|
||||
@Test
|
||||
public void testSimpleConfigurationKabobStyle() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(SimpleConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.job-name=job", "spring.batch.job.step-name=step1",
|
||||
"spring.batch.job.chunk-size=5");
|
||||
.withUserConfiguration(SimpleConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.job-name=job", "spring.batch.job.step-name=step1",
|
||||
"spring.batch.job.chunk-size=5");
|
||||
|
||||
validateConfiguration(applicationContextRunner);
|
||||
}
|
||||
|
||||
@@ -76,26 +76,26 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testFullDelimitedConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(JobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.savestate=true",
|
||||
"spring.batch.job.flatfileitemreader.name=fullDelimitedConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.maxItemCount=5",
|
||||
"spring.batch.job.flatfileitemreader.currentItemCount=2",
|
||||
"spring.batch.job.flatfileitemreader.comments=#,$",
|
||||
"spring.batch.job.flatfileitemreader.resource=/testUTF16.csv",
|
||||
"spring.batch.job.flatfileitemreader.strict=true",
|
||||
"spring.batch.job.flatfileitemreader.encoding=UTF-16",
|
||||
"spring.batch.job.flatfileitemreader.linesToSkip=1",
|
||||
"spring.batch.job.flatfileitemreader.delimited=true",
|
||||
"spring.batch.job.flatfileitemreader.delimiter=@",
|
||||
"spring.batch.job.flatfileitemreader.quoteCharacter=%",
|
||||
"spring.batch.job.flatfileitemreader.includedFields=1,3,5",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.parsingStrict=false");
|
||||
.withUserConfiguration(JobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.savestate=true",
|
||||
"spring.batch.job.flatfileitemreader.name=fullDelimitedConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.maxItemCount=5",
|
||||
"spring.batch.job.flatfileitemreader.currentItemCount=2",
|
||||
"spring.batch.job.flatfileitemreader.comments=#,$",
|
||||
"spring.batch.job.flatfileitemreader.resource=/testUTF16.csv",
|
||||
"spring.batch.job.flatfileitemreader.strict=true",
|
||||
"spring.batch.job.flatfileitemreader.encoding=UTF-16",
|
||||
"spring.batch.job.flatfileitemreader.linesToSkip=1",
|
||||
"spring.batch.job.flatfileitemreader.delimited=true",
|
||||
"spring.batch.job.flatfileitemreader.delimiter=@",
|
||||
"spring.batch.job.flatfileitemreader.quoteCharacter=%",
|
||||
"spring.batch.job.flatfileitemreader.includedFields=1,3,5",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.parsingStrict=false");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -130,21 +130,20 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testFixedWidthConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(JobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, FlatFileItemReaderAutoConfiguration.class,
|
||||
RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.savestate=true",
|
||||
"spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.comments=#,$",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.strict=true",
|
||||
"spring.batch.job.flatfileitemreader.fixedLength=true",
|
||||
"spring.batch.job.flatfileitemreader.ranges=3-4,7-8,11",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.parsingStrict=false");
|
||||
.withUserConfiguration(JobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.savestate=true",
|
||||
"spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.comments=#,$",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.strict=true",
|
||||
"spring.batch.job.flatfileitemreader.fixedLength=true",
|
||||
"spring.batch.job.flatfileitemreader.ranges=3-4,7-8,11",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.parsingStrict=false");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -188,15 +187,14 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testCustomLineMapper() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomLineMapperConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
.withUserConfiguration(CustomLineMapperConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -225,20 +223,18 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testCustomRecordSeparatorAndSkippedLines() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(RecordSeparatorAndSkippedLinesJobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, FlatFileItemReaderAutoConfiguration.class,
|
||||
RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.linesToSkip=2",
|
||||
"spring.batch.job.flatfileitemreader.fixedLength=true",
|
||||
"spring.batch.job.flatfileitemreader.ranges=3-4,7-8,11",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
.withUserConfiguration(RecordSeparatorAndSkippedLinesJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.linesToSkip=2",
|
||||
"spring.batch.job.flatfileitemreader.fixedLength=true",
|
||||
"spring.batch.job.flatfileitemreader.ranges=3-4,7-8,11",
|
||||
"spring.batch.job.flatfileitemreader.names=foo,bar,baz",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -268,17 +264,15 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testCustomMapping() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, FlatFileItemReaderAutoConfiguration.class,
|
||||
RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.maxItemCount=1",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemReaderAutoConfiguration.class, RangeConverter.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemreader.name=fixedWidthConfiguration",
|
||||
"spring.batch.job.flatfileitemreader.resource=/test.txt",
|
||||
"spring.batch.job.flatfileitemreader.maxItemCount=1",
|
||||
"spring.batch.job.flatfileitemreader.strict=true");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertThat(ise.getMessage())
|
||||
.isEqualTo("A LineAggregator must be configured if the " + "output is not formatted or delimited");
|
||||
.isEqualTo("A LineAggregator must be configured if the " + "output is not formatted or delimited");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception thrown", e);
|
||||
@@ -124,7 +124,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertThat(ise.getMessage())
|
||||
.isEqualTo("A LineAggregator must be configured if the " + "output is not formatted or delimited");
|
||||
.isEqualTo("A LineAggregator must be configured if the " + "output is not formatted or delimited");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception thrown", e);
|
||||
@@ -134,23 +134,22 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testDelimitedFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(DelimitedJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-16",
|
||||
"spring.batch.job.flatfileitemwriter.saveState=false",
|
||||
"spring.batch.job.flatfileitemwriter.shouldDeleteIfEmpty=true",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item",
|
||||
"spring.batch.job.flatfileitemwriter.append=true",
|
||||
"spring.batch.job.flatfileitemwriter.forceSync=true",
|
||||
"spring.batch.job.flatfileitemwriter.shouldDeleteIfExists=false",
|
||||
"spring.batch.job.flatfileitemwriter.transactional=false");
|
||||
.withUserConfiguration(DelimitedJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-16",
|
||||
"spring.batch.job.flatfileitemwriter.saveState=false",
|
||||
"spring.batch.job.flatfileitemwriter.shouldDeleteIfEmpty=true",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item", "spring.batch.job.flatfileitemwriter.append=true",
|
||||
"spring.batch.job.flatfileitemwriter.forceSync=true",
|
||||
"spring.batch.job.flatfileitemwriter.shouldDeleteIfExists=false",
|
||||
"spring.batch.job.flatfileitemwriter.transactional=false");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -169,7 +168,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_16).size()).isEqualTo(3);
|
||||
assertThat(Assertions.contentOf((new ClassPathResource("writerTestUTF16.txt")).getFile())
|
||||
.equals(new FileSystemResource(this.outputFile)));
|
||||
.equals(new FileSystemResource(this.outputFile)));
|
||||
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "saveState")).isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "append")).isTrue();
|
||||
@@ -182,20 +181,20 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testFormattedFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(FormattedJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=2", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.formatted=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item",
|
||||
"spring.batch.job.flatfileitemwriter.format=item = %s",
|
||||
"spring.batch.job.flatfileitemwriter.minimumLength=8",
|
||||
"spring.batch.job.flatfileitemwriter.maximumLength=10");
|
||||
.withUserConfiguration(FormattedJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=2", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.formatted=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item",
|
||||
"spring.batch.job.flatfileitemwriter.format=item = %s",
|
||||
"spring.batch.job.flatfileitemwriter.minimumLength=8",
|
||||
"spring.batch.job.flatfileitemwriter.maximumLength=10");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -213,7 +212,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(2);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("item = foo\nitem = bar\n");
|
||||
});
|
||||
}
|
||||
@@ -221,18 +220,18 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testFormattedFieldExtractorFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(FormattedFieldExtractorJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.formatted=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item",
|
||||
"spring.batch.job.flatfileitemwriter.format=item = %s");
|
||||
.withUserConfiguration(FormattedFieldExtractorJobConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.formatted=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item",
|
||||
"spring.batch.job.flatfileitemwriter.format=item = %s");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -250,7 +249,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
assertThat(Assertions.linesOf(this.outputFile).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("item = f\nitem = b\nitem = b\n");
|
||||
});
|
||||
}
|
||||
@@ -258,16 +257,16 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testFieldExtractorFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(FieldExtractorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true");
|
||||
.withUserConfiguration(FieldExtractorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -285,7 +284,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("f\nb\nb\n");
|
||||
});
|
||||
}
|
||||
@@ -293,15 +292,15 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testCustomLineAggregatorFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(LineAggregatorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8");
|
||||
.withUserConfiguration(LineAggregatorConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -319,7 +318,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(3);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("{item=foo}\n{item=bar}\n{item=baz}\n");
|
||||
});
|
||||
}
|
||||
@@ -327,17 +326,17 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void testHeaderFooterFileGeneration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(HeaderFooterConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item");
|
||||
.withUserConfiguration(HeaderFooterConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
FlatFileItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.flatfileitemwriter.name=fooWriter",
|
||||
String.format("spring.batch.job.flatfileitemwriter.resource=file://%s",
|
||||
this.outputFile.getAbsolutePath()),
|
||||
"spring.batch.job.flatfileitemwriter.encoding=UTF-8",
|
||||
"spring.batch.job.flatfileitemwriter.delimited=true",
|
||||
"spring.batch.job.flatfileitemwriter.names=item");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -355,7 +354,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
assertThat(Assertions.linesOf(this.outputFile, StandardCharsets.UTF_8).size()).isEqualTo(5);
|
||||
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("header\nfoo\nbar\nbaz\nfooter");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,12 +101,12 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void baseTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
|
||||
runTest(applicationContextRunner, false);
|
||||
@@ -115,21 +115,21 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void baseTestWithWriterDataSource() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcbatchitemwriter.datasource.enable=true",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false", "spring.batch.job.jobName=job",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.jdbcbatchitemwriter.name=fooWriter",
|
||||
"spring.batch.job.jdbcbatchitemwriter.sql=INSERT INTO item (item_name) VALUES (:item_name)",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"jdbcbatchitemwriter.datasource.url=" + DATASOURCE_URL,
|
||||
"jdbcbatchitemwriter.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"jdbcbatchitemwriter.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"jdbcbatchitemwriter.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME);
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcbatchitemwriter.datasource.enable=true",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false", "spring.batch.job.jobName=job",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.jdbcbatchitemwriter.name=fooWriter",
|
||||
"spring.batch.job.jdbcbatchitemwriter.sql=INSERT INTO item (item_name) VALUES (:item_name)",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"jdbcbatchitemwriter.datasource.url=" + DATASOURCE_URL,
|
||||
"jdbcbatchitemwriter.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"jdbcbatchitemwriter.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"jdbcbatchitemwriter.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME);
|
||||
|
||||
runTest(applicationContextRunner, true);
|
||||
}
|
||||
@@ -137,13 +137,13 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void customSqlParameterSourceTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedDifferentKeyNameJobConfiguration.class,
|
||||
CustomSqlParameterSourceProviderConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedDifferentKeyNameJobConfiguration.class,
|
||||
CustomSqlParameterSourceProviderConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
|
||||
runTest(applicationContextRunner, false);
|
||||
@@ -152,13 +152,13 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void preparedStatementSetterTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class,
|
||||
ItemPreparedStatementSetterConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class,
|
||||
ItemPreparedStatementSetterConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
runTest(applicationContextRunner, false);
|
||||
}
|
||||
@@ -193,8 +193,8 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "usingNamedParameters")).isTrue();
|
||||
if (!isWriterDataSourcePresent) {
|
||||
assertThatThrownBy(() -> context.getBean("jdbcBatchItemWriterSpringDataSource"))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'jdbcBatchItemWriterSpringDataSource' available");
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'jdbcBatchItemWriterSpringDataSource' available");
|
||||
}
|
||||
else {
|
||||
assertThat(context.getBean("jdbcBatchItemWriterSpringDataSource")).isNotNull();
|
||||
@@ -229,8 +229,10 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (defaultServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort))
|
||||
.start();
|
||||
defaultServer = server;
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
|
||||
|
||||
@@ -121,16 +121,17 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
assertThat(items.get(1).get("ITEM_NAME")).isEqualTo("bar");
|
||||
assertThat(items.get(2).get("ITEM_NAME")).isEqualTo("baz");
|
||||
assertThatThrownBy(() -> context.getBean("readerSpringDataSource"))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'readerSpringDataSource' available");
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'readerSpringDataSource' available");
|
||||
});
|
||||
}
|
||||
|
||||
private ApplicationContextRunner applicationContextRunner() {
|
||||
return new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class).withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class));
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,15 +173,15 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testCustomRowMapper() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, RowMapperConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=rowMapperJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select * from item",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, RowMapperConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=rowMapperJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select * from item",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -207,23 +208,23 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRoseyScenario() {
|
||||
final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=roseyJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.saveState=false",
|
||||
"spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.maxItemCount=15",
|
||||
"spring.batch.job.jdbccursoritemreader.currentItemCount=2",
|
||||
"spring.batch.job.jdbccursoritemreader.fetchSize=4",
|
||||
"spring.batch.job.jdbccursoritemreader.maxRows=6",
|
||||
"spring.batch.job.jdbccursoritemreader.queryTimeout=8",
|
||||
"spring.batch.job.jdbccursoritemreader.ignoreWarnings=true",
|
||||
"spring.batch.job.jdbccursoritemreader.verifyCursorPosition=true",
|
||||
"spring.batch.job.jdbccursoritemreader.driverSupportsAbsolute=true",
|
||||
"spring.batch.job.jdbccursoritemreader.useSharedExtendedConnection=true",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select * from foo");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=roseyJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.saveState=false",
|
||||
"spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.maxItemCount=15",
|
||||
"spring.batch.job.jdbccursoritemreader.currentItemCount=2",
|
||||
"spring.batch.job.jdbccursoritemreader.fetchSize=4",
|
||||
"spring.batch.job.jdbccursoritemreader.maxRows=6",
|
||||
"spring.batch.job.jdbccursoritemreader.queryTimeout=8",
|
||||
"spring.batch.job.jdbccursoritemreader.ignoreWarnings=true",
|
||||
"spring.batch.job.jdbccursoritemreader.verifyCursorPosition=true",
|
||||
"spring.batch.job.jdbccursoritemreader.driverSupportsAbsolute=true",
|
||||
"spring.batch.job.jdbccursoritemreader.useSharedExtendedConnection=true",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select * from foo");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
@@ -239,7 +240,8 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "saveState")).isFalse();
|
||||
assertThat(ReflectionTestUtils.getField(
|
||||
(ExecutionContextUserSupport) ReflectionTestUtils.getField(itemReader, "executionContextUserSupport"),
|
||||
"name")).isEqualTo("fooReader");
|
||||
"name"))
|
||||
.isEqualTo("fooReader");
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "maxItemCount")).isEqualTo(15);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "currentItemCount")).isEqualTo(2);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "fetchSize")).isEqualTo(4);
|
||||
@@ -254,12 +256,12 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testNoName() {
|
||||
final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=noNameJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=noNameJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5");
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
runTest(applicationContextRunner);
|
||||
@@ -269,12 +271,12 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
public void testSqlName() {
|
||||
final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader");
|
||||
.withUserConfiguration(TaskLauncherConfiguration.class, BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcCursorItemReaderAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader");
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
runTest(applicationContextRunner);
|
||||
@@ -314,8 +316,10 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (defaultServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort))
|
||||
.start();
|
||||
defaultServer = server;
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME);
|
||||
|
||||
@@ -71,17 +71,17 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
final String topicName = "topic1";
|
||||
populateSingleTopic(topicName);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.poll-time-out-in-seconds=2",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.poll-time-out-in-seconds=2",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -113,18 +113,18 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
final String topicName = "topic2";
|
||||
populateSingleTopic(topicName);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.partitions=0,1",
|
||||
"spring.batch.job.kafkaitemreader.poll-time-out-in-seconds=2",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.partitions=0,1",
|
||||
"spring.batch.job.kafkaitemreader.poll-time-out-in-seconds=2",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -150,16 +150,16 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
final String topicName = "topic3";
|
||||
populateSingleTopic(topicName);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.consumer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.consumer.group-id=1", "spring.batch.job.kafkaitemreader.name=kafkaItemReader",
|
||||
"spring.batch.job.kafkaitemreader.topic=" + topicName,
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
Date startTime = new Date();
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -196,7 +196,8 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
private void populateSingleTopic(String topic) {
|
||||
Map<String, Object> configps = new HashMap<>(KafkaTestUtils.producerProps(embeddedKafkaBroker));
|
||||
Producer<String, Object> producer = new DefaultKafkaProducerFactory<>(configps, new StringSerializer(),
|
||||
new JsonSerializer<>()).createProducer();
|
||||
new JsonSerializer<>())
|
||||
.createProducer();
|
||||
Map<String, Object> testMap = new HashMap<>();
|
||||
testMap.put("first_name", "jane");
|
||||
producer.send(new ProducerRecord<>(topic, "my-aggregate-id", testMap));
|
||||
|
||||
@@ -68,15 +68,15 @@ public class KafkaItemWriterTests {
|
||||
public void testBaseKafkaItemWriter() {
|
||||
final String topicName = "topic1";
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.producer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.producer.keySerializer=org.springframework.kafka.support.serializer.JsonSerializer",
|
||||
"spring.batch.job.kafkaitemwriter.topic=" + topicName);
|
||||
.withUserConfiguration(CustomMappingConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
KafkaItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=job", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5",
|
||||
"spring.kafka.producer.bootstrap-servers=" + embeddedKafkaBroker.getBrokersAsString(),
|
||||
"spring.kafka.producer.keySerializer=org.springframework.kafka.support.serializer.JsonSerializer",
|
||||
"spring.batch.job.kafkaitemwriter.topic=" + topicName);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
waitForTopicPopulation(context);
|
||||
@@ -87,7 +87,8 @@ public class KafkaItemWriterTests {
|
||||
private void validateResults(String topicName) {
|
||||
Map<String, Object> configs = new HashMap<>(KafkaTestUtils.consumerProps("1", "false", embeddedKafkaBroker));
|
||||
Consumer<String, Object> consumer = new DefaultKafkaConsumerFactory<>(configs, new StringDeserializer(),
|
||||
new JsonDeserializer<>()).createConsumer();
|
||||
new JsonDeserializer<>())
|
||||
.createConsumer();
|
||||
consumer.subscribe(singleton(topicName));
|
||||
|
||||
ConsumerRecords<String, Object> consumerRecords = KafkaTestUtils.getRecords(consumer);
|
||||
|
||||
@@ -105,15 +105,15 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
void basicTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemReaderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.template.default-receive-queue=foo", "spring.rabbitmq.host=" + host,
|
||||
"spring.rabbitmq.port=" + amqpPort);
|
||||
.withUserConfiguration(BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemReaderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.template.default-receive-queue=foo", "spring.rabbitmq.host=" + host,
|
||||
"spring.rabbitmq.port=" + amqpPort);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobExecution jobExecution = runJob(context);
|
||||
@@ -131,15 +131,15 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
void basicTestWithItemType() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(ItemTypeConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemReaderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.template.default-receive-queue=foo", "spring.rabbitmq.host=" + host,
|
||||
"spring.rabbitmq.port=" + amqpPort);
|
||||
.withUserConfiguration(ItemTypeConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemReaderAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.template.default-receive-queue=foo", "spring.rabbitmq.host=" + host,
|
||||
"spring.rabbitmq.port=" + amqpPort);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobExecution jobExecution = runJob(context);
|
||||
@@ -156,13 +156,13 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
@Test
|
||||
void useAmqpTemplateTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(MockTemplateConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.host=" + host, "spring.rabbitmq.port=" + amqpPort);
|
||||
.withUserConfiguration(MockTemplateConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemReaderAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.amqpitemreader.enabled=true",
|
||||
"spring.rabbitmq.host=" + host, "spring.rabbitmq.port=" + amqpPort);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
runJob(context);
|
||||
|
||||
@@ -126,12 +126,12 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
void basicTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemWriterAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
.withUserConfiguration(BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemWriterAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobExecution jobExecution = runJob(context);
|
||||
@@ -151,11 +151,11 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
void useAmqpTemplateTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(MockConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
.withUserConfiguration(MockConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
runJob(context);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
|
||||
+ "have exactly 1 instance of the TaskBatchExecutionListener but has " + length);
|
||||
}
|
||||
((AbstractJob) bean)
|
||||
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,8 @@ public class TaskBatchExecutionListenerFactoryBean implements FactoryBean<TaskBa
|
||||
|
||||
if (AopUtils.isJdkDynamicProxy(this.taskExplorer)) {
|
||||
SimpleTaskExplorer dereferencedTaskRepository = (SimpleTaskExplorer) ((Advised) this.taskExplorer)
|
||||
.getTargetSource().getTarget();
|
||||
.getTargetSource()
|
||||
.getTarget();
|
||||
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField,
|
||||
dereferencedTaskRepository);
|
||||
|
||||
@@ -140,7 +140,8 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
|
||||
if (incrementer != null) {
|
||||
JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.taskJobExplorer)
|
||||
.getNextJobParameters(job).toJobParameters();
|
||||
.getNextJobParameters(job)
|
||||
.toJobParameters();
|
||||
parameters = merge(nextParameters, jobParameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
|
||||
for (StepExecution curStepExecution : executed) {
|
||||
if (!result.contains(curStepExecution)) {
|
||||
StepExecution partitionStepExecution = DeployerPartitionHandler.this.jobExplorer
|
||||
.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId());
|
||||
.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId());
|
||||
|
||||
BatchStatus batchStatus = partitionStepExecution.getStatus();
|
||||
if (batchStatus != null && isComplete(batchStatus)) {
|
||||
|
||||
@@ -88,9 +88,9 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
validateRequest();
|
||||
|
||||
Long jobExecutionId = Long
|
||||
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
|
||||
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID));
|
||||
Long stepExecutionId = Long
|
||||
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
|
||||
.parseLong(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID));
|
||||
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
|
||||
|
||||
if (stepExecution == null) {
|
||||
@@ -129,7 +129,7 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
|
||||
Assert.isTrue(
|
||||
this.stepLocator.getStepNames()
|
||||
.contains(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)),
|
||||
.contains(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)),
|
||||
"The step requested cannot be found in the provided BeanFactory");
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ public class TaskLauncherHandler implements Runnable {
|
||||
copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
|
||||
|
||||
Map<String, String> environmentVariables = this.environmentVariablesProvider
|
||||
.getEnvironmentVariables(copyContext);
|
||||
.getEnvironmentVariables(copyContext);
|
||||
|
||||
if (this.defaultArgsAsEnvironmentVars) {
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
|
||||
@@ -37,10 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class TaskJobLauncherAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
|
||||
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
|
||||
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
|
||||
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
|
||||
@@ -52,31 +51,37 @@ public class TaskJobLauncherAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.applicationRunnerOrder=100").run(context -> {
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(100);
|
||||
});
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.applicationRunnerOrder=100")
|
||||
.run(context -> {
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(100);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithBatchJobNames() {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.batch.job.name=job1", "spring.cloud.task.batch.jobName=foobar").run(context -> {
|
||||
validateJobNames(context, "job1");
|
||||
});
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true", "spring.batch.job.name=job1",
|
||||
"spring.cloud.task.batch.jobName=foobar")
|
||||
.run(context -> {
|
||||
validateJobNames(context, "job1");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskBatchJobNames() {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.jobNames=job1,job2").run(context -> {
|
||||
validateJobNames(context, "job1,job2");
|
||||
});
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.jobNames=job1,job2")
|
||||
.run(context -> {
|
||||
validateJobNames(context, "job1,job2");
|
||||
});
|
||||
}
|
||||
|
||||
private void validateJobNames(AssertableApplicationContext context, String jobNames) throws Exception {
|
||||
JobLauncherApplicationRunner jobLauncherApplicationRunner = context
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner, "jobName");
|
||||
assertThat(names).isEqualTo(jobNames);
|
||||
|
||||
@@ -63,9 +63,9 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
||||
TransactionAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class))
|
||||
.withUserConfiguration(BatchConfiguration.class);
|
||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, TransactionAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class))
|
||||
.withUserConfiguration(BatchConfiguration.class);
|
||||
|
||||
@Test
|
||||
void basicExecution() {
|
||||
@@ -95,8 +95,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.build();
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.build();
|
||||
// start a job instance
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
||||
runFailedJob(jobLauncherContext, job, jobParameters);
|
||||
@@ -114,9 +114,11 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
this.contextRunner.run((context) -> {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder().preventRestart()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.preventRestart()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer())
|
||||
.build();
|
||||
runFailedJob(jobLauncherContext, job, new JobParameters());
|
||||
runFailedJob(jobLauncherContext, job, new JobParameters());
|
||||
// A failed job that is not restartable does not re-use the job params of
|
||||
@@ -137,10 +139,12 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
PlatformTransactionManager transactionManager = context.getBean(PlatformTransactionManager.class);
|
||||
JobLauncherApplicationRunnerContext jobLauncherContext = new JobLauncherApplicationRunnerContext(context);
|
||||
Job job = jobLauncherContext.jobBuilder()
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
.start(jobLauncherContext.stepBuilder().tasklet(throwingTasklet(), transactionManager).build())
|
||||
.incrementer(new RunIdIncrementer())
|
||||
.build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
runFailedJob(jobLauncherContext, job, jobParameters);
|
||||
assertThat(jobLauncherContext.jobInstances()).hasSize(1);
|
||||
// try to re-run a failed execution with non identifying parameters
|
||||
|
||||
@@ -113,8 +113,8 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
public void testNoTaskJobLauncher() {
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
"--spring.cloud.task.batch.failOnJobFailurePollInterval=500", "--spring.batch.job.enabled=false" };
|
||||
this.applicationContext = SpringApplication.run(
|
||||
new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
|
||||
this.applicationContext = SpringApplication
|
||||
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
|
||||
JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
|
||||
assertThat(jobExplorer.getJobNames().size()).isEqualTo(0);
|
||||
}
|
||||
@@ -140,15 +140,15 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
public void testApplicationRunnerSetToFalse() {
|
||||
String[] enabledArgs = new String[] {};
|
||||
this.applicationContext = SpringApplication
|
||||
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
|
||||
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
|
||||
validateContext();
|
||||
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class)).isNotNull();
|
||||
|
||||
Executable executable = () -> this.applicationContext.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(executable::execute)
|
||||
.withMessage("No qualifying bean of type "
|
||||
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
|
||||
.withMessage("No qualifying bean of type "
|
||||
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
|
||||
validateContext();
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
@@ -169,10 +169,11 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
private void validateForFail(String errorMessage, Class<?> clazz, String[] enabledArgs) {
|
||||
Executable executable = () -> this.applicationContext = SpringApplication
|
||||
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
|
||||
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute).havingCause()
|
||||
.withMessage(errorMessage);
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute)
|
||||
.havingCause()
|
||||
.withMessage(errorMessage);
|
||||
}
|
||||
|
||||
@Component
|
||||
@@ -199,10 +200,11 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -252,19 +254,21 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
@Bean
|
||||
public Job jobFail() {
|
||||
return new JobBuilder("jobA", this.jobRepository)
|
||||
.start(new StepBuilder("step1", this.jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", this.jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job jobFun() {
|
||||
return new JobBuilder("jobSucceed", this.jobRepository)
|
||||
.start(new StepBuilder("step1Succeed", this.jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1Succeed", this.jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,16 +75,18 @@ public class PrefixTests {
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-h2.sql").setType(EmbeddedDatabaseType.H2)
|
||||
.build();
|
||||
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-h2.sql")
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -74,16 +74,18 @@ class PrimaryKeyTests {
|
||||
@Bean
|
||||
Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder().addScript("classpath:schema-with-primary-keys-h2.sql")
|
||||
.setType(EmbeddedDatabaseType.H2).build();
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -144,7 +144,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
@@ -156,9 +156,9 @@ public class TaskBatchExecutionListenerTests {
|
||||
this.applicationContext = SpringApplication.run(TaskNotEnabledConfiguration.class, ARGS);
|
||||
assertThat(applicationContext.getBean(Job.class)).isNotNull();
|
||||
assertThatThrownBy(() -> applicationContext.getBean(TaskBatchExecutionListenerBeanPostProcessor.class))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
assertThatThrownBy(() -> applicationContext.getBean(TaskBatchExecutionListener.class))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,7 +170,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
@@ -185,7 +185,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(0);
|
||||
}
|
||||
@@ -199,11 +199,11 @@ public class TaskBatchExecutionListenerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
|
||||
.isEqualTo(1);
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,7 +215,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
|
||||
@@ -260,7 +260,7 @@ public class TaskBatchExecutionListenerTests {
|
||||
SingleTaskConfiguration.class }, ARGS);
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = this.applicationContext
|
||||
.getBean(TaskBatchExecutionListenerBeanPostProcessor.class);
|
||||
.getBean(TaskBatchExecutionListenerBeanPostProcessor.class);
|
||||
|
||||
beanPostProcessor.setJobNames(jobNames);
|
||||
return beanPostProcessor;
|
||||
@@ -287,10 +287,11 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -308,10 +309,11 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -332,10 +334,11 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Override
|
||||
public Job getObject() {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -365,28 +368,29 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job(JobRepository jobRepository) {
|
||||
return new JobBuilder("job", jobRepository)
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
|
||||
throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}, new ResourcelessTransactionManager()).build()).build();
|
||||
.start(new StepBuilder("step1", jobRepository).tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
|
||||
throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}, new ResourcelessTransactionManager()).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource myDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("myDataSource");
|
||||
.setName("myDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource incorrectDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("incorrectDataSource");
|
||||
.setName("incorrectDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -410,19 +414,21 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job1(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job1", jobRepository)
|
||||
.start(new StepBuilder("job1step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job1");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("job1step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job1");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job job2(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
|
||||
return new JobBuilder("job2", jobRepository)
|
||||
.start(new StepBuilder("job2step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job2");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build()).build();
|
||||
.start(new StepBuilder("job2step1", jobRepository).tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job2");
|
||||
return RepeatStatus.FINISHED;
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -181,13 +181,13 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -236,18 +236,21 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments().isEmpty()).isTrue();
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
|
||||
assertThat(request.getDefinition()
|
||||
.getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
|
||||
assertThat(request.getDefinition()
|
||||
.getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.isEqualTo("step1");
|
||||
.isEqualTo("step1");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME))
|
||||
.isEqualTo("partitionedJobTask_partitionedJob_step1:partition1");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
|
||||
.isEqualTo("partitionedJobTask_partitionedJob_step1:partition1");
|
||||
assertThat(request.getDefinition()
|
||||
.getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
|
||||
.isEqualTo("2");
|
||||
.isEqualTo("2");
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -290,7 +293,7 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -526,11 +529,11 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -592,11 +595,11 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -787,11 +790,11 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -878,14 +881,14 @@ public class DeployerPartitionHandlerTests {
|
||||
AppDefinition appDefinition = request.getDefinition();
|
||||
assertThat(appDefinition.getName()).isEqualTo("partitionedJobTask");
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(
|
||||
formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))))
|
||||
.isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i))))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,19 +140,19 @@ public class DeployerStepExecutionHandlerTests {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
.thenReturn("2");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
|
||||
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
|
||||
this.handler.run();
|
||||
@@ -166,19 +166,19 @@ public class DeployerStepExecutionHandlerTests {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
.thenReturn("2");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
|
||||
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new JobInterruptedException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
@@ -194,19 +194,19 @@ public class DeployerStepExecutionHandlerTests {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)).thenReturn(true);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "workerStep", "foo", "bar" });
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
.thenReturn("2");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
|
||||
when(this.jobExplorer.getStepExecution(1L, 2L)).thenReturn(workerStep);
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
|
||||
@@ -175,7 +175,8 @@ public class SimpleTaskAutoConfiguration {
|
||||
// retrieve the count of dataSources (without instantiating them) excluding
|
||||
// DataSource proxy beans
|
||||
long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
|
||||
.filter((name -> !ScopedProxyUtils.isScopedTarget(name))).count();
|
||||
.filter((name -> !ScopedProxyUtils.isScopedTarget(name)))
|
||||
.count();
|
||||
|
||||
if (configurers == 0 && dataSources > 1) {
|
||||
throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than"
|
||||
|
||||
@@ -46,22 +46,22 @@ public class TaskRuntimeHints implements RuntimeHintsRegistrar {
|
||||
hints.resources().registerPattern("org/springframework/cloud/task/schema-hsqldb.sql");
|
||||
hints.resources().registerPattern("org/springframework/cloud/task/schema-sqlserver.sql");
|
||||
|
||||
hints.reflection().registerType(
|
||||
TypeReference.of("org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection().registerType(TypeReference.of("org.springframework.cloud.task.repository.TaskExecution"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer"),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("org.springframework.cloud.task.repository.TaskExecution"), hint -> hint
|
||||
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS));
|
||||
|
||||
if (!ClassUtils.isPresent("com.zaxxer.hikari.HikariDataSource", classLoader)) {
|
||||
return;
|
||||
}
|
||||
hints.reflection().registerType(Statement[].class, hint -> {
|
||||
});
|
||||
hints.reflection().registerType(TypeReference.of("com.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry[]"),
|
||||
hint -> {
|
||||
});
|
||||
hints.reflection()
|
||||
.registerType(TypeReference.of("com.zaxxer.hikari.util.ConcurrentBag$IConcurrentBagEntry[]"), hint -> {
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ class ObservationApplicationRunner implements ApplicationRunner {
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
TaskObservationContext context = new TaskObservationContext(this.beanName);
|
||||
Observation observation = TaskDocumentedObservation.TASK_RUNNER_OBSERVATION
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
|
||||
try (Observation.Scope scope = observation.start().openScope()) {
|
||||
this.delegate.run(args);
|
||||
|
||||
@@ -51,8 +51,8 @@ class ObservationCommandLineRunner implements CommandLineRunner {
|
||||
public void run(String... args) throws Exception {
|
||||
TaskObservationContext context = new TaskObservationContext(this.beanName);
|
||||
Observation observation = TaskDocumentedObservation.TASK_RUNNER_OBSERVATION
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
try (Observation.Scope scope = observation.start().openScope()) {
|
||||
this.delegate.run(args);
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class TaskLifecycleListener
|
||||
TaskExecutionException taskExecutionException = (TaskExecutionException) exception;
|
||||
if (taskExecutionException.getCause() instanceof InvocationTargetException) {
|
||||
InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException
|
||||
.getCause();
|
||||
.getCause();
|
||||
if (invocationTargetException != null && invocationTargetException.getTargetException() != null) {
|
||||
exception = invocationTargetException.getTargetException();
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class TaskLifecycleListener
|
||||
}
|
||||
if (this.taskProperties.getExecutionid() != null) {
|
||||
TaskExecution taskExecution = this.taskExplorer
|
||||
.getTaskExecution(this.taskProperties.getExecutionid());
|
||||
.getTaskExecution(this.taskProperties.getExecutionid());
|
||||
Assert.notNull(taskExecution, String.format("Invalid TaskExecution, ID %s not found",
|
||||
this.taskProperties.getExecutionid()));
|
||||
Assert.isNull(taskExecution.getEndTime(),
|
||||
|
||||
@@ -134,19 +134,19 @@ public class TaskListenerExecutorObjectFactory implements ObjectFactory<TaskExec
|
||||
if (!beforeTaskMethods.isEmpty()) {
|
||||
for (Method beforeTaskMethod : beforeTaskMethods.keySet()) {
|
||||
this.beforeTaskInstances.computeIfAbsent(beforeTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
if (!afterTaskMethods.isEmpty()) {
|
||||
for (Method afterTaskMethod : afterTaskMethods.keySet()) {
|
||||
this.afterTaskInstances.computeIfAbsent(afterTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
if (!failedTaskMethods.isEmpty()) {
|
||||
for (Method failedTaskMethod : failedTaskMethods.keySet()) {
|
||||
this.failedTaskInstances.computeIfAbsent(failedTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,18 +73,18 @@ public class TaskObservations {
|
||||
this.taskObservationContext = new TaskExecutionObservationContext(taskExecution);
|
||||
|
||||
Observation observation = TaskExecutionObservation.TASK_ACTIVE
|
||||
.observation(this.customObservationConvention, new DefaultTaskExecutionObservationConvention(),
|
||||
this.taskObservationContext, this.observationRegistry)
|
||||
.contextualName(String.valueOf(taskExecution.getExecutionId()))
|
||||
.observationConvention(this.observationsProvider)
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(),
|
||||
getValueOrDefault(taskExecution.getTaskName()))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(),
|
||||
"" + taskExecution.getExecutionId())
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(),
|
||||
(getValueOrDefault(taskExecution.getParentExecutionId())))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.asString(),
|
||||
(getValueOrDefault(taskExecution.getExternalExecutionId())));
|
||||
.observation(this.customObservationConvention, new DefaultTaskExecutionObservationConvention(),
|
||||
this.taskObservationContext, this.observationRegistry)
|
||||
.contextualName(String.valueOf(taskExecution.getExecutionId()))
|
||||
.observationConvention(this.observationsProvider)
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(),
|
||||
getValueOrDefault(taskExecution.getTaskName()))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(),
|
||||
"" + taskExecution.getExecutionId())
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(),
|
||||
(getValueOrDefault(taskExecution.getParentExecutionId())))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.asString(),
|
||||
(getValueOrDefault(taskExecution.getExternalExecutionId())));
|
||||
|
||||
if (taskObservationCloudKeyValues != null) {
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.asString(),
|
||||
|
||||
@@ -222,12 +222,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
arguments, null, externalExecutionId);
|
||||
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", nextExecutionId, Types.BIGINT).addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
|
||||
.addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
|
||||
.addValue("taskExecutionId", nextExecutionId, Types.BIGINT)
|
||||
.addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
|
||||
.addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
|
||||
|
||||
this.jdbcTemplate.update(getQuery(SAVE_TASK_EXECUTION), queryParameters);
|
||||
insertTaskArguments(nextExecutionId, arguments);
|
||||
@@ -247,11 +248,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
null, externalExecutionId, parentExecutionId);
|
||||
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
|
||||
.addValue("exitCode", null, Types.INTEGER).addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
|
||||
.addValue("taskExecutionId", executionId, Types.BIGINT);
|
||||
.addValue("startTime", startTime == null ? null : Timestamp.valueOf(startTime), Types.TIMESTAMP)
|
||||
.addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
|
||||
.addValue("taskExecutionId", executionId, Types.BIGINT);
|
||||
|
||||
String updateString = START_TASK_EXECUTION_PREFIX;
|
||||
|
||||
@@ -282,11 +284,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
final MapSqlParameterSource parameters = new MapSqlParameterSource()
|
||||
.addValue("endTime", endTime == null ? null : Timestamp.valueOf(endTime), Types.TIMESTAMP)
|
||||
.addValue("exitCode", exitCode, Types.INTEGER).addValue("exitMessage", exitMessage, Types.VARCHAR)
|
||||
.addValue("errorMessage", errorMessage, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
.addValue("endTime", endTime == null ? null : Timestamp.valueOf(endTime), Types.TIMESTAMP)
|
||||
.addValue("exitCode", exitCode, Types.INTEGER)
|
||||
.addValue("exitMessage", exitMessage, Types.VARCHAR)
|
||||
.addValue("errorMessage", errorMessage, Types.VARCHAR)
|
||||
.addValue("lastUpdated", Timestamp.valueOf(LocalDateTime.now()), Types.TIMESTAMP)
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
|
||||
this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION), parameters);
|
||||
}
|
||||
@@ -503,8 +506,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
|
||||
if (this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID), queryParameters) != 1) {
|
||||
throw new IllegalStateException("Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
@@ -580,8 +583,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
*/
|
||||
private void insertArgument(long taskExecutionId, String taskParam) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT)
|
||||
.addValue("taskParam", taskParam, Types.VARCHAR);
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT)
|
||||
.addValue("taskParam", taskParam, Types.VARCHAR);
|
||||
this.jdbcTemplate.update(getQuery(CREATE_TASK_ARGUMENT), queryParameters);
|
||||
}
|
||||
|
||||
|
||||
@@ -308,12 +308,12 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
final TaskExecution tempTaskExecution = tempTaskExecutions
|
||||
.get(taskExecutionMapEntry.getValue().getTaskName());
|
||||
.get(taskExecutionMapEntry.getValue().getTaskName());
|
||||
if (tempTaskExecution == null
|
||||
|| tempTaskExecution.getStartTime().isBefore(taskExecutionMapEntry.getValue().getStartTime())
|
||||
|| (tempTaskExecution.getStartTime().equals(taskExecutionMapEntry.getValue().getStartTime())
|
||||
&& tempTaskExecution.getExecutionId() < taskExecutionMapEntry.getValue()
|
||||
.getExecutionId())) {
|
||||
.getExecutionId())) {
|
||||
tempTaskExecutions.put(taskExecutionMapEntry.getValue().getTaskName(),
|
||||
taskExecutionMapEntry.getValue());
|
||||
}
|
||||
|
||||
@@ -38,8 +38,12 @@ public class Db2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause, boolean remainingPageQuery,
|
||||
String rowNumClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(selectClause).append(" FROM (SELECT ").append(selectClause).append(", ")
|
||||
.append("ROW_NUMBER() OVER() as TMP_ROW_NUM");
|
||||
sql.append("SELECT ")
|
||||
.append(selectClause)
|
||||
.append(" FROM (SELECT ")
|
||||
.append(selectClause)
|
||||
.append(", ")
|
||||
.append("ROW_NUMBER() OVER() as TMP_ROW_NUM");
|
||||
sql.append(" FROM (SELECT ").append(selectClause).append(" FROM ").append(this.getFromClause());
|
||||
SqlPagingQueryUtils.buildWhereClause(this, remainingPageQuery, sql);
|
||||
sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
|
||||
|
||||
@@ -29,8 +29,12 @@ public class H2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String limitClause = new StringBuilder().append("OFFSET ").append(pageable.getOffset())
|
||||
.append(" ROWS FETCH NEXT ").append(pageable.getPageSize()).append(" ROWS ONLY").toString();
|
||||
String limitClause = new StringBuilder().append("OFFSET ")
|
||||
.append(pageable.getOffset())
|
||||
.append(" ROWS FETCH NEXT ")
|
||||
.append(pageable.getPageSize())
|
||||
.append(" ROWS ONLY")
|
||||
.toString();
|
||||
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,11 @@ public class HsqlPagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String topClause = new StringBuilder().append("LIMIT ").append(pageable.getOffset()).append(" ")
|
||||
.append(pageable.getPageSize()).toString();
|
||||
String topClause = new StringBuilder().append("LIMIT ")
|
||||
.append(pageable.getOffset())
|
||||
.append(" ")
|
||||
.append(pageable.getPageSize())
|
||||
.toString();
|
||||
return SqlPagingQueryUtils.generateTopJumpToQuery(this, topClause);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,11 @@ public class MariaDbPagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String topClause = new StringBuilder().append("LIMIT ").append(pageable.getOffset()).append(", ")
|
||||
.append(pageable.getPageSize()).toString();
|
||||
String topClause = new StringBuilder().append("LIMIT ")
|
||||
.append(pageable.getOffset())
|
||||
.append(", ")
|
||||
.append(pageable.getPageSize())
|
||||
.toString();
|
||||
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, topClause);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,11 @@ public class MySqlPagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String topClause = new StringBuilder().append("LIMIT ").append(pageable.getOffset()).append(", ")
|
||||
.append(pageable.getPageSize()).toString();
|
||||
String topClause = new StringBuilder().append("LIMIT ")
|
||||
.append(pageable.getOffset())
|
||||
.append(", ")
|
||||
.append(pageable.getPageSize())
|
||||
.toString();
|
||||
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, topClause);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,12 @@ public class OraclePagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause, boolean remainingPageQuery,
|
||||
String rowNumClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(selectClause).append(" FROM (SELECT ").append(selectClause).append(", ")
|
||||
.append("ROWNUM as TMP_ROW_NUM");
|
||||
sql.append("SELECT ")
|
||||
.append(selectClause)
|
||||
.append(" FROM (SELECT ")
|
||||
.append(selectClause)
|
||||
.append(", ")
|
||||
.append("ROWNUM as TMP_ROW_NUM");
|
||||
sql.append(" FROM (SELECT ").append(selectClause).append(" FROM ").append(this.getFromClause());
|
||||
SqlPagingQueryUtils.buildWhereClause(this, remainingPageQuery, sql);
|
||||
sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
|
||||
|
||||
@@ -29,8 +29,11 @@ public class PostgresPagingQueryProvider extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String limitClause = new StringBuilder().append("LIMIT ").append(pageable.getPageSize()).append(" OFFSET ")
|
||||
.append(pageable.getOffset()).toString();
|
||||
String limitClause = new StringBuilder().append("LIMIT ")
|
||||
.append(pageable.getPageSize())
|
||||
.append(" OFFSET ")
|
||||
.append(pageable.getOffset())
|
||||
.toString();
|
||||
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,16 @@ public class SqlServerPagingQueryProvider extends AbstractSqlPagingQueryProvider
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause, boolean remainingPageQuery,
|
||||
String rowNumClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(selectClause).append(" FROM (SELECT ").append(selectClause).append(", ")
|
||||
.append("ROW_NUMBER() OVER (ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this))
|
||||
.append(") AS TMP_ROW_NUM ").append(" FROM ").append(getFromClause());
|
||||
sql.append("SELECT ")
|
||||
.append(selectClause)
|
||||
.append(" FROM (SELECT ")
|
||||
.append(selectClause)
|
||||
.append(", ")
|
||||
.append("ROW_NUMBER() OVER (ORDER BY ")
|
||||
.append(SqlPagingQueryUtils.buildSortClause(this))
|
||||
.append(") AS TMP_ROW_NUM ")
|
||||
.append(" FROM ")
|
||||
.append(getFromClause());
|
||||
SqlPagingQueryUtils.buildWhereClause(this, remainingPageQuery, sql);
|
||||
sql.append(") TASK_EXECUTION_PAGE ");
|
||||
sql.append(" WHERE ").append(rowNumClause);
|
||||
|
||||
@@ -125,14 +125,14 @@ public enum DatabaseType {
|
||||
if (StringUtils.hasText(databaseProductName) && !databaseProductName.equals("DB2/Linux")
|
||||
&& databaseProductName.startsWith("DB2")) {
|
||||
String databaseProductVersion = JdbcUtils
|
||||
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
|
||||
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
|
||||
|
||||
@Override
|
||||
public Object processMetaData(DatabaseMetaData dbmd)
|
||||
throws SQLException, MetaDataAccessException {
|
||||
return dbmd.getDatabaseProductVersion();
|
||||
}
|
||||
}).toString();
|
||||
@Override
|
||||
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
|
||||
return dbmd.getDatabaseProductVersion();
|
||||
}
|
||||
})
|
||||
.toString();
|
||||
|
||||
if (databaseProductVersion.startsWith("ARI")) {
|
||||
databaseProductName = "DB2VSE";
|
||||
@@ -140,9 +140,9 @@ public enum DatabaseType {
|
||||
else if (databaseProductVersion.startsWith("DSN")) {
|
||||
databaseProductName = "DB2ZOS";
|
||||
}
|
||||
else if (databaseProductName.indexOf("AS") != -1
|
||||
&& (databaseProductVersion.startsWith("QSQ") || databaseProductVersion
|
||||
.substring(databaseProductVersion.indexOf('V')).matches("V\\dR\\d[mM]\\d"))) {
|
||||
else if (databaseProductName.indexOf("AS") != -1 && (databaseProductVersion.startsWith("QSQ")
|
||||
|| databaseProductVersion.substring(databaseProductVersion.indexOf('V'))
|
||||
.matches("V\\dR\\d[mM]\\d"))) {
|
||||
databaseProductName = "DB2AS400";
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean<TaskExecutionDao
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
((JdbcTaskExecutionDao) this.dao)
|
||||
.setTaskIncrementer(incrementerFactory.getIncrementer(databaseType, this.tablePrefix + "SEQ"));
|
||||
.setTaskIncrementer(incrementerFactory.getIncrementer(databaseType, this.tablePrefix + "SEQ"));
|
||||
}
|
||||
|
||||
private boolean isSqlServerTableSequenceAvailable(String incrementerName) {
|
||||
|
||||
@@ -40,9 +40,9 @@ public class SimpleSingleTaskAutoConfigurationTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class, EmbeddedDataSourceConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRepository() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
TaskRepository taskRepository = context.getBean(TaskRepository.class);
|
||||
@@ -77,9 +77,9 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
context.getBean(TaskRepository.class);
|
||||
@@ -93,10 +93,11 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1L);
|
||||
@@ -105,17 +106,18 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRepositoryBeansDependOnTaskRepositoryInitializer() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
|
||||
String[] taskRepositoryNames = beanFactory.getBeanNamesForType(TaskRepository.class);
|
||||
assertThat(taskRepositoryNames).isNotEmpty();
|
||||
for (String taskRepositoryName : taskRepositoryNames) {
|
||||
assertThat(beanFactory.getBeanDefinition(taskRepositoryName).getDependsOn())
|
||||
.contains("taskRepositoryInitializer");
|
||||
.contains("taskRepositoryInitializer");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -123,11 +125,11 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, applicationContextRunner);
|
||||
}
|
||||
@@ -135,11 +137,11 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testTaskNameResolver() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.name=myTestName");
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.name=myTestName");
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskNameResolver taskNameResolver = context.getBean(TaskNameResolver.class);
|
||||
assertThat(taskNameResolver.getTaskName()).isEqualTo("myTestName");
|
||||
@@ -149,9 +151,9 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testMultipleConfigurers() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleConfigurers.class);
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleConfigurers.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
@@ -161,9 +163,9 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testMultipleDataSources() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleDataSources.class);
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(MultipleDataSources.class);
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
@@ -205,10 +207,11 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(DataSourceProxyConfiguration.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(DataSourceProxyConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
assertThat(context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
|
||||
SimpleTaskAutoConfiguration taskConfiguration = context.getBean(SimpleTaskAutoConfiguration.class);
|
||||
|
||||
@@ -77,11 +77,11 @@ public class TaskCoreTests {
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,11 +95,11 @@ public class TaskCoreTests {
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,11 +117,11 @@ public class TaskCoreTests {
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(EXCEPTION_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(output.contains(ERROR_MESSAGE)).as("Test results have incorrect exit message: " + output).isTrue();
|
||||
assertThat(output.contains(EXCEPTION_MESSAGE)).as("Test results have exception message: " + output).isTrue();
|
||||
}
|
||||
@@ -141,7 +141,8 @@ public class TaskCoreTests {
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(EXCEPTION_INVALID_TASK_EXECUTION_ID))
|
||||
.as("Test results do not show the correct exception message: " + output).isTrue();
|
||||
.as("Test results do not show the correct exception message: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
|
||||
@@ -52,10 +52,10 @@ public class DefaultTaskConfigurerTests {
|
||||
public void resourcelessTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer();
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer("foo");
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
.isEqualTo("org.springframework.batch.support.transaction.ResourcelessTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,20 +66,20 @@ public class DefaultTaskConfigurerTests {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource,
|
||||
TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataSourceTransactionManagerTest() {
|
||||
DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource, "FOO", null);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
defaultTaskConfigurer = new DefaultTaskConfigurer(this.dataSource, "FOO", this.context);
|
||||
assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
.isEqualTo("org.springframework.jdbc.support.JdbcTransactionManager");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,9 +51,9 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
@Test
|
||||
public void testZeroCustomTransactionManagerConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, ZeroTransactionManagerConfiguration.class))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, ZeroTransactionManagerConfiguration.class))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
@@ -76,9 +76,9 @@ public class RepositoryTransactionManagerConfigurationTests {
|
||||
|
||||
private void testConfiguration(Class configurationClass) {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, configurationClass))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, configurationClass))
|
||||
.withPropertyValues("application.name=transactionManagerTask");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
|
||||
@@ -63,15 +63,17 @@ class ObservationIntegrationTests {
|
||||
void testSuccessfulObservation() {
|
||||
List<FinishedSpan> finishedSpans = finishedSpans();
|
||||
|
||||
SpansAssert.then(finishedSpans).thenASpanWithNameEqualTo("my-command-line-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myCommandLineRunner").backToSpans()
|
||||
.thenASpanWithNameEqualTo("my-application-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myApplicationRunner");
|
||||
SpansAssert.then(finishedSpans)
|
||||
.thenASpanWithNameEqualTo("my-command-line-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myCommandLineRunner")
|
||||
.backToSpans()
|
||||
.thenASpanWithNameEqualTo("my-application-runner")
|
||||
.hasTag("spring.cloud.task.runner.bean-name", "myApplicationRunner");
|
||||
MeterRegistryAssert.then(this.meterRegistry)
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myCommandLineRunner"))
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myApplicationRunner"));
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myCommandLineRunner"))
|
||||
.hasTimerWithNameAndTags("spring.cloud.task.runner",
|
||||
KeyValues.of("spring.cloud.task.runner.bean-name", "myApplicationRunner"));
|
||||
}
|
||||
|
||||
private List<FinishedSpan> finishedSpans() {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class TaskExecutionListenerTests {
|
||||
public void testTaskCreate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", LocalDateTime.now(), LocalDateTime.now(),
|
||||
null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution, taskExecutionListener);
|
||||
@@ -131,15 +131,16 @@ public class TaskExecutionListenerTests {
|
||||
public void testAfterTaskErrorCreate() {
|
||||
setupContextForAfterTaskErrorAnnotatedListener();
|
||||
AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener taskExecutionListener = this.context
|
||||
.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
.getBean(AfterTaskErrorAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
assertThat(taskExecutionListener.isTaskStartup()).isTrue();
|
||||
assertThat(taskExecutionListener.isTaskEnd()).isTrue();
|
||||
assertThat(taskExecutionListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(taskExecutionListener.getTaskExecution().getErrorMessage()
|
||||
.contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure")).isTrue();
|
||||
assertThat(taskExecutionListener.getTaskExecution()
|
||||
.getErrorMessage()
|
||||
.contains("Failed to process @BeforeTask or @AfterTask annotation because: AfterTaskFailure")).isTrue();
|
||||
assertThat(taskExecutionListener.getThrowable()).isNull();
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ public class TaskExecutionListenerTests {
|
||||
public void testTaskUpdate() {
|
||||
setupContextForTaskExecutionListener();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
@@ -170,10 +171,10 @@ public class TaskExecutionListenerTests {
|
||||
setupContextForTaskExecutionListener();
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultTaskListenerConfiguration.TestTaskExecutionListener taskExecutionListener = this.context
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
.getBean(DefaultTaskListenerConfiguration.TestTaskExecutionListener.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context
|
||||
.publishEvent(new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
|
||||
new ArrayList<>(), null, null);
|
||||
@@ -188,7 +189,7 @@ public class TaskExecutionListenerTests {
|
||||
public void testAnnotationCreate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
TaskExecution taskExecution = new TaskExecution(0, null, "wombat", LocalDateTime.now(), LocalDateTime.now(),
|
||||
null, new ArrayList<>(), null, null);
|
||||
verifyListenerResults(false, false, taskExecution, annotatedListener);
|
||||
@@ -202,7 +203,7 @@ public class TaskExecutionListenerTests {
|
||||
public void testAnnotationUpdate() {
|
||||
setupContextForAnnotatedListener();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), new String[0], this.context,
|
||||
Duration.ofSeconds(50)));
|
||||
|
||||
@@ -221,10 +222,10 @@ public class TaskExecutionListenerTests {
|
||||
setupContextForAnnotatedListener();
|
||||
SpringApplication application = new SpringApplication();
|
||||
DefaultAnnotationConfiguration.AnnotatedTaskListener annotatedListener = this.context
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
.getBean(DefaultAnnotationConfiguration.AnnotatedTaskListener.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context
|
||||
.publishEvent(new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(0, 1, "wombat", LocalDateTime.now(), LocalDateTime.now(), null,
|
||||
new ArrayList<>(), null, null);
|
||||
@@ -240,8 +241,9 @@ public class TaskExecutionListenerTests {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
assertThat(actualListener.getThrowable()).isNotNull();
|
||||
assertThat(actualListener.getThrowable() instanceof RuntimeException).isTrue();
|
||||
assertThat(actualListener.getTaskExecution().getErrorMessage()
|
||||
.startsWith("java.lang.RuntimeException: This was expected")).isTrue();
|
||||
assertThat(actualListener.getTaskExecution()
|
||||
.getErrorMessage()
|
||||
.startsWith("java.lang.RuntimeException: This was expected")).isTrue();
|
||||
}
|
||||
else if (isTaskEnd) {
|
||||
assertThat(actualListener.getTaskExecution().getExitMessage()).isEqualTo(TestListener.END_MESSAGE);
|
||||
@@ -257,7 +259,7 @@ public class TaskExecutionListenerTests {
|
||||
assertThat(actualListener.getTaskExecution().getExecutionId()).isEqualTo(taskExecution.getExecutionId());
|
||||
assertThat(actualListener.getTaskExecution().getExitCode()).isEqualTo(taskExecution.getExitCode());
|
||||
assertThat(actualListener.getTaskExecution().getExternalExecutionId())
|
||||
.isEqualTo(taskExecution.getExternalExecutionId());
|
||||
.isEqualTo(taskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
private void setupContextForTaskExecutionListener() {
|
||||
|
||||
@@ -130,8 +130,8 @@ public class TaskLifecycleListenerTests {
|
||||
SpringApplication application = new SpringApplication();
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context
|
||||
.publishEvent(new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
verifyTaskExecution(0, true, 1, exception, null);
|
||||
}
|
||||
@@ -148,8 +148,8 @@ public class TaskLifecycleListenerTests {
|
||||
this.taskExplorer = this.context.getBean(TaskExplorer.class);
|
||||
this.context.publishEvent(new ExitCodeEvent(this.context, exitCode));
|
||||
this.context.publishEvent(new ApplicationFailedEvent(application, new String[0], this.context, exception));
|
||||
this.context.publishEvent(
|
||||
new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
this.context
|
||||
.publishEvent(new ApplicationReadyEvent(application, new String[0], this.context, Duration.ofSeconds(50)));
|
||||
|
||||
verifyTaskExecution(0, true, exitCode, exception, null);
|
||||
assertThat(TestListener.getStartupOrderList().size()).isEqualTo(2);
|
||||
@@ -197,7 +197,8 @@ public class TaskLifecycleListenerTests {
|
||||
taskLifecycleListener.start();
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains("Multiple start events have been received"))
|
||||
.as("Test results do not show error message: " + output).isTrue();
|
||||
.as("Test results do not show error message: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -266,7 +267,8 @@ public class TaskLifecycleListenerTests {
|
||||
|
||||
if (update) {
|
||||
assertThat(taskExecution.getEndTime().isAfter(taskExecution.getStartTime())
|
||||
|| taskExecution.getEndTime().isEqual(taskExecution.getStartTime())).isTrue();
|
||||
|| taskExecution.getEndTime().isEqual(taskExecution.getStartTime()))
|
||||
.isTrue();
|
||||
assertThat(taskExecution.getExitCode()).isNotNull();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskStartupListener() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -96,7 +96,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskFailedListener() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -110,7 +110,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskEndListener() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -123,7 +123,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyAllListener() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -142,7 +142,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskStartupListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -155,7 +155,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskFailedListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -169,7 +169,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyTaskEndListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
@@ -182,7 +182,7 @@ public class TaskListenerExecutorObjectFactoryTests {
|
||||
@Test
|
||||
public void verifyAllListenerWithMultipleInstances() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
.withUserConfiguration(TaskExecutionListenerMultipleInstanceConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
setup(context);
|
||||
|
||||
@@ -90,7 +90,8 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
TaskExecutionObservation.TASK_ACTIVE.getDefaultConvention();
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags("spring.cloud.task", Tags
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags("spring.cloud.task", Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(), TaskObservations.STATUS_SUCCESS));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
@@ -111,23 +112,29 @@ public class TaskObservationsTests {
|
||||
taskObservations.onTaskEnd(taskExecution);
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "0"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "0"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(), TaskObservations.STATUS_SUCCESS));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX, Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(),
|
||||
TaskObservations.STATUS_SUCCESS));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "unknown", "123");
|
||||
|
||||
@@ -148,20 +155,25 @@ public class TaskObservationsTests {
|
||||
taskExecution.setExitCode(1);
|
||||
taskObservations.onTaskEnd(taskExecution);
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), "-1"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), "-1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "1"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(), TaskObservations.STATUS_FAILURE));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX, Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(),
|
||||
TaskObservations.STATUS_FAILURE));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
}
|
||||
@@ -194,30 +206,38 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.asString(), ORGANIZATION_NAME));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.asString(), ORGANIZATION_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.asString(), SPACE_ID));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.asString(), SPACE_ID));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.asString(), SPACE_NAME));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.asString(), SPACE_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.asString(), APPLICATION_NAME));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.asString(), APPLICATION_NAME));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.asString(), APPLICATION_ID));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.asString(), APPLICATION_ID));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.asString(), APPLICATION_VERSION));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.asString(), APPLICATION_VERSION));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.asString(), INSTANCE_INDEX));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.asString(), INSTANCE_INDEX));
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
}
|
||||
@@ -225,13 +245,13 @@ public class TaskObservationsTests {
|
||||
@Test
|
||||
public void testCloudVariablesUninitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CloudConfigurationForDefaultValues.class));
|
||||
.withConfiguration(AutoConfigurations.of(CloudConfigurationForDefaultValues.class));
|
||||
applicationContextRunner.run((context) -> {
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues = context
|
||||
.getBean(TaskObservationCloudKeyValues.class);
|
||||
.getBean(TaskObservationCloudKeyValues.class);
|
||||
|
||||
assertThat(taskObservationCloudKeyValues).as("taskObservationCloudKeyValues should not be null")
|
||||
.isNotNull();
|
||||
.isNotNull();
|
||||
|
||||
this.taskObservations = new TaskObservations(this.observationRegistry, taskObservationCloudKeyValues, null);
|
||||
|
||||
@@ -244,30 +264,38 @@ public class TaskObservationsTests {
|
||||
|
||||
verifyDefaultKeyValues();
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.asString(), "default"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.asString(), "default"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.asString(), UNKNOWN));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.asString(), UNKNOWN));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.asString(), "0"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.asString(), "0"));
|
||||
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
|
||||
verifyLongTaskTimerAfterStop(longTaskTimer, "myTask72", "123");
|
||||
});
|
||||
@@ -285,42 +313,48 @@ public class TaskObservationsTests {
|
||||
private LongTaskTimer initializeBasicTest(String taskName, String executionId) {
|
||||
// Test Long Task Timer while the task is running.
|
||||
LongTaskTimer longTaskTimer = simpleMeterRegistry
|
||||
.find(TaskExecutionObservation.TASK_ACTIVE.getPrefix() + ".active").longTaskTimer();
|
||||
.find(TaskExecutionObservation.TASK_ACTIVE.getPrefix() + ".active")
|
||||
.longTaskTimer();
|
||||
System.out.println(simpleMeterRegistry.getMetersAsString());
|
||||
assertThat(longTaskTimer).withFailMessage("LongTask timer should be created on Task start").isNotNull();
|
||||
assertThat(longTaskTimer.activeTasks()).isEqualTo(1);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString()))
|
||||
.isEqualTo(taskName);
|
||||
.isEqualTo(taskName);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString()))
|
||||
.isEqualTo(executionId);
|
||||
.isEqualTo(executionId);
|
||||
return longTaskTimer;
|
||||
}
|
||||
|
||||
private void verifyDefaultKeyValues() {
|
||||
// Test Timer
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString(), "myTask72"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString(), "123"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), "-1"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.asString(), "-1"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "0"));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX,
|
||||
Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.asString(), "0"));
|
||||
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry).hasTimerWithNameAndTags(PREFIX, Tags
|
||||
.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(), TaskObservations.STATUS_SUCCESS));
|
||||
MeterRegistryAssert.assertThat(this.simpleMeterRegistry)
|
||||
.hasTimerWithNameAndTags(PREFIX, Tags.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.asString(),
|
||||
TaskObservations.STATUS_SUCCESS));
|
||||
}
|
||||
|
||||
private void verifyLongTaskTimerAfterStop(LongTaskTimer longTaskTimer, String taskName, String executionId) {
|
||||
// Test Long Task Timer after the task has completed.
|
||||
assertThat(longTaskTimer.activeTasks()).isEqualTo(0);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_NAME.asString()))
|
||||
.isEqualTo(taskName);
|
||||
.isEqualTo(taskName);
|
||||
assertThat(longTaskTimer.getId().getTag(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.asString()))
|
||||
.isEqualTo(executionId);
|
||||
.isEqualTo(executionId);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -42,8 +42,8 @@ class H2TaskRepositoryIntegrationTests {
|
||||
void testTaskRepository(ModeEnum mode) {
|
||||
String connectionUrl = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;MODE=%s", UUID.randomUUID(), mode);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TestConfiguration.class).withBean(DataSource.class,
|
||||
() -> new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""));
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.withBean(DataSource.class, () -> new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""));
|
||||
|
||||
applicationContextRunner.run((context -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MariaDbTaskRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void testTaskExplorer() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(MariaDbTaskRepositoryIntegrationTests.TestConfiguration.class);
|
||||
.withUserConfiguration(MariaDbTaskRepositoryIntegrationTests.TestConfiguration.class);
|
||||
|
||||
applicationContextRunner.run((context -> {
|
||||
TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
|
||||
@@ -80,7 +80,7 @@ public class MariaDbTaskRepositoryIntegrationTests {
|
||||
if (firstTime) {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
databasePopulator
|
||||
.addScript(new ClassPathResource("/org/springframework/cloud/task/schema-mariadb.sql"));
|
||||
.addScript(new ClassPathResource("/org/springframework/cloud/task/schema-mariadb.sql"));
|
||||
databasePopulator.execute(datasource);
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage())
|
||||
.isEqualTo("Task names must not contain any empty elements but 2 of 4 were empty or null.");
|
||||
.isEqualTo("Task names must not contain any empty elements but 2 of 4 were empty or null.");
|
||||
return;
|
||||
}
|
||||
fail("Expected an IllegalArgumentException to be thrown.");
|
||||
@@ -82,7 +82,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO1");
|
||||
assertThat(latestTaskExecutions.size() == 1)
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue();
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
|
||||
final TaskExecution lastTaskExecution = latestTaskExecutions.get(0);
|
||||
assertThat(lastTaskExecution.getTaskName()).isEqualTo("FOO1");
|
||||
@@ -102,7 +103,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO1", "FOO3",
|
||||
"FOO4");
|
||||
assertThat(latestTaskExecutions.size() == 3)
|
||||
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size()).isTrue();
|
||||
.as("Expected 3 taskExecutions but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
|
||||
LocalDateTime startDateTime = latestTaskExecutions.get(0).getStartTime();
|
||||
assertThat(startDateTime.getYear()).isEqualTo(2016);
|
||||
@@ -142,7 +144,8 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
long executionIdOffset = initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final List<TaskExecution> latestTaskExecutions = this.dao.getLatestTaskExecutionsByTaskNames("FOO5");
|
||||
assertThat(latestTaskExecutions.size() == 1)
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size()).isTrue();
|
||||
.as("Expected only 1 taskExecution but got " + latestTaskExecutions.size())
|
||||
.isTrue();
|
||||
|
||||
LocalDateTime startDateTime = latestTaskExecutions.get(0).getStartTime();
|
||||
|
||||
@@ -187,7 +190,7 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
final TaskExecution latestTaskExecution = this.dao.getLatestTaskExecutionForTaskName("Bar5");
|
||||
assertThat(latestTaskExecution).as("Expected the latestTaskExecution to be null but got" + latestTaskExecution)
|
||||
.isNull();
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -288,13 +291,19 @@ public abstract class BaseTaskExecutionDaoTestCases {
|
||||
}
|
||||
|
||||
private LocalDateTime getDate(int year, int month, int day, int hour, int minute) {
|
||||
return LocalDateTime.now().withYear(year).withMonth(month).withDayOfMonth(day).withHour(hour).withMinute(minute)
|
||||
.withSecond(0);
|
||||
return LocalDateTime.now()
|
||||
.withYear(year)
|
||||
.withMonth(month)
|
||||
.withDayOfMonth(day)
|
||||
.withHour(hour)
|
||||
.withMinute(minute)
|
||||
.withSecond(0);
|
||||
}
|
||||
|
||||
private long createTaskExecution(TaskExecution te) {
|
||||
return this.dao.createTaskExecution(te.getTaskName(), te.getStartTime(), te.getArguments(),
|
||||
te.getExternalExecutionId()).getExecutionId();
|
||||
return this.dao
|
||||
.createTaskExecution(te.getTaskName(), te.getStartTime(), te.getArguments(), te.getExternalExecutionId())
|
||||
.getExecutionId();
|
||||
}
|
||||
|
||||
protected TaskExecution getTaskExecution(String taskName, String externalExecutionId) {
|
||||
|
||||
@@ -219,7 +219,8 @@ public class JdbcTaskExecutionDaoMariaDBIntegrationTests extends BaseTaskExecuti
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(
|
||||
this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("START_TIME")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
.getTotalElements())
|
||||
.isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -227,9 +228,9 @@ public class JdbcTaskExecutionDaoMariaDBIntegrationTests extends BaseTaskExecuti
|
||||
public void testFindRunningTaskExecutionsIllegalSort() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThatThrownBy(() -> this.dao
|
||||
.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT")))
|
||||
.getTotalElements()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT")))
|
||||
.getTotalElements()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -238,7 +239,8 @@ public class JdbcTaskExecutionDaoMariaDBIntegrationTests extends BaseTaskExecuti
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(
|
||||
this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("StArT_TiMe")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
.getTotalElements())
|
||||
.isEqualTo(4);
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
@@ -282,7 +284,7 @@ public class JdbcTaskExecutionDaoMariaDBIntegrationTests extends BaseTaskExecuti
|
||||
if (firstTime) {
|
||||
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
|
||||
databasePopulator
|
||||
.addScript(new ClassPathResource("/org/springframework/cloud/task/schema-mariadb.sql"));
|
||||
.addScript(new ClassPathResource("/org/springframework/cloud/task/schema-mariadb.sql"));
|
||||
databasePopulator.execute(datasource);
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class TaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
getDao(testType);
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, 4, Sort.by("START_TIME")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -243,9 +243,9 @@ public class TaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
public void testFindRunningTaskExecutionsIllegalSort() {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThatThrownBy(() -> this.dao
|
||||
.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT")))
|
||||
.getTotalElements()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("ILLEGAL_SORT")))
|
||||
.getTotalElements()).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("Invalid sort option selected: ILLEGAL_SORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -254,7 +254,8 @@ public class TaskExecutionDaoTests extends BaseTaskExecutionDaoTestCases {
|
||||
initializeRepositoryNotInOrderWithMultipleTaskExecutions();
|
||||
assertThat(
|
||||
this.dao.findRunningTaskExecutions("FOO1", PageRequest.of(1, Integer.MAX_VALUE, Sort.by("StArT_TiMe")))
|
||||
.getTotalElements()).isEqualTo(4);
|
||||
.getTotalElements())
|
||||
.isEqualTo(4);
|
||||
}
|
||||
|
||||
private TaskExecution initializeTaskExecutionWithExternalExecutionId() {
|
||||
|
||||
@@ -79,8 +79,8 @@ public class FindAllPagingQueryProviderTests {
|
||||
public void testGeneratedQuery(String databaseProductName, String expectedQuery) throws Exception {
|
||||
String actualQuery = TestDBUtils.getPagingQueryProvider(databaseProductName).getPageQuery(this.pageable);
|
||||
assertThat(actualQuery)
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ public class WhereClausePagingQueryProviderTests {
|
||||
"TASK_EXECUTION_ID = '0000'");
|
||||
String actualQuery = pagingQueryProvider.getPageQuery(this.pageable);
|
||||
assertThat(actualQuery)
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
.as(String.format("the generated query for %s, was not the expected query", databaseProductName))
|
||||
.isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@ public class SimpleTaskExplorerTests {
|
||||
for (Long taskExecutionId : expectedResults.keySet()) {
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(taskExecutionId);
|
||||
assertThat(actualTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(taskExecutionId), actualTaskExecution);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +110,7 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
TaskExecution actualTaskExecution = this.taskExplorer.getTaskExecution(-5);
|
||||
assertThat(actualTaskExecution).as(String.format("expected null for actualTaskExecution %s", testType))
|
||||
.isNull();
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -119,9 +120,9 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> entry : expectedResults.entrySet()) {
|
||||
String taskName = entry.getValue().getTaskName();
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName)).as(
|
||||
String.format("task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(1);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByTaskName(taskName))
|
||||
.as(String.format("task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,8 @@ public class SimpleTaskExplorerTests {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getTaskExecutionCount())
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType)).isEqualTo(33);
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -140,7 +142,8 @@ public class SimpleTaskExplorerTests {
|
||||
testDefaultContext(testType);
|
||||
createSampleDataSet(33);
|
||||
assertThat(this.taskExplorer.getRunningTaskExecutionCount())
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType)).isEqualTo(33);
|
||||
.as(String.format("task count did not match expected result for test Type %s", testType))
|
||||
.isEqualTo(33);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -164,17 +167,19 @@ public class SimpleTaskExplorerTests {
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
|
||||
Page<TaskExecution> actualResults = this.taskExplorer.findRunningTaskExecutions(TASK_NAME, pageable);
|
||||
assertThat(actualResults.getNumberOfElements()).as(String
|
||||
.format("Running task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
assertThat(actualResults.getNumberOfElements())
|
||||
.as(String.format("Running task count for task name did not match expected result for testType %s",
|
||||
testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : actualResults) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from repo %s not expected for testType %s",
|
||||
result.getExecutionId(), testType))
|
||||
.isTrue();
|
||||
.as(String.format("result returned from repo %s not expected for testType %s", result.getExecutionId(),
|
||||
testType))
|
||||
.isTrue();
|
||||
assertThat(result.getEndTime())
|
||||
.as(String.format("result had non null for endTime for the testType %s", testType)).isNull();
|
||||
.as(String.format("result had non null for endTime for the testType %s", testType))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +190,10 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> sampleDataSet = createSampleDataSet(33);
|
||||
sampleDataSet.values().forEach(taskExecution -> {
|
||||
Page<TaskExecution> taskExecutionsByExecutionId = this.taskExplorer
|
||||
.findTaskExecutionsByExecutionId(taskExecution.getExternalExecutionId(), PageRequest.of(0, 5));
|
||||
.findTaskExecutionsByExecutionId(taskExecution.getExternalExecutionId(), PageRequest.of(0, 5));
|
||||
assertThat(taskExecutionsByExecutionId.getTotalElements()).isEqualTo(1);
|
||||
assertThat(this.taskExplorer
|
||||
.getTaskExecutionCountByExternalExecutionId(taskExecution.getExternalExecutionId())).isEqualTo(1);
|
||||
.getTaskExecutionCountByExternalExecutionId(taskExecution.getExternalExecutionId())).isEqualTo(1);
|
||||
TaskExecution resultTaskExecution = taskExecutionsByExecutionId.getContent().get(0);
|
||||
assertThat(resultTaskExecution.getExecutionId()).isEqualTo(taskExecution.getExecutionId());
|
||||
});
|
||||
@@ -223,7 +228,7 @@ public class SimpleTaskExplorerTests {
|
||||
assertThat(expectedResults.keySet()).contains(taskExecution.getExecutionId());
|
||||
});
|
||||
assertThat(this.taskExplorer.getTaskExecutionCountByExternalExecutionId(EXTERNAL_EXECUTION_ID))
|
||||
.isEqualTo(SAME_EXTERNAL_ID_COUNT);
|
||||
.isEqualTo(SAME_EXTERNAL_ID_COUNT);
|
||||
|
||||
}
|
||||
|
||||
@@ -247,17 +252,18 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
Page<TaskExecution> resultSet = this.taskExplorer.findTaskExecutionsByName(TASK_NAME, pageable);
|
||||
assertThat(resultSet.getNumberOfElements()).as(String
|
||||
.format("Running task count for task name did not match expected result for testType %s", testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
assertThat(resultSet.getNumberOfElements())
|
||||
.as(String.format("Running task count for task name did not match expected result for testType %s",
|
||||
testType))
|
||||
.isEqualTo(TEST_COUNT);
|
||||
|
||||
for (TaskExecution result : resultSet) {
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId())).as(
|
||||
String.format("result returned from %s repo %s not expected", testType, result.getExecutionId()))
|
||||
.isTrue();
|
||||
assertThat(expectedResults.containsKey(result.getExecutionId()))
|
||||
.as(String.format("result returned from %s repo %s not expected", testType, result.getExecutionId()))
|
||||
.isTrue();
|
||||
assertThat(result.getTaskName())
|
||||
.as(String.format("taskName for taskExecution is incorrect for testType %s", testType))
|
||||
.isEqualTo(TASK_NAME);
|
||||
.as(String.format("taskName for taskExecution is incorrect for testType %s", testType))
|
||||
.isEqualTo(TASK_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +280,8 @@ public class SimpleTaskExplorerTests {
|
||||
List<String> actualTaskNames = this.taskExplorer.getTaskNames();
|
||||
for (String taskName : actualTaskNames) {
|
||||
assertThat(expectedResults.contains(taskName))
|
||||
.as(String.format("taskName was not in expected results for testType %s", testType)).isTrue();
|
||||
.as(String.format("taskName was not in expected results for testType %s", testType))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,9 +338,10 @@ public class SimpleTaskExplorerTests {
|
||||
Map<Long, TaskExecution> expectedResults = createSampleDataSet(5);
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : expectedResults.entrySet()) {
|
||||
TaskExecution latestTaskExecution = this.taskExplorer
|
||||
.getLatestTaskExecutionForTaskName(taskExecutionMapEntry.getValue().getTaskName());
|
||||
.getLatestTaskExecutionForTaskName(taskExecutionMapEntry.getValue().getTaskName());
|
||||
assertThat(latestTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
}
|
||||
@@ -352,11 +360,12 @@ public class SimpleTaskExplorerTests {
|
||||
}
|
||||
|
||||
final List<TaskExecution> latestTaskExecutions = this.taskExplorer
|
||||
.getLatestTaskExecutionsByTaskNames(taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
.getLatestTaskExecutionsByTaskNames(taskNamesAsList.toArray(new String[taskNamesAsList.size()]));
|
||||
|
||||
for (TaskExecution latestTaskExecution : latestTaskExecutions) {
|
||||
assertThat(latestTaskExecution)
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType)).isNotNull();
|
||||
.as(String.format("expected a taskExecution but got null for test type %s", testType))
|
||||
.isNotNull();
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(latestTaskExecution.getExecutionId()),
|
||||
latestTaskExecution);
|
||||
}
|
||||
@@ -370,9 +379,9 @@ public class SimpleTaskExplorerTests {
|
||||
Page<TaskExecution> taskPage = this.taskExplorer.findAll(pageable);
|
||||
int pagesExpected = (int) Math.ceil(totalNumberOfExecs / ((double) pageable.getPageSize()));
|
||||
assertThat(taskPage.getTotalPages()).as("actual page count return was not the expected total")
|
||||
.isEqualTo(pagesExpected);
|
||||
.isEqualTo(pagesExpected);
|
||||
assertThat(taskPage.getTotalElements()).as("actual element count was not the expected count")
|
||||
.isEqualTo(totalNumberOfExecs);
|
||||
.isEqualTo(totalNumberOfExecs);
|
||||
|
||||
// Verify pagination
|
||||
Pageable actualPageable = PageRequest.of(0, pageable.getPageSize());
|
||||
@@ -388,12 +397,12 @@ public class SimpleTaskExplorerTests {
|
||||
expectedPageSize = totalNumberOfExecs % pageable.getPageSize();
|
||||
}
|
||||
assertThat(actualTaskExecutions.size())
|
||||
.as(String.format("Element count on page did not match on the %n page", pageNumber))
|
||||
.isEqualTo(expectedPageSize);
|
||||
.as(String.format("Element count on page did not match on the %n page", pageNumber))
|
||||
.isEqualTo(expectedPageSize);
|
||||
for (TaskExecution actualExecution : actualTaskExecutions) {
|
||||
assertThat(actualExecution.getExecutionId())
|
||||
.as(String.format("Element on page %n did not match expected", pageNumber))
|
||||
.isEqualTo((long) expectedTaskExecutionIter.next());
|
||||
.as(String.format("Element on page %n did not match expected", pageNumber))
|
||||
.isEqualTo((long) expectedTaskExecutionIter.next());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedResults.get(actualExecution.getExecutionId()),
|
||||
actualExecution);
|
||||
elementCount++;
|
||||
@@ -418,8 +427,8 @@ public class SimpleTaskExplorerTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
this.context.getAutowireCapableBeanFactory()
|
||||
.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
}
|
||||
|
||||
private void initializeMapExplorerTest() {
|
||||
@@ -427,8 +436,8 @@ public class SimpleTaskExplorerTests {
|
||||
this.context.register(TestConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
|
||||
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
this.context.getAutowireCapableBeanFactory()
|
||||
.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
|
||||
}
|
||||
|
||||
private Map<Long, TaskExecution> createSampleDataSet(int count) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SimpleTaskNameResolverTests {
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertThat(taskNameResolver.getTaskName()
|
||||
.startsWith("org.springframework.context.support.GenericApplicationContext")).isTrue();
|
||||
.startsWith("org.springframework.context.support.GenericApplicationContext")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,7 +64,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateEmptyExecution() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -74,7 +74,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -84,7 +84,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TaskExecution actualTaskExecution = TestDBUtils.getTaskExecutionFromDB(this.dataSource,
|
||||
expectedTaskExecution.getExecutionId());
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
|
||||
@@ -94,7 +94,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
@@ -112,7 +112,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithNoParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
@@ -128,7 +128,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
public void testUpdateExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -139,7 +139,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
public void testUpdateNullExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -150,7 +150,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@Test
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1, expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -161,7 +161,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void startTaskExecutionWithParent() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
@@ -179,7 +179,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCompleteTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(77);
|
||||
expectedTaskExecution.setExitMessage(UUID.randomUUID().toString());
|
||||
@@ -193,7 +193,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxExitDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
@@ -208,7 +208,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
simpleTaskRepository.setMaxExitMessageSize(5);
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setExitMessage(new String(new char[SimpleTaskRepository.MAX_EXIT_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
@@ -220,13 +220,13 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNoParamMaxErrorDefaultMessageSize() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution, this.taskRepository);
|
||||
assertThat(actualTaskExecution.getErrorMessage().length())
|
||||
.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
|
||||
.isEqualTo(SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,7 +236,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
simpleTaskRepository.setMaxErrorMessageSize(5);
|
||||
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(simpleTaskRepository);
|
||||
expectedTaskExecution.setErrorMessage(new String(new char[SimpleTaskRepository.MAX_ERROR_MESSAGE_SIZE + 1]));
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
@@ -302,7 +302,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNegativeException() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
|
||||
@@ -317,7 +317,7 @@ public class SimpleTaskRepositoryJdbcTests {
|
||||
@DirtiesContext
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testCreateEmptyExecution() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testCreateTaskExecutionNoParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testUpdateExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(UUID.randomUUID().toString());
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -78,7 +78,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testUpdateNullExternalExecutionId() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
this.taskRepository.updateExternalExecutionId(expectedTaskExecution.getExecutionId(),
|
||||
expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -89,7 +89,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testInvalidExecutionIdForExternalExecutionIdUpdate() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExternalExecutionId(null);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
this.taskRepository.updateExternalExecutionId(-1, expectedTaskExecution.getExternalExecutionId());
|
||||
@@ -99,7 +99,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testCreateTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionWithParams(this.taskRepository);
|
||||
TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
|
||||
getSingleTaskExecutionFromMapRepository(expectedTaskExecution.getExecutionId()));
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void startTaskExecutionWithParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setArguments(Collections.singletonList("foo=" + UUID.randomUUID().toString()));
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
@@ -124,7 +124,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void startTaskExecutionWithNoParam() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
@@ -140,7 +140,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void startTaskExecutionWithParent() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
.createAndStoreEmptyTaskExecution(this.taskRepository);
|
||||
|
||||
expectedTaskExecution.setStartTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setTaskName(UUID.randomUUID().toString());
|
||||
@@ -157,7 +157,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testCompleteTaskExecution() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setEndTime(LocalDateTime.now());
|
||||
expectedTaskExecution.setExitCode(0);
|
||||
TaskExecution actualTaskExecution = TaskExecutionCreator.completeExecution(this.taskRepository,
|
||||
@@ -167,7 +167,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
|
||||
private TaskExecution getSingleTaskExecutionFromMapRepository(long taskExecutionId) {
|
||||
Map<Long, TaskExecution> taskMap = ((MapTaskExecutionDao) ((SimpleTaskRepository) this.taskRepository)
|
||||
.getTaskExecutionDao()).getTaskExecutions();
|
||||
.getTaskExecutionDao()).getTaskExecutions();
|
||||
assertTrue("taskExecutionId must be in MapTaskExecutionRepository", taskMap.containsKey(taskExecutionId));
|
||||
return taskMap.get(taskExecutionId);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class SimpleTaskRepositoryMapTests {
|
||||
@Test
|
||||
public void testCreateTaskExecutionNullEndTime() {
|
||||
TaskExecution expectedTaskExecution = TaskExecutionCreator
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
.createAndStoreTaskExecutionNoParams(this.taskRepository);
|
||||
expectedTaskExecution.setExitCode(-1);
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
|
||||
TaskExecutionCreator.completeExecution(this.taskRepository, expectedTaskExecution);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TaskDatabaseInitializerTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(new JdbcTemplate(this.context.getBean(DataSource.class)).queryForList("select * from TASK_EXECUTION")
|
||||
.size()).isEqualTo(0);
|
||||
.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class TestVerifierUtils {
|
||||
*/
|
||||
public static Appender getMockAppender() {
|
||||
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
|
||||
.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
|
||||
final Appender mockAppender = mock(Appender.class);
|
||||
when(mockAppender.getName()).thenReturn("MOCK");
|
||||
root.addAppender(mockAppender);
|
||||
@@ -131,55 +131,63 @@ public final class TestVerifierUtils {
|
||||
*/
|
||||
public static void verifyTaskExecution(TaskExecution expectedTaskExecution, TaskExecution actualTaskExecution) {
|
||||
assertThat(actualTaskExecution.getExecutionId()).as("taskExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExecutionId());
|
||||
.isEqualTo(expectedTaskExecution.getExecutionId());
|
||||
if (actualTaskExecution.getStartTime() != null) {
|
||||
assertThat(actualTaskExecution.getStartTime().getHour() == expectedTaskExecution.getStartTime().getHour())
|
||||
.as("startTime hour must be equal").isTrue();
|
||||
.as("startTime hour must be equal")
|
||||
.isTrue();
|
||||
assertThat(
|
||||
actualTaskExecution.getStartTime().getMinute() == expectedTaskExecution.getStartTime().getMinute())
|
||||
.as("startTime minute must be equal").isTrue();
|
||||
.as("startTime minute must be equal")
|
||||
.isTrue();
|
||||
assertThat(
|
||||
actualTaskExecution.getStartTime().getSecond() == expectedTaskExecution.getStartTime().getSecond())
|
||||
.as("startTime second must be equal").isTrue();
|
||||
.as("startTime second must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getStartTime().getDayOfYear() == expectedTaskExecution.getStartTime()
|
||||
.getDayOfYear()).as("startTime day must be equal").isTrue();
|
||||
.getDayOfYear()).as("startTime day must be equal").isTrue();
|
||||
assertThat(actualTaskExecution.getStartTime().getYear() == expectedTaskExecution.getStartTime().getYear())
|
||||
.as("startTime year must be equal").isTrue();
|
||||
.as("startTime year must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getStartTime().getMonthValue() == expectedTaskExecution.getStartTime()
|
||||
.getMonthValue()).as("startTime month must be equal").isTrue();
|
||||
.getMonthValue()).as("startTime month must be equal").isTrue();
|
||||
}
|
||||
if (actualTaskExecution.getEndTime() != null) {
|
||||
assertThat(actualTaskExecution.getEndTime().getHour() == expectedTaskExecution.getEndTime().getHour())
|
||||
.as("endTime hour must be equal").isTrue();
|
||||
.as("endTime hour must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getEndTime().getMinute() == expectedTaskExecution.getEndTime().getMinute())
|
||||
.as("endTime minute must be equal").isTrue();
|
||||
.as("endTime minute must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getEndTime().getSecond() == expectedTaskExecution.getEndTime().getSecond())
|
||||
.as("endTime second must be equal").isTrue();
|
||||
.as("endTime second must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getEndTime().getDayOfYear() == expectedTaskExecution.getEndTime()
|
||||
.getDayOfYear()).as("endTime day must be equal").isTrue();
|
||||
.getDayOfYear()).as("endTime day must be equal").isTrue();
|
||||
assertThat(actualTaskExecution.getEndTime().getYear() == expectedTaskExecution.getEndTime().getYear())
|
||||
.as("endTime year must be equal").isTrue();
|
||||
.as("endTime year must be equal")
|
||||
.isTrue();
|
||||
assertThat(actualTaskExecution.getEndTime().getMonthValue() == expectedTaskExecution.getEndTime()
|
||||
.getMonthValue()).as("endTime month must be equal").isTrue();
|
||||
.getMonthValue()).as("endTime month must be equal").isTrue();
|
||||
}
|
||||
assertThat(actualTaskExecution.getExitCode()).as("exitCode must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExitCode());
|
||||
.isEqualTo(expectedTaskExecution.getExitCode());
|
||||
assertThat(actualTaskExecution.getTaskName()).as("taskName must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getTaskName());
|
||||
.isEqualTo(expectedTaskExecution.getTaskName());
|
||||
assertThat(actualTaskExecution.getExitMessage()).as("exitMessage must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExitMessage());
|
||||
.isEqualTo(expectedTaskExecution.getExitMessage());
|
||||
assertThat(actualTaskExecution.getErrorMessage()).as("errorMessage must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getErrorMessage());
|
||||
.isEqualTo(expectedTaskExecution.getErrorMessage());
|
||||
assertThat(actualTaskExecution.getExternalExecutionId()).as("externalExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getExternalExecutionId());
|
||||
.isEqualTo(expectedTaskExecution.getExternalExecutionId());
|
||||
assertThat(actualTaskExecution.getParentExecutionId()).as("parentExecutionId must be equal")
|
||||
.isEqualTo(expectedTaskExecution.getParentExecutionId());
|
||||
.isEqualTo(expectedTaskExecution.getParentExecutionId());
|
||||
|
||||
if (expectedTaskExecution.getArguments() != null) {
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should not be null").isNotNull();
|
||||
assertThat(actualTaskExecution.getArguments().size())
|
||||
.as("arguments result set count should match expected count")
|
||||
.isEqualTo(expectedTaskExecution.getArguments().size());
|
||||
.as("arguments result set count should match expected count")
|
||||
.isEqualTo(expectedTaskExecution.getArguments().size());
|
||||
}
|
||||
else {
|
||||
assertThat(actualTaskExecution.getArguments()).as("arguments should be null").isNull();
|
||||
|
||||
@@ -71,21 +71,23 @@ public class JobConfiguration {
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return new StepBuilder("step2", this.jobRepository)
|
||||
.<String, String>chunk(DEFAULT_CHUNK_COUNT, transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt(item) * -1);
|
||||
.<String, String>chunk(DEFAULT_CHUNK_COUNT, transactionManager)
|
||||
.reader(new ListItemReader<>(Arrays.asList("1", "2", "3", "4", "5", "6")))
|
||||
.processor(new ItemProcessor<String, String>() {
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt(item) * -1);
|
||||
}
|
||||
})
|
||||
.writer(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
for (Object item : items) {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}).writer(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
for (Object item : items) {
|
||||
System.out.println(">> " + item);
|
||||
}
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,14 +63,19 @@ public class JobSkipConfiguration {
|
||||
|
||||
@Bean
|
||||
public Step step2() {
|
||||
return new StepBuilder("step2", this.jobRepository).chunk(3, transactionManager).faultTolerant()
|
||||
.skip(IllegalStateException.class).skipLimit(100).reader(new SkipItemReader())
|
||||
.processor(new ItemProcessor<Object, Object>() {
|
||||
@Override
|
||||
public String process(Object item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt((String) item) * -1);
|
||||
}
|
||||
}).writer(new SkipItemWriter()).build();
|
||||
return new StepBuilder("step2", this.jobRepository).chunk(3, transactionManager)
|
||||
.faultTolerant()
|
||||
.skip(IllegalStateException.class)
|
||||
.skipLimit(100)
|
||||
.reader(new SkipItemReader())
|
||||
.processor(new ItemProcessor<Object, Object>() {
|
||||
@Override
|
||||
public String process(Object item) throws Exception {
|
||||
return String.valueOf(Integer.parseInt((String) item) * -1);
|
||||
}
|
||||
})
|
||||
.writer(new SkipItemWriter())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class TaskStartTests {
|
||||
TaskExecution te = taskExecutions.iterator().next();
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,7 +169,7 @@ public class TaskStartTests {
|
||||
TaskExecution te = taskExecutions.iterator().next();
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
assertThat(this.taskExplorer.getTaskExecution(1).getTaskName()).isEqualTo("batchEvents");
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class TaskStartTests {
|
||||
Page<TaskExecution> taskExecutions = this.taskExplorer.findAll(PageRequest.of(0, 10));
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
assertThat(this.taskExplorer.getTaskExecution(1).getStartTime().isEqual(startDate)).isTrue();
|
||||
|
||||
}
|
||||
@@ -227,7 +227,8 @@ public class TaskStartTests {
|
||||
testFailed = true;
|
||||
}
|
||||
assertThat(testFailed)
|
||||
.as("Expected TaskExecutionException for because of " + "single-instance-enabled is enabled").isTrue();
|
||||
.as("Expected TaskExecutionException for because of " + "single-instance-enabled is enabled")
|
||||
.isTrue();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public class TaskInitializerTests {
|
||||
TaskExecution te = taskExecutions.iterator().next();
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -160,7 +160,7 @@ public class TaskInitializerTests {
|
||||
TaskExecution te = taskExecutions.iterator().next();
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
private boolean tableExists() throws SQLException {
|
||||
|
||||
@@ -132,7 +132,7 @@ public class TaskLauncherSinkTests {
|
||||
assertThat(taskExecutions.getTotalElements()).as("Only one row is expected").isEqualTo(1);
|
||||
assertThat(waitForTaskToComplete()).isTrue();
|
||||
assertThat(taskExecutions.iterator().next().getExitCode().intValue()).as("return code should be 0")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
private boolean tableExists() throws SQLException {
|
||||
@@ -190,8 +190,9 @@ public class TaskLauncherSinkTests {
|
||||
public Server initH2TCPServer() {
|
||||
Server server;
|
||||
try {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
server = Server
|
||||
.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -71,9 +71,10 @@ public class BatchExecutionEventTests {
|
||||
@Test
|
||||
public void testContext() {
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build()
|
||||
.run(getCommandLineParams("--spring.cloud.stream.bindings.job-execution-events.destination=bazbar"));
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(getCommandLineParams("--spring.cloud.stream.bindings.job-execution-events.destination=bazbar"));
|
||||
|
||||
assertThat(this.applicationContext.getBean("jobExecutionEventsListener")).isNotNull();
|
||||
assertThat(this.applicationContext.getBean("stepExecutionEventsListener")).isNotNull();
|
||||
@@ -90,8 +91,9 @@ public class BatchExecutionEventTests {
|
||||
"--spring.cloud.task.batch.events.jobExecutionEventBindingName=foobar", "foobar", 1);
|
||||
JobExecutionEvent jobExecutionEvent = this.objectMapper.readValue(result.get(0).getPayload(),
|
||||
JobExecutionEvent.class);
|
||||
Assertions.assertThat(jobExecutionEvent.getJobInstance().getJobName()).isEqualTo("job")
|
||||
.as("Job name should be job");
|
||||
Assertions.assertThat(jobExecutionEvent.getJobInstance().getJobName())
|
||||
.isEqualTo("job")
|
||||
.as("Job name should be job");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,8 +180,10 @@ public class BatchExecutionEventTests {
|
||||
List<Message<byte[]>> results = new ArrayList<>();
|
||||
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(clazz)).web(WebApplicationType.NONE)
|
||||
.build().run(getCommandLineParams(channelBinding, enableFailJobConfig));
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(clazz))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(getCommandLineParams(channelBinding, enableFailJobConfig));
|
||||
|
||||
OutputDestination target = this.applicationContext.getBean(OutputDestination.class);
|
||||
|
||||
|
||||
@@ -66,19 +66,23 @@ public class TaskEventTests {
|
||||
List<Message<byte[]>> result = testListener(
|
||||
"--spring.cloud.task.batch.events.itemWriteEventBindingName=task-events", "task-events", 2);
|
||||
TaskExecution taskExecution = this.objectMapper.readValue(result.get(0).getPayload(), TaskExecution.class);
|
||||
Assertions.assertThat(taskExecution.getTaskName()).isEqualTo(TASK_NAME)
|
||||
.as(String.format("Task name should be '%s'", TASK_NAME));
|
||||
Assertions.assertThat(taskExecution.getTaskName())
|
||||
.isEqualTo(TASK_NAME)
|
||||
.as(String.format("Task name should be '%s'", TASK_NAME));
|
||||
taskExecution = this.objectMapper.readValue(result.get(1).getPayload(), TaskExecution.class);
|
||||
Assertions.assertThat(taskExecution.getTaskName()).isEqualTo(TASK_NAME)
|
||||
.as(String.format("Task name should be '%s'", TASK_NAME));
|
||||
Assertions.assertThat(taskExecution.getTaskName())
|
||||
.isEqualTo(TASK_NAME)
|
||||
.as(String.format("Task name should be '%s'", TASK_NAME));
|
||||
}
|
||||
|
||||
private List<Message<byte[]>> testListener(String channelBinding, String bindingName, int numberToRead) {
|
||||
List<Message<byte[]>> results = new ArrayList<>();
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(BatchExecutionEventTests.BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run(getCommandLineParams(channelBinding));
|
||||
.sources(TestChannelBinderConfiguration
|
||||
.getCompleteConfiguration(BatchExecutionEventTests.BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(getCommandLineParams(channelBinding));
|
||||
OutputDestination target = this.applicationContext.getBean(OutputDestination.class);
|
||||
for (int i = 0; i < numberToRead; i++) {
|
||||
results.add(target.receive(10000, bindingName));
|
||||
|
||||
@@ -58,4 +58,5 @@ public class JobConfiguration {
|
||||
}, transactionManager).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,5 @@ class BatchJobTestConfiguration {
|
||||
public PostgreSQLContainer<?> postgresSQLContainer() {
|
||||
return new PostgreSQLContainer(DockerImageName.parse("postgres:15.1"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,8 @@ import org.springframework.boot.SpringApplication;
|
||||
public class TestBatchJobApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] myArgs = {"--spring.batch.jdbc.initialize-schema=always"};
|
||||
SpringApplication.from(BatchJobApplication::main).
|
||||
with(BatchJobTestConfiguration.class).
|
||||
run(myArgs);
|
||||
String[] myArgs = { "--spring.batch.jdbc.initialize-schema=always" };
|
||||
SpringApplication.from(BatchJobApplication::main).with(BatchJobTestConfiguration.class).run(myArgs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,8 +51,9 @@ public class MessagePublisher<P> {
|
||||
}
|
||||
|
||||
public void publishWithThrowableHeader(String bindingName, P payload, String header) {
|
||||
Message<P> message = MessageBuilder.withPayload(payload).setHeader(BatchJobHeaders.BATCH_EXCEPTION, header)
|
||||
.build();
|
||||
Message<P> message = MessageBuilder.withPayload(payload)
|
||||
.setHeader(BatchJobHeaders.BATCH_EXCEPTION, header)
|
||||
.build();
|
||||
publishMessage(bindingName, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,11 +90,11 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
Field chunkProviderField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProvider");
|
||||
ReflectionUtils.makeAccessible(chunkProviderField);
|
||||
SimpleChunkProvider chunkProvider = (SimpleChunkProvider) ReflectionUtils
|
||||
.getField(chunkProviderField, tasklet);
|
||||
.getField(chunkProviderField, tasklet);
|
||||
Field chunkProcessorField = ReflectionUtils.findField(ChunkOrientedTasklet.class, "chunkProcessor");
|
||||
ReflectionUtils.makeAccessible(chunkProcessorField);
|
||||
SimpleChunkProcessor chunkProcessor = (SimpleChunkProcessor) ReflectionUtils
|
||||
.getField(chunkProcessorField, tasklet);
|
||||
.getField(chunkProcessorField, tasklet);
|
||||
registerItemReadEvents(chunkProvider);
|
||||
registerSkipEvents(chunkProvider);
|
||||
registerItemProcessEvents(chunkProcessor);
|
||||
@@ -115,21 +115,21 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
private void registerItemProcessEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemProcessListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER));
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_PROCESS_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemReadEvents(SimpleChunkProvider chunkProvider) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER)) {
|
||||
chunkProvider.registerListener((ItemReadListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER));
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_READ_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
private void registerItemWriteEvents(SimpleChunkProcessor chunkProcessor) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER)) {
|
||||
chunkProcessor.registerListener((ItemWriteListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER));
|
||||
.getBean(BatchEventAutoConfiguration.ITEM_WRITE_EVENTS_LISTENER));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
if (bean instanceof AbstractJob job
|
||||
&& this.applicationContext.containsBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER)) {
|
||||
JobExecutionListener jobExecutionEventsListener = (JobExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER);
|
||||
.getBean(BatchEventAutoConfiguration.JOB_EXECUTION_EVENTS_LISTENER);
|
||||
|
||||
job.registerJobExecutionListener(jobExecutionEventsListener);
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class TaskBatchEventListenerBeanPostProcessor implements BeanPostProcesso
|
||||
private void registerStepExecutionEventListener(Object bean) {
|
||||
if (this.applicationContext.containsBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER)) {
|
||||
StepExecutionListener stepExecutionListener = (StepExecutionListener) this.applicationContext
|
||||
.getBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
.getBean(BatchEventAutoConfiguration.STEP_EXECUTION_EVENTS_LISTENER);
|
||||
AbstractStep step = (AbstractStep) bean;
|
||||
step.registerStepExecutionListener(stepExecutionListener);
|
||||
}
|
||||
|
||||
@@ -82,8 +82,10 @@ public class EventListenerTests {
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
|
||||
this.applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run();
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(BatchEventsApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run();
|
||||
StreamBridge streamBridge = this.applicationContext.getBean(StreamBridge.class);
|
||||
MessagePublisher messagePublisher = new MessagePublisher(streamBridge);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
@@ -125,22 +127,22 @@ public class EventListenerTests {
|
||||
this.eventEmittingItemProcessListener.onProcessError("HELLO", new RuntimeException("Test Exception"));
|
||||
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("Exception while item was being processed");
|
||||
.isEqualTo("Exception while item was being processed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemProcessListenerAfterProcess() {
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS_EQUAL", "HELLO_AFTER_PROCESS_EQUAL");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("item equaled result after processing");
|
||||
.isEqualTo("item equaled result after processing");
|
||||
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_NOT_EQUAL", "WORLD");
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("item did not equal result after processing");
|
||||
.isEqualTo("item did not equal result after processing");
|
||||
|
||||
this.eventEmittingItemProcessListener.afterProcess("HELLO_AFTER_PROCESS", null);
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemProcessEventBindingName()))
|
||||
.isEqualTo("1 item was filtered");
|
||||
.isEqualTo("1 item was filtered");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,7 +155,7 @@ public class EventListenerTests {
|
||||
public void EventEmittingSkipListenerSkipRead() {
|
||||
this.eventEmittingSkipListener.onSkipInRead(new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getSkipEventBindingName()))
|
||||
.isEqualTo("Skipped when reading.");
|
||||
.isEqualTo("Skipped when reading.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +176,7 @@ public class EventListenerTests {
|
||||
public void EventEmittingItemReadListener() {
|
||||
this.eventEmittingItemReadListener.onReadError(new RuntimeException("Text Exception"));
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemReadEventBindingName()))
|
||||
.isEqualTo("Exception while item was being read");
|
||||
.isEqualTo("Exception while item was being read");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,14 +195,14 @@ public class EventListenerTests {
|
||||
public void EventEmittingItemWriteListenerBeforeWrite() {
|
||||
this.eventEmittingItemWriteListener.beforeWrite(getSampleList());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemWriteEventBindingName()))
|
||||
.isEqualTo("3 items to be written.");
|
||||
.isEqualTo("3 items to be written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void EventEmittingItemWriteListenerAfterWrite() {
|
||||
this.eventEmittingItemWriteListener.afterWrite(getSampleList());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemWriteEventBindingName()))
|
||||
.isEqualTo("3 items have been written.");
|
||||
.isEqualTo("3 items have been written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,7 +211,7 @@ public class EventListenerTests {
|
||||
this.eventEmittingItemWriteListener.onWriteError(exception, getSampleList());
|
||||
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getItemWriteEventBindingName()))
|
||||
.isEqualTo("Exception while 3 items are attempted to be written.");
|
||||
.isEqualTo("Exception while 3 items are attempted to be written.");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -266,7 +268,7 @@ public class EventListenerTests {
|
||||
final String CHUNK_MESSAGE = "Before Chunk Processing";
|
||||
this.eventEmittingChunkListener.beforeChunk(getChunkContext());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getChunkEventBindingName()))
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,7 +276,7 @@ public class EventListenerTests {
|
||||
final String CHUNK_MESSAGE = "After Chunk Processing";
|
||||
this.eventEmittingChunkListener.afterChunk(getChunkContext());
|
||||
assertThat(getStringFromDestination(this.taskEventProperties.getChunkEventBindingName()))
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
.isEqualTo(CHUNK_MESSAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -88,12 +88,12 @@ public class JobExecutionEventTests {
|
||||
assertThat(jobExecutionEvent.getJobParameters()).as("jobParameters should not be null").isNotNull();
|
||||
|
||||
assertThat(jobExecutionEvent.getJobParameters().getParameters().size()).as("jobParameters size did not match")
|
||||
.isEqualTo(0);
|
||||
.isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getJobInstance().getJobName()).as("jobInstance name did not match")
|
||||
.isEqualTo(JOB_NAME);
|
||||
.isEqualTo(JOB_NAME);
|
||||
assertThat(jobExecutionEvent.getStepExecutions().size()).as("no step executions were expected").isEqualTo(0);
|
||||
assertThat(jobExecutionEvent.getExitStatus().getExitCode()).as("exitStatus did not match expected")
|
||||
.isEqualTo("UNKNOWN");
|
||||
.isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,13 +118,13 @@ public class JobExecutionEventTests {
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D")).as("Job Parameter D was expected").isNotNull();
|
||||
|
||||
assertThat(jobExecutionEvent.getJobParameters().getString("A")).as("Job Parameter A value was not correct")
|
||||
.isEqualTo("FOO");
|
||||
.isEqualTo("FOO");
|
||||
assertThat(jobExecutionEvent.getJobParameters().getLong("B")).as("Job Parameter B value was not correct")
|
||||
.isEqualTo(Long.valueOf(1));
|
||||
.isEqualTo(Long.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDouble("C")).as("Job Parameter C value was not correct")
|
||||
.isEqualTo(Double.valueOf(1));
|
||||
.isEqualTo(Double.valueOf(1));
|
||||
assertThat(jobExecutionEvent.getJobParameters().getDate("D")).as("Job Parameter D value was not correct")
|
||||
.isEqualTo(testDate);
|
||||
.isEqualTo(testDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -285,20 +285,19 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void testOrderConfiguration() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean(
|
||||
"org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", "--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.cloud.task.batch.events.item-process-order=5",
|
||||
"--spring.cloud.task.batch.events.item-read-order=5",
|
||||
"--spring.cloud.task.batch.events.item-write-order=5",
|
||||
"--spring.cloud.task.batch.events.job-execution-order=5",
|
||||
"--spring.cloud.task.batch.events.skip-order=5",
|
||||
"--spring.cloud.task.batch.events.step-execution-order=5");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean("org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false", "--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.batch.events.chunk-order=5",
|
||||
"--spring.cloud.task.batch.events.item-process-order=5",
|
||||
"--spring.cloud.task.batch.events.item-read-order=5",
|
||||
"--spring.cloud.task.batch.events.item-write-order=5",
|
||||
"--spring.cloud.task.batch.events.job-execution-order=5",
|
||||
"--spring.cloud.task.batch.events.skip-order=5",
|
||||
"--spring.cloud.task.batch.events.step-execution-order=5");
|
||||
applicationContextRunner.run((context) -> {
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
Ordered ordered = (Ordered) context.getBean(beanName);
|
||||
@@ -311,35 +310,33 @@ public class JobExecutionEventTests {
|
||||
@Test
|
||||
public void singleStepBatchJobSkip() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean(
|
||||
"org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", "spring.batch.job.jobName=FOO");
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean("org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false", "--spring.main.web-environment=false",
|
||||
"spring.batch.job.jobName=FOO");
|
||||
applicationContextRunner.run((context) -> {
|
||||
NoSuchBeanDefinitionException exception = Assertions.assertThrows(NoSuchBeanDefinitionException.class,
|
||||
() -> {
|
||||
context.getBean("jobExecutionEventsListener");
|
||||
});
|
||||
assertThat(exception.getMessage())
|
||||
.contains(String.format("No bean named 'jobExecutionEventsListener' available"));
|
||||
.contains(String.format("No bean named 'jobExecutionEventsListener' available"));
|
||||
});
|
||||
}
|
||||
|
||||
private void testDisabledConfiguration(String property, String disabledListener) {
|
||||
String disabledPropertyArg = (property != null) ? "--" + property + "=false" : "";
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean(
|
||||
"org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
|
||||
"--spring.main.web-environment=false", disabledPropertyArg);
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
|
||||
.withBean("org.springframework.cloud.task.batch.listener.JobExecutionEventTests$BatchEventTestApplication",
|
||||
BatchEventTestApplication.class)
|
||||
.withPropertyValues("--spring.cloud.task.closecontext_enabled=false", "--spring.main.web-environment=false",
|
||||
disabledPropertyArg);
|
||||
applicationContextRunner.run((context) -> {
|
||||
boolean exceptionThrown = false;
|
||||
for (String beanName : LISTENER_BEAN_NAMES) {
|
||||
@@ -351,7 +348,7 @@ public class JobExecutionEventTests {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertThat(exceptionThrown).as(String.format("Did not expect %s bean in context", beanName))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
else {
|
||||
context.getBean(beanName);
|
||||
|
||||
@@ -56,23 +56,23 @@ public class StepExecutionEventTests {
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.getStepName()).as("stepName result was not as expected").isEqualTo(STEP_NAME);
|
||||
assertThat(stepExecutionEvent.getStartTime()).as("startTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getStartTime());
|
||||
.isEqualTo(stepExecution.getStartTime());
|
||||
assertThat(stepExecutionEvent.getEndTime()).as("endTime result was not as expected")
|
||||
.isEqualTo(stepExecution.getEndTime());
|
||||
.isEqualTo(stepExecution.getEndTime());
|
||||
assertThat(stepExecutionEvent.getLastUpdated()).as("lastUpdated result was not as expected")
|
||||
.isEqualTo(stepExecution.getLastUpdated());
|
||||
.isEqualTo(stepExecution.getLastUpdated());
|
||||
assertThat(stepExecutionEvent.getCommitCount()).as("commitCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getCommitCount());
|
||||
.isEqualTo(stepExecution.getCommitCount());
|
||||
assertThat(stepExecutionEvent.getReadCount()).as("readCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadCount());
|
||||
.isEqualTo(stepExecution.getReadCount());
|
||||
assertThat(stepExecutionEvent.getReadSkipCount()).as("readSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getReadSkipCount());
|
||||
.isEqualTo(stepExecution.getReadSkipCount());
|
||||
assertThat(stepExecutionEvent.getWriteCount()).as("writeCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteCount());
|
||||
.isEqualTo(stepExecution.getWriteCount());
|
||||
assertThat(stepExecutionEvent.getWriteSkipCount()).as("writeSkipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getWriteSkipCount());
|
||||
.isEqualTo(stepExecution.getWriteSkipCount());
|
||||
assertThat(stepExecutionEvent.getSkipCount()).as("skipCount result was not as expected")
|
||||
.isEqualTo(stepExecution.getSkipCount());
|
||||
.isEqualTo(stepExecution.getSkipCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,9 +90,9 @@ public class StepExecutionEventTests {
|
||||
StepExecution stepExecution = getBasicStepExecution();
|
||||
StepExecutionEvent stepExecutionEvent = new StepExecutionEvent(stepExecution);
|
||||
assertThat(stepExecutionEvent.getSummary())
|
||||
.isEqualTo("StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
+ " exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,"
|
||||
+ " writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0");
|
||||
.isEqualTo("StepExecutionEvent: id=null, version=null, name=STEP_NAME, status=STARTING,"
|
||||
+ " exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0,"
|
||||
+ " writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -97,7 +97,7 @@ public class TaskBatchEventListenerBeanPostProcessorTests {
|
||||
@Test
|
||||
public void testPostProcessor() {
|
||||
TaskBatchEventListenerBeanPostProcessor postProcessor = this.context
|
||||
.getBean(TaskBatchEventListenerBeanPostProcessor.class);
|
||||
.getBean(TaskBatchEventListenerBeanPostProcessor.class);
|
||||
assertThat(postProcessor).isNotNull();
|
||||
TaskletStep updatedTaskletStep = (TaskletStep) postProcessor.postProcessBeforeInitialization(this.taskletStep,
|
||||
"FOO");
|
||||
|
||||
@@ -43,8 +43,9 @@ public class TaskLaunchConfigurationExistingTests {
|
||||
@Test
|
||||
public void testTaskLauncher() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class).web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
TaskLaunchConfigurationExistingTests.TestTaskDeployerConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
LocalTaskLauncher taskLauncher = context.getBean(LocalTaskLauncher.class);
|
||||
assertThat(testTaskLauncher).isNotNull();
|
||||
assertThat(taskLauncher).isNotNull();
|
||||
|
||||
@@ -60,7 +60,8 @@ public class TaskLauncherFunctionTests {
|
||||
public void testProcessorFromFunction() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
|
||||
InputDestination source = context.getBean(InputDestination.class);
|
||||
TaskLaunchRequest request = new TaskLaunchRequest(VALID_URL, Collections.emptyList(),
|
||||
@@ -79,7 +80,8 @@ public class TaskLauncherFunctionTests {
|
||||
commandLineArgs.add(PARAM2);
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, commandLineArgs, null,
|
||||
context);
|
||||
verifySuccessWithParams(testTaskLauncher);
|
||||
@@ -96,7 +98,8 @@ public class TaskLauncherFunctionTests {
|
||||
public void testSuccessWithAppName() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskString(VALID_URL, null, APP_NAME, context);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
|
||||
@@ -112,7 +115,8 @@ public class TaskLauncherFunctionTests {
|
||||
public void testInvalidJar() throws Exception {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = launchTaskTaskLaunchRequest(INVALID_URL, null,
|
||||
APP_NAME, context);
|
||||
verifySuccessWithAppName(testTaskLauncher);
|
||||
@@ -123,9 +127,10 @@ public class TaskLauncherFunctionTests {
|
||||
public void testNoRun() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(TaskLauncherSinkTestApplication.class))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.run("--spring.jmx.enabled=false")) {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher = context
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
assertThat(testTaskLauncher.status(DEFAULT_STATUS).getState()).isEqualTo(LaunchState.unknown);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@ public class TaskEventTests {
|
||||
@Test
|
||||
public void testDefaultConfiguration() {
|
||||
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder()
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(TaskEventsApplication.class))
|
||||
.web(WebApplicationType.NONE).build().run();
|
||||
.sources(TestChannelBinderConfiguration.getCompleteConfiguration(TaskEventsApplication.class))
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run();
|
||||
assertThat(applicationContext.getBean("taskEventEmitter")).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user