Updated to files to fit the Standard.
This commit is contained in:
@@ -51,9 +51,8 @@ public class RangeConverter implements Converter<String, Range> {
|
||||
return new Range(start, end);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"%s is in an illegal format. Ranges must be specified as startIndex-endIndex",
|
||||
source));
|
||||
throw new IllegalArgumentException(String
|
||||
.format("%s is in an illegal format. Ranges must be specified as startIndex-endIndex", source));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,8 @@ public class SingleStepJobAutoConfiguration {
|
||||
@Autowired(required = false)
|
||||
private ItemProcessor<Map<String, Object>, Map<String, Object>> itemProcessor;
|
||||
|
||||
public SingleStepJobAutoConfiguration(JobBuilderFactory jobBuilderFactory,
|
||||
StepBuilderFactory stepBuilderFactory, SingleStepJobProperties properties,
|
||||
ApplicationContext context) {
|
||||
public SingleStepJobAutoConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory,
|
||||
SingleStepJobProperties properties, ApplicationContext context) {
|
||||
|
||||
validateProperties(properties);
|
||||
|
||||
@@ -72,27 +71,23 @@ public class SingleStepJobAutoConfiguration {
|
||||
Assert.hasText(properties.getJobName(), "A job name is required");
|
||||
Assert.hasText(properties.getStepName(), "A step name is required");
|
||||
Assert.notNull(properties.getChunkSize(), "A chunk size is required");
|
||||
Assert.isTrue(properties.getChunkSize() > 0,
|
||||
"A chunk size greater than zero is required");
|
||||
Assert.isTrue(properties.getChunkSize() > 0, "A chunk size greater than zero is required");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "job-name")
|
||||
public Job job(ItemReader<Map<String, Object>> itemReader,
|
||||
ItemWriter<Map<String, Object>> itemWriter) {
|
||||
public Job job(ItemReader<Map<String, Object>> itemReader, ItemWriter<Map<String, Object>> itemWriter) {
|
||||
|
||||
SimpleStepBuilder<Map<String, Object>, Map<String, Object>> stepBuilder = this.stepBuilderFactory
|
||||
.get(this.properties.getStepName())
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(
|
||||
this.properties.getChunkSize())
|
||||
.reader(itemReader);
|
||||
.<Map<String, Object>, Map<String, Object>>chunk(this.properties.getChunkSize()).reader(itemReader);
|
||||
|
||||
stepBuilder.processor(this.itemProcessor);
|
||||
|
||||
Step step = stepBuilder.writer(itemWriter).build();
|
||||
|
||||
return this.jobBuilderFactory.get(this.properties.getJobName()).start(step)
|
||||
.build();
|
||||
return this.jobBuilderFactory.get(this.properties.getJobName()).start(step).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,47 +58,36 @@ public class FlatFileItemReaderAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.flatfileitemreader", name = "name")
|
||||
public FlatFileItemReader<Map<String, Object>> itemReader(
|
||||
@Autowired(required = false) LineTokenizer lineTokenizer,
|
||||
@Autowired(required = false) FieldSetMapper<Map<String, Object>> fieldSetMapper,
|
||||
@Autowired(required = false) LineMapper<Map<String, Object>> lineMapper,
|
||||
@Autowired(required = false) LineCallbackHandler skippedLinesCallback,
|
||||
@Autowired(required = false) RecordSeparatorPolicy recordSeparatorPolicy) {
|
||||
public FlatFileItemReader<Map<String, Object>> itemReader(@Autowired(required = false) LineTokenizer lineTokenizer,
|
||||
@Autowired(required = false) FieldSetMapper<Map<String, Object>> fieldSetMapper,
|
||||
@Autowired(required = false) LineMapper<Map<String, Object>> lineMapper,
|
||||
@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()]));
|
||||
.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) {
|
||||
mapFlatFileItemReaderBuilder
|
||||
.recordSeparatorPolicy(recordSeparatorPolicy);
|
||||
mapFlatFileItemReaderBuilder.recordSeparatorPolicy(recordSeparatorPolicy);
|
||||
}
|
||||
mapFlatFileItemReaderBuilder.fieldSetMapper(fieldSetMapper);
|
||||
mapFlatFileItemReaderBuilder.lineMapper(lineMapper);
|
||||
mapFlatFileItemReaderBuilder.skippedLinesCallback(skippedLinesCallback);
|
||||
|
||||
if (this.properties.isDelimited()) {
|
||||
mapFlatFileItemReaderBuilder.delimited()
|
||||
.quoteCharacter(this.properties.getQuoteCharacter())
|
||||
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())
|
||||
.includedFields(this.properties.getIncludedFields().toArray(new Integer[0]))
|
||||
.names(this.properties.getNames()).beanMapperStrict(this.properties.isParsingStrict())
|
||||
.fieldSetMapper(new MapFieldSetMapper());
|
||||
}
|
||||
else if (this.properties.isFixedLength()) {
|
||||
mapFlatFileItemReaderBuilder.fixedLength()
|
||||
.columns(this.properties.getRanges().toArray(new Range[0]))
|
||||
.names(this.properties.getNames())
|
||||
.fieldSetMapper(new MapFieldSetMapper())
|
||||
mapFlatFileItemReaderBuilder.fixedLength().columns(this.properties.getRanges().toArray(new Range[0]))
|
||||
.names(this.properties.getNames()).fieldSetMapper(new MapFieldSetMapper())
|
||||
.beanMapperStrict(this.properties.isParsingStrict());
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ public class FlatFileItemReaderProperties {
|
||||
private boolean strict = true;
|
||||
|
||||
/**
|
||||
* Configure the encoding used by the reader to read the input source. The default value
|
||||
* is {@link FlatFileItemReader#DEFAULT_CHARSET}.
|
||||
* Configure the encoding used by the reader to read the input source. The default
|
||||
* value is {@link FlatFileItemReader#DEFAULT_CHARSET}.
|
||||
*/
|
||||
private String encoding = FlatFileItemReader.DEFAULT_CHARSET;
|
||||
|
||||
|
||||
@@ -71,44 +71,37 @@ public class FlatFileItemWriterAutoConfiguration {
|
||||
public FlatFileItemWriter<Map<String, Object>> itemWriter() {
|
||||
|
||||
if (this.properties.isDelimited() && this.properties.isFormatted()) {
|
||||
throw new IllegalStateException(
|
||||
"An output file must be either delimited or formatted or a custom "
|
||||
+ "LineAggregator must be provided. Your current configuration specifies both delimited and formatted");
|
||||
throw new IllegalStateException("An output file must be either delimited or formatted or a custom "
|
||||
+ "LineAggregator must be provided. Your current configuration specifies both delimited and formatted");
|
||||
}
|
||||
else if ((this.properties.isFormatted() || this.properties.isDelimited())
|
||||
&& this.lineAggregator != null) {
|
||||
throw new IllegalStateException("A LineAggregator must be configured if the "
|
||||
+ "output is not formatted or delimited");
|
||||
else if ((this.properties.isFormatted() || this.properties.isDelimited()) && this.lineAggregator != null) {
|
||||
throw new IllegalStateException(
|
||||
"A LineAggregator must be configured if the " + "output is not formatted or delimited");
|
||||
}
|
||||
|
||||
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())
|
||||
.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);
|
||||
.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());
|
||||
FlatFileItemWriterBuilder.DelimitedBuilder<Map<String, Object>> delimitedBuilder = builder.delimited()
|
||||
.delimiter(this.properties.getDelimiter());
|
||||
|
||||
if (this.fieldExtractor != null) {
|
||||
delimitedBuilder.fieldExtractor(this.fieldExtractor);
|
||||
}
|
||||
else {
|
||||
delimitedBuilder.fieldExtractor(
|
||||
new MapFieldExtractor(this.properties.getNames()));
|
||||
delimitedBuilder.fieldExtractor(new MapFieldExtractor(this.properties.getNames()));
|
||||
}
|
||||
}
|
||||
else if (this.properties.isFormatted()) {
|
||||
FlatFileItemWriterBuilder.FormattedBuilder<Map<String, Object>> formattedBuilder = builder
|
||||
.formatted().format(this.properties.getFormat())
|
||||
.locale(this.properties.getLocale())
|
||||
FlatFileItemWriterBuilder.FormattedBuilder<Map<String, Object>> formattedBuilder = builder.formatted()
|
||||
.format(this.properties.getFormat()).locale(this.properties.getLocale())
|
||||
.maximumLength(this.properties.getMaximumLength())
|
||||
.minimumLength(this.properties.getMinimumLength());
|
||||
|
||||
@@ -116,8 +109,7 @@ public class FlatFileItemWriterAutoConfiguration {
|
||||
formattedBuilder.fieldExtractor(this.fieldExtractor);
|
||||
}
|
||||
else {
|
||||
formattedBuilder.fieldExtractor(
|
||||
new MapFieldExtractor(this.properties.getNames()));
|
||||
formattedBuilder.fieldExtractor(new MapFieldExtractor(this.properties.getNames()));
|
||||
}
|
||||
}
|
||||
else if (this.lineAggregator != null) {
|
||||
|
||||
@@ -37,8 +37,8 @@ public class FlatFileItemWriterProperties {
|
||||
private Resource resource;
|
||||
|
||||
/**
|
||||
* Configure the use of the {@code DelimitedLineAggregator} to generate the output per item.
|
||||
* Default is {@code false}.
|
||||
* Configure the use of the {@code DelimitedLineAggregator} to generate the output per
|
||||
* item. Default is {@code false}.
|
||||
*/
|
||||
private boolean delimited;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FlatFileItemWriterProperties {
|
||||
|
||||
/**
|
||||
* Configure the minimum record length.
|
||||
*/
|
||||
*/
|
||||
private int minimumLength = 0;
|
||||
|
||||
/**
|
||||
@@ -74,12 +74,14 @@ public class FlatFileItemWriterProperties {
|
||||
private String delimiter = ",";
|
||||
|
||||
/**
|
||||
* File encoding for the output file. Defaults to {@code FlatFileItemWriter.DEFAULT_CHARSET})
|
||||
* File encoding for the output file. Defaults to
|
||||
* {@code FlatFileItemWriter.DEFAULT_CHARSET})
|
||||
*/
|
||||
private String encoding = FlatFileItemWriter.DEFAULT_CHARSET;
|
||||
|
||||
/**
|
||||
* A flag indicating that changes should be force-synced to disk on flush. Defaults to {@code false}.
|
||||
* A flag indicating that changes should be force-synced to disk on flush. Defaults to
|
||||
* {@code false}.
|
||||
*/
|
||||
private boolean forceSync = false;
|
||||
|
||||
@@ -89,12 +91,14 @@ public class FlatFileItemWriterProperties {
|
||||
private String[] names;
|
||||
|
||||
/**
|
||||
* Configure if the output file is found if it should be appended to. Defaults to {@code false}.
|
||||
* Configure if the output file is found if it should be appended to. Defaults to
|
||||
* {@code false}.
|
||||
*/
|
||||
private boolean append = false;
|
||||
|
||||
/**
|
||||
* String used to separate lines in output. Defaults to the {@code System} property {@code line.separator}.
|
||||
* String used to separate lines in output. Defaults to the {@code System} property
|
||||
* {@code line.separator}.
|
||||
*/
|
||||
private String lineSeparator = FlatFileItemWriter.DEFAULT_LINE_SEPARATOR;
|
||||
|
||||
@@ -117,12 +121,14 @@ public class FlatFileItemWriterProperties {
|
||||
private boolean shouldDeleteIfEmpty = false;
|
||||
|
||||
/**
|
||||
* Indicates whether an existing output file should be deleted on startup. Defaults to {@code true}.
|
||||
* Indicates whether an existing output file should be deleted on startup. Defaults to
|
||||
* {@code true}.
|
||||
*/
|
||||
private boolean shouldDeleteIfExists = true;
|
||||
|
||||
/**
|
||||
* Indicates whether flushing the buffer should be delayed while a transaction is active. Defaults to {@code true}.
|
||||
* Indicates whether flushing the buffer should be delayed while a transaction is
|
||||
* active. Defaults to {@code true}.
|
||||
*/
|
||||
private boolean transactional = FlatFileItemWriter.DEFAULT_TRANSACTIONAL;
|
||||
|
||||
|
||||
@@ -29,9 +29,10 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* Establishes the default {@link DataSource} for the Task when creating a {@link DataSource}
|
||||
* for {@link org.springframework.batch.item.database.JdbcCursorItemReader}
|
||||
* or {@link org.springframework.batch.item.database.JdbcBatchItemWriter}.
|
||||
* Establishes the default {@link DataSource} for the Task when creating a
|
||||
* {@link DataSource} for
|
||||
* {@link org.springframework.batch.item.database.JdbcCursorItemReader} or
|
||||
* {@link org.springframework.batch.item.database.JdbcBatchItemWriter}.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 3.0
|
||||
@@ -44,7 +45,8 @@ class JDBCSingleStepDataSourceAutoConfiguration {
|
||||
return new DefaultTaskConfigurer(dataSource);
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcsinglestep.datasource", name = "enable", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcsinglestep.datasource", name = "enable", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnMissingBean(name = "springDataSourceProperties")
|
||||
@Bean(name = "springDataSourceProperties")
|
||||
@ConfigurationProperties("spring.datasource")
|
||||
@@ -53,11 +55,14 @@ class JDBCSingleStepDataSourceAutoConfiguration {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcsinglestep.datasource", name = "enable", havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcsinglestep.datasource", name = "enable", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@Bean(name = "springDataSource")
|
||||
@Primary
|
||||
public DataSource dataSource(@Qualifier("springDataSourceProperties")DataSourceProperties springDataSourceProperties) {
|
||||
DataSource dataSource = springDataSourceProperties.initializeDataSourceBuilder().build();
|
||||
public DataSource dataSource(
|
||||
@Qualifier("springDataSourceProperties") DataSourceProperties springDataSourceProperties) {
|
||||
DataSource dataSource = springDataSourceProperties.initializeDataSourceBuilder().build();
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,8 +54,7 @@ import org.springframework.context.annotation.Import;
|
||||
@Import(JDBCSingleStepDataSourceAutoConfiguration.class)
|
||||
public class JdbcBatchItemWriterAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(JdbcBatchItemWriterAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory.getLog(JdbcBatchItemWriterAutoConfiguration.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private ItemPreparedStatementSetter itemPreparedStatementSetter;
|
||||
@@ -70,8 +69,7 @@ public class JdbcBatchItemWriterAutoConfiguration {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
public JdbcBatchItemWriterAutoConfiguration(DataSource dataSource,
|
||||
JdbcBatchItemWriterProperties properties) {
|
||||
public JdbcBatchItemWriterAutoConfiguration(DataSource dataSource, JdbcBatchItemWriterProperties properties) {
|
||||
this.dataSource = dataSource;
|
||||
this.properties = properties;
|
||||
}
|
||||
@@ -91,12 +89,10 @@ public class JdbcBatchItemWriterAutoConfiguration {
|
||||
JdbcBatchItemWriterBuilder<Map<String, Object>> jdbcBatchItemWriterBuilder = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.dataSource(writerDataSource).sql(this.properties.getSql());
|
||||
if (this.itemPreparedStatementSetter != null) {
|
||||
jdbcBatchItemWriterBuilder
|
||||
.itemPreparedStatementSetter(this.itemPreparedStatementSetter);
|
||||
jdbcBatchItemWriterBuilder.itemPreparedStatementSetter(this.itemPreparedStatementSetter);
|
||||
}
|
||||
else if (this.itemSqlParameterSourceProvider != null) {
|
||||
jdbcBatchItemWriterBuilder
|
||||
.itemSqlParameterSourceProvider(this.itemSqlParameterSourceProvider);
|
||||
jdbcBatchItemWriterBuilder.itemSqlParameterSourceProvider(this.itemSqlParameterSourceProvider);
|
||||
}
|
||||
else {
|
||||
jdbcBatchItemWriterBuilder.columnMapped();
|
||||
@@ -105,17 +101,21 @@ public class JdbcBatchItemWriterAutoConfiguration {
|
||||
return jdbcBatchItemWriterBuilder.build();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcbatchitemwriter.datasource", name = "enable", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcbatchitemwriter.datasource", name = "enable",
|
||||
havingValue = "true")
|
||||
@Bean(name = "jdbcBatchItemWriterDataSourceProperties")
|
||||
@ConfigurationProperties("jdbcbatchitemwriter.datasource")
|
||||
public DataSourceProperties jdbcBatchItemWriterDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcbatchitemwriter.datasource", name = "enable", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbcbatchitemwriter.datasource", name = "enable",
|
||||
havingValue = "true")
|
||||
@Bean(name = "jdbcBatchItemWriterSpringDataSource")
|
||||
public DataSource writerDataSource(@Qualifier("jdbcBatchItemWriterDataSourceProperties") DataSourceProperties writerDataSourceProperties) {
|
||||
DataSource result = writerDataSourceProperties.initializeDataSourceBuilder().build();
|
||||
public DataSource writerDataSource(
|
||||
@Qualifier("jdbcBatchItemWriterDataSourceProperties") DataSourceProperties writerDataSourceProperties) {
|
||||
DataSource result = writerDataSourceProperties.initializeDataSourceBuilder().build();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class JdbcBatchItemWriterProperties {
|
||||
private String sql;
|
||||
|
||||
/**
|
||||
* If set to {@code true}, confirms that every insert results in the update of at least one
|
||||
* row in the database. Defaults to {@code true}.
|
||||
* If set to {@code true}, confirms that every insert results in the update of at
|
||||
* least one row in the database. Defaults to {@code true}.
|
||||
*/
|
||||
private boolean assertUpdates = true;
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
@Import(JDBCSingleStepDataSourceAutoConfiguration.class)
|
||||
public class JdbcCursorItemReaderAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(JdbcCursorItemReaderAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory.getLog(JdbcCursorItemReaderAutoConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
ApplicationContext applicationContext;
|
||||
@@ -66,41 +65,34 @@ public class JdbcCursorItemReaderAutoConfiguration {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public JdbcCursorItemReaderAutoConfiguration(
|
||||
JdbcCursorItemReaderProperties properties, DataSource dataSource) {
|
||||
public JdbcCursorItemReaderAutoConfiguration(JdbcCursorItemReaderProperties properties, DataSource dataSource) {
|
||||
this.properties = properties;
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JdbcCursorItemReader<Map<String, Object>> itemReader(@Autowired(required = false) RowMapper<Map<String, Object>> rowMapper,
|
||||
@Autowired(required = false) PreparedStatementSetter preparedStatementSetter) {
|
||||
public JdbcCursorItemReader<Map<String, Object>> itemReader(
|
||||
@Autowired(required = false) RowMapper<Map<String, Object>> rowMapper,
|
||||
@Autowired(required = false) PreparedStatementSetter preparedStatementSetter) {
|
||||
DataSource readerDataSource = this.dataSource;
|
||||
try {
|
||||
readerDataSource = this.applicationContext.getBean("jdbcCursorItemReaderSpringDataSource", DataSource.class);
|
||||
readerDataSource = this.applicationContext.getBean("jdbcCursorItemReaderSpringDataSource",
|
||||
DataSource.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.info("Using Default Data Source for the JdbcCursorItemReader");
|
||||
|
||||
}
|
||||
return new JdbcCursorItemReaderBuilder<Map<String, Object>>()
|
||||
.name(this.properties.getName())
|
||||
.currentItemCount(this.properties.getCurrentItemCount())
|
||||
.dataSource(readerDataSource)
|
||||
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)
|
||||
.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();
|
||||
.useSharedExtendedConnection(this.properties.isUseSharedExtendedConnection()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -109,16 +101,19 @@ public class JdbcCursorItemReaderAutoConfiguration {
|
||||
return new MapRowMapper();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbccursoritemreader.datasource", name = "enable", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbccursoritemreader.datasource", name = "enable",
|
||||
havingValue = "true")
|
||||
@Bean(name = "jdbcCursorItemReaderDataSourceProperties")
|
||||
@ConfigurationProperties("jdbccursoritemreader.datasource")
|
||||
public DataSourceProperties jdbcCursorItemReaderDataSourceProperties() {
|
||||
return new DataSourceProperties();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbccursoritemreader.datasource", name = "enable", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job.jdbccursoritemreader.datasource", name = "enable",
|
||||
havingValue = "true")
|
||||
@Bean(name = "jdbcCursorItemReaderSpringDataSource")
|
||||
public DataSource readerDataSource(@Qualifier("jdbcCursorItemReaderDataSourceProperties")DataSourceProperties readerDataSourceProperties) {
|
||||
public DataSource readerDataSource(
|
||||
@Qualifier("jdbcCursorItemReaderDataSourceProperties") DataSourceProperties readerDataSourceProperties) {
|
||||
DataSource result = readerDataSourceProperties.initializeDataSourceBuilder().build();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -27,14 +27,15 @@ public class JdbcCursorItemReaderProperties {
|
||||
|
||||
/**
|
||||
* Configure whether the state of the
|
||||
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted
|
||||
* within the {@link org.springframework.batch.item.ExecutionContext} for
|
||||
* restart purposes. Defaults to {@code true}.
|
||||
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
|
||||
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
|
||||
* Defaults to {@code true}.
|
||||
*/
|
||||
private boolean saveState = true;
|
||||
|
||||
/**
|
||||
* Returns the configured value of the name used to calculate {@code ExecutionContext} keys.
|
||||
* Returns the configured value of the name used to calculate {@code ExecutionContext}
|
||||
* keys.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
@@ -83,8 +84,8 @@ public class JdbcCursorItemReaderProperties {
|
||||
|
||||
/**
|
||||
* Establishes whether the connection used for the cursor is being used by all other
|
||||
* processing and is, therefore, part of the same transaction.
|
||||
* Defaults to {@code false}
|
||||
* processing and is, therefore, part of the same transaction. Defaults to
|
||||
* {@code false}
|
||||
*/
|
||||
private boolean useSharedExtendedConnection;
|
||||
|
||||
|
||||
@@ -64,11 +64,9 @@ public class KafkaItemReaderAutoConfiguration {
|
||||
kafkaItemReaderProperties.getPartitions().add(0);
|
||||
}
|
||||
return new KafkaItemReaderBuilder<Object, Map<String, Object>>()
|
||||
.partitions(kafkaItemReaderProperties.getPartitions())
|
||||
.consumerProperties(consumerProperties)
|
||||
.partitions(kafkaItemReaderProperties.getPartitions()).consumerProperties(consumerProperties)
|
||||
.name(kafkaItemReaderProperties.getName())
|
||||
.pollTimeout(Duration
|
||||
.ofSeconds(kafkaItemReaderProperties.getPollTimeOutInSeconds()))
|
||||
.pollTimeout(Duration.ofSeconds(kafkaItemReaderProperties.getPollTimeOutInSeconds()))
|
||||
.saveState(kafkaItemReaderProperties.isSaveState()).topic(kafkaItemReaderProperties.getTopic()).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,14 +48,16 @@ public class KafkaItemReaderProperties {
|
||||
private List<Integer> partitions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Establish the {@code pollTimeout} for the {@code poll()} operations. Defaults to 30 seconds.
|
||||
* Establish the {@code pollTimeout} for the {@code poll()} operations. Defaults to 30
|
||||
* seconds.
|
||||
*/
|
||||
private long pollTimeOutInSeconds = 30L;
|
||||
|
||||
/**
|
||||
* Configure whether the state of the {@link org.springframework.batch.item.ItemStreamSupport}
|
||||
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
|
||||
* for restart purposes. Defaults to {@code true}.
|
||||
* Configure whether the state of the
|
||||
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
|
||||
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
|
||||
* Defaults to {@code true}.
|
||||
*/
|
||||
private boolean saveState = true;
|
||||
|
||||
@@ -127,10 +129,12 @@ public class KafkaItemReaderProperties {
|
||||
public void setPollTimeOutInSeconds(long pollTimeOutInSeconds) {
|
||||
this.pollTimeOutInSeconds = pollTimeOutInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
|
||||
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
|
||||
* for restart purposes. Defaults to true.
|
||||
* Configure if the state of the
|
||||
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
|
||||
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
|
||||
* Defaults to true.
|
||||
* @return current status of the saveState flag.
|
||||
*/
|
||||
public boolean isSaveState() {
|
||||
@@ -138,12 +142,13 @@ public class KafkaItemReaderProperties {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
|
||||
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
|
||||
* for restart purposes.
|
||||
* @param saveState true if state should be persisted. Defaults to true.
|
||||
* Configure if the state of the
|
||||
* {@link org.springframework.batch.item.ItemStreamSupport} should be persisted within
|
||||
* the {@link org.springframework.batch.item.ExecutionContext} for restart purposes.
|
||||
* @param saveState true if state should be persisted. Defaults to true.
|
||||
*/
|
||||
public void setSaveState(boolean saveState) {
|
||||
this.saveState = saveState;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,9 +65,8 @@ public class KafkaItemWriterAutoConfiguration {
|
||||
validateProperties(kafkaItemWriterProperties);
|
||||
KafkaTemplate template = new KafkaTemplate(producerFactory);
|
||||
template.setDefaultTopic(kafkaItemWriterProperties.getTopic());
|
||||
return new KafkaItemWriterBuilder<Object, Map<String, Object>>()
|
||||
.delete(kafkaItemWriterProperties.isDelete()).kafkaTemplate(template)
|
||||
.itemKeyMapper(itemKeyMapper).build();
|
||||
return new KafkaItemWriterBuilder<Object, Map<String, Object>>().delete(kafkaItemWriterProperties.isDelete())
|
||||
.kafkaTemplate(template).itemKeyMapper(itemKeyMapper).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -86,13 +85,11 @@ public class KafkaItemWriterAutoConfiguration {
|
||||
ProducerFactory<Object, Map<String, Object>> producerFactory() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
configs.putAll(this.kafkaProperties.getProducer().buildProperties());
|
||||
return new DefaultKafkaProducerFactory<>(configs, null,
|
||||
new JsonSerializer<>());
|
||||
return new DefaultKafkaProducerFactory<>(configs, null, new JsonSerializer<>());
|
||||
}
|
||||
|
||||
private void validateProperties(KafkaItemWriterProperties kafkaItemWriterProperties) {
|
||||
Assert.hasText(kafkaItemWriterProperties.getTopic(),
|
||||
"topic must not be empty or null");
|
||||
Assert.hasText(kafkaItemWriterProperties.getTopic(), "topic must not be empty or null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(AmqpItemReaderProperties.class)
|
||||
@AutoConfigureAfter(BatchAutoConfiguration.class)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemreader.enabled",
|
||||
havingValue = "true", matchIfMissing = false)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemreader.enabled", havingValue = "true", matchIfMissing = false)
|
||||
public class AmqpItemReaderAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
@@ -65,8 +64,8 @@ public class AmqpItemReaderAutoConfiguration {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemreader.jsonConverterEnabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemreader.jsonConverterEnabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
|
||||
@@ -40,14 +40,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(AmqpItemWriterProperties.class)
|
||||
@AutoConfigureAfter(BatchAutoConfiguration.class)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemwriter.enabled",
|
||||
havingValue = "true", matchIfMissing = false)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemwriter.enabled", havingValue = "true", matchIfMissing = false)
|
||||
public class AmqpItemWriterAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public AmqpItemWriter<Map<String, Object>> amqpItemWriter(AmqpTemplate amqpTemplate) {
|
||||
return new AmqpItemWriterBuilder<Map<String, Object>>().amqpTemplate(amqpTemplate)
|
||||
.build();
|
||||
return new AmqpItemWriterBuilder<Map<String, Object>>().amqpTemplate(amqpTemplate).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -55,8 +53,8 @@ public class AmqpItemWriterAutoConfiguration {
|
||||
return new AmqpItemWriterProperties();
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemwriter.jsonConverterEnabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(name = "spring.batch.job.amqpitemwriter.jsonConverterEnabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
|
||||
@@ -47,7 +47,8 @@ public class AmqpItemWriterProperties {
|
||||
|
||||
/**
|
||||
* Enables or disables the {@code AmqpItemWriter}.
|
||||
* @param enabled if {@code true} then {@code AmqpItemWriter} is enabled. Defaults to {@code false}.
|
||||
* @param enabled if {@code true} then {@code AmqpItemWriter} is enabled. Defaults to
|
||||
* {@code false}.
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
|
||||
@@ -91,8 +91,7 @@ public class SingleStepJobAutoConfigurationTests {
|
||||
new SingleStepJobAutoConfiguration(null, null, properties, null);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage())
|
||||
.isEqualTo("A chunk size greater than zero is required");
|
||||
assertThat(iae.getMessage()).isEqualTo("A chunk size greater than zero is required");
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("wrong exception was thrown", t);
|
||||
@@ -106,12 +105,9 @@ public class SingleStepJobAutoConfigurationTests {
|
||||
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",
|
||||
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);
|
||||
@@ -120,17 +116,14 @@ 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);
|
||||
validateConfiguration(applicationContextRunner);
|
||||
}
|
||||
|
||||
private void validateConfiguration(ApplicationContextRunner applicationContextRunner) {
|
||||
|
||||
@@ -76,15 +76,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -134,15 +130,12 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -195,14 +188,11 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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");
|
||||
@@ -234,16 +224,13 @@ 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",
|
||||
.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",
|
||||
@@ -267,8 +254,7 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
ListLineCallbackHandler callbackHandler = context
|
||||
.getBean(ListLineCallbackHandler.class);
|
||||
ListLineCallbackHandler callbackHandler = context.getBean(ListLineCallbackHandler.class);
|
||||
|
||||
assertThat(callbackHandler.getLines().size()).isEqualTo(2);
|
||||
|
||||
@@ -282,14 +268,12 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -329,8 +313,7 @@ public class FlatFileItemReaderAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public LineTokenizer lineTokenizer() {
|
||||
return line -> new DefaultFieldSet(
|
||||
new String[] { line.substring(0, 5), line.substring(6) },
|
||||
return line -> new DefaultFieldSet(new String[] { line.substring(0, 5), line.substring(6) },
|
||||
new String[] { "one", "two" });
|
||||
}
|
||||
|
||||
|
||||
@@ -82,17 +82,15 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
properties.setFormatted(true);
|
||||
properties.setDelimited(true);
|
||||
|
||||
FlatFileItemWriterAutoConfiguration configuration = new FlatFileItemWriterAutoConfiguration(
|
||||
properties);
|
||||
FlatFileItemWriterAutoConfiguration configuration = new FlatFileItemWriterAutoConfiguration(properties);
|
||||
|
||||
try {
|
||||
configuration.itemWriter();
|
||||
fail("Exception should have been thrown when both formatted and delimited are selected");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertThat(ise.getMessage()).isEqualTo(
|
||||
"An output file must be either delimited or formatted or a custom "
|
||||
+ "LineAggregator must be provided. Your current configuration specifies both delimited and formatted");
|
||||
assertThat(ise.getMessage()).isEqualTo("An output file must be either delimited or formatted or a custom "
|
||||
+ "LineAggregator must be provided. Your current configuration specifies both delimited and formatted");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception thrown", e);
|
||||
@@ -101,8 +99,7 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
properties.setFormatted(true);
|
||||
properties.setDelimited(false);
|
||||
|
||||
ReflectionTestUtils.setField(configuration, "lineAggregator",
|
||||
new PassThroughLineAggregator<>());
|
||||
ReflectionTestUtils.setField(configuration, "lineAggregator", new PassThroughLineAggregator<>());
|
||||
|
||||
try {
|
||||
configuration.itemWriter();
|
||||
@@ -110,8 +107,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);
|
||||
@@ -126,8 +122,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);
|
||||
@@ -138,16 +133,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -178,15 +169,11 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
AssertFile.assertFileEquals(new ClassPathResource("writerTestUTF16.txt"),
|
||||
new FileSystemResource(this.outputFile));
|
||||
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "saveState"))
|
||||
.isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "saveState")).isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "append")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "forceSync"))
|
||||
.isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer,
|
||||
"shouldDeleteIfExists")).isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "transactional"))
|
||||
.isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "forceSync")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "shouldDeleteIfExists")).isFalse();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "transactional")).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -194,17 +181,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -228,8 +210,8 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
AssertFile.assertLineCount(2, this.outputFile);
|
||||
|
||||
String results = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileSystemResource(this.outputFile).getInputStream()));
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("item = foo\nitem = bar\n");
|
||||
});
|
||||
}
|
||||
@@ -238,17 +220,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -270,8 +247,8 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
|
||||
String results = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileSystemResource(this.outputFile).getInputStream()));
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("item = f\nitem = b\nitem = b\n");
|
||||
});
|
||||
}
|
||||
@@ -280,17 +257,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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");
|
||||
@@ -310,8 +282,8 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
|
||||
String results = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileSystemResource(this.outputFile).getInputStream()));
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("f\nb\nb\n");
|
||||
});
|
||||
}
|
||||
@@ -320,17 +292,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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");
|
||||
|
||||
@@ -349,8 +316,8 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
AssertFile.assertLineCount(3, this.outputFile);
|
||||
|
||||
String results = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileSystemResource(this.outputFile).getInputStream()));
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("{item=foo}\n{item=bar}\n{item=baz}\n");
|
||||
});
|
||||
}
|
||||
@@ -359,17 +326,12 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
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",
|
||||
.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",
|
||||
@@ -390,8 +352,8 @@ public class FlatFileItemWriterAutoConfigurationTests {
|
||||
|
||||
AssertFile.assertLineCount(5, this.outputFile);
|
||||
|
||||
String results = FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileSystemResource(this.outputFile).getInputStream()));
|
||||
String results = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileSystemResource(this.outputFile).getInputStream()));
|
||||
assertThat(results).isEqualTo("header\nfoo\nbar\nbaz\nfooter");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
|
||||
static {
|
||||
randomPort = TestSocketUtils.findAvailableTcpPort();
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort
|
||||
+ "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE";
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
|
||||
+ "DB_CLOSE_ON_EXIT=FALSE";
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -100,43 +100,35 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void baseTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskLauncherConfiguration.class,
|
||||
JdbcBatchItemWriterAutoConfigurationTests.DelimitedJobConfiguration.class
|
||||
)
|
||||
.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");
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
|
||||
runTest(applicationContextRunner, false);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
@@ -144,16 +136,13 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void customSqlParameterSourceTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskLauncherConfiguration.class,
|
||||
.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");
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
|
||||
runTest(applicationContextRunner, false);
|
||||
@@ -162,22 +151,18 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
@Test
|
||||
public void preparedStatementSetterTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
TaskLauncherConfiguration.class,
|
||||
.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");
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, JdbcBatchItemWriterAutoConfiguration.class))
|
||||
.withPropertyValues("spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
applicationContextRunner = updatePropertiesForTest(applicationContextRunner);
|
||||
runTest(applicationContextRunner, false);
|
||||
}
|
||||
|
||||
private ApplicationContextRunner updatePropertiesForTest(
|
||||
ApplicationContextRunner applicationContextRunner) {
|
||||
private ApplicationContextRunner updatePropertiesForTest(ApplicationContextRunner applicationContextRunner) {
|
||||
return applicationContextRunner.withPropertyValues("spring.batch.job.jobName=job",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.jdbcbatchitemwriter.name=fooWriter",
|
||||
@@ -194,8 +179,7 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
dataSource = context.getBean("jdbcBatchItemWriterSpringDataSource", DataSource.class);
|
||||
}
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
List<Map<String, Object>> result = jdbcTemplate
|
||||
.queryForList("SELECT item_name FROM item ORDER BY item_name");
|
||||
List<Map<String, Object>> result = jdbcTemplate.queryForList("SELECT item_name FROM item ORDER BY item_name");
|
||||
assertThat(result.size()).isEqualTo(3);
|
||||
|
||||
assertThat(result.get(0).get("item_name")).isEqualTo("bar");
|
||||
@@ -203,16 +187,13 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
assertThat(result.get(2).get("item_name")).isEqualTo("foo");
|
||||
|
||||
JdbcBatchItemWriter writer = context.getBean(JdbcBatchItemWriter.class);
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "assertUpdates"))
|
||||
.isTrue();
|
||||
assertThat((Integer) ReflectionTestUtils.getField(writer, "parameterCount"))
|
||||
.isEqualTo(1);
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "usingNamedParameters"))
|
||||
.isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "assertUpdates")).isTrue();
|
||||
assertThat((Integer) ReflectionTestUtils.getField(writer, "parameterCount")).isEqualTo(1);
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(writer, "usingNamedParameters")).isTrue();
|
||||
if (!isWriterDataSourcePresent) {
|
||||
assertThatThrownBy(() -> context.getBean("jdbcBatchItemWriterSpringDataSource"))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'jdbcBatchItemWriterSpringDataSource' available");
|
||||
assertThatThrownBy(() -> context.getBean("jdbcBatchItemWriterSpringDataSource"))
|
||||
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||
.hasMessageContaining("No bean named 'jdbcBatchItemWriterSpringDataSource' available");
|
||||
}
|
||||
else {
|
||||
assertThat(context.getBean("jdbcBatchItemWriterSpringDataSource")).isNotNull();
|
||||
@@ -247,19 +228,16 @@ 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);
|
||||
dataSource.setUrl(DATASOURCE_URL);
|
||||
dataSource.setUsername(DATASOURCE_USER_NAME);
|
||||
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
|
||||
ClassPathResource setupResource = new ClassPathResource(
|
||||
"schema-h2.sql");
|
||||
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(
|
||||
setupResource);
|
||||
ClassPathResource setupResource = new ClassPathResource("schema-h2.sql");
|
||||
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(setupResource);
|
||||
resourceDatabasePopulator.execute(dataSource);
|
||||
}
|
||||
}
|
||||
@@ -340,11 +318,9 @@ public class JdbcBatchItemWriterAutoConfigurationTests {
|
||||
public ItemPreparedStatementSetter itemPreparedStatementSetter() {
|
||||
return new ItemPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(Object item, PreparedStatement ps)
|
||||
throws SQLException {
|
||||
public void setValues(Object item, PreparedStatement ps) throws SQLException {
|
||||
Map<String, Object> mapItem = (Map<String, Object>) item;
|
||||
StatementCreatorUtils.setParameterValue(ps, 1,
|
||||
SqlTypeValue.TYPE_UNKNOWN, mapItem.get("item_name"));
|
||||
StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, mapItem.get("item_name"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
|
||||
static {
|
||||
randomPort = TestSocketUtils.findAvailableTcpPort();
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort
|
||||
+ "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE";
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
|
||||
+ "DB_CLOSE_ON_EXIT=FALSE";
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -93,13 +93,12 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testIntegration() {
|
||||
ApplicationContextRunner applicationContextRunner = applicationContextRunner()
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationJob",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select item_name from item",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
ApplicationContextRunner applicationContextRunner = applicationContextRunner().withPropertyValues(
|
||||
"spring.batch.job.jobName=integrationJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select item_name from item",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false");
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -114,38 +113,32 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class)
|
||||
.getWrittenItems();
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class).getWrittenItems();
|
||||
|
||||
assertThat(items.size()).isEqualTo(3);
|
||||
assertThat(items.get(0).get("ITEM_NAME")).isEqualTo("foo");
|
||||
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
|
||||
public void testIntegrationReaderDataSourceEnabled() {
|
||||
ApplicationContextRunner applicationContextRunner = applicationContextRunner()
|
||||
.withPropertyValues("spring.batch.job.jobName=integrationReaderJob",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
ApplicationContextRunner applicationContextRunner = applicationContextRunner().withPropertyValues(
|
||||
"spring.batch.job.jobName=integrationReaderJob", "spring.batch.job.stepName=step1",
|
||||
"spring.batch.job.chunkSize=5", "spring.batch.job.jdbccursoritemreader.name=fooReader",
|
||||
"spring.batch.job.jdbccursoritemreader.sql=select item_name from item",
|
||||
"spring.batch.jdbc.initialize-schema=always",
|
||||
"spring.batch.job.jdbcsinglestep.datasource.enable=false",
|
||||
"spring.batch.jdbc.initialize-schema=always", "spring.batch.job.jdbcsinglestep.datasource.enable=false",
|
||||
"spring.batch.job.jdbccursoritemreader.datasource.enable=true",
|
||||
"jdbccursoritemreader.datasource.url=" + DATASOURCE_URL,
|
||||
"jdbccursoritemreader.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
@@ -165,8 +158,7 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class)
|
||||
.getWrittenItems();
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class).getWrittenItems();
|
||||
|
||||
assertThat(items.size()).isEqualTo(3);
|
||||
assertThat(items.get(0).get("ITEM_NAME")).isEqualTo("foo");
|
||||
@@ -181,13 +173,10 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
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");
|
||||
@@ -205,8 +194,7 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class)
|
||||
.getWrittenItems();
|
||||
List<Map<String, Object>> items = context.getBean(ListItemWriter.class).getWrittenItems();
|
||||
|
||||
assertThat(items.size()).isEqualTo(3);
|
||||
assertThat(items.get(0).get("item")).isEqualTo("foo");
|
||||
@@ -220,13 +208,10 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
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",
|
||||
@@ -241,8 +226,7 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
JdbcCursorItemReader<Map<String, Object>> itemReader = context
|
||||
.getBean(JdbcCursorItemReader.class);
|
||||
JdbcCursorItemReader<Map<String, Object>> itemReader = context.getBean(JdbcCursorItemReader.class);
|
||||
|
||||
validateBean(itemReader);
|
||||
});
|
||||
@@ -251,31 +235,19 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
private void validateBean(JdbcCursorItemReader itemReader) {
|
||||
assertThat(itemReader.getSql()).isEqualTo("select * from foo");
|
||||
assertThat(itemReader.getDataSource()).isNotNull();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "saveState"))
|
||||
.isFalse();
|
||||
assertThat(
|
||||
ReflectionTestUtils.getField(
|
||||
(ExecutionContextUserSupport) ReflectionTestUtils
|
||||
.getField(itemReader, "executionContextUserSupport"),
|
||||
"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);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "maxRows"))
|
||||
.isEqualTo(6);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "queryTimeout"))
|
||||
.isEqualTo(8);
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "ignoreWarnings"))
|
||||
.isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader,
|
||||
"verifyCursorPosition")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader,
|
||||
"driverSupportsAbsolute")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader,
|
||||
"useSharedExtendedConnection")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "saveState")).isFalse();
|
||||
assertThat(ReflectionTestUtils.getField(
|
||||
(ExecutionContextUserSupport) ReflectionTestUtils.getField(itemReader, "executionContextUserSupport"),
|
||||
"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);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "maxRows")).isEqualTo(6);
|
||||
assertThat((Integer) ReflectionTestUtils.getField(itemReader, "queryTimeout")).isEqualTo(8);
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "ignoreWarnings")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "verifyCursorPosition")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "driverSupportsAbsolute")).isTrue();
|
||||
assertThat((Boolean) ReflectionTestUtils.getField(itemReader, "useSharedExtendedConnection")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,18 +255,14 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
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);
|
||||
}).isInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("UnsatisfiedDependencyException");
|
||||
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("UnsatisfiedDependencyException");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,18 +270,14 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
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");
|
||||
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);
|
||||
}).isInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("UnsatisfiedDependencyException");
|
||||
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("UnsatisfiedDependencyException");
|
||||
}
|
||||
|
||||
private void runTest(ApplicationContextRunner applicationContextRunner) {
|
||||
@@ -332,7 +296,8 @@ public class JdbcCursorItemReaderAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@AutoConfigureBefore({JdbcCursorItemReaderAutoConfiguration.class, JDBCSingleStepDataSourceAutoConfiguration.class})
|
||||
@AutoConfigureBefore({ JdbcCursorItemReaderAutoConfiguration.class,
|
||||
JDBCSingleStepDataSourceAutoConfiguration.class })
|
||||
@Configuration
|
||||
public static class TaskLauncherConfiguration {
|
||||
|
||||
@@ -343,19 +308,16 @@ 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);
|
||||
dataSource.setUrl(DATASOURCE_URL);
|
||||
dataSource.setUsername(DATASOURCE_USER_NAME);
|
||||
dataSource.setPassword(DATASOURCE_USER_PASSWORD);
|
||||
ClassPathResource setupResource = new ClassPathResource(
|
||||
"schema-h2.sql");
|
||||
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(
|
||||
setupResource);
|
||||
ClassPathResource setupResource = new ClassPathResource("schema-h2.sql");
|
||||
ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(setupResource);
|
||||
resourceDatabasePopulator.setContinueOnError(true);
|
||||
resourceDatabasePopulator.execute(dataSource);
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
@BeforeAll
|
||||
public static void setupTest(EmbeddedKafkaBroker embeddedKafka) {
|
||||
embeddedKafkaBroker = embeddedKafka;
|
||||
embeddedKafka.addTopics(new NewTopic("topic1", 1, (short) 1),
|
||||
new NewTopic("topic2", 2, (short) 1),
|
||||
embeddedKafka.addTopics(new NewTopic("topic1", 1, (short) 1), new NewTopic("topic2", 2, (short) 1),
|
||||
new NewTopic("topic3", 1, (short) 1));
|
||||
}
|
||||
|
||||
@@ -72,22 +71,16 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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());
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -120,23 +113,17 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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());
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -163,21 +150,15 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
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",
|
||||
.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());
|
||||
"spring.kafka.consumer.value-deserializer=" + JsonDeserializer.class.getName());
|
||||
Date startTime = new Date();
|
||||
applicationContextRunner.run((context) -> {
|
||||
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
|
||||
@@ -212,10 +193,9 @@ 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();
|
||||
Map<String, Object> configps = new HashMap<>(KafkaTestUtils.producerProps(embeddedKafkaBroker));
|
||||
Producer<String, Object> producer = new DefaultKafkaProducerFactory<>(configps, new StringSerializer(),
|
||||
new JsonSerializer<>()).createProducer();
|
||||
Map<String, Object> testMap = new HashMap<>();
|
||||
testMap.put("first_name", "jane");
|
||||
producer.send(new ProducerRecord<>(topic, "my-aggregate-id", testMap));
|
||||
@@ -235,10 +215,12 @@ public class KafkaItemReaderAutoConfigurationTests {
|
||||
@EnableBatchProcessing
|
||||
@Configuration
|
||||
public static class CustomMappingConfiguration {
|
||||
|
||||
@Bean
|
||||
public ListItemWriter<Map<String, Object>> itemWriter() {
|
||||
return new ListItemWriter<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,16 +68,12 @@ public class KafkaItemWriterTests {
|
||||
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(),
|
||||
.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);
|
||||
|
||||
@@ -88,14 +84,12 @@ 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();
|
||||
Map<String, Object> configs = new HashMap<>(KafkaTestUtils.consumerProps("1", "false", embeddedKafkaBroker));
|
||||
Consumer<String, Object> consumer = new DefaultKafkaConsumerFactory<>(configs, new StringDeserializer(),
|
||||
new JsonDeserializer<>()).createConsumer();
|
||||
consumer.subscribe(singleton(topicName));
|
||||
|
||||
ConsumerRecords<String, Object> consumerRecords = KafkaTestUtils
|
||||
.getRecords(consumer);
|
||||
ConsumerRecords<String, Object> consumerRecords = KafkaTestUtils.getRecords(consumer);
|
||||
assertThat(consumerRecords.count()).isEqualTo(5);
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
consumerRecords.forEach(cs -> {
|
||||
@@ -137,8 +131,7 @@ public class KafkaItemWriterTests {
|
||||
return new ListItemReader<>(list);
|
||||
}
|
||||
|
||||
private void addNameToReaderList(List<Map<String, Object>> itemReaderList,
|
||||
String value) {
|
||||
private void addNameToReaderList(List<Map<String, Object>> itemReaderList, String value) {
|
||||
Map<String, Object> prepMap = new HashMap<>();
|
||||
prepMap.put("first_name", value);
|
||||
itemReaderList.add(prepMap);
|
||||
|
||||
@@ -68,8 +68,7 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
static {
|
||||
GenericContainer rabbitmq = new RabbitMQContainer("rabbitmq:3.8.9")
|
||||
.withExposedPorts(5672);
|
||||
GenericContainer rabbitmq = new RabbitMQContainer("rabbitmq:3.8.9").withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
host = rabbitmq.getHost();
|
||||
@@ -107,17 +106,12 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
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,
|
||||
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) -> {
|
||||
@@ -138,17 +132,12 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
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,
|
||||
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) -> {
|
||||
@@ -167,17 +156,12 @@ public class AmqpItemReaderAutoConfigurationTests {
|
||||
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);
|
||||
.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);
|
||||
|
||||
@@ -81,8 +81,7 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
private String[] configurations;
|
||||
|
||||
static {
|
||||
GenericContainer rabbitmq = new RabbitMQContainer("rabbitmq:3.8.9")
|
||||
.withExposedPorts(5672);
|
||||
GenericContainer rabbitmq = new RabbitMQContainer("rabbitmq:3.8.9").withExposedPorts(5672);
|
||||
rabbitmq.start();
|
||||
final Integer mappedPort = rabbitmq.getMappedPort(5672);
|
||||
host = rabbitmq.getHost();
|
||||
@@ -95,8 +94,7 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
addNameToReaderList(sampleData, "Judy");
|
||||
}
|
||||
|
||||
private static void addNameToReaderList(List<Map<String, Object>> itemReaderList,
|
||||
String value) {
|
||||
private static void addNameToReaderList(List<Map<String, Object>> itemReaderList, String value) {
|
||||
Map<String, Object> prepMap = new HashMap<>();
|
||||
prepMap.put("first_name", value);
|
||||
itemReaderList.add(prepMap);
|
||||
@@ -110,14 +108,11 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
AmqpAdmin admin = new RabbitAdmin(this.connectionFactory);
|
||||
admin.declareQueue(new Queue(QUEUE_NAME));
|
||||
admin.declareExchange(new TopicExchange(EXCHANGE_NAME));
|
||||
admin.declareBinding(new Binding(QUEUE_NAME, Binding.DestinationType.QUEUE,
|
||||
EXCHANGE_NAME, "#", null));
|
||||
admin.declareBinding(new Binding(QUEUE_NAME, Binding.DestinationType.QUEUE, EXCHANGE_NAME, "#", null));
|
||||
this.configurations = new String[] { "spring.batch.job.jobName=integrationJob",
|
||||
"spring.batch.job.stepName=step1", "spring.batch.job.chunkSize=5",
|
||||
"spring.rabbitmq.template.exchange=" + EXCHANGE_NAME,
|
||||
"spring.rabbitmq.host=" + host,
|
||||
"spring.batch.job.amqpitemwriter.enabled=true",
|
||||
"spring.rabbitmq.port=" + amqpPort };
|
||||
"spring.rabbitmq.template.exchange=" + EXCHANGE_NAME, "spring.rabbitmq.host=" + host,
|
||||
"spring.batch.job.amqpitemwriter.enabled=true", "spring.rabbitmq.port=" + amqpPort };
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -132,12 +127,9 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(BaseConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemWriterAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class,
|
||||
DataSourceAutoConfiguration.class))
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class, AmqpItemWriterAutoConfiguration.class,
|
||||
RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
@@ -149,10 +141,8 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
}
|
||||
|
||||
for (Map<String, Object> sampleEntry : sampleData) {
|
||||
Map<String, Object> map = (Map<String, Object>) template
|
||||
.receiveAndConvert(QUEUE_NAME);
|
||||
assertThat(map.get("first_name"))
|
||||
.isEqualTo(sampleEntry.get("first_name"));
|
||||
Map<String, Object> map = (Map<String, Object>) template.receiveAndConvert(QUEUE_NAME);
|
||||
assertThat(map.get("first_name")).isEqualTo(sampleEntry.get("first_name"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -161,12 +151,9 @@ public class AmqpItemWriterAutoConfigurationTests {
|
||||
void useAmqpTemplateTest() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(MockConfiguration.class)
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class,
|
||||
SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemWriterAutoConfiguration.class,
|
||||
DataSourceAutoConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, SingleStepJobAutoConfiguration.class,
|
||||
AmqpItemWriterAutoConfiguration.class, DataSourceAutoConfiguration.class))
|
||||
.withPropertyValues(this.configurations);
|
||||
|
||||
applicationContextRunner.run((context) -> {
|
||||
|
||||
@@ -31,14 +31,12 @@ public class JobLaunchCondition extends AllNestedConditions {
|
||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure",
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(name = "spring.cloud.task.batch.fail-on-job-failure", havingValue = "true")
|
||||
static class FailOnJobFailureCondition {
|
||||
|
||||
}
|
||||
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
static class SpringBatchJobCondition {
|
||||
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnBean({Job.class, TaskLifecycleListener.class})
|
||||
@ConditionalOnProperty(
|
||||
name = { "spring.cloud.task.batch.listener.enable",
|
||||
"spring.cloud.task.batch.listener.enabled" },
|
||||
@ConditionalOnBean({ Job.class, TaskLifecycleListener.class })
|
||||
@ConditionalOnProperty(name = { "spring.cloud.task.batch.listener.enable", "spring.cloud.task.batch.listener.enabled" },
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
public class TaskBatchAutoConfiguration {
|
||||
|
||||
@@ -68,15 +66,13 @@ public class TaskBatchAutoConfiguration {
|
||||
private TaskProperties taskProperties;
|
||||
|
||||
@Bean
|
||||
public TaskBatchExecutionListenerFactoryBean taskBatchExecutionListener(
|
||||
TaskExplorer taskExplorer) {
|
||||
public TaskBatchExecutionListenerFactoryBean taskBatchExecutionListener(TaskExplorer taskExplorer) {
|
||||
TaskConfigurer taskConfigurer = null;
|
||||
if (!this.context.getBeansOfType(TaskConfigurer.class).isEmpty()) {
|
||||
taskConfigurer = this.context.getBean(TaskConfigurer.class);
|
||||
}
|
||||
if (taskConfigurer != null && taskConfigurer.getTaskDataSource() != null) {
|
||||
return new TaskBatchExecutionListenerFactoryBean(
|
||||
taskConfigurer.getTaskDataSource(), taskExplorer,
|
||||
return new TaskBatchExecutionListenerFactoryBean(taskConfigurer.getTaskDataSource(), taskExplorer,
|
||||
this.taskProperties.getTablePrefix());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -43,28 +43,24 @@ public class TaskBatchExecutionListenerBeanPostProcessor implements BeanPostProc
|
||||
private List<String> jobNames = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (this.jobNames.size() > 0 && !this.jobNames.contains(beanName)) {
|
||||
return bean;
|
||||
}
|
||||
int length = this.applicationContext
|
||||
.getBeanNamesForType(TaskBatchExecutionListener.class).length;
|
||||
int length = this.applicationContext.getBeanNamesForType(TaskBatchExecutionListener.class).length;
|
||||
|
||||
if (bean instanceof AbstractJob) {
|
||||
if (length != 1) {
|
||||
throw new IllegalStateException("The application context is required to "
|
||||
+ "have exactly 1 instance of the TaskBatchExecutionListener but has "
|
||||
+ length);
|
||||
+ "have exactly 1 instance of the TaskBatchExecutionListener but has " + length);
|
||||
}
|
||||
((AbstractJob) bean).registerJobExecutionListener(
|
||||
this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
((AbstractJob) bean)
|
||||
.registerJobExecutionListener(this.applicationContext.getBean(TaskBatchExecutionListener.class));
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class TaskBatchExecutionListenerFactoryBean
|
||||
implements FactoryBean<TaskBatchExecutionListener> {
|
||||
public class TaskBatchExecutionListenerFactoryBean implements FactoryBean<TaskBatchExecutionListener> {
|
||||
|
||||
private TaskBatchExecutionListener listener;
|
||||
|
||||
@@ -57,8 +56,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
* @param dataSource the dataSource to use for the TaskBatchExecutionListener.
|
||||
* @param taskExplorer the taskExplorer to use for the TaskBatchExecutionListener.
|
||||
*/
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource,
|
||||
TaskExplorer taskExplorer) {
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource, TaskExplorer taskExplorer) {
|
||||
this.dataSource = dataSource;
|
||||
this.taskExplorer = taskExplorer;
|
||||
}
|
||||
@@ -70,8 +68,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
* @param tablePrefix the prefix for the task tables accessed by the
|
||||
* TaskBatchExecutionListener.
|
||||
*/
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource,
|
||||
TaskExplorer taskExplorer, String tablePrefix) {
|
||||
public TaskBatchExecutionListenerFactoryBean(DataSource dataSource, TaskExplorer taskExplorer, String tablePrefix) {
|
||||
this(dataSource, taskExplorer);
|
||||
Assert.hasText(tablePrefix, "tablePrefix must not be null nor empty.");
|
||||
this.tablePrefix = tablePrefix;
|
||||
@@ -86,8 +83,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
this.listener = new TaskBatchExecutionListener(getMapTaskBatchDao());
|
||||
}
|
||||
else {
|
||||
this.listener = new TaskBatchExecutionListener(
|
||||
new JdbcTaskBatchDao(this.dataSource, this.tablePrefix));
|
||||
this.listener = new TaskBatchExecutionListener(new JdbcTaskBatchDao(this.dataSource, this.tablePrefix));
|
||||
}
|
||||
|
||||
return this.listener;
|
||||
@@ -104,8 +100,7 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
}
|
||||
|
||||
private MapTaskBatchDao getMapTaskBatchDao() throws Exception {
|
||||
Field taskExecutionDaoField = ReflectionUtils.findField(SimpleTaskExplorer.class,
|
||||
"taskExecutionDao");
|
||||
Field taskExecutionDaoField = ReflectionUtils.findField(SimpleTaskExplorer.class, "taskExecutionDao");
|
||||
taskExecutionDaoField.setAccessible(true);
|
||||
|
||||
MapTaskExecutionDao taskExecutionDao;
|
||||
@@ -114,12 +109,11 @@ public class TaskBatchExecutionListenerFactoryBean
|
||||
SimpleTaskExplorer dereferencedTaskRepository = (SimpleTaskExplorer) ((Advised) this.taskExplorer)
|
||||
.getTargetSource().getTarget();
|
||||
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils
|
||||
.getField(taskExecutionDaoField, dereferencedTaskRepository);
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField,
|
||||
dereferencedTaskRepository);
|
||||
}
|
||||
else {
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils
|
||||
.getField(taskExecutionDaoField, this.taskExplorer);
|
||||
taskExecutionDao = (MapTaskExecutionDao) ReflectionUtils.getField(taskExecutionDaoField, this.taskExplorer);
|
||||
}
|
||||
|
||||
return new MapTaskBatchDao(taskExecutionDao.getBatchJobAssociations());
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Glenn Renfro
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
implements FactoryBean<TaskJobLauncherApplicationRunner> {
|
||||
public class TaskJobLauncherApplicationRunnerFactoryBean implements FactoryBean<TaskJobLauncherApplicationRunner> {
|
||||
|
||||
private JobLauncher jobLauncher;
|
||||
|
||||
@@ -54,10 +53,9 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, List<Job> jobs,
|
||||
TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry,
|
||||
JobRepository jobRepository, BatchProperties batchProperties) {
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean(JobLauncher jobLauncher, JobExplorer jobExplorer, List<Job> jobs,
|
||||
TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
BatchProperties batchProperties) {
|
||||
Assert.notNull(taskBatchProperties, "taskBatchProperties must not be null");
|
||||
Assert.notNull(batchProperties, "batchProperties must not be null");
|
||||
Assert.notEmpty(jobs, "jobs must not be null nor empty");
|
||||
@@ -85,8 +83,7 @@ public class TaskJobLauncherApplicationRunnerFactoryBean
|
||||
@Override
|
||||
public TaskJobLauncherApplicationRunner getObject() {
|
||||
TaskJobLauncherApplicationRunner taskJobLauncherApplicationRunner = new TaskJobLauncherApplicationRunner(
|
||||
this.jobLauncher, this.jobExplorer, this.jobRepository,
|
||||
this.taskBatchProperties);
|
||||
this.jobLauncher, this.jobExplorer, this.jobRepository, this.taskBatchProperties);
|
||||
taskJobLauncherApplicationRunner.setJobs(this.jobs);
|
||||
if (StringUtils.hasText(this.jobName)) {
|
||||
taskJobLauncherApplicationRunner.setJobName(this.jobName);
|
||||
|
||||
@@ -49,16 +49,13 @@ public class TaskJobLauncherAutoConfiguration {
|
||||
private TaskBatchProperties properties;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnClass(
|
||||
name = "org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner")
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunner(
|
||||
JobLauncher jobLauncher, JobExplorer jobExplorer, List<Job> jobs,
|
||||
JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
@ConditionalOnClass(name = "org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner")
|
||||
public TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunner(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, List<Job> jobs, JobRegistry jobRegistry, JobRepository jobRepository,
|
||||
BatchProperties batchProperties) {
|
||||
TaskJobLauncherApplicationRunnerFactoryBean taskJobLauncherApplicationRunnerFactoryBean;
|
||||
taskJobLauncherApplicationRunnerFactoryBean = new TaskJobLauncherApplicationRunnerFactoryBean(
|
||||
jobLauncher, jobExplorer, jobs, this.properties, jobRegistry,
|
||||
jobRepository, batchProperties);
|
||||
taskJobLauncherApplicationRunnerFactoryBean = new TaskJobLauncherApplicationRunnerFactoryBean(jobLauncher,
|
||||
jobExplorer, jobs, this.properties, jobRegistry, jobRepository, batchProperties);
|
||||
|
||||
return taskJobLauncherApplicationRunnerFactoryBean;
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunner {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(TaskJobLauncherApplicationRunner.class);
|
||||
private static final Log logger = LogFactory.getLog(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
private JobLauncher taskJobLauncher;
|
||||
|
||||
@@ -93,9 +92,8 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
* @param taskBatchProperties the properties used to configure the
|
||||
* taskBatchProperties.
|
||||
*/
|
||||
public TaskJobLauncherApplicationRunner(JobLauncher jobLauncher,
|
||||
JobExplorer jobExplorer, JobRepository jobRepository,
|
||||
TaskBatchProperties taskBatchProperties) {
|
||||
public TaskJobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository, TaskBatchProperties taskBatchProperties) {
|
||||
super(jobLauncher, jobExplorer, jobRepository);
|
||||
this.taskJobLauncher = jobLauncher;
|
||||
this.taskJobExplorer = jobExplorer;
|
||||
@@ -115,18 +113,14 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
monitorJobExecutions();
|
||||
}
|
||||
|
||||
protected void execute(Job job, JobParameters jobParameters)
|
||||
throws JobExecutionAlreadyRunningException, JobRestartException,
|
||||
JobInstanceAlreadyCompleteException, JobParametersInvalidException {
|
||||
protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
|
||||
JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
|
||||
String jobName = job.getName();
|
||||
JobParameters parameters = jobParameters;
|
||||
boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName,
|
||||
parameters);
|
||||
boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName, parameters);
|
||||
if (jobInstanceExists) {
|
||||
JobExecution lastJobExecution = this.taskJobRepository
|
||||
.getLastJobExecution(jobName, jobParameters);
|
||||
if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution)
|
||||
&& job.isRestartable()) {
|
||||
JobExecution lastJobExecution = this.taskJobRepository.getLastJobExecution(jobName, jobParameters);
|
||||
if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution) && job.isRestartable()) {
|
||||
// Retry a failed or stopped execution with previous parameters
|
||||
JobParameters previousParameters = lastJobExecution.getJobParameters();
|
||||
/*
|
||||
@@ -135,8 +129,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
* they are required (or need to be modified) on a restart, they need to
|
||||
* be (re)specified.
|
||||
*/
|
||||
JobParameters previousIdentifyingParameters = removeNonIdentifying(
|
||||
previousParameters);
|
||||
JobParameters previousIdentifyingParameters = removeNonIdentifying(previousParameters);
|
||||
// merge additional parameters with previous ones (overriding those with
|
||||
// the same key)
|
||||
parameters = merge(previousIdentifyingParameters, jobParameters);
|
||||
@@ -145,15 +138,14 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
else {
|
||||
JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
|
||||
if (incrementer != null) {
|
||||
JobParameters nextParameters = new JobParametersBuilder(jobParameters,
|
||||
this.taskJobExplorer).getNextJobParameters(job).toJobParameters();
|
||||
JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.taskJobExplorer)
|
||||
.getNextJobParameters(job).toJobParameters();
|
||||
parameters = merge(nextParameters, jobParameters);
|
||||
}
|
||||
}
|
||||
JobExecution execution = this.taskJobLauncher.run(job, parameters);
|
||||
if (this.taskApplicationEventPublisher != null) {
|
||||
this.taskApplicationEventPublisher
|
||||
.publishEvent(new JobExecutionEvent(execution));
|
||||
this.taskApplicationEventPublisher.publishEvent(new JobExecutionEvent(execution));
|
||||
}
|
||||
this.jobExecutionList.add(execution);
|
||||
if (execution.getStatus().equals(BatchStatus.FAILED)) {
|
||||
@@ -171,8 +163,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
List<JobExecution> failedJobExecutions = new ArrayList<>();
|
||||
RepeatStatus repeatStatus = RepeatStatus.FINISHED;
|
||||
for (JobExecution jobExecution : this.jobExecutionList) {
|
||||
JobExecution currentJobExecution = this.taskJobExplorer
|
||||
.getJobExecution(jobExecution.getId());
|
||||
JobExecution currentJobExecution = this.taskJobExplorer.getJobExecution(jobExecution.getId());
|
||||
BatchStatus batchStatus = currentJobExecution.getStatus();
|
||||
if (batchStatus.isRunning()) {
|
||||
repeatStatus = RepeatStatus.CONTINUABLE;
|
||||
@@ -183,8 +174,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
}
|
||||
Thread.sleep(this.taskBatchProperties.getFailOnJobFailurePollInterval());
|
||||
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED)
|
||||
&& failedJobExecutions.size() > 0) {
|
||||
if (repeatStatus.equals(RepeatStatus.FINISHED) && failedJobExecutions.size() > 0) {
|
||||
throwJobFailedException(failedJobExecutions);
|
||||
}
|
||||
return repeatStatus;
|
||||
@@ -194,10 +184,10 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
|
||||
private void throwJobFailedException(List<JobExecution> failedJobExecutions) {
|
||||
StringBuilder message = new StringBuilder("The following Jobs have failed: \n");
|
||||
for (JobExecution failedJobExecution : failedJobExecutions) {
|
||||
message.append(String.format("Job %s failed during "
|
||||
+ "execution for job instance id %s with jobExecutionId of %s \n",
|
||||
failedJobExecution.getJobInstance().getJobName(),
|
||||
failedJobExecution.getJobId(), failedJobExecution.getId()));
|
||||
message.append(String.format(
|
||||
"Job %s failed during " + "execution for job instance id %s with jobExecutionId of %s \n",
|
||||
failedJobExecution.getJobInstance().getJobName(), failedJobExecution.getJobId(),
|
||||
failedJobExecution.getId()));
|
||||
}
|
||||
|
||||
logger.error(message);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class TaskBatchExecutionListener implements JobExecutionListener, Ordered {
|
||||
public class TaskBatchExecutionListener implements JobExecutionListener, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TaskBatchExecutionListener.class);
|
||||
|
||||
@@ -57,12 +57,10 @@ public class TaskBatchExecutionListener implements JobExecutionListener, Ordere
|
||||
@Override
|
||||
public void beforeJob(JobExecution jobExecution) {
|
||||
if (this.taskExecution == null) {
|
||||
logger.warn(
|
||||
"This job was executed outside the scope of a task but still used the task listener.");
|
||||
logger.warn("This job was executed outside the scope of a task but still used the task listener.");
|
||||
}
|
||||
else {
|
||||
logger.info(String.format(
|
||||
"The job execution id %s was run within the task execution %s",
|
||||
logger.info(String.format("The job execution id %s was run within the task execution %s",
|
||||
jobExecution.getId(), this.taskExecution.getExecutionId()));
|
||||
this.taskBatchDao.saveRelationship(this.taskExecution, jobExecution);
|
||||
}
|
||||
@@ -72,4 +70,5 @@ public class TaskBatchExecutionListener implements JobExecutionListener, Ordere
|
||||
public int getOrder() {
|
||||
return Ordered.HIGHEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,8 +69,7 @@ public class JdbcTaskBatchDao implements TaskBatchDao {
|
||||
public void saveRelationship(TaskExecution taskExecution, JobExecution jobExecution) {
|
||||
Assert.notNull(taskExecution, "A taskExecution is required");
|
||||
Assert.notNull(jobExecution, "A jobExecution is required");
|
||||
this.jdbcTemplate.update(getQuery(INSERT_STATEMENT),
|
||||
taskExecution.getExecutionId(), jobExecution.getId());
|
||||
this.jdbcTemplate.update(getQuery(INSERT_STATEMENT), taskExecution.getExecutionId(), jobExecution.getId());
|
||||
}
|
||||
|
||||
private String getQuery(String base) {
|
||||
|
||||
@@ -48,8 +48,7 @@ public class MapTaskBatchDao implements TaskBatchDao {
|
||||
Assert.notNull(jobExecution, "A jobExecution is required");
|
||||
|
||||
if (this.relationships.containsKey(taskExecution.getExecutionId())) {
|
||||
this.relationships.get(taskExecution.getExecutionId())
|
||||
.add(jobExecution.getId());
|
||||
this.relationships.get(taskExecution.getExecutionId()).add(jobExecution.getId());
|
||||
}
|
||||
else {
|
||||
TreeSet<Long> jobExecutionIds = new TreeSet<>();
|
||||
|
||||
@@ -74,8 +74,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Michael Minella
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class DeployerPartitionHandler
|
||||
implements PartitionHandler, EnvironmentAware, InitializingBean {
|
||||
public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAware, InitializingBean {
|
||||
|
||||
/**
|
||||
* ID of Spring Cloud Task job execution.
|
||||
@@ -145,21 +144,23 @@ public class DeployerPartitionHandler
|
||||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TaskRepository taskRepository;
|
||||
|
||||
/**
|
||||
* Constructor initializing the DeployerPartitionHandler instance.
|
||||
* @param taskLauncher The {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute partitioned tasks.
|
||||
* @param taskLauncher The
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute
|
||||
* partitioned tasks.
|
||||
* @param jobExplorer The {@link JobExplorer} to acquire the status of the job.
|
||||
* @param resource The {@link Resource} to the app to be launched.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecutor If task launches should occur asynchronously then provide a {@link ThreadPoolTaskExecutor}. Default is null.
|
||||
* @param taskExecutor If task launches should occur asynchronously then provide a
|
||||
* {@link ThreadPoolTaskExecutor}. Default is null.
|
||||
*/
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, TaskRepository taskRepository,
|
||||
TaskExecutor taskExecutor) {
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName, TaskRepository taskRepository,
|
||||
TaskExecutor taskExecutor) {
|
||||
Assert.notNull(taskLauncher, "A taskLauncher is required");
|
||||
Assert.notNull(jobExplorer, "A jobExplorer is required");
|
||||
Assert.notNull(resource, "A resource is required");
|
||||
@@ -176,13 +177,15 @@ public class DeployerPartitionHandler
|
||||
|
||||
/**
|
||||
* Constructor initializing the DeployerPartitionHandler instance.
|
||||
* @param taskLauncher The {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute partitioned tasks.
|
||||
* @param taskLauncher The
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} used to execute
|
||||
* partitioned tasks.
|
||||
* @param jobExplorer The {@link JobExplorer} to acquire the status of the job.
|
||||
* @param resource The {@link Resource} to the app to be launched.
|
||||
* @param stepName The name of the step.
|
||||
*/
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, TaskRepository taskRepository) {
|
||||
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName, TaskRepository taskRepository) {
|
||||
this(taskLauncher, jobExplorer, resource, stepName, taskRepository, new SyncTaskExecutor());
|
||||
}
|
||||
|
||||
@@ -190,8 +193,7 @@ public class DeployerPartitionHandler
|
||||
* Used to provide any environment variables to be set on each worker launched.
|
||||
* @param environmentVariablesProvider an {@link EnvironmentVariablesProvider}
|
||||
*/
|
||||
public void setEnvironmentVariablesProvider(
|
||||
EnvironmentVariablesProvider environmentVariablesProvider) {
|
||||
public void setEnvironmentVariablesProvider(EnvironmentVariablesProvider environmentVariablesProvider) {
|
||||
this.environmentVariablesProvider = environmentVariablesProvider;
|
||||
}
|
||||
|
||||
@@ -208,8 +210,7 @@ public class DeployerPartitionHandler
|
||||
* Used to provide any command line arguements to be passed to each worker launched.
|
||||
* @param commandLineArgsProvider {@link CommandLineArgsProvider}
|
||||
*/
|
||||
public void setCommandLineArgsProvider(
|
||||
CommandLineArgsProvider commandLineArgsProvider) {
|
||||
public void setCommandLineArgsProvider(CommandLineArgsProvider commandLineArgsProvider) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
}
|
||||
|
||||
@@ -250,8 +251,10 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Map of deployment properties to be used by the {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}.
|
||||
* @param deploymentProperties properties to be used by the {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}
|
||||
* Map of deployment properties to be used by the
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}.
|
||||
* @param deploymentProperties properties to be used by the
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}
|
||||
*/
|
||||
public void setDeploymentProperties(Map<String, String> deploymentProperties) {
|
||||
this.deploymentProperties = deploymentProperties;
|
||||
@@ -271,19 +274,17 @@ public class DeployerPartitionHandler
|
||||
this.taskExecution = taskExecution;
|
||||
|
||||
if (this.commandLineArgsProvider == null) {
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
this.commandLineArgsProvider = provider;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter,
|
||||
StepExecution stepExecution) throws Exception {
|
||||
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter, StepExecution stepExecution)
|
||||
throws Exception {
|
||||
|
||||
final Set<StepExecution> tempCandidates = stepSplitter.split(stepExecution,
|
||||
this.gridSize);
|
||||
final Set<StepExecution> tempCandidates = stepSplitter.split(stepExecution, this.gridSize);
|
||||
|
||||
// Following two lines due to https://jira.spring.io/browse/BATCH-2490
|
||||
final Set<StepExecution> candidates = new HashSet<>(tempCandidates.size());
|
||||
@@ -306,23 +307,18 @@ public class DeployerPartitionHandler
|
||||
return pollReplies(stepExecution, executed, candidates, partitions);
|
||||
}
|
||||
|
||||
private void launchWorkers(Set<StepExecution> candidates,
|
||||
Set<StepExecution> executed) {
|
||||
private void launchWorkers(Set<StepExecution> candidates, Set<StepExecution> executed) {
|
||||
TaskLauncherHandler taskLauncherHandler = new TaskLauncherHandler(this.commandLineArgsProvider,
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars,
|
||||
this.stepName, this.taskExecution, this.environmentVariablesProvider,
|
||||
this.resource, this.deploymentProperties,
|
||||
this.taskLauncher,
|
||||
this.applicationName);
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars, this.stepName, this.taskExecution,
|
||||
this.environmentVariablesProvider, this.resource, this.deploymentProperties, this.taskLauncher,
|
||||
this.applicationName);
|
||||
for (StepExecution execution : candidates) {
|
||||
if (this.currentWorkers < this.maxWorkers || this.maxWorkers < 0) {
|
||||
if (this.taskExecutor != null) {
|
||||
TaskLauncherHandler taskLauncherThread = new TaskLauncherHandler(this.commandLineArgsProvider,
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars,
|
||||
this.stepName, this.taskExecution, this.environmentVariablesProvider,
|
||||
this.resource, this.deploymentProperties,
|
||||
this.taskLauncher,
|
||||
this.applicationName, execution);
|
||||
this.taskRepository, this.defaultArgsAsEnvironmentVars, this.stepName, this.taskExecution,
|
||||
this.environmentVariablesProvider, this.resource, this.deploymentProperties,
|
||||
this.taskLauncher, this.applicationName, execution);
|
||||
this.taskExecutor.execute(taskLauncherThread);
|
||||
}
|
||||
else {
|
||||
@@ -335,8 +331,7 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
private Collection<StepExecution> pollReplies(final StepExecution masterStepExecution,
|
||||
final Set<StepExecution> executed, final Set<StepExecution> candidates,
|
||||
final int size) throws Exception {
|
||||
final Set<StepExecution> executed, final Set<StepExecution> candidates, final int size) throws Exception {
|
||||
|
||||
final Collection<StepExecution> result = new ArrayList<>(executed.size());
|
||||
|
||||
@@ -348,8 +343,7 @@ public class DeployerPartitionHandler
|
||||
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)) {
|
||||
@@ -388,8 +382,7 @@ public class DeployerPartitionHandler
|
||||
}
|
||||
|
||||
private boolean isComplete(BatchStatus status) {
|
||||
return status.equals(BatchStatus.COMPLETED)
|
||||
|| status.isGreaterThan(BatchStatus.STARTED);
|
||||
return status.equals(BatchStatus.COMPLETED) || status.isGreaterThan(BatchStatus.STARTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -400,9 +393,9 @@ public class DeployerPartitionHandler
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.environmentVariablesProvider == null) {
|
||||
this.environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(
|
||||
this.environment);
|
||||
this.environmentVariablesProvider = new SimpleEnvironmentVariablesProvider(this.environment);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
|
||||
private StepLocator stepLocator;
|
||||
|
||||
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository) {
|
||||
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer, JobRepository jobRepository) {
|
||||
Assert.notNull(beanFactory, "A beanFactory is required");
|
||||
Assert.notNull(jobExplorer, "A jobExplorer is required");
|
||||
Assert.notNull(jobRepository, "A jobRepository is required");
|
||||
@@ -88,26 +87,23 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
|
||||
validateRequest();
|
||||
|
||||
Long jobExecutionId = Long.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));
|
||||
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId,
|
||||
stepExecutionId);
|
||||
Long jobExecutionId = Long
|
||||
.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));
|
||||
StepExecution stepExecution = this.jobExplorer.getStepExecution(jobExecutionId, stepExecutionId);
|
||||
|
||||
if (stepExecution == null) {
|
||||
throw new NoSuchStepException(String.format(
|
||||
"No StepExecution could be located for step execution id %s within job execution %s",
|
||||
stepExecutionId, jobExecutionId));
|
||||
throw new NoSuchStepException(
|
||||
String.format("No StepExecution could be located for step execution id %s within job execution %s",
|
||||
stepExecutionId, jobExecutionId));
|
||||
}
|
||||
|
||||
String stepName = this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
|
||||
String stepName = this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME);
|
||||
Step step = this.stepLocator.getStep(stepName);
|
||||
|
||||
try {
|
||||
this.logger.debug(String.format(
|
||||
"Executing step %s with step execution id %s and job execution id %s",
|
||||
this.logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s",
|
||||
stepExecution.getStepName(), stepExecutionId, jobExecutionId));
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -124,23 +120,16 @@ public class DeployerStepExecutionHandler implements CommandLineRunner {
|
||||
}
|
||||
|
||||
private void validateRequest() {
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID),
|
||||
"A job execution id is required");
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID),
|
||||
"A step execution id is required");
|
||||
Assert.isTrue(
|
||||
this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME),
|
||||
Assert.isTrue(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME),
|
||||
"A step name is required");
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class NoOpEnvironmentVariablesProvider implements EnvironmentVariablesPro
|
||||
* @return an empty {@link Map}
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getEnvironmentVariables(
|
||||
ExecutionContext executionContext) {
|
||||
public Map<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,11 +71,9 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getEnvironmentVariables(
|
||||
ExecutionContext executionContext) {
|
||||
public Map<String, String> getEnvironmentVariables(ExecutionContext executionContext) {
|
||||
|
||||
Map<String, String> environmentProperties = new HashMap<>(
|
||||
this.environmentProperties.size());
|
||||
Map<String, String> environmentProperties = new HashMap<>(this.environmentProperties.size());
|
||||
|
||||
if (this.includeCurrentEnvironment) {
|
||||
environmentProperties.putAll(getCurrentEnvironmentProperties());
|
||||
@@ -91,11 +89,9 @@ public class SimpleEnvironmentVariablesProvider implements EnvironmentVariablesP
|
||||
|
||||
Set<String> keys = new HashSet<>();
|
||||
|
||||
for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment)
|
||||
.getPropertySources()) {
|
||||
for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment).getPropertySources()) {
|
||||
if (propertySource instanceof MapPropertySource) {
|
||||
keys.addAll(Arrays
|
||||
.asList(((MapPropertySource) propertySource).getPropertyNames()));
|
||||
keys.addAll(Arrays.asList(((MapPropertySource) propertySource).getPropertyNames()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,26 +64,32 @@ public class TaskLauncherHandler implements Runnable {
|
||||
private Log logger = LogFactory.getLog(TaskLauncherHandler.class);
|
||||
|
||||
/**
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides command line
|
||||
* arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are used
|
||||
* internally by Spring Cloud Task and Spring Batch are passed as environment variables instead of command line arguments.
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides
|
||||
* command line arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the
|
||||
* partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are
|
||||
* used internally by Spring Cloud Task and Spring Batch are passed as environment
|
||||
* variables instead of command line arguments.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecution The {@link TaskExecution} to be associated with the partition.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that provides the environmennt variables.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that
|
||||
* provides the environmennt variables.
|
||||
* @param resource The {@link Resource} to be launched.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties for the partition.
|
||||
* @param taskLauncher {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to launch the partition.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties
|
||||
* for the partition.
|
||||
* @param taskLauncher
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to
|
||||
* launch the partition.
|
||||
* @param applicationName The name to be associated with task.
|
||||
* @param workerStepExecution The {@link StepExecution} for the paritition.
|
||||
*/
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider,
|
||||
TaskRepository taskRepository, boolean defaultArgsAsEnvironmentVars,
|
||||
String stepName, TaskExecution taskExecution, EnvironmentVariablesProvider
|
||||
environmentVariablesProvider, Resource resource, Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
String applicationName, StepExecution workerStepExecution) {
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider, TaskRepository taskRepository,
|
||||
boolean defaultArgsAsEnvironmentVars, String stepName, TaskExecution taskExecution,
|
||||
EnvironmentVariablesProvider environmentVariablesProvider, Resource resource,
|
||||
Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, String applicationName,
|
||||
StepExecution workerStepExecution) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
this.taskRepository = taskRepository;
|
||||
this.defaultArgsAsEnvironmentVars = defaultArgsAsEnvironmentVars;
|
||||
@@ -98,25 +104,30 @@ public class TaskLauncherHandler implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides command line
|
||||
* arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are used
|
||||
* internally by Spring Cloud Task and Spring Batch are passed as environment variables instead of command line arguments.
|
||||
* @param commandLineArgsProvider The {@link CommandLineArgsProvider} that provides
|
||||
* command line arguments passed to each partition's execution.
|
||||
* @param taskRepository The {@link TaskRepository} task repository for launching the
|
||||
* partition.
|
||||
* @param defaultArgsAsEnvironmentVars - If set to true, the default args that are
|
||||
* used internally by Spring Cloud Task and Spring Batch are passed as environment
|
||||
* variables instead of command line arguments.
|
||||
* @param stepName The name of the step.
|
||||
* @param taskExecution The {@link TaskExecution} to be associated with the partition.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that provides the environmennt variables.
|
||||
* @param environmentVariablesProvider {@link EnvironmentVariablesProvider} that
|
||||
* provides the environmennt variables.
|
||||
* @param resource The {@link Resource} to be launched.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties for the partition.
|
||||
* @param taskLauncher {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to launch the partition.
|
||||
* @param deploymentProperties The {@link Map} containing the deployment properties
|
||||
* for the partition.
|
||||
* @param taskLauncher
|
||||
* {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} that is used to
|
||||
* launch the partition.
|
||||
* @param applicationName The name to be associated with task.
|
||||
*/
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider,
|
||||
TaskRepository taskRepository, boolean defaultArgsAsEnvironmentVars,
|
||||
String stepName, TaskExecution taskExecution, EnvironmentVariablesProvider
|
||||
environmentVariablesProvider, Resource resource, Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher,
|
||||
String applicationName) {
|
||||
public TaskLauncherHandler(CommandLineArgsProvider commandLineArgsProvider, TaskRepository taskRepository,
|
||||
boolean defaultArgsAsEnvironmentVars, String stepName, TaskExecution taskExecution,
|
||||
EnvironmentVariablesProvider environmentVariablesProvider, Resource resource,
|
||||
Map<String, String> deploymentProperties,
|
||||
org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, String applicationName) {
|
||||
this.commandLineArgsProvider = commandLineArgsProvider;
|
||||
this.taskRepository = taskRepository;
|
||||
this.defaultArgsAsEnvironmentVars = defaultArgsAsEnvironmentVars;
|
||||
@@ -134,7 +145,6 @@ public class TaskLauncherHandler implements Runnable {
|
||||
launchWorker(this.workerStepExecution);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launches the partition for the StepExecution.
|
||||
* @param workerStepExecution The {@link StepExecution}
|
||||
@@ -142,8 +152,7 @@ public class TaskLauncherHandler implements Runnable {
|
||||
public void launchWorker(StepExecution workerStepExecution) {
|
||||
List<String> arguments = new ArrayList<>();
|
||||
|
||||
ExecutionContext copyContext = new ExecutionContext(
|
||||
workerStepExecution.getExecutionContext());
|
||||
ExecutionContext copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
|
||||
|
||||
arguments.addAll(this.commandLineArgsProvider.getCommandLineArgs(copyContext));
|
||||
|
||||
@@ -153,69 +162,61 @@ public class TaskLauncherHandler implements Runnable {
|
||||
partitionTaskExecution = this.taskRepository.createTaskExecution();
|
||||
}
|
||||
else {
|
||||
logger.warn(
|
||||
"TaskRepository was not set so external execution id will not be recorded.");
|
||||
logger.warn("TaskRepository was not set so external execution id will not be recorded.");
|
||||
}
|
||||
|
||||
if (!this.defaultArgsAsEnvironmentVars) {
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId())));
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getId())));
|
||||
String.valueOf(workerStepExecution.getId())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, this.stepName));
|
||||
arguments
|
||||
.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
String.format("%s_%s_%s", this.taskExecution.getTaskName(),
|
||||
workerStepExecution.getJobExecution().getJobInstance()
|
||||
.getJobName(),
|
||||
workerStepExecution.getStepName())));
|
||||
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
|
||||
workerStepExecution.getStepName())));
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
|
||||
String.valueOf(this.taskExecution.getExecutionId())));
|
||||
String.valueOf(this.taskExecution.getExecutionId())));
|
||||
|
||||
if (partitionTaskExecution != null) {
|
||||
arguments.add(formatArgument(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID,
|
||||
String.valueOf(partitionTaskExecution.getExecutionId())));
|
||||
String.valueOf(partitionTaskExecution.getExecutionId())));
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId()));
|
||||
String.valueOf(workerStepExecution.getJobExecution().getId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
|
||||
String.valueOf(workerStepExecution.getId()));
|
||||
String.valueOf(workerStepExecution.getId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, this.stepName);
|
||||
environmentVariables
|
||||
.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_NAME,
|
||||
String.format("%s_%s_%s", this.taskExecution.getTaskName(),
|
||||
workerStepExecution.getJobExecution().getJobInstance()
|
||||
.getJobName(),
|
||||
workerStepExecution.getStepName()));
|
||||
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
|
||||
workerStepExecution.getStepName()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
|
||||
String.valueOf(this.taskExecution.getExecutionId()));
|
||||
String.valueOf(this.taskExecution.getExecutionId()));
|
||||
environmentVariables.put(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID,
|
||||
String.valueOf(partitionTaskExecution.getExecutionId()));
|
||||
String.valueOf(partitionTaskExecution.getExecutionId()));
|
||||
}
|
||||
|
||||
AppDefinition definition = new AppDefinition(resolveApplicationName(),
|
||||
environmentVariables);
|
||||
AppDefinition definition = new AppDefinition(resolveApplicationName(), environmentVariables);
|
||||
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, this.resource,
|
||||
this.deploymentProperties, arguments);
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, this.resource, this.deploymentProperties,
|
||||
arguments);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Requesting the launch of the following application: " + request);
|
||||
logger.debug("Requesting the launch of the following application: " + request);
|
||||
}
|
||||
String externalExecutionId = this.taskLauncher.launch(request);
|
||||
|
||||
if (this.taskRepository != null) {
|
||||
this.taskRepository.updateExternalExecutionId(
|
||||
partitionTaskExecution.getExecutionId(), externalExecutionId);
|
||||
this.taskRepository.updateExternalExecutionId(partitionTaskExecution.getExecutionId(), externalExecutionId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,63 +37,48 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class TaskJobLauncherAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class,
|
||||
TaskJobLauncherAutoConfiguration.class))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(BatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class))
|
||||
.withUserConfiguration(TaskBatchExecutionListenerTests.JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class);
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class);
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLR() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true")
|
||||
.run(context -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(TaskJobLauncherApplicationRunner.class);
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class)
|
||||
.getOrder()).isEqualTo(0);
|
||||
});
|
||||
this.contextRunner.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(TaskJobLauncherApplicationRunner.class);
|
||||
assertThat(context.getBean(TaskJobLauncherApplicationRunner.class).getOrder()).isEqualTo(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoBuiltDataSourceWithTaskJobLauncherCLROrder() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"spring.cloud.task.batch.commandLineRunnerOrder=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.commandLineRunnerOrder=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 -> {
|
||||
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 -> {
|
||||
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 {
|
||||
private void validateJobNames(AssertableApplicationContext context, String jobNames) throws Exception {
|
||||
JobLauncherApplicationRunner jobLauncherApplicationRunner = context
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner,
|
||||
"jobName");
|
||||
Object names = ReflectionTestUtils.getField(jobLauncherApplicationRunner, "jobName");
|
||||
assertThat(names).isEqualTo(jobNames);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { TaskJobLauncherApplicationRunnerCoreTests.BatchConfiguration.class })
|
||||
@ContextConfiguration(classes = { TaskJobLauncherApplicationRunnerCoreTests.BatchConfiguration.class })
|
||||
public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
|
||||
@Autowired
|
||||
@@ -103,8 +102,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
Tasklet tasklet = (contribution, chunkContext) -> RepeatStatus.FINISHED;
|
||||
this.step = this.steps.get("step").tasklet(tasklet).build();
|
||||
this.job = this.jobs.get("job").start(this.step).build();
|
||||
this.runner = new TaskJobLauncherApplicationRunner(this.jobLauncher,
|
||||
this.jobExplorer, this.jobRepository, new TaskBatchProperties());
|
||||
this.runner = new TaskJobLauncherApplicationRunner(this.jobLauncher, this.jobExplorer, this.jobRepository,
|
||||
new TaskBatchProperties());
|
||||
|
||||
}
|
||||
|
||||
@@ -113,26 +112,23 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
public void basicExecution() throws Exception {
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
this.runner.execute(this.job,
|
||||
new JobParametersBuilder().addLong("id", 1L).toJobParameters());
|
||||
this.runner.execute(this.job, new JobParametersBuilder().addLong("id", 1L).toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
// @Test
|
||||
// @Test
|
||||
public void incrementExistingExecution() throws Exception {
|
||||
this.job = this.jobs.get("job").start(this.step)
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
this.job = this.jobs.get("job").start(this.step).incrementer(new RunIdIncrementer()).build();
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
this.runner.execute(this.job, new JobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
// @Test
|
||||
// @Test
|
||||
public void retryFailedExecution() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
runFailedJob(new JobParameters());
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
@@ -142,16 +138,13 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void runDifferentInstances() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build()).build();
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build()).build();
|
||||
// start a job instance
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo")
|
||||
.toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("name", "foo").toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
// start a different job instance
|
||||
JobParameters otherJobParameters = new JobParametersBuilder()
|
||||
.addString("name", "bar").toJobParameters();
|
||||
JobParameters otherJobParameters = new JobParametersBuilder().addString("name", "bar").toJobParameters();
|
||||
runFailedJob(otherJobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
|
||||
}
|
||||
@@ -160,8 +153,8 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
@Test
|
||||
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
|
||||
this.job = this.jobs.get("job").preventRestart()
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build()).incrementer(new RunIdIncrementer())
|
||||
.build();
|
||||
runFailedJob(new JobParameters());
|
||||
runFailedJob(new JobParameters());
|
||||
// A failed job that is not restartable does not re-use the job params of
|
||||
@@ -171,40 +164,35 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
// try to re-run a failed execution
|
||||
Executable executable = () -> this.runner.execute(this.job,
|
||||
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
|
||||
assertThatExceptionOfType(JobRestartException.class)
|
||||
.isThrownBy(executable::execute)
|
||||
assertThatExceptionOfType(JobRestartException.class).isThrownBy(executable::execute)
|
||||
.withMessage("JobInstance already exists and is not restartable");
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false).toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
runFailedJob(new JobParametersBuilder(jobParameters).addLong("run.id", 1L)
|
||||
.toJobParameters());
|
||||
runFailedJob(new JobParametersBuilder(jobParameters).addLong("run.id", 1L).toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
}
|
||||
|
||||
@DirtiesContext
|
||||
@Test
|
||||
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution()
|
||||
throws Exception {
|
||||
this.job = this.jobs.get("job")
|
||||
.start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution() throws Exception {
|
||||
this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(throwingTasklet()).build())
|
||||
.incrementer(new RunIdIncrementer()).build();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
|
||||
.addLong("foo", 2L, false).toJobParameters();
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false).addLong("foo", 2L, false)
|
||||
.toJobParameters();
|
||||
runFailedJob(jobParameters);
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
// try to re-run a failed execution with non identifying parameters
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L)
|
||||
.addLong("id", 2L, false).addLong("foo", 3L, false).toJobParameters());
|
||||
runFailedJob(new JobParametersBuilder().addLong("run.id", 1L).addLong("id", 2L, false).addLong("foo", 3L, false)
|
||||
.toJobParameters());
|
||||
assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
|
||||
JobInstance jobInstance = jobExplorer.getLastJobInstance("job");
|
||||
|
||||
@@ -212,7 +200,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
|
||||
assertThat(executions).hasSize(2);
|
||||
|
||||
JobExecution firstJobExecution = executions.get(0);
|
||||
JobExecution firstJobExecution = executions.get(0);
|
||||
JobExecution secondJobExecution = executions.get(1);
|
||||
if ((executions.get(0).getId() > executions.get(1).getId())) {
|
||||
firstJobExecution = executions.get(1);
|
||||
@@ -261,7 +249,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
private DataSource dataSource;
|
||||
|
||||
public BatchConfiguration() throws Exception {
|
||||
}
|
||||
@@ -317,7 +305,7 @@ public class TaskJobLauncherApplicationRunnerCoreTests {
|
||||
databasePopulator.addScript(new ClassPathResource("org/springframework/batch/core/schema-drop-h2.sql"));
|
||||
dataSourceInitializer.setDatabaseCleaner(databasePopulator);
|
||||
return dataSourceInitializer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -84,10 +84,8 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFail() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class,
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE, TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class,
|
||||
enabledArgs);
|
||||
}
|
||||
|
||||
@@ -97,45 +95,37 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
*/
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFailWithAnnotation() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureAnnotatedConfiguration.class,
|
||||
enabledArgs);
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureAnnotatedConfiguration.class, enabledArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherCLRSuccessFailWithTaskExecutor() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true",
|
||||
"--spring.cloud.task.batch.failOnJobFailurePollInterval=500" };
|
||||
validateForFail(DEFAULT_ERROR_MESSAGE,
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureTaskExecutorConfiguration.class,
|
||||
enabledArgs);
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureTaskExecutorConfiguration.class, enabledArgs);
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class);
|
||||
assertThat(jobExplorer.getJobNames().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTaskJobLauncherPickOneJob() {
|
||||
String[] enabledArgs = new String[] {
|
||||
"--spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.fail-on-job-failure=true",
|
||||
"--spring.cloud.task.batch.jobNames=jobSucceed" };
|
||||
boolean isExceptionThrown = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(new Class[] {
|
||||
TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class },
|
||||
this.applicationContext = SpringApplication.run(
|
||||
new Class[] { TaskJobLauncherApplicationRunnerTests.JobWithFailureConfiguration.class },
|
||||
enabledArgs);
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
@@ -148,19 +138,15 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
@Test
|
||||
public void testApplicationRunnerSetToFalse() {
|
||||
String[] enabledArgs = new String[] {};
|
||||
this.applicationContext = SpringApplication.run(
|
||||
new Class[] {
|
||||
TaskJobLauncherApplicationRunnerTests.JobConfiguration.class },
|
||||
enabledArgs);
|
||||
this.applicationContext = SpringApplication
|
||||
.run(new Class[] { TaskJobLauncherApplicationRunnerTests.JobConfiguration.class }, enabledArgs);
|
||||
validateContext();
|
||||
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class))
|
||||
.isNotNull();
|
||||
assertThat(this.applicationContext.getBean(JobLauncherApplicationRunner.class)).isNotNull();
|
||||
|
||||
Executable executable = () -> this.applicationContext
|
||||
.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
Executable executable = () -> this.applicationContext.getBean(TaskJobLauncherApplicationRunner.class);
|
||||
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||
.isThrownBy(executable::execute).withMessage("No qualifying bean of type "
|
||||
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(executable::execute)
|
||||
.withMessage("No qualifying bean of type "
|
||||
+ "'org.springframework.cloud.task.batch.handler.TaskJobLauncherApplicationRunner' available");
|
||||
validateContext();
|
||||
}
|
||||
@@ -168,24 +154,21 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
private void validateContext() {
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private void validateForFail(String errorMessage, Class clazz, String[] enabledArgs) {
|
||||
Executable executable = () -> this.applicationContext = SpringApplication.run(
|
||||
new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class },
|
||||
enabledArgs);
|
||||
Executable executable = () -> this.applicationContext = SpringApplication
|
||||
.run(new Class[] { clazz, PropertyPlaceholderAutoConfiguration.class }, enabledArgs);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(executable::execute).has(new Condition<Throwable>() {
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(executable::execute)
|
||||
.has(new Condition<Throwable>() {
|
||||
@Override
|
||||
public boolean matches(Throwable value) {
|
||||
return errorMessage.equals(value.getCause().getMessage());
|
||||
@@ -207,23 +190,20 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
return this.jobBuilderFactory.get("job").start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableBatchProcessing
|
||||
@ImportAutoConfiguration({ PropertyPlaceholderAutoConfiguration.class,
|
||||
BatchAutoConfiguration.class, TaskBatchAutoConfiguration.class,
|
||||
TaskJobLauncherAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
@ImportAutoConfiguration({ PropertyPlaceholderAutoConfiguration.class, BatchAutoConfiguration.class,
|
||||
TaskBatchAutoConfiguration.class, TaskJobLauncherAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class })
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
@EnableTask
|
||||
@@ -237,24 +217,21 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
|
||||
@Bean
|
||||
public Job jobFail() {
|
||||
return this.jobBuilderFactory.get("jobA")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}
|
||||
}).build()).build();
|
||||
return this.jobBuilderFactory.get("jobA").start(this.stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
throw new IllegalStateException("WHOOPS");
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job jobFun() {
|
||||
return this.jobBuilderFactory.get("jobSucceed").start(
|
||||
this.stepBuilderFactory.get("step1Succeed").tasklet(new Tasklet() {
|
||||
return this.jobBuilderFactory.get("jobSucceed")
|
||||
.start(this.stepBuilderFactory.get("step1Succeed").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) {
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
@@ -264,8 +241,7 @@ public class TaskJobLauncherApplicationRunnerTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
public static class JobWithFailureAnnotatedConfiguration
|
||||
extends JobWithFailureConfiguration {
|
||||
public static class JobWithFailureAnnotatedConfiguration extends JobWithFailureConfiguration {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ public class PrefixTests {
|
||||
|
||||
@Test
|
||||
public void testPrefix() {
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class,
|
||||
"--spring.cloud.task.tablePrefix=FOO_");
|
||||
this.applicationContext = SpringApplication.run(JobConfiguration.class, "--spring.cloud.task.tablePrefix=FOO_");
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
@@ -74,8 +73,8 @@ public class PrefixTests {
|
||||
|
||||
@Bean
|
||||
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
return jobBuilderFactory.get("job").start(stepBuilderFactory
|
||||
.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
return jobBuilderFactory.get("job")
|
||||
.start(stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
@@ -83,8 +82,8 @@ public class PrefixTests {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,23 +133,20 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
public void testFactoryBean() {
|
||||
this.applicationContext = SpringApplication.run(JobFactoryBeanConfiguration.class,
|
||||
ARGS);
|
||||
this.applicationContext = SpringApplication.run(JobFactoryBeanConfiguration.class, ARGS);
|
||||
validateContext();
|
||||
}
|
||||
|
||||
private void validateContext() {
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@@ -158,27 +155,24 @@ 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
|
||||
public void testMultipleDataSources() {
|
||||
this.applicationContext = SpringApplication
|
||||
.run(JobConfigurationMultipleDataSources.class, ARGS);
|
||||
this.applicationContext = SpringApplication.run(JobConfigurationMultipleDataSources.class, ARGS);
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next())
|
||||
.getExecutionId()).isEqualTo(1);
|
||||
assertThat(taskExplorer.getTaskExecution(jobExecutionIds.iterator().next()).getExecutionId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -187,11 +181,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(0);
|
||||
}
|
||||
@@ -202,36 +195,30 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
assertThat((long) taskExplorer
|
||||
.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
|
||||
.isEqualTo(1);
|
||||
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIds.iterator().next()))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJobs() {
|
||||
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class,
|
||||
"--spring.batch.job.name=job1");
|
||||
this.applicationContext = SpringApplication.run(MultipleJobConfiguration.class, "--spring.batch.job.name=job1");
|
||||
|
||||
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
|
||||
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application",
|
||||
PageRequest.of(0, 1));
|
||||
Page<TaskExecution> page = taskExplorer.findTaskExecutionsByName("application", PageRequest.of(0, 1));
|
||||
|
||||
Set<Long> jobExecutionIds = taskExplorer.getJobExecutionIdsByTaskExecutionId(
|
||||
page.iterator().next().getExecutionId());
|
||||
Set<Long> jobExecutionIds = taskExplorer
|
||||
.getJobExecutionIdsByTaskExecutionId(page.iterator().next().getExecutionId());
|
||||
|
||||
assertThat(jobExecutionIds.size()).isEqualTo(1);
|
||||
Iterator<Long> jobExecutionIdsIterator = jobExecutionIds.iterator();
|
||||
assertThat((long) taskExplorer
|
||||
.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next()))
|
||||
.isEqualTo(1);
|
||||
assertThat((long) taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecutionIdsIterator.next())).isEqualTo(1);
|
||||
|
||||
}
|
||||
|
||||
@@ -242,23 +229,19 @@ public class TaskBatchExecutionListenerTests {
|
||||
jobNames.add("job2");
|
||||
jobNames.add("TESTOBJECT");
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(
|
||||
jobNames);
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(jobNames);
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor
|
||||
.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
assertThat(bean).isEqualTo(testObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchExecutionListenerBeanPostProcessorWithEmptyJobNames() {
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(
|
||||
Collections.emptyList());
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = beanPostProcessor(Collections.emptyList());
|
||||
|
||||
SimpleJob testObject = new SimpleJob();
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor
|
||||
.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
SimpleJob bean = (SimpleJob) beanPostProcessor.postProcessBeforeInitialization(testObject, "TESTOBJECT");
|
||||
assertThat(bean).isEqualTo(testObject);
|
||||
}
|
||||
|
||||
@@ -269,12 +252,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
});
|
||||
}
|
||||
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(
|
||||
List<String> jobNames) {
|
||||
this.applicationContext = SpringApplication.run(new Class[] {
|
||||
JobConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, BatchAutoConfiguration.class,
|
||||
TaskBatchAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
private TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor(List<String> jobNames) {
|
||||
this.applicationContext = SpringApplication.run(new Class[] { JobConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
BatchAutoConfiguration.class, TaskBatchAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class }, ARGS);
|
||||
|
||||
TaskBatchExecutionListenerBeanPostProcessor beanPostProcessor = this.applicationContext
|
||||
@@ -329,10 +310,10 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Bean
|
||||
public Job job() {
|
||||
return this.jobBuilderFactory.get("job")
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
.start(this.stepBuilderFactory.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -355,8 +336,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Override
|
||||
public Job getObject() {
|
||||
return JobFactoryBeanConfiguration.this.jobBuilderFactory.get("job")
|
||||
.start(JobFactoryBeanConfiguration.this.stepBuilderFactory
|
||||
.get("step1").tasklet((contribution, chunkContext) -> {
|
||||
.start(JobFactoryBeanConfiguration.this.stepBuilderFactory.get("step1")
|
||||
.tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build())
|
||||
@@ -383,32 +364,29 @@ public class TaskBatchExecutionListenerTests {
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
public static class JobConfigurationMultipleDataSources {
|
||||
|
||||
|
||||
@Bean
|
||||
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
|
||||
return jobBuilderFactory.get("job")
|
||||
.start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution,
|
||||
ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
return jobBuilderFactory.get("job").start(stepBuilderFactory.get("step1").tasklet(new Tasklet() {
|
||||
@Override
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
System.out.println("Executed");
|
||||
return RepeatStatus.FINISHED;
|
||||
}
|
||||
}).build()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public DataSource myDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2).setName("myDataSource");
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("myDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource incorrectDataSource() {
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2).setName("incorrectDataSource");
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||
.setName("incorrectDataSource");
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -438,8 +416,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Bean
|
||||
public Job job1() {
|
||||
return this.jobBuilderFactory.get("job1").start(
|
||||
this.stepBuilderFactory.get("job1step1").tasklet((contribution, chunkContext) -> {
|
||||
return this.jobBuilderFactory.get("job1")
|
||||
.start(this.stepBuilderFactory.get("job1step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job1");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
@@ -447,8 +425,8 @@ public class TaskBatchExecutionListenerTests {
|
||||
|
||||
@Bean
|
||||
public Job job2() {
|
||||
return this.jobBuilderFactory.get("job2").start(
|
||||
this.stepBuilderFactory.get("job2step1").tasklet((contribution, chunkContext) -> {
|
||||
return this.jobBuilderFactory.get("job2")
|
||||
.start(this.stepBuilderFactory.get("job2step1").tasklet((contribution, chunkContext) -> {
|
||||
System.out.println("Executed job2");
|
||||
return RepeatStatus.FINISHED;
|
||||
}).build()).build();
|
||||
|
||||
@@ -91,49 +91,43 @@ public class DeployerPartitionHandlerTests {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
this.environment = new MockEnvironment();
|
||||
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(),
|
||||
new Date(), "", Collections.emptyList(), null, null, null);
|
||||
Mockito.lenient().when(taskRepository.createTaskExecution())
|
||||
.thenReturn(taskExecution);
|
||||
TaskExecution taskExecution = new TaskExecution(2, 0, "name", new Date(), new Date(), "",
|
||||
Collections.emptyList(), null, null, null);
|
||||
Mockito.lenient().when(taskRepository.createTaskExecution()).thenReturn(taskExecution);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedConstructorValidation() {
|
||||
validateDeprecatedConstructorValidation(null, null, null, null,
|
||||
"A taskLauncher is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, null, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, null,
|
||||
null, "A resource is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, null, "A step name is required");
|
||||
validateDeprecatedConstructorValidation(null, null, null, null, "A taskLauncher is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, null, null, null, "A jobExplorer is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, null, null,
|
||||
"A resource is required");
|
||||
validateDeprecatedConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null,
|
||||
"A step name is required");
|
||||
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", this.taskRepository);
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step-name",
|
||||
this.taskRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorValidation() {
|
||||
validateConstructorValidation(null, null, null, null, null,
|
||||
"A taskLauncher is required");
|
||||
validateConstructorValidation(this.taskLauncher, null, null, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null,
|
||||
null, "A resource is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
null, null, "A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
null, null, "A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", null, "A TaskRepository is required");
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource,
|
||||
"step-name", this.taskRepository);
|
||||
validateConstructorValidation(null, null, null, null, null, "A taskLauncher is required");
|
||||
validateConstructorValidation(this.taskLauncher, null, null, null, null, "A jobExplorer is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, null, null, null, "A resource is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null, null,
|
||||
"A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, null, null,
|
||||
"A step name is required");
|
||||
validateConstructorValidation(this.taskLauncher, this.jobExplorer, this.resource, "step-name", null,
|
||||
"A TaskRepository is required");
|
||||
new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step-name",
|
||||
this.taskRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPartitions() throws Exception {
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
StepExecution stepExecution = new StepExecution("step1", new JobExecution(1L));
|
||||
@@ -153,11 +147,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
@@ -167,18 +161,15 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -188,16 +179,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, "4")))
|
||||
.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();
|
||||
.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();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -212,33 +201,30 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setDefaultArgsAsEnvironmentVars(true);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null, new ArrayList<>(), null,
|
||||
null);
|
||||
taskExecution.setTaskName("partitionedJobTask");
|
||||
|
||||
Set<StepExecution> stepExecutions = new HashSet<>();
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -250,23 +236,17 @@ 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");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).isEqualTo("1");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.isEqualTo("4");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)).isEqualTo("4");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.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_STEP_NAME))
|
||||
.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");
|
||||
assertThat(request.getDefinition().getProperties()
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
|
||||
.isEqualTo("2");
|
||||
.get(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID)).isEqualTo("55");
|
||||
assertThat(request.getDefinition().getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_EXECUTION_ID))
|
||||
.isEqualTo("2");
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -281,15 +261,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null,
|
||||
new ArrayList<>(), null, null);
|
||||
TaskExecution taskExecution = new TaskExecution(55, null, null, null, null, null, new ArrayList<>(), null,
|
||||
null);
|
||||
|
||||
taskExecution.setTaskName("partitionedJobTask");
|
||||
|
||||
@@ -297,8 +277,7 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
@@ -306,13 +285,11 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_PARENT_EXECUTION_ID, "55"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -336,19 +313,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository, threadPoolTaskExecutor);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository, threadPoolTaskExecutor);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
@@ -362,24 +339,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
Thread.sleep(5000);
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -393,19 +364,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setMaxWorkers(2);
|
||||
|
||||
@@ -420,24 +391,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -451,19 +416,19 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.FAILED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.FAILED);
|
||||
|
||||
StepExecution workerStepExecutionStart3 = getStepExecutionStart(jobExecution, 6L);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(
|
||||
workerStepExecutionStart3, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish3 = getStepExecutionFinish(workerStepExecutionStart3,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
handler.setMaxWorkers(2);
|
||||
|
||||
@@ -478,24 +443,18 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L))
|
||||
.thenReturn(workerStepExecutionFinish3);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 6L)).thenReturn(workerStepExecutionFinish3);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(3))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(3)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allValues = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allValues, 3);
|
||||
|
||||
@@ -524,11 +483,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
|
||||
Map<String, String> environmentParameters = new HashMap<>(2);
|
||||
environmentParameters.put("foo", "bar");
|
||||
@@ -546,17 +505,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -568,14 +524,12 @@ 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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -593,11 +547,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
Map<String, String> environmentParameters = new HashMap<>(2);
|
||||
@@ -616,17 +570,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -634,20 +585,17 @@ public class DeployerPartitionHandlerTests {
|
||||
assertThat(request.getDefinition().getProperties().size()).isEqualTo(3);
|
||||
assertThat(request.getDefinition().getProperties().get("foo")).isEqualTo("bar");
|
||||
assertThat(request.getDefinition().getProperties().get("baz")).isEqualTo("qux");
|
||||
assertThat(request.getDefinition().getProperties().get("task"))
|
||||
.isEqualTo("batch");
|
||||
assertThat(request.getDefinition().getProperties().get("task")).isEqualTo("batch");
|
||||
|
||||
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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -662,15 +610,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setPollInterval(20000L);
|
||||
@@ -684,33 +632,26 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Date startTime = new Date();
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
Date endTime = new Date();
|
||||
verify(this.taskLauncher, times(2))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(2)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allRequests, 2);
|
||||
|
||||
validateStepExecutionResults(results);
|
||||
|
||||
assertThat(endTime.getTime() - startTime.getTime() >= 19999)
|
||||
.as("Time difference was too small: "
|
||||
+ (endTime.getTime() - startTime.getTime()))
|
||||
.isTrue();
|
||||
.as("Time difference was too small: " + (endTime.getTime() - startTime.getTime())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -720,15 +661,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setPollInterval(20000L);
|
||||
@@ -743,10 +684,8 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
Mockito.lenient().when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
@@ -764,15 +703,15 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart1 = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(
|
||||
workerStepExecutionStart1, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish1 = getStepExecutionFinish(workerStepExecutionStart1,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
StepExecution workerStepExecutionStart2 = getStepExecutionStart(jobExecution, 5L);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(
|
||||
workerStepExecutionStart2, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish2 = getStepExecutionFinish(workerStepExecutionStart2,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
handler.setGridSize(2);
|
||||
@@ -785,23 +724,18 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart2);
|
||||
when(this.splitter.split(masterStepExecution, 2)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L))
|
||||
.thenReturn(workerStepExecutionFinish2);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish1);
|
||||
when(this.jobExplorer.getStepExecution(1L, 5L)).thenReturn(workerStepExecutionFinish2);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher, times(2))
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher, times(2)).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor
|
||||
.getAllValues();
|
||||
List<AppDeploymentRequest> allRequests = this.appDeploymentRequestArgumentCaptor.getAllValues();
|
||||
|
||||
validateAppDeploymentRequests(allRequests, 2);
|
||||
|
||||
@@ -815,11 +749,11 @@ public class DeployerPartitionHandlerTests {
|
||||
JobExecution jobExecution = masterStepExecution.getJobExecution();
|
||||
|
||||
StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(
|
||||
workerStepExecutionStart, BatchStatus.COMPLETED);
|
||||
StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart,
|
||||
BatchStatus.COMPLETED);
|
||||
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher,
|
||||
this.jobExplorer, this.resource, "step1", this.taskRepository);
|
||||
DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer,
|
||||
this.resource, "step1", this.taskRepository);
|
||||
handler.setEnvironment(this.environment);
|
||||
|
||||
Map<String, String> deploymentProperties = new HashMap<>(2);
|
||||
@@ -835,17 +769,14 @@ public class DeployerPartitionHandlerTests {
|
||||
stepExecutions.add(workerStepExecutionStart);
|
||||
when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions);
|
||||
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L))
|
||||
.thenReturn(workerStepExecutionFinish);
|
||||
when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish);
|
||||
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
handler.beforeTask(taskExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter,
|
||||
masterStepExecution);
|
||||
Collection<StepExecution> results = handler.handle(this.splitter, masterStepExecution);
|
||||
|
||||
verify(this.taskLauncher)
|
||||
.launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture());
|
||||
|
||||
AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue();
|
||||
|
||||
@@ -857,14 +788,12 @@ 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, "4")))
|
||||
.isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
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, "4"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
StepExecution resultStepExecution = results.iterator().next();
|
||||
@@ -876,18 +805,16 @@ public class DeployerPartitionHandlerTests {
|
||||
return String.format("--%s=%s", key, value);
|
||||
}
|
||||
|
||||
private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart,
|
||||
BatchStatus status) {
|
||||
StepExecution workerStepExecutionFinish = new StepExecution(
|
||||
stepExecutionStart.getStepName(), stepExecutionStart.getJobExecution());
|
||||
private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart, BatchStatus status) {
|
||||
StepExecution workerStepExecutionFinish = new StepExecution(stepExecutionStart.getStepName(),
|
||||
stepExecutionStart.getJobExecution());
|
||||
workerStepExecutionFinish.setId(stepExecutionStart.getId());
|
||||
workerStepExecutionFinish.setStatus(status);
|
||||
return workerStepExecutionFinish;
|
||||
}
|
||||
|
||||
private StepExecution getStepExecutionStart(JobExecution jobExecution, long id) {
|
||||
StepExecution workerStepExecutionStart = new StepExecution(
|
||||
"step1:partition" + (id - 3), jobExecution);
|
||||
StepExecution workerStepExecutionStart = new StepExecution("step1:partition" + (id - 3), jobExecution);
|
||||
workerStepExecutionStart.setId(id);
|
||||
return workerStepExecutionStart;
|
||||
}
|
||||
@@ -917,8 +844,7 @@ public class DeployerPartitionHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAppDeploymentRequests(List<AppDeploymentRequest> allRequests,
|
||||
int numberOfPartitions) {
|
||||
private void validateAppDeploymentRequests(List<AppDeploymentRequest> allRequests, int numberOfPartitions) {
|
||||
Collections.sort(allRequests, new Comparator<AppDeploymentRequest>() {
|
||||
@Override
|
||||
public int compare(AppDeploymentRequest o1, AppDeploymentRequest o2) {
|
||||
@@ -926,8 +852,7 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
String o1Command = "";
|
||||
for (String commandlineArgument : commandlineArguments) {
|
||||
if (commandlineArgument.contains(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
if (commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
o1Command = commandlineArgument;
|
||||
break;
|
||||
}
|
||||
@@ -937,8 +862,7 @@ public class DeployerPartitionHandlerTests {
|
||||
|
||||
String o2Command = "";
|
||||
for (String commandlineArgument : commandlineArguments) {
|
||||
if (commandlineArgument.contains(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
if (commandlineArgument.contains(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)) {
|
||||
o2Command = commandlineArgument;
|
||||
break;
|
||||
}
|
||||
@@ -955,39 +879,32 @@ 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")))
|
||||
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();
|
||||
assertThat(request.getCommandlineArguments()
|
||||
.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();
|
||||
.contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))).isTrue();
|
||||
assertThat(request.getCommandlineArguments().contains(formatArgs("spring.cloud.task.executionid", "2")))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDeprecatedConstructorValidation(TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName,
|
||||
String expectedMessage) {
|
||||
private void validateDeprecatedConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer,
|
||||
Resource resource, String stepName, String expectedMessage) {
|
||||
try {
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName,
|
||||
this.taskRepository);
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName, this.taskRepository);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(expectedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConstructorValidation(TaskLauncher taskLauncher,
|
||||
JobExplorer jobExplorer, Resource resource, String stepName,
|
||||
TaskRepository taskRepository, String expectedMessage) {
|
||||
private void validateConstructorValidation(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource,
|
||||
String stepName, TaskRepository taskRepository, String expectedMessage) {
|
||||
try {
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName,
|
||||
taskRepository);
|
||||
new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName, taskRepository);
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(expectedMessage);
|
||||
|
||||
@@ -71,8 +71,7 @@ public class DeployerStepExecutionHandlerTests {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
|
||||
this.handler = new DeployerStepExecutionHandler(this.beanFactory,
|
||||
this.jobExplorer, this.jobRepository);
|
||||
this.handler = new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer, this.jobRepository);
|
||||
|
||||
ReflectionTestUtils.setField(this.handler, "environment", this.environment);
|
||||
}
|
||||
@@ -80,113 +79,80 @@ public class DeployerStepExecutionHandlerTests {
|
||||
@Test
|
||||
public void testConstructorValidation() {
|
||||
validateConstructorValidation(null, null, null, "A beanFactory is required");
|
||||
validateConstructorValidation(this.beanFactory, null, null,
|
||||
"A jobExplorer is required");
|
||||
validateConstructorValidation(this.beanFactory, this.jobExplorer, null,
|
||||
"A jobRepository is required");
|
||||
validateConstructorValidation(this.beanFactory, null, null, "A jobExplorer is required");
|
||||
validateConstructorValidation(this.beanFactory, this.jobExplorer, null, "A jobRepository is required");
|
||||
|
||||
new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer,
|
||||
this.jobRepository);
|
||||
new DeployerStepExecutionHandler(this.beanFactory, this.jobExplorer, this.jobRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationOfRequestValuesExist() throws Exception {
|
||||
validateEnvironmentConfiguration("A job execution id is required", new String[0]);
|
||||
validateEnvironmentConfiguration("A step execution id is required", new String[] {
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID });
|
||||
validateEnvironmentConfiguration("A step execution id is required",
|
||||
new String[] { DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID });
|
||||
validateEnvironmentConfiguration("A step name is required",
|
||||
new String[] {
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
new String[] { DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationOfRequestStepFound() throws Exception {
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class))
|
||||
.thenReturn(new String[] { "bar", "baz" });
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "bar", "baz" });
|
||||
|
||||
try {
|
||||
this.handler.run();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertThat(iae.getMessage()).isEqualTo(
|
||||
"The step requested cannot be found in the provided BeanFactory");
|
||||
assertThat(iae.getMessage()).isEqualTo("The step requested cannot be found in the provided BeanFactory");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingStepExecution() throws Exception {
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class))
|
||||
.thenReturn(new String[] { "foo", "bar", "baz" });
|
||||
when(this.environment.getProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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("foo");
|
||||
when(this.beanFactory.getBeanNamesForType(Step.class)).thenReturn(new String[] { "foo", "bar", "baz" });
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.thenReturn("2");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)).thenReturn("1");
|
||||
|
||||
try {
|
||||
this.handler.run();
|
||||
}
|
||||
catch (NoSuchStepException nsse) {
|
||||
assertThat(nsse.getMessage()).isEqualTo(
|
||||
"No StepExecution could be located for step execution id 2 within job execution 1");
|
||||
assertThat(nsse.getMessage())
|
||||
.isEqualTo("No StepExecution could be located for step execution id 2 within job execution 1");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunSuccessful() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
|
||||
this.handler.run();
|
||||
@@ -197,74 +163,50 @@ public class DeployerStepExecutionHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testJobInterruptedException() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new JobInterruptedException("expected")).when(this.step)
|
||||
.execute(workerStep);
|
||||
doThrow(new JobInterruptedException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
this.handler.run();
|
||||
|
||||
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
|
||||
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus())
|
||||
.isEqualTo(BatchStatus.STOPPED);
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus()).isEqualTo(BatchStatus.STOPPED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRuntimeException() throws Exception {
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L),
|
||||
2L);
|
||||
StepExecution workerStep = new StepExecution("workerStep", new JobExecution(1L), 2L);
|
||||
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(
|
||||
DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
when(this.environment
|
||||
.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn("1");
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID))
|
||||
.thenReturn(true);
|
||||
when(this.environment.containsProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID))
|
||||
.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");
|
||||
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");
|
||||
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");
|
||||
when(this.environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME))
|
||||
.thenReturn("workerStep");
|
||||
when(this.beanFactory.getBean("workerStep", Step.class)).thenReturn(this.step);
|
||||
doThrow(new RuntimeException("expected")).when(this.step).execute(workerStep);
|
||||
|
||||
@@ -272,12 +214,10 @@ public class DeployerStepExecutionHandlerTests {
|
||||
|
||||
verify(this.jobRepository).update(this.stepExecutionArgumentCaptor.capture());
|
||||
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus())
|
||||
.isEqualTo(BatchStatus.FAILED);
|
||||
assertThat(this.stepExecutionArgumentCaptor.getValue().getStatus()).isEqualTo(BatchStatus.FAILED);
|
||||
}
|
||||
|
||||
private void validateEnvironmentConfiguration(String errorMessage,
|
||||
String[] properties) throws Exception {
|
||||
private void validateEnvironmentConfiguration(String errorMessage, String[] properties) throws Exception {
|
||||
|
||||
for (String property : properties) {
|
||||
when(this.environment.containsProperty(property)).thenReturn(true);
|
||||
@@ -291,8 +231,8 @@ public class DeployerStepExecutionHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConstructorValidation(BeanFactory beanFactory,
|
||||
JobExplorer jobExplorer, JobRepository jobRepository, String message) {
|
||||
private void validateConstructorValidation(BeanFactory beanFactory, JobExplorer jobExplorer,
|
||||
JobRepository jobRepository, String message) {
|
||||
try {
|
||||
new DeployerStepExecutionHandler(beanFactory, jobExplorer, jobRepository);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,11 @@ public class NoOpEnvironmentVariablesProviderTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Map<String, String> environmentVariables = this.provider
|
||||
.getEnvironmentVariables(null);
|
||||
Map<String, String> environmentVariables = this.provider.getEnvironmentVariables(null);
|
||||
assertThat(environmentVariables).isNotNull();
|
||||
assertThat(environmentVariables.isEmpty()).isTrue();
|
||||
|
||||
Map<String, String> environmentVariables2 = this.provider
|
||||
.getEnvironmentVariables(null);
|
||||
Map<String, String> environmentVariables2 = this.provider.getEnvironmentVariables(null);
|
||||
assertThat(environmentVariables == environmentVariables2).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
|
||||
@@ -56,8 +55,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
provider.setAppendedArgs(appendedValues);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
@@ -76,8 +74,7 @@ public class SimpleCommandLineArgsProviderTests {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));
|
||||
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
|
||||
taskExecution);
|
||||
SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(taskExecution);
|
||||
provider.setAppendedArgs(null);
|
||||
|
||||
List<String> commandLineArgs = provider.getCommandLineArgs(null);
|
||||
|
||||
@@ -96,16 +96,14 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
|
||||
* infrastructure.
|
||||
* @param context the context to be used.
|
||||
*/
|
||||
public DefaultTaskConfigurer(DataSource dataSource, String tablePrefix,
|
||||
ApplicationContext context) {
|
||||
public DefaultTaskConfigurer(DataSource dataSource, String tablePrefix, ApplicationContext context) {
|
||||
this.dataSource = dataSource;
|
||||
this.context = context;
|
||||
|
||||
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean;
|
||||
|
||||
if (this.dataSource != null) {
|
||||
taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(this.dataSource,
|
||||
tablePrefix);
|
||||
taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(this.dataSource, tablePrefix);
|
||||
}
|
||||
else {
|
||||
taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean();
|
||||
@@ -136,27 +134,22 @@ public class DefaultTaskConfigurer implements TaskConfigurer {
|
||||
if (isDataSourceAvailable()) {
|
||||
try {
|
||||
Class.forName("javax.persistence.EntityManager");
|
||||
if (this.context != null && this.context
|
||||
.getBeanNamesForType(EntityManager.class).length > 0) {
|
||||
logger.debug(
|
||||
"EntityManager was found, using JpaTransactionManager");
|
||||
if (this.context != null && this.context.getBeanNamesForType(EntityManager.class).length > 0) {
|
||||
logger.debug("EntityManager was found, using JpaTransactionManager");
|
||||
this.transactionManager = new JpaTransactionManager();
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException ignore) {
|
||||
logger.debug(
|
||||
"No EntityManager was found, using DataSourceTransactionManager");
|
||||
logger.debug("No EntityManager was found, using DataSourceTransactionManager");
|
||||
}
|
||||
finally {
|
||||
if (this.transactionManager == null) {
|
||||
this.transactionManager = new DataSourceTransactionManager(
|
||||
this.dataSource);
|
||||
this.transactionManager = new DataSourceTransactionManager(this.dataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.debug(
|
||||
"No DataSource was found, using ResourcelessTransactionManager");
|
||||
logger.debug("No DataSource was found, using ResourcelessTransactionManager");
|
||||
this.transactionManager = new ResourcelessTransactionManager();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,13 +55,12 @@ import org.springframework.util.CollectionUtils;
|
||||
@EnableTransactionManagement
|
||||
@EnableConfigurationProperties({ TaskProperties.class })
|
||||
// @checkstyle:off
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.autoconfiguration", name = "enabled",
|
||||
havingValue = "true", matchIfMissing = true)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.autoconfiguration", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
// @checkstyle:on
|
||||
public class SimpleTaskAutoConfiguration {
|
||||
|
||||
protected static final Log logger = LogFactory
|
||||
.getLog(SimpleTaskAutoConfiguration.class);
|
||||
protected static final Log logger = LogFactory.getLog(SimpleTaskAutoConfiguration.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<DataSource> dataSources;
|
||||
@@ -85,7 +84,6 @@ public class SimpleTaskAutoConfiguration {
|
||||
return this.taskRepository;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public PlatformTransactionManager springCloudTaskTransactionManager() {
|
||||
return this.platformTransactionManager;
|
||||
@@ -104,8 +102,7 @@ public class SimpleTaskAutoConfiguration {
|
||||
@Bean
|
||||
@Lazy(false)
|
||||
public TaskRepositoryInitializer taskRepositoryInitializer() {
|
||||
TaskRepositoryInitializer taskRepositoryInitializer = new TaskRepositoryInitializer(
|
||||
this.taskProperties);
|
||||
TaskRepositoryInitializer taskRepositoryInitializer = new TaskRepositoryInitializer(this.taskProperties);
|
||||
DataSource initializerDataSource = getDefaultConfigurer().getTaskDataSource();
|
||||
if (initializerDataSource != null) {
|
||||
taskRepositoryInitializer.setDataSource(initializerDataSource);
|
||||
@@ -114,7 +111,6 @@ public class SimpleTaskAutoConfiguration {
|
||||
return taskRepositoryInitializer;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@Profile("cloud")
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues() {
|
||||
@@ -132,8 +128,7 @@ public class SimpleTaskAutoConfiguration {
|
||||
|
||||
TaskConfigurer taskConfigurer = getDefaultConfigurer();
|
||||
|
||||
logger.debug(String.format("Using %s TaskConfigurer",
|
||||
taskConfigurer.getClass().getName()));
|
||||
logger.debug(String.format("Using %s TaskConfigurer", taskConfigurer.getClass().getName()));
|
||||
|
||||
this.taskRepository = taskConfigurer.getTaskRepository();
|
||||
this.platformTransactionManager = taskConfigurer.getTransactionManager();
|
||||
@@ -148,18 +143,14 @@ public class SimpleTaskAutoConfiguration {
|
||||
|
||||
if (configurers < 1) {
|
||||
TaskConfigurer taskConfigurer;
|
||||
if (!CollectionUtils.isEmpty(this.dataSources)
|
||||
&& this.dataSources.size() == 1) {
|
||||
taskConfigurer = new DefaultTaskConfigurer(
|
||||
this.dataSources.iterator().next(),
|
||||
if (!CollectionUtils.isEmpty(this.dataSources) && this.dataSources.size() == 1) {
|
||||
taskConfigurer = new DefaultTaskConfigurer(this.dataSources.iterator().next(),
|
||||
this.taskProperties.getTablePrefix(), this.context);
|
||||
}
|
||||
else {
|
||||
taskConfigurer = new DefaultTaskConfigurer(
|
||||
this.taskProperties.getTablePrefix());
|
||||
taskConfigurer = new DefaultTaskConfigurer(this.taskProperties.getTablePrefix());
|
||||
}
|
||||
this.context.getBeanFactory().registerSingleton("taskConfigurer",
|
||||
taskConfigurer);
|
||||
this.context.getBeanFactory().registerSingleton("taskConfigurer", taskConfigurer);
|
||||
return taskConfigurer;
|
||||
}
|
||||
else {
|
||||
@@ -167,8 +158,7 @@ public class SimpleTaskAutoConfiguration {
|
||||
return this.context.getBean(TaskConfigurer.class);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Expected one TaskConfigurer but found " + configurers);
|
||||
throw new IllegalStateException("Expected one TaskConfigurer but found " + configurers);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,14 +167,12 @@ public class SimpleTaskAutoConfiguration {
|
||||
int configurers = this.context.getBeanNamesForType(TaskConfigurer.class).length;
|
||||
// retrieve the count of dataSources (without instantiating them) excluding
|
||||
// DataSource proxy beans
|
||||
long dataSources = Arrays
|
||||
.stream(this.context.getBeanNamesForType(DataSource.class))
|
||||
long dataSources = Arrays.stream(this.context.getBeanNamesForType(DataSource.class))
|
||||
.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"
|
||||
+ " one DataSource, found " + dataSources);
|
||||
throw new IllegalStateException("To use the default TaskConfigurer the context must contain no more than"
|
||||
+ " one DataSource, found " + dataSources);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,29 +73,27 @@ public class SingleInstanceTaskListener implements ApplicationListener<Applicati
|
||||
|
||||
private PlatformTransactionManager platformTransactionManager;
|
||||
|
||||
public SingleInstanceTaskListener(LockRegistry lockRegistry,
|
||||
TaskNameResolver taskNameResolver, TaskProperties taskProperties,
|
||||
ApplicationEventPublisher applicationEventPublisher,
|
||||
public SingleInstanceTaskListener(LockRegistry lockRegistry, TaskNameResolver taskNameResolver,
|
||||
TaskProperties taskProperties, ApplicationEventPublisher applicationEventPublisher,
|
||||
ApplicationContext applicationContext) {
|
||||
this.lockRegistry = lockRegistry;
|
||||
this.taskNameResolver = taskNameResolver;
|
||||
this.taskProperties = taskProperties;
|
||||
this.lockRegistryLeaderInitiator = new LockRegistryLeaderInitiator(
|
||||
this.lockRegistry);
|
||||
this.lockRegistryLeaderInitiator = new LockRegistryLeaderInitiator(this.lockRegistry);
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public SingleInstanceTaskListener(DataSource dataSource,
|
||||
TaskNameResolver taskNameResolver, TaskProperties taskProperties,
|
||||
ApplicationEventPublisher applicationEventPublisher,
|
||||
public SingleInstanceTaskListener(DataSource dataSource, TaskNameResolver taskNameResolver,
|
||||
TaskProperties taskProperties, ApplicationEventPublisher applicationEventPublisher,
|
||||
ApplicationContext applicationContext) {
|
||||
this.taskNameResolver = taskNameResolver;
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
this.dataSource = dataSource;
|
||||
this.taskProperties = taskProperties;
|
||||
this.applicationContext = applicationContext;
|
||||
this.platformTransactionManager = this.applicationContext.getBean("springCloudTaskTransactionManager", PlatformTransactionManager.class);
|
||||
this.platformTransactionManager = this.applicationContext.getBean("springCloudTaskTransactionManager",
|
||||
PlatformTransactionManager.class);
|
||||
}
|
||||
|
||||
@BeforeTask
|
||||
@@ -103,12 +101,9 @@ public class SingleInstanceTaskListener implements ApplicationListener<Applicati
|
||||
if (this.lockRegistry == null) {
|
||||
this.lockRegistry = getDefaultLockRegistry(taskExecution.getExecutionId());
|
||||
}
|
||||
this.lockRegistryLeaderInitiator = new LockRegistryLeaderInitiator(
|
||||
this.lockRegistry,
|
||||
new DefaultCandidate(String.valueOf(taskExecution.getExecutionId()),
|
||||
this.taskNameResolver.getTaskName()));
|
||||
this.lockRegistryLeaderInitiator
|
||||
.setApplicationEventPublisher(this.applicationEventPublisher);
|
||||
this.lockRegistryLeaderInitiator = new LockRegistryLeaderInitiator(this.lockRegistry, new DefaultCandidate(
|
||||
String.valueOf(taskExecution.getExecutionId()), this.taskNameResolver.getTaskName()));
|
||||
this.lockRegistryLeaderInitiator.setApplicationEventPublisher(this.applicationEventPublisher);
|
||||
this.lockRegistryLeaderInitiator.setPublishFailedEvents(true);
|
||||
this.lockRegistryLeaderInitiator.start();
|
||||
while (!this.lockReady) {
|
||||
@@ -119,15 +114,13 @@ public class SingleInstanceTaskListener implements ApplicationListener<Applicati
|
||||
logger.warn("Thread Sleep Failed", ex);
|
||||
}
|
||||
if (this.lockFailed) {
|
||||
String errorMessage = String.format(
|
||||
"Task with name \"%s\" is already running.",
|
||||
String errorMessage = String.format("Task with name \"%s\" is already running.",
|
||||
this.taskNameResolver.getTaskName());
|
||||
try {
|
||||
this.lockRegistryLeaderInitiator.destroy();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new TaskExecutionException("Failed to destroy lock.",
|
||||
exception);
|
||||
throw new TaskExecutionException("Failed to destroy lock.", exception);
|
||||
}
|
||||
throw new TaskExecutionException(errorMessage);
|
||||
}
|
||||
@@ -140,8 +133,7 @@ public class SingleInstanceTaskListener implements ApplicationListener<Applicati
|
||||
}
|
||||
|
||||
@FailedTask
|
||||
public void unlockTaskOnError(TaskExecution taskExecution, Throwable throwable)
|
||||
throws Exception {
|
||||
public void unlockTaskOnError(TaskExecution taskExecution, Throwable throwable) throws Exception {
|
||||
this.lockRegistryLeaderInitiator.destroy();
|
||||
}
|
||||
|
||||
@@ -156,8 +148,7 @@ public class SingleInstanceTaskListener implements ApplicationListener<Applicati
|
||||
}
|
||||
|
||||
private LockRegistry getDefaultLockRegistry(long executionId) {
|
||||
DefaultLockRepository lockRepository = new DefaultLockRepository(this.dataSource,
|
||||
String.valueOf(executionId));
|
||||
DefaultLockRepository lockRepository = new DefaultLockRepository(this.dataSource, String.valueOf(executionId));
|
||||
lockRepository.setPrefix(this.taskProperties.getTablePrefix());
|
||||
lockRepository.setTimeToLive(this.taskProperties.getSingleInstanceLockTtl());
|
||||
lockRepository.setApplicationContext(this.applicationContext);
|
||||
|
||||
@@ -36,8 +36,7 @@ import org.springframework.integration.support.locks.PassThruLockRegistry;
|
||||
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task", name = "single-instance-enabled",
|
||||
havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task", name = "single-instance-enabled", havingValue = "true")
|
||||
public class SingleTaskConfiguration {
|
||||
|
||||
@Autowired
|
||||
@@ -52,12 +51,12 @@ public class SingleTaskConfiguration {
|
||||
@Bean
|
||||
public SingleInstanceTaskListener taskListener(TaskNameResolver resolver, ApplicationContext applicationContext) {
|
||||
if (this.taskConfigurer.getTaskDataSource() == null) {
|
||||
return new SingleInstanceTaskListener(new PassThruLockRegistry(), resolver,
|
||||
this.taskProperties, this.applicationEventPublisher, applicationContext);
|
||||
return new SingleInstanceTaskListener(new PassThruLockRegistry(), resolver, this.taskProperties,
|
||||
this.applicationEventPublisher, applicationContext);
|
||||
}
|
||||
|
||||
return new SingleInstanceTaskListener(this.taskConfigurer.getTaskDataSource(),
|
||||
resolver, this.taskProperties, this.applicationEventPublisher, applicationContext);
|
||||
return new SingleInstanceTaskListener(this.taskConfigurer.getTaskDataSource(), resolver, this.taskProperties,
|
||||
this.applicationEventPublisher, applicationContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class TaskLifecycleConfiguration {
|
||||
|
||||
protected static final Log logger = LogFactory
|
||||
.getLog(TaskLifecycleConfiguration.class);
|
||||
protected static final Log logger = LogFactory.getLog(TaskLifecycleConfiguration.class);
|
||||
|
||||
private TaskProperties taskProperties;
|
||||
|
||||
@@ -67,12 +66,11 @@ public class TaskLifecycleConfiguration {
|
||||
private TaskObservationCloudKeyValues taskObservationCloudKeyValues;
|
||||
|
||||
@Autowired
|
||||
public TaskLifecycleConfiguration(TaskProperties taskProperties,
|
||||
ConfigurableApplicationContext context, TaskRepository taskRepository,
|
||||
TaskExplorer taskExplorer, TaskNameResolver taskNameResolver,
|
||||
ObjectProvider<ApplicationArguments> applicationArguments,
|
||||
@Autowired(required = false) ObservationRegistry observationRegistry,
|
||||
@Autowired(required = false) TaskObservationCloudKeyValues taskObservationCloudKeyValues) {
|
||||
public TaskLifecycleConfiguration(TaskProperties taskProperties, ConfigurableApplicationContext context,
|
||||
TaskRepository taskRepository, TaskExplorer taskExplorer, TaskNameResolver taskNameResolver,
|
||||
ObjectProvider<ApplicationArguments> applicationArguments,
|
||||
@Autowired(required = false) ObservationRegistry observationRegistry,
|
||||
@Autowired(required = false) TaskObservationCloudKeyValues taskObservationCloudKeyValues) {
|
||||
|
||||
this.taskProperties = taskProperties;
|
||||
this.context = context;
|
||||
@@ -96,11 +94,10 @@ public class TaskLifecycleConfiguration {
|
||||
@PostConstruct
|
||||
protected void initialize() {
|
||||
if (!this.initialized) {
|
||||
this.taskLifecycleListener = new TaskLifecycleListener(this.taskRepository,
|
||||
this.taskNameResolver, this.applicationArguments, this.taskExplorer,
|
||||
this.taskProperties,
|
||||
new TaskListenerExecutorObjectFactory(this.context),
|
||||
this.observationRegistry, taskObservationCloudKeyValues);
|
||||
this.taskLifecycleListener = new TaskLifecycleListener(this.taskRepository, this.taskNameResolver,
|
||||
this.applicationArguments, this.taskExplorer, this.taskProperties,
|
||||
new TaskListenerExecutorObjectFactory(this.context), this.observationRegistry,
|
||||
taskObservationCloudKeyValues);
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@@ -103,4 +103,5 @@ public class TaskObservationCloudKeyValues {
|
||||
public void setInstanceIndex(String instanceIndex) {
|
||||
this.instanceIndex = instanceIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,5 @@ public class DefaultTaskObservationConvention implements TaskObservationConventi
|
||||
public String getName() {
|
||||
return "spring.cloud.task.runner";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,8 +51,9 @@ class ObservationApplicationRunner implements ApplicationRunner {
|
||||
@Override
|
||||
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 observation = TaskDocumentedObservation.TASK_RUNNER_OBSERVATION
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
|
||||
try (Observation.Scope scope = observation.start().openScope()) {
|
||||
this.delegate.run(args);
|
||||
|
||||
@@ -50,8 +50,9 @@ class ObservationCommandLineRunner implements CommandLineRunner {
|
||||
@Override
|
||||
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 observation = TaskDocumentedObservation.TASK_RUNNER_OBSERVATION
|
||||
.observation(this.taskObservationConvention, INSTANCE, context, registry())
|
||||
.contextualName(this.beanName);
|
||||
try (Observation.Scope scope = observation.start().openScope()) {
|
||||
this.delegate.run(args);
|
||||
}
|
||||
@@ -70,4 +71,5 @@ class ObservationCommandLineRunner implements CommandLineRunner {
|
||||
}
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,12 +39,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class ObservationTaskAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
static ObservationCommandLineRunnerBeanPostProcessor observedCommandLineRunnerBeanPostProcessor(BeanFactory beanFactory) {
|
||||
static ObservationCommandLineRunnerBeanPostProcessor observedCommandLineRunnerBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
return new ObservationCommandLineRunnerBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
static ObservationApplicationRunnerBeanPostProcessor observedApplicationRunnerBeanPostProcessor(BeanFactory beanFactory) {
|
||||
static ObservationApplicationRunnerBeanPostProcessor observedApplicationRunnerBeanPostProcessor(
|
||||
BeanFactory beanFactory) {
|
||||
return new ObservationApplicationRunnerBeanPostProcessor(beanFactory);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,5 +57,7 @@ enum TaskDocumentedObservation implements DocumentedObservation {
|
||||
return "spring.cloud.task.runner.bean-name";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,4 +35,5 @@ public class TaskObservationContext extends Observation.Context {
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,5 @@ public interface TaskObservationConvention extends Observation.ObservationConven
|
||||
default boolean supportsContext(Observation.Context context) {
|
||||
return context instanceof TaskObservationContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ import io.micrometer.common.KeyValues;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
|
||||
/**
|
||||
* /**
|
||||
* Default {@link TaskExecutionObservationConvention} implementation.
|
||||
* /** Default {@link TaskExecutionObservationConvention} implementation.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 3.0.0
|
||||
@@ -41,15 +40,16 @@ public class DefaultTaskExecutionObservationConvention implements TaskExecutionO
|
||||
|
||||
private KeyValues getKeyValuesForTaskExecution(TaskExecutionObservationContext context) {
|
||||
TaskExecution execution = context.getTaskExecution();
|
||||
return KeyValues.of(
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), context.getStatus(),
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.getKeyName(), String.valueOf(execution.getExitCode()),
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(),
|
||||
String.valueOf(execution.getExecutionId()));
|
||||
return KeyValues.of(TaskExecutionObservation.TaskKeyValues.TASK_STATUS.getKeyName(), context.getStatus(),
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_EXIT_CODE.getKeyName(),
|
||||
String.valueOf(execution.getExitCode()),
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(),
|
||||
String.valueOf(execution.getExecutionId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "spring.cloud.task";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ package org.springframework.cloud.task.listener;
|
||||
*
|
||||
* @author Michael Minella
|
||||
* @since 1.2
|
||||
* @deprecated since 3.0 in favor of the default implementations of {@link TaskExecutionListener}
|
||||
* @deprecated since 3.0 in favor of the default implementations of
|
||||
* {@link TaskExecutionListener}
|
||||
*/
|
||||
@Deprecated
|
||||
public class TaskExecutionListenerSupport implements TaskExecutionListener {
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.micrometer.observation.docs.DocumentedObservation;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public enum TaskExecutionObservation implements DocumentedObservation {
|
||||
|
||||
/**
|
||||
* Metrics created around a task execution.
|
||||
*/
|
||||
@@ -41,6 +42,7 @@ public enum TaskExecutionObservation implements DocumentedObservation {
|
||||
return "spring.cloud.task";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public KeyName[] getLowCardinalityKeyNames() {
|
||||
return TaskKeyValues.values();
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.cloud.task.repository.TaskExecution;
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class TaskExecutionObservationContext extends Observation.Context {
|
||||
|
||||
private final TaskExecution taskExecution;
|
||||
|
||||
private String exceptionMessage = "none";
|
||||
@@ -57,4 +58,5 @@ public class TaskExecutionObservationContext extends Observation.Context {
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ import io.micrometer.observation.Observation;
|
||||
* @author Glenn Renfro
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public interface TaskExecutionObservationConvention extends Observation.ObservationConvention<TaskExecutionObservationContext> {
|
||||
public interface TaskExecutionObservationConvention
|
||||
extends Observation.ObservationConvention<TaskExecutionObservationContext> {
|
||||
|
||||
@Override
|
||||
default boolean supportsContext(Observation.Context context) {
|
||||
return context instanceof TaskExecutionObservationContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ import org.springframework.util.StringUtils;
|
||||
* @author Michael Minella
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class TaskLifecycleListener implements ApplicationListener<ApplicationEvent>,
|
||||
SmartLifecycle, DisposableBean, Ordered {
|
||||
public class TaskLifecycleListener
|
||||
implements ApplicationListener<ApplicationEvent>, SmartLifecycle, DisposableBean, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TaskLifecycleListener.class);
|
||||
|
||||
@@ -135,18 +135,16 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
* @param taskListenerExecutorObjectFactory {@link TaskListenerExecutorObjectFactory}
|
||||
* to initialize TaskListenerExecutor for a task
|
||||
*/
|
||||
public TaskLifecycleListener(TaskRepository taskRepository,
|
||||
TaskNameResolver taskNameResolver, ApplicationArguments applicationArguments,
|
||||
TaskExplorer taskExplorer, TaskProperties taskProperties,
|
||||
public TaskLifecycleListener(TaskRepository taskRepository, TaskNameResolver taskNameResolver,
|
||||
ApplicationArguments applicationArguments, TaskExplorer taskExplorer, TaskProperties taskProperties,
|
||||
TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory,
|
||||
@Autowired(required = false) ObservationRegistry observationRegistry,
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues) {
|
||||
@Autowired(required = false) ObservationRegistry observationRegistry,
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues) {
|
||||
Assert.notNull(taskRepository, "A taskRepository is required");
|
||||
Assert.notNull(taskNameResolver, "A taskNameResolver is required");
|
||||
Assert.notNull(taskExplorer, "A taskExplorer is required");
|
||||
Assert.notNull(taskProperties, "TaskProperties is required");
|
||||
Assert.notNull(taskListenerExecutorObjectFactory,
|
||||
"A TaskListenerExecutorObjectFactory is required");
|
||||
Assert.notNull(taskListenerExecutorObjectFactory, "A TaskListenerExecutorObjectFactory is required");
|
||||
|
||||
this.taskRepository = taskRepository;
|
||||
this.taskNameResolver = taskNameResolver;
|
||||
@@ -155,7 +153,8 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
this.taskProperties = taskProperties;
|
||||
this.taskListenerExecutorObjectFactory = taskListenerExecutorObjectFactory;
|
||||
observationRegistry = observationRegistry == null ? ObservationRegistry.NOOP : observationRegistry;
|
||||
this.taskObservations = new TaskObservations(observationRegistry, taskObservationCloudKeyValues, observationConvention);
|
||||
this.taskObservations = new TaskObservations(observationRegistry, taskObservationCloudKeyValues,
|
||||
observationConvention);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,8 +169,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent applicationEvent) {
|
||||
if (applicationEvent instanceof ApplicationFailedEvent) {
|
||||
this.applicationFailedException = ((ApplicationFailedEvent) applicationEvent)
|
||||
.getException();
|
||||
this.applicationFailedException = ((ApplicationFailedEvent) applicationEvent).getException();
|
||||
doTaskEnd();
|
||||
}
|
||||
else if (applicationEvent instanceof ExitCodeEvent) {
|
||||
@@ -196,21 +194,18 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
this.taskExecution.setEndTime(new Date());
|
||||
|
||||
if (this.applicationFailedException != null) {
|
||||
this.taskExecution.setErrorMessage(
|
||||
stackTraceToString(this.applicationFailedException));
|
||||
this.taskExecution.setErrorMessage(stackTraceToString(this.applicationFailedException));
|
||||
}
|
||||
|
||||
this.taskExecution.setExitCode(calcExitStatus());
|
||||
if (this.applicationFailedException != null) {
|
||||
setExitMessage(invokeOnTaskError(this.taskExecution,
|
||||
this.applicationFailedException));
|
||||
setExitMessage(invokeOnTaskError(this.taskExecution, this.applicationFailedException));
|
||||
}
|
||||
|
||||
setExitMessage(invokeOnTaskEnd(this.taskExecution));
|
||||
this.taskRepository.completeTaskExecution(this.taskExecution.getExecutionId(),
|
||||
this.taskExecution.getExitCode(), this.taskExecution.getEndTime(),
|
||||
this.taskExecution.getExitMessage(),
|
||||
this.taskExecution.getErrorMessage());
|
||||
this.taskExecution.getExitMessage(), this.taskExecution.getErrorMessage());
|
||||
|
||||
this.finished = true;
|
||||
|
||||
@@ -220,8 +215,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
}
|
||||
else if (!this.started) {
|
||||
logger.error("An event to end a task has been received for a task that has "
|
||||
+ "not yet started.");
|
||||
logger.error("An event to end a task has been received for a task that has " + "not yet started.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,12 +234,10 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
Throwable exception = this.listenerException;
|
||||
if (exception instanceof TaskExecutionException) {
|
||||
TaskExecutionException taskExecutionException = (TaskExecutionException) exception;
|
||||
if (taskExecutionException
|
||||
.getCause() instanceof InvocationTargetException) {
|
||||
if (taskExecutionException.getCause() instanceof InvocationTargetException) {
|
||||
InvocationTargetException invocationTargetException = (InvocationTargetException) taskExecutionException
|
||||
.getCause();
|
||||
if (invocationTargetException != null
|
||||
&& invocationTargetException.getTargetException() != null) {
|
||||
if (invocationTargetException != null && invocationTargetException.getTargetException() != null) {
|
||||
exception = invocationTargetException.getTargetException();
|
||||
}
|
||||
}
|
||||
@@ -268,11 +260,9 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
this.taskExecutionListeners = new ArrayList<>();
|
||||
this.taskListenerExecutorObjectFactory.getObject();
|
||||
if (!CollectionUtils.isEmpty(this.taskExecutionListenersFromContext)) {
|
||||
this.taskExecutionListeners
|
||||
.addAll(this.taskExecutionListenersFromContext);
|
||||
this.taskExecutionListeners.addAll(this.taskExecutionListenersFromContext);
|
||||
}
|
||||
this.taskExecutionListeners
|
||||
.add(this.taskListenerExecutorObjectFactory.getObject());
|
||||
this.taskExecutionListeners.add(this.taskListenerExecutorObjectFactory.getObject());
|
||||
|
||||
List<String> args = new ArrayList<>(0);
|
||||
|
||||
@@ -282,35 +272,27 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
if (this.taskProperties.getExecutionid() != null) {
|
||||
TaskExecution taskExecution = this.taskExplorer
|
||||
.getTaskExecution(this.taskProperties.getExecutionid());
|
||||
Assert.notNull(taskExecution,
|
||||
String.format("Invalid TaskExecution, ID %s not found",
|
||||
this.taskProperties.getExecutionid()));
|
||||
Assert.isNull(taskExecution.getEndTime(), String.format(
|
||||
"Invalid TaskExecution, ID %s task is already complete",
|
||||
Assert.notNull(taskExecution, String.format("Invalid TaskExecution, ID %s not found",
|
||||
this.taskProperties.getExecutionid()));
|
||||
this.taskExecution = this.taskRepository.startTaskExecution(
|
||||
this.taskProperties.getExecutionid(),
|
||||
Assert.isNull(taskExecution.getEndTime(),
|
||||
String.format("Invalid TaskExecution, ID %s task is already complete",
|
||||
this.taskProperties.getExecutionid()));
|
||||
this.taskExecution = this.taskRepository.startTaskExecution(this.taskProperties.getExecutionid(),
|
||||
this.taskNameResolver.getTaskName(), new Date(), args,
|
||||
this.taskProperties.getExternalExecutionId(),
|
||||
this.taskProperties.getParentExecutionId());
|
||||
this.taskProperties.getExternalExecutionId(), this.taskProperties.getParentExecutionId());
|
||||
}
|
||||
else {
|
||||
TaskExecution taskExecution = new TaskExecution();
|
||||
taskExecution.setTaskName(this.taskNameResolver.getTaskName());
|
||||
taskExecution.setStartTime(new Date());
|
||||
taskExecution.setArguments(args);
|
||||
taskExecution.setExternalExecutionId(
|
||||
this.taskProperties.getExternalExecutionId());
|
||||
taskExecution.setParentExecutionId(
|
||||
this.taskProperties.getParentExecutionId());
|
||||
this.taskExecution = this.taskRepository
|
||||
.createTaskExecution(taskExecution);
|
||||
taskExecution.setExternalExecutionId(this.taskProperties.getExternalExecutionId());
|
||||
taskExecution.setParentExecutionId(this.taskProperties.getParentExecutionId());
|
||||
this.taskExecution = this.taskRepository.createTaskExecution(taskExecution);
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.error(
|
||||
"Multiple start events have been received. The first one was "
|
||||
+ "recorded.");
|
||||
logger.error("Multiple start events have been received. The first one was " + "recorded.");
|
||||
}
|
||||
|
||||
setExitMessage(invokeOnTaskStartup(this.taskExecution));
|
||||
@@ -326,8 +308,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
private TaskExecution invokeOnTaskStartup(TaskExecution taskExecution) {
|
||||
this.taskObservations.onTaskStartup(taskExecution);
|
||||
TaskExecution listenerTaskExecution = getTaskExecutionCopy(taskExecution);
|
||||
List<TaskExecutionListener> startupListenerList = new ArrayList<>(
|
||||
this.taskExecutionListeners);
|
||||
List<TaskExecutionListener> startupListenerList = new ArrayList<>(this.taskExecutionListeners);
|
||||
if (!CollectionUtils.isEmpty(startupListenerList)) {
|
||||
try {
|
||||
Collections.reverse(startupListenerList);
|
||||
@@ -360,8 +341,8 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
catch (Throwable listenerException) {
|
||||
String errorMessage = stackTraceToString(listenerException);
|
||||
if (StringUtils.hasText(listenerTaskExecution.getErrorMessage())) {
|
||||
errorMessage = String.format("%s :Task also threw this Exception: %s",
|
||||
errorMessage, listenerTaskExecution.getErrorMessage());
|
||||
errorMessage = String.format("%s :Task also threw this Exception: %s", errorMessage,
|
||||
listenerTaskExecution.getErrorMessage());
|
||||
}
|
||||
logger.error(errorMessage);
|
||||
listenerTaskExecution.setErrorMessage(errorMessage);
|
||||
@@ -371,8 +352,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
return listenerTaskExecution;
|
||||
}
|
||||
|
||||
private TaskExecution invokeOnTaskError(TaskExecution taskExecution,
|
||||
Throwable throwable) {
|
||||
private TaskExecution invokeOnTaskError(TaskExecution taskExecution, Throwable throwable) {
|
||||
if (this.taskObservations != null) {
|
||||
this.taskObservations.onTaskFailed(throwable);
|
||||
}
|
||||
@@ -388,8 +368,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
String errorMessage;
|
||||
if (StringUtils.hasText(listenerTaskExecution.getErrorMessage())) {
|
||||
errorMessage = String.format("%s :While handling " + "this error: %s",
|
||||
listenerException.getMessage(),
|
||||
listenerTaskExecution.getErrorMessage());
|
||||
listenerException.getMessage(), listenerTaskExecution.getErrorMessage());
|
||||
}
|
||||
else {
|
||||
errorMessage = listenerTaskExecution.getErrorMessage();
|
||||
@@ -405,14 +384,12 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
private TaskExecution getTaskExecutionCopy(TaskExecution taskExecution) {
|
||||
Date startTime = new Date(taskExecution.getStartTime().getTime());
|
||||
Date endTime = (taskExecution.getEndTime() == null) ? null
|
||||
: new Date(taskExecution.getEndTime().getTime());
|
||||
Date endTime = (taskExecution.getEndTime() == null) ? null : new Date(taskExecution.getEndTime().getTime());
|
||||
|
||||
return new TaskExecution(taskExecution.getExecutionId(),
|
||||
taskExecution.getExitCode(), taskExecution.getTaskName(), startTime,
|
||||
endTime, taskExecution.getExitMessage(),
|
||||
Collections.unmodifiableList(taskExecution.getArguments()),
|
||||
taskExecution.getErrorMessage(), taskExecution.getExternalExecutionId());
|
||||
return new TaskExecution(taskExecution.getExecutionId(), taskExecution.getExitCode(),
|
||||
taskExecution.getTaskName(), startTime, endTime, taskExecution.getExitMessage(),
|
||||
Collections.unmodifiableList(taskExecution.getArguments()), taskExecution.getErrorMessage(),
|
||||
taskExecution.getExternalExecutionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,13 +49,11 @@ import org.springframework.core.annotation.AnnotationUtils;
|
||||
* @author Isik Erhan
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class TaskListenerExecutorObjectFactory
|
||||
implements ObjectFactory<TaskExecutionListener> {
|
||||
public class TaskListenerExecutorObjectFactory implements ObjectFactory<TaskExecutionListener> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TaskListenerExecutor.class);
|
||||
|
||||
private final Set<Class<?>> nonAnnotatedClasses = Collections
|
||||
.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private final Set<Class<?>> nonAnnotatedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@@ -75,8 +73,7 @@ public class TaskListenerExecutorObjectFactory
|
||||
this.afterTaskInstances = new HashMap<>();
|
||||
this.failedTaskInstances = new HashMap<>();
|
||||
initializeExecutor();
|
||||
return new TaskListenerExecutor(this.beforeTaskInstances, this.afterTaskInstances,
|
||||
this.failedTaskInstances);
|
||||
return new TaskListenerExecutor(this.beforeTaskInstances, this.afterTaskInstances, this.failedTaskInstances);
|
||||
}
|
||||
|
||||
private void initializeExecutor() {
|
||||
@@ -92,8 +89,7 @@ public class TaskListenerExecutorObjectFactory
|
||||
// An unresolvable bean type, probably from a lazy bean - let's ignore
|
||||
// it.
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not resolve target class for bean with name '"
|
||||
+ beanName + "'", ex);
|
||||
logger.debug("Could not resolve target class for bean with name '" + beanName + "'", ex);
|
||||
}
|
||||
}
|
||||
if (type != null) {
|
||||
@@ -105,10 +101,7 @@ public class TaskListenerExecutorObjectFactory
|
||||
catch (RuntimeException ex) {
|
||||
// An invalid scoped proxy arrangement - let's ignore it.
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Could not resolve target bean for scoped proxy '"
|
||||
+ beanName + "'",
|
||||
ex);
|
||||
logger.debug("Could not resolve target bean for scoped proxy '" + beanName + "'", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,9 +110,7 @@ public class TaskListenerExecutorObjectFactory
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new BeanInitializationException(
|
||||
"Failed to process @BeforeTask "
|
||||
+ "annotation on bean with name '" + beanName
|
||||
+ "'",
|
||||
"Failed to process @BeforeTask " + "annotation on bean with name '" + beanName + "'",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
@@ -130,12 +121,11 @@ public class TaskListenerExecutorObjectFactory
|
||||
|
||||
private void processBean(String beanName, final Class<?> type) {
|
||||
if (!this.nonAnnotatedClasses.contains(type)) {
|
||||
Map<Method, BeforeTask> beforeTaskMethods = (new MethodGetter<BeforeTask>())
|
||||
.getMethods(type, BeforeTask.class);
|
||||
Map<Method, AfterTask> afterTaskMethods = (new MethodGetter<AfterTask>())
|
||||
.getMethods(type, AfterTask.class);
|
||||
Map<Method, FailedTask> failedTaskMethods = (new MethodGetter<FailedTask>())
|
||||
.getMethods(type, FailedTask.class);
|
||||
Map<Method, BeforeTask> beforeTaskMethods = (new MethodGetter<BeforeTask>()).getMethods(type,
|
||||
BeforeTask.class);
|
||||
Map<Method, AfterTask> afterTaskMethods = (new MethodGetter<AfterTask>()).getMethods(type, AfterTask.class);
|
||||
Map<Method, FailedTask> failedTaskMethods = (new MethodGetter<FailedTask>()).getMethods(type,
|
||||
FailedTask.class);
|
||||
|
||||
if (beforeTaskMethods.isEmpty() && afterTaskMethods.isEmpty()) {
|
||||
this.nonAnnotatedClasses.add(type);
|
||||
@@ -143,22 +133,19 @@ public class TaskListenerExecutorObjectFactory
|
||||
}
|
||||
if (!beforeTaskMethods.isEmpty()) {
|
||||
for (Method beforeTaskMethod : beforeTaskMethods.keySet()) {
|
||||
this.beforeTaskInstances
|
||||
.computeIfAbsent(beforeTaskMethod, k -> new LinkedHashSet<>())
|
||||
this.beforeTaskInstances.computeIfAbsent(beforeTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
if (!afterTaskMethods.isEmpty()) {
|
||||
for (Method afterTaskMethod : afterTaskMethods.keySet()) {
|
||||
this.afterTaskInstances
|
||||
.computeIfAbsent(afterTaskMethod, k -> new LinkedHashSet<>())
|
||||
this.afterTaskInstances.computeIfAbsent(afterTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
if (!failedTaskMethods.isEmpty()) {
|
||||
for (Method failedTaskMethod : failedTaskMethods.keySet()) {
|
||||
this.failedTaskInstances
|
||||
.computeIfAbsent(failedTaskMethod, k -> new LinkedHashSet<>())
|
||||
this.failedTaskInstances.computeIfAbsent(failedTaskMethod, k -> new LinkedHashSet<>())
|
||||
.add(this.context.getBean(beanName));
|
||||
}
|
||||
}
|
||||
@@ -167,11 +154,10 @@ public class TaskListenerExecutorObjectFactory
|
||||
|
||||
private static class MethodGetter<T extends Annotation> {
|
||||
|
||||
public Map<Method, T> getMethods(final Class<?> type,
|
||||
final Class<T> annotationClass) {
|
||||
public Map<Method, T> getMethods(final Class<?> type, final Class<T> annotationClass) {
|
||||
return MethodIntrospector.selectMethods(type,
|
||||
(MethodIntrospector.MetadataLookup<T>) method -> AnnotationUtils
|
||||
.findAnnotation(method, annotationClass));
|
||||
(MethodIntrospector.MetadataLookup<T>) method -> AnnotationUtils.findAnnotation(method,
|
||||
annotationClass));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,8 +51,9 @@ public class TaskObservations {
|
||||
|
||||
private Observation.ObservationConvention customObservationConvention;
|
||||
|
||||
public TaskObservations(ObservationRegistry observationRegistry, TaskObservationCloudKeyValues taskObservationCloudKeyValues,
|
||||
Observation.ObservationConvention customObservationConvention) {
|
||||
public TaskObservations(ObservationRegistry observationRegistry,
|
||||
TaskObservationCloudKeyValues taskObservationCloudKeyValues,
|
||||
Observation.ObservationConvention customObservationConvention) {
|
||||
this.observationRegistry = observationRegistry;
|
||||
this.taskObservationCloudKeyValues = taskObservationCloudKeyValues;
|
||||
this.customObservationConvention = customObservationConvention;
|
||||
@@ -68,34 +69,38 @@ public class TaskObservations {
|
||||
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
|
||||
|
||||
this.taskObservationContext = new TaskExecutionObservationContext(taskExecution);
|
||||
|
||||
Observation observation = TaskExecutionObservation.TASK_ACTIVE.observation(this.customObservationConvention, new DefaultTaskExecutionObservationConvention(), this.taskObservationContext, this.observationRegistry)
|
||||
.contextualName(String.valueOf(taskExecution.getExecutionId()))
|
||||
.keyValuesProvider(this.observationsProvider)
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(), getValueOrDefault(taskExecution.getTaskName()))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(), "" + taskExecution.getExecutionId())
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.getKeyName(),
|
||||
(getValueOrDefault(taskExecution.getParentExecutionId())))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.getKeyName(),
|
||||
(getValueOrDefault(taskExecution.getExternalExecutionId())));
|
||||
Observation observation = TaskExecutionObservation.TASK_ACTIVE
|
||||
.observation(this.customObservationConvention, new DefaultTaskExecutionObservationConvention(),
|
||||
this.taskObservationContext, this.observationRegistry)
|
||||
.contextualName(String.valueOf(taskExecution.getExecutionId()))
|
||||
.keyValuesProvider(this.observationsProvider)
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_NAME.getKeyName(),
|
||||
getValueOrDefault(taskExecution.getTaskName()))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXECUTION_ID.getKeyName(),
|
||||
"" + taskExecution.getExecutionId())
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_PARENT_EXECUTION_ID.getKeyName(),
|
||||
(getValueOrDefault(taskExecution.getParentExecutionId())))
|
||||
.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_EXTERNAL_EXECUTION_ID.getKeyName(),
|
||||
(getValueOrDefault(taskExecution.getExternalExecutionId())));
|
||||
|
||||
if (taskObservationCloudKeyValues != null) {
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_ORG_NAME.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getOrganizationName());
|
||||
this.taskObservationCloudKeyValues.getOrganizationName());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_ID.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getSpaceId());
|
||||
this.taskObservationCloudKeyValues.getSpaceId());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_SPACE_NAME.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getSpaceName());
|
||||
this.taskObservationCloudKeyValues.getSpaceName());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_ID.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getApplicationId());
|
||||
this.taskObservationCloudKeyValues.getApplicationId());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_NAME.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getApplicationName());
|
||||
this.taskObservationCloudKeyValues.getApplicationName());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_APP_VERSION.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getApplicationVersion());
|
||||
observation.lowCardinalityKeyValue(TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getInstanceIndex());
|
||||
this.taskObservationCloudKeyValues.getApplicationVersion());
|
||||
observation.lowCardinalityKeyValue(
|
||||
TaskExecutionObservation.TaskKeyValues.TASK_CF_INSTANCE_INDEX.getKeyName(),
|
||||
this.taskObservationCloudKeyValues.getInstanceIndex());
|
||||
}
|
||||
observation.start();
|
||||
|
||||
@@ -107,8 +112,8 @@ public class TaskObservations {
|
||||
}
|
||||
|
||||
public void onTaskFailed(Throwable throwable) {
|
||||
this.taskObservationContext.setStatus(STATUS_FAILURE);
|
||||
this.scope.getCurrentObservation().error(throwable);
|
||||
this.taskObservationContext.setStatus(STATUS_FAILURE);
|
||||
this.scope.getCurrentObservation().error(throwable);
|
||||
}
|
||||
|
||||
public void onTaskEnd(TaskExecution taskExecution) {
|
||||
@@ -118,4 +123,5 @@ public class TaskObservations {
|
||||
this.scope.getCurrentObservation().stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
private Map<Method, Set<Object>> failedTaskInstances;
|
||||
|
||||
public TaskListenerExecutor(Map<Method, Set<Object>> beforeTaskInstances,
|
||||
Map<Method, Set<Object>> afterTaskInstances,
|
||||
Map<Method, Set<Object>> failedTaskInstances) {
|
||||
Map<Method, Set<Object>> afterTaskInstances, Map<Method, Set<Object>> failedTaskInstances) {
|
||||
|
||||
this.beforeTaskInstances = beforeTaskInstances;
|
||||
this.afterTaskInstances = afterTaskInstances;
|
||||
@@ -56,8 +55,7 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
*/
|
||||
@Override
|
||||
public void onTaskStartup(TaskExecution taskExecution) {
|
||||
executeTaskListener(taskExecution, this.beforeTaskInstances.keySet(),
|
||||
this.beforeTaskInstances);
|
||||
executeTaskListener(taskExecution, this.beforeTaskInstances.keySet(), this.beforeTaskInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,8 +64,7 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
*/
|
||||
@Override
|
||||
public void onTaskEnd(TaskExecution taskExecution) {
|
||||
executeTaskListener(taskExecution, this.afterTaskInstances.keySet(),
|
||||
this.afterTaskInstances);
|
||||
executeTaskListener(taskExecution, this.afterTaskInstances.keySet(), this.afterTaskInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,8 +74,8 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
*/
|
||||
@Override
|
||||
public void onTaskFailed(TaskExecution taskExecution, Throwable throwable) {
|
||||
executeTaskListenerWithThrowable(taskExecution, throwable,
|
||||
this.failedTaskInstances.keySet(), this.failedTaskInstances);
|
||||
executeTaskListenerWithThrowable(taskExecution, throwable, this.failedTaskInstances.keySet(),
|
||||
this.failedTaskInstances);
|
||||
}
|
||||
|
||||
private void executeTaskListener(TaskExecution taskExecution, Set<Method> methods,
|
||||
@@ -89,27 +86,24 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
method.invoke(instance, taskExecution);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new TaskExecutionException(
|
||||
"@BeforeTask and @AfterTask annotated methods must be public.",
|
||||
e);
|
||||
throw new TaskExecutionException("@BeforeTask and @AfterTask annotated methods must be public.", e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new TaskExecutionException(String.format(
|
||||
"Failed to process @BeforeTask or @AfterTask"
|
||||
+ " annotation because: %s",
|
||||
e.getTargetException().getMessage()), e);
|
||||
throw new TaskExecutionException(
|
||||
String.format("Failed to process @BeforeTask or @AfterTask" + " annotation because: %s",
|
||||
e.getTargetException().getMessage()),
|
||||
e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new TaskExecutionException("taskExecution parameter "
|
||||
+ "is required for @BeforeTask and @AfterTask annotated methods",
|
||||
throw new TaskExecutionException(
|
||||
"taskExecution parameter " + "is required for @BeforeTask and @AfterTask annotated methods",
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeTaskListenerWithThrowable(TaskExecution taskExecution,
|
||||
Throwable throwable, Set<Method> methods,
|
||||
private void executeTaskListenerWithThrowable(TaskExecution taskExecution, Throwable throwable, Set<Method> methods,
|
||||
Map<Method, Set<Object>> instances) {
|
||||
for (Method method : methods) {
|
||||
for (Object instance : instances.get(method)) {
|
||||
@@ -117,19 +111,17 @@ public class TaskListenerExecutor implements TaskExecutionListener {
|
||||
method.invoke(instance, taskExecution, throwable);
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new TaskExecutionException(
|
||||
"@FailedTask annotated methods must be public.", e);
|
||||
throw new TaskExecutionException("@FailedTask annotated methods must be public.", e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new TaskExecutionException(String.format(
|
||||
"Failed to process @FailedTask " + "annotation because: %s",
|
||||
e.getTargetException().getMessage()), e);
|
||||
throw new TaskExecutionException(
|
||||
String.format("Failed to process @FailedTask " + "annotation because: %s",
|
||||
e.getTargetException().getMessage()),
|
||||
e);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new TaskExecutionException(
|
||||
"taskExecution and throwable parameters "
|
||||
+ "are required for @FailedTask annotated methods",
|
||||
e);
|
||||
throw new TaskExecutionException("taskExecution and throwable parameters "
|
||||
+ "are required for @FailedTask annotated methods", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ public class TaskExecution {
|
||||
this.arguments = new ArrayList<>();
|
||||
}
|
||||
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName,
|
||||
Date startTime, Date endTime, String exitMessage, List<String> arguments,
|
||||
String errorMessage, String externalExecutionId, Long parentExecutionId) {
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName, Date startTime, Date endTime,
|
||||
String exitMessage, List<String> arguments, String errorMessage, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
|
||||
Assert.notNull(arguments, "arguments must not be null");
|
||||
this.executionId = executionId;
|
||||
@@ -107,12 +107,11 @@ public class TaskExecution {
|
||||
this.parentExecutionId = parentExecutionId;
|
||||
}
|
||||
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName,
|
||||
Date startTime, Date endTime, String exitMessage, List<String> arguments,
|
||||
String errorMessage, String externalExecutionId) {
|
||||
public TaskExecution(long executionId, Integer exitCode, String taskName, Date startTime, Date endTime,
|
||||
String exitMessage, List<String> arguments, String errorMessage, String externalExecutionId) {
|
||||
|
||||
this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments,
|
||||
errorMessage, externalExecutionId, null);
|
||||
this(executionId, exitCode, taskName, startTime, endTime, exitMessage, arguments, errorMessage,
|
||||
externalExecutionId, null);
|
||||
}
|
||||
|
||||
public long getExecutionId() {
|
||||
@@ -193,12 +192,10 @@ public class TaskExecution {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TaskExecution{" + "executionId=" + this.executionId
|
||||
+ ", parentExecutionId=" + this.parentExecutionId + ", exitCode="
|
||||
+ this.exitCode + ", taskName='" + this.taskName + '\'' + ", startTime="
|
||||
+ this.startTime + ", endTime=" + this.endTime + ", exitMessage='"
|
||||
+ this.exitMessage + '\'' + ", externalExecutionId='"
|
||||
+ this.externalExecutionId + '\'' + ", errorMessage='" + this.errorMessage
|
||||
return "TaskExecution{" + "executionId=" + this.executionId + ", parentExecutionId=" + this.parentExecutionId
|
||||
+ ", exitCode=" + this.exitCode + ", taskName='" + this.taskName + '\'' + ", startTime="
|
||||
+ this.startTime + ", endTime=" + this.endTime + ", exitMessage='" + this.exitMessage + '\''
|
||||
+ ", externalExecutionId='" + this.externalExecutionId + '\'' + ", errorMessage='" + this.errorMessage
|
||||
+ '\'' + ", arguments=" + this.arguments + '}';
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ public interface TaskRepository {
|
||||
* @return the updated {@link TaskExecution}
|
||||
*/
|
||||
@Transactional("springCloudTaskTransactionManager")
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage);
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage);
|
||||
|
||||
/**
|
||||
* Notifies the repository that a taskExecution has completed.
|
||||
@@ -53,8 +52,8 @@ public interface TaskRepository {
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Transactional("springCloudTaskTransactionManager")
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage, String errorMessage);
|
||||
TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage,
|
||||
String errorMessage);
|
||||
|
||||
/**
|
||||
* Notifies the repository that a taskExecution needs to be created.
|
||||
@@ -99,8 +98,8 @@ public interface TaskRepository {
|
||||
* @return TaskExecution created based on the parameters.
|
||||
*/
|
||||
@Transactional("springCloudTaskTransactionManager")
|
||||
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId);
|
||||
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Notifies the repository to update the taskExecution's externalExecutionId.
|
||||
@@ -122,7 +121,7 @@ public interface TaskRepository {
|
||||
* a TaskExecution.
|
||||
*/
|
||||
@Transactional("springCloudTaskTransactionManager")
|
||||
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId, Long parentExecutionId);
|
||||
TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId);
|
||||
|
||||
}
|
||||
|
||||
@@ -66,10 +66,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
/**
|
||||
* SELECT clause for task execution.
|
||||
*/
|
||||
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, "
|
||||
+ "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID ";
|
||||
public static final String SELECT_CLAUSE = "TASK_EXECUTION_ID, " + "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, " + "EXTERNAL_EXECUTION_ID, PARENT_EXECUTION_ID ";
|
||||
|
||||
/**
|
||||
* FROM clause for task execution.
|
||||
@@ -116,15 +114,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private static final String GET_EXECUTION_BY_ID = "SELECT TASK_EXECUTION_ID, "
|
||||
+ "START_TIME, END_TIME, TASK_NAME, EXIT_CODE, "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, "
|
||||
+ "PARENT_EXECUTION_ID "
|
||||
+ "EXIT_MESSAGE, ERROR_MESSAGE, LAST_UPDATED, EXTERNAL_EXECUTION_ID, " + "PARENT_EXECUTION_ID "
|
||||
+ "from %PREFIX%EXECUTION where TASK_EXECUTION_ID = :taskExecutionId";
|
||||
|
||||
private static final String FIND_ARGUMENT_FROM_ID = "SELECT TASK_EXECUTION_ID, "
|
||||
+ "TASK_PARAM from %PREFIX%EXECUTION_PARAMS where TASK_EXECUTION_ID = :taskExecutionId";
|
||||
|
||||
private static final String TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM "
|
||||
+ "%PREFIX%EXECUTION ";
|
||||
private static final String TASK_EXECUTION_COUNT = "SELECT COUNT(*) FROM " + "%PREFIX%EXECUTION ";
|
||||
|
||||
private static final String TASK_EXECUTION_COUNT_BY_NAME = "SELECT COUNT(*) FROM "
|
||||
+ "%PREFIX%EXECUTION where TASK_NAME = :taskName";
|
||||
@@ -138,8 +134,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
private static final String LAST_TASK_EXECUTIONS_BY_TASK_NAMES = "select TE2.* from ("
|
||||
+ "select MAX(TE.TASK_EXECUTION_ID) as TASK_EXECUTION_ID, TE.TASK_NAME, TE.START_TIME from ("
|
||||
+ "select TASK_NAME, MAX(START_TIME) as START_TIME"
|
||||
+ " FROM %PREFIX%EXECUTION where TASK_NAME in (:taskNames)"
|
||||
+ " GROUP BY TASK_NAME" + ") TE_MAX "
|
||||
+ " FROM %PREFIX%EXECUTION where TASK_NAME in (:taskNames)" + " GROUP BY TASK_NAME" + ") TE_MAX "
|
||||
+ "inner join %PREFIX%EXECUTION TE ON TE.TASK_NAME = TE_MAX.TASK_NAME AND TE.START_TIME = TE_MAX.START_TIME "
|
||||
+ "group by TE.TASK_NAME, TE.START_TIME" + ") TE1 "
|
||||
+ "inner join %PREFIX%EXECUTION TE2 ON TE1.TASK_EXECUTION_ID = TE2.TASK_EXECUTION_ID "
|
||||
@@ -152,6 +147,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
private static final String FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID = "SELECT JOB_EXECUTION_ID "
|
||||
+ "FROM %PREFIX%TASK_BATCH WHERE TASK_EXECUTION_ID = :taskExecutionId";
|
||||
|
||||
private static final Set<String> validSortColumns = new HashSet<>(10);
|
||||
|
||||
static {
|
||||
@@ -168,9 +164,13 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
private final NamedParameterJdbcTemplate jdbcTemplate;
|
||||
|
||||
private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX;
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private LinkedHashMap<String, Order> orderMap;
|
||||
|
||||
private DataFieldMaxValueIncrementer taskIncrementer;
|
||||
|
||||
/**
|
||||
@@ -199,25 +199,22 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments, externalExecutionId,
|
||||
null);
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId, Long parentExecutionId) {
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
long nextExecutionId = getNextExecutionId();
|
||||
|
||||
TaskExecution taskExecution = new TaskExecution(nextExecutionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId);
|
||||
TaskExecution taskExecution = new TaskExecution(nextExecutionId, null, taskName, startTime, null, null,
|
||||
arguments, null, externalExecutionId);
|
||||
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", nextExecutionId, Types.BIGINT)
|
||||
.addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("startTime", startTime, Types.TIMESTAMP)
|
||||
.addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("taskExecutionId", nextExecutionId, Types.BIGINT).addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("startTime", startTime, Types.TIMESTAMP).addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", new Date(), Types.TIMESTAMP)
|
||||
.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT);
|
||||
@@ -228,25 +225,20 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId) {
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId,
|
||||
parentExecutionId);
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
TaskExecution taskExecution = new TaskExecution(executionId, null, taskName, startTime, null, null, arguments,
|
||||
null, externalExecutionId, parentExecutionId);
|
||||
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("startTime", startTime, Types.TIMESTAMP)
|
||||
.addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("taskName", taskName, Types.VARCHAR)
|
||||
.addValue("lastUpdated", new Date(), Types.TIMESTAMP)
|
||||
.addValue("startTime", startTime, Types.TIMESTAMP).addValue("exitCode", null, Types.INTEGER)
|
||||
.addValue("taskName", taskName, Types.VARCHAR).addValue("lastUpdated", new Date(), Types.TIMESTAMP)
|
||||
.addValue("parentExecutionId", parentExecutionId, Types.BIGINT)
|
||||
.addValue("taskExecutionId", executionId, Types.BIGINT);
|
||||
|
||||
@@ -257,8 +249,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
else {
|
||||
updateString += START_TASK_EXECUTION_EXTERNAL_ID_SUFFIX;
|
||||
queryParameters.addValue("externalExecutionId", externalExecutionId,
|
||||
Types.VARCHAR);
|
||||
queryParameters.addValue("externalExecutionId", externalExecutionId, Types.VARCHAR);
|
||||
}
|
||||
|
||||
this.jdbcTemplate.update(getQuery(updateString), queryParameters);
|
||||
@@ -267,22 +258,20 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode,
|
||||
Date endTime, String exitMessage, String errorMessage) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime, String exitMessage,
|
||||
String errorMessage) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskExecutionId",
|
||||
taskExecutionId, Types.BIGINT);
|
||||
|
||||
// Check if given TaskExecution's Id already exists, if none is found
|
||||
// it is invalid and an exception should be thrown.
|
||||
if (this.jdbcTemplate.queryForObject(getQuery(CHECK_TASK_EXECUTION_EXISTS),
|
||||
queryParameters, Integer.class) != 1) {
|
||||
throw new IllegalStateException(
|
||||
"Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
if (this.jdbcTemplate.queryForObject(getQuery(CHECK_TASK_EXECUTION_EXISTS), queryParameters,
|
||||
Integer.class) != 1) {
|
||||
throw new IllegalStateException("Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
}
|
||||
|
||||
final MapSqlParameterSource parameters = new MapSqlParameterSource()
|
||||
.addValue("endTime", endTime, Types.TIMESTAMP)
|
||||
.addValue("exitCode", exitCode, Types.INTEGER)
|
||||
.addValue("endTime", endTime, Types.TIMESTAMP).addValue("exitCode", exitCode, Types.INTEGER)
|
||||
.addValue("exitMessage", exitMessage, Types.VARCHAR)
|
||||
.addValue("errorMessage", errorMessage, Types.VARCHAR)
|
||||
.addValue("lastUpdated", new Date(), Types.TIMESTAMP)
|
||||
@@ -292,20 +281,18 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode,
|
||||
Date endTime, String exitMessage) {
|
||||
public void completeTaskExecution(long taskExecutionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
completeTaskExecution(taskExecutionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution getTaskExecution(long executionId) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", executionId, Types.BIGINT);
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskExecutionId",
|
||||
executionId, Types.BIGINT);
|
||||
|
||||
try {
|
||||
TaskExecution taskExecution = this.jdbcTemplate.queryForObject(
|
||||
getQuery(GET_EXECUTION_BY_ID), queryParameters,
|
||||
new TaskExecutionRowMapper());
|
||||
TaskExecution taskExecution = this.jdbcTemplate.queryForObject(getQuery(GET_EXECUTION_BY_ID),
|
||||
queryParameters, new TaskExecutionRowMapper());
|
||||
taskExecution.setArguments(getTaskArguments(executionId));
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -317,12 +304,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public long getTaskExecutionCountByTaskName(String taskName) {
|
||||
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskName", taskName, Types.VARCHAR);
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskName", taskName,
|
||||
Types.VARCHAR);
|
||||
|
||||
try {
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
getQuery(TASK_EXECUTION_COUNT_BY_NAME), queryParameters, Long.class);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(TASK_EXECUTION_COUNT_BY_NAME), queryParameters,
|
||||
Long.class);
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
return 0;
|
||||
@@ -331,12 +318,11 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
@Override
|
||||
public long getRunningTaskExecutionCountByTaskName(String taskName) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskName", taskName, Types.VARCHAR);
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskName", taskName,
|
||||
Types.VARCHAR);
|
||||
|
||||
try {
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
getQuery(RUNNING_TASK_EXECUTION_COUNT_BY_NAME), queryParameters,
|
||||
return this.jdbcTemplate.queryForObject(getQuery(RUNNING_TASK_EXECUTION_COUNT_BY_NAME), queryParameters,
|
||||
Long.class);
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
@@ -349,8 +335,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
try {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource();
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
getQuery(RUNNING_TASK_EXECUTION_COUNT), queryParameters, Long.class);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(RUNNING_TASK_EXECUTION_COUNT), queryParameters,
|
||||
Long.class);
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
return 0;
|
||||
@@ -369,15 +355,14 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
}
|
||||
|
||||
Assert.isTrue(taskNamesAsList.size() == taskNames.length, String.format(
|
||||
"Task names must not contain any empty elements but %s of %s were empty or null.",
|
||||
taskNames.length - taskNamesAsList.size(), taskNames.length));
|
||||
Assert.isTrue(taskNamesAsList.size() == taskNames.length,
|
||||
String.format("Task names must not contain any empty elements but %s of %s were empty or null.",
|
||||
taskNames.length - taskNamesAsList.size(), taskNames.length));
|
||||
|
||||
try {
|
||||
final Map<String, List<String>> paramMap = Collections
|
||||
.singletonMap("taskNames", taskNamesAsList);
|
||||
return this.jdbcTemplate.query(getQuery(LAST_TASK_EXECUTIONS_BY_TASK_NAMES),
|
||||
paramMap, new TaskExecutionRowMapper());
|
||||
final Map<String, List<String>> paramMap = Collections.singletonMap("taskNames", taskNamesAsList);
|
||||
return this.jdbcTemplate.query(getQuery(LAST_TASK_EXECUTIONS_BY_TASK_NAMES), paramMap,
|
||||
new TaskExecutionRowMapper());
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
return Collections.emptyList();
|
||||
@@ -387,8 +372,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution getLatestTaskExecutionForTaskName(String taskName) {
|
||||
Assert.hasText(taskName, "The task name must not be empty.");
|
||||
final List<TaskExecution> taskExecutions = this
|
||||
.getLatestTaskExecutionsByTaskNames(taskName);
|
||||
final List<TaskExecution> taskExecutions = this.getLatestTaskExecutionsByTaskNames(taskName);
|
||||
if (taskExecutions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -397,8 +381,7 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Only expected a single TaskExecution but received "
|
||||
+ taskExecutions.size());
|
||||
"Only expected a single TaskExecution but received " + taskExecutions.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,8 +389,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
public long getTaskExecutionCount() {
|
||||
|
||||
try {
|
||||
return this.jdbcTemplate.queryForObject(getQuery(TASK_EXECUTION_COUNT),
|
||||
new MapSqlParameterSource(), Long.class);
|
||||
return this.jdbcTemplate.queryForObject(getQuery(TASK_EXECUTION_COUNT), new MapSqlParameterSource(),
|
||||
Long.class);
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
return 0;
|
||||
@@ -415,32 +398,26 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName,
|
||||
Pageable pageable) {
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
|
||||
RUNNING_TASK_WHERE_CLAUSE,
|
||||
new MapSqlParameterSource("taskName", taskName),
|
||||
getRunningTaskExecutionCountByTaskName(taskName));
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName, Pageable pageable) {
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, RUNNING_TASK_WHERE_CLAUSE,
|
||||
new MapSqlParameterSource("taskName", taskName), getRunningTaskExecutionCountByTaskName(taskName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName,
|
||||
Pageable pageable) {
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE,
|
||||
TASK_NAME_WHERE_CLAUSE, new MapSqlParameterSource("taskName", taskName),
|
||||
getTaskExecutionCountByTaskName(taskName));
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName, Pageable pageable) {
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, TASK_NAME_WHERE_CLAUSE,
|
||||
new MapSqlParameterSource("taskName", taskName), getTaskExecutionCountByTaskName(taskName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTaskNames() {
|
||||
return this.jdbcTemplate.queryForList(getQuery(FIND_TASK_NAMES),
|
||||
new MapSqlParameterSource(), String.class);
|
||||
return this.jdbcTemplate.queryForList(getQuery(FIND_TASK_NAMES), new MapSqlParameterSource(), String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findAll(Pageable pageable) {
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null,
|
||||
new MapSqlParameterSource(), getTaskExecutionCount());
|
||||
return queryForPageableResults(pageable, SELECT_CLAUSE, FROM_CLAUSE, null, new MapSqlParameterSource(),
|
||||
getTaskExecutionCount());
|
||||
}
|
||||
|
||||
public void setTaskIncrementer(DataFieldMaxValueIncrementer taskIncrementer) {
|
||||
@@ -453,12 +430,11 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
@Override
|
||||
public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("jobExecutionId", jobExecutionId, Types.BIGINT);
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("jobExecutionId",
|
||||
jobExecutionId, Types.BIGINT);
|
||||
|
||||
try {
|
||||
return this.jdbcTemplate.queryForObject(
|
||||
getQuery(FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID), queryParameters,
|
||||
return this.jdbcTemplate.queryForObject(getQuery(FIND_TASK_EXECUTION_BY_JOB_EXECUTION_ID), queryParameters,
|
||||
Long.class);
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
@@ -468,21 +444,18 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
@Override
|
||||
public Set<Long> getJobExecutionIdsByTaskExecutionId(long taskExecutionId) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.addValue("taskExecutionId", taskExecutionId, Types.BIGINT);
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource().addValue("taskExecutionId",
|
||||
taskExecutionId, Types.BIGINT);
|
||||
|
||||
try {
|
||||
return this.jdbcTemplate.query(
|
||||
getQuery(FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID), queryParameters,
|
||||
return this.jdbcTemplate.query(getQuery(FIND_JOB_EXECUTION_BY_TASK_EXECUTION_ID), queryParameters,
|
||||
new ResultSetExtractor<Set<Long>>() {
|
||||
@Override
|
||||
public Set<Long> extractData(ResultSet resultSet)
|
||||
throws SQLException, DataAccessException {
|
||||
public Set<Long> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
|
||||
Set<Long> jobExecutionIds = new TreeSet<>();
|
||||
|
||||
while (resultSet.next()) {
|
||||
jobExecutionIds
|
||||
.add(resultSet.getLong("JOB_EXECUTION_ID"));
|
||||
jobExecutionIds.add(resultSet.getLong("JOB_EXECUTION_ID"));
|
||||
}
|
||||
|
||||
return jobExecutionIds;
|
||||
@@ -495,23 +468,18 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateExternalExecutionId(long taskExecutionId,
|
||||
String externalExecutionId) {
|
||||
public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
|
||||
final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
|
||||
.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.");
|
||||
if (this.jdbcTemplate.update(getQuery(UPDATE_TASK_EXECUTION_EXTERNAL_EXECUTION_ID), queryParameters) != 1) {
|
||||
throw new IllegalStateException("Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
private Page<TaskExecution> queryForPageableResults(Pageable pageable,
|
||||
String selectClause, String fromClause, String whereClause,
|
||||
MapSqlParameterSource queryParameters, long totalCount) {
|
||||
private Page<TaskExecution> queryForPageableResults(Pageable pageable, String selectClause, String fromClause,
|
||||
String whereClause, MapSqlParameterSource queryParameters, long totalCount) {
|
||||
SqlPagingQueryProviderFactoryBean factoryBean = new SqlPagingQueryProviderFactoryBean();
|
||||
factoryBean.setSelectClause(selectClause);
|
||||
factoryBean.setFromClause(fromClause);
|
||||
@@ -551,8 +519,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
String query = pagingQueryProvider.getPageQuery(pageable);
|
||||
List<TaskExecution> resultList = this.jdbcTemplate.query(getQuery(query),
|
||||
queryParameters, new TaskExecutionRowMapper());
|
||||
List<TaskExecution> resultList = this.jdbcTemplate.query(getQuery(query), queryParameters,
|
||||
new TaskExecutionRowMapper());
|
||||
return new PageImpl<>(resultList, pageable, totalCount);
|
||||
}
|
||||
|
||||
@@ -572,8 +540,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that inserts an individual records into the TASK_EXECUTION_PARAMS
|
||||
* table.
|
||||
* Convenience method that inserts an individual records into the
|
||||
* TASK_EXECUTION_PARAMS table.
|
||||
* @param taskExecutionId id of a task execution
|
||||
* @param taskParam task parameters
|
||||
*/
|
||||
@@ -613,11 +581,10 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao {
|
||||
if (rs.wasNull()) {
|
||||
parentExecutionId = null;
|
||||
}
|
||||
return new TaskExecution(id, getNullableExitCode(rs),
|
||||
rs.getString("TASK_NAME"), rs.getTimestamp("START_TIME"),
|
||||
rs.getTimestamp("END_TIME"), rs.getString("EXIT_MESSAGE"),
|
||||
getTaskArguments(id), rs.getString("ERROR_MESSAGE"),
|
||||
rs.getString("EXTERNAL_EXECUTION_ID"), parentExecutionId);
|
||||
return new TaskExecution(id, getNullableExitCode(rs), rs.getString("TASK_NAME"),
|
||||
rs.getTimestamp("START_TIME"), rs.getTimestamp("END_TIME"), rs.getString("EXIT_MESSAGE"),
|
||||
getTaskArguments(id), rs.getString("ERROR_MESSAGE"), rs.getString("EXTERNAL_EXECUTION_ID"),
|
||||
parentExecutionId);
|
||||
}
|
||||
|
||||
private Integer getNullableExitCode(ResultSet rs) throws SQLException {
|
||||
|
||||
@@ -58,34 +58,30 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments, externalExecutionId,
|
||||
null);
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
return createTaskExecution(taskName, startTime, arguments, externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId, Long parentExecutionId) {
|
||||
public TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
long taskExecutionId = getNextExecutionId();
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName,
|
||||
startTime, null, null, arguments, null, externalExecutionId,
|
||||
parentExecutionId);
|
||||
TaskExecution taskExecution = new TaskExecution(taskExecutionId, null, taskName, startTime, null, null,
|
||||
arguments, null, externalExecutionId, parentExecutionId);
|
||||
this.taskExecutions.put(taskExecutionId, taskExecution);
|
||||
return taskExecution;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionid) {
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments,
|
||||
externalExecutionid, null);
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionid) {
|
||||
return startTaskExecution(executionId, taskName, startTime, arguments, externalExecutionid, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionid,
|
||||
Long parentExecutionId) {
|
||||
public TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionid, Long parentExecutionId) {
|
||||
TaskExecution taskExecution = this.taskExecutions.get(executionId);
|
||||
taskExecution.setTaskName(taskName);
|
||||
taskExecution.setStartTime(startTime);
|
||||
@@ -98,11 +94,10 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage, String errorMessage) {
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage,
|
||||
String errorMessage) {
|
||||
if (!this.taskExecutions.containsKey(executionId)) {
|
||||
throw new IllegalStateException(
|
||||
"Invalid TaskExecution, ID " + executionId + " not found.");
|
||||
throw new IllegalStateException("Invalid TaskExecution, ID " + executionId + " not found.");
|
||||
}
|
||||
|
||||
TaskExecution taskExecution = this.taskExecutions.get(executionId);
|
||||
@@ -113,8 +108,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage) {
|
||||
public void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
@@ -138,8 +132,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
public long getRunningTaskExecutionCountByTaskName(String taskName) {
|
||||
int count = 0;
|
||||
for (Map.Entry<Long, TaskExecution> entry : this.taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName)
|
||||
&& entry.getValue().getEndTime() == null) {
|
||||
if (entry.getValue().getTaskName().equals(taskName) && entry.getValue().getEndTime() == null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -163,30 +156,25 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName,
|
||||
Pageable pageable) {
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName, Pageable pageable) {
|
||||
Set<TaskExecution> result = getTaskExecutionTreeSet();
|
||||
for (Map.Entry<Long, TaskExecution> entry : this.taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName)
|
||||
&& entry.getValue().getEndTime() == null) {
|
||||
if (entry.getValue().getTaskName().equals(taskName) && entry.getValue().getEndTime() == null) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
return getPageFromList(new ArrayList<>(result), pageable,
|
||||
getRunningTaskExecutionCountByTaskName(taskName));
|
||||
return getPageFromList(new ArrayList<>(result), pageable, getRunningTaskExecutionCountByTaskName(taskName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName,
|
||||
Pageable pageable) {
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName, Pageable pageable) {
|
||||
Set<TaskExecution> filteredSet = getTaskExecutionTreeSet();
|
||||
for (Map.Entry<Long, TaskExecution> entry : this.taskExecutions.entrySet()) {
|
||||
if (entry.getValue().getTaskName().equals(taskName)) {
|
||||
filteredSet.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
return getPageFromList(new ArrayList<>(filteredSet), pageable,
|
||||
getTaskExecutionCountByTaskName(taskName));
|
||||
return getPageFromList(new ArrayList<>(filteredSet), pageable, getTaskExecutionCountByTaskName(taskName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,8 +208,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
|
||||
found:
|
||||
|
||||
for (Map.Entry<Long, Set<Long>> association : this.batchJobAssociations
|
||||
.entrySet()) {
|
||||
for (Map.Entry<Long, Set<Long>> association : this.batchJobAssociations.entrySet()) {
|
||||
for (Long curJobExecutionId : association.getValue()) {
|
||||
if (curJobExecutionId.equals(jobExecutionId)) {
|
||||
taskId = association.getKey();
|
||||
@@ -236,8 +223,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public Set<Long> getJobExecutionIdsByTaskExecutionId(long taskExecutionId) {
|
||||
if (this.batchJobAssociations.containsKey(taskExecutionId)) {
|
||||
return Collections
|
||||
.unmodifiableSet(this.batchJobAssociations.get(taskExecutionId));
|
||||
return Collections.unmodifiableSet(this.batchJobAssociations.get(taskExecutionId));
|
||||
}
|
||||
else {
|
||||
return new TreeSet<>();
|
||||
@@ -245,11 +231,9 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateExternalExecutionId(long taskExecutionId,
|
||||
String externalExecutionId) {
|
||||
public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId) {
|
||||
TaskExecution taskExecution = this.taskExecutions.get(taskExecutionId);
|
||||
Assert.notNull(taskExecution,
|
||||
"Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
Assert.notNull(taskExecution, "Invalid TaskExecution, ID " + taskExecutionId + " not found.");
|
||||
taskExecution.setExternalExecutionId(externalExecutionId);
|
||||
}
|
||||
|
||||
@@ -263,22 +247,17 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
public int compare(TaskExecution e1, TaskExecution e2) {
|
||||
int result = e1.getStartTime().compareTo(e2.getStartTime());
|
||||
if (result == 0) {
|
||||
result = Long.valueOf(e1.getExecutionId())
|
||||
.compareTo(e2.getExecutionId());
|
||||
result = Long.valueOf(e1.getExecutionId()).compareTo(e2.getExecutionId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Page getPageFromList(List<TaskExecution> executionList, Pageable pageable,
|
||||
long maxSize) {
|
||||
long toIndex = (pageable.getOffset() + pageable.getPageSize() > executionList
|
||||
.size()) ? executionList.size()
|
||||
: pageable.getOffset() + pageable.getPageSize();
|
||||
return new PageImpl<>(
|
||||
executionList.subList((int) pageable.getOffset(), (int) toIndex),
|
||||
pageable, maxSize);
|
||||
private Page getPageFromList(List<TaskExecution> executionList, Pageable pageable, long maxSize) {
|
||||
long toIndex = (pageable.getOffset() + pageable.getPageSize() > executionList.size()) ? executionList.size()
|
||||
: pageable.getOffset() + pageable.getPageSize();
|
||||
return new PageImpl<>(executionList.subList((int) pageable.getOffset(), (int) toIndex), pageable, maxSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -294,34 +273,29 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
}
|
||||
|
||||
Assert.isTrue(taskNamesAsList.size() == taskNames.length, String.format(
|
||||
"Task names must not contain any empty elements but %s of %s were empty or null.",
|
||||
taskNames.length - taskNamesAsList.size(), taskNames.length));
|
||||
Assert.isTrue(taskNamesAsList.size() == taskNames.length,
|
||||
String.format("Task names must not contain any empty elements but %s of %s were empty or null.",
|
||||
taskNames.length - taskNamesAsList.size(), taskNames.length));
|
||||
|
||||
final Map<String, TaskExecution> tempTaskExecutions = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : this.taskExecutions
|
||||
.entrySet()) {
|
||||
if (!taskNamesAsList
|
||||
.contains(taskExecutionMapEntry.getValue().getTaskName())) {
|
||||
for (Map.Entry<Long, TaskExecution> taskExecutionMapEntry : this.taskExecutions.entrySet()) {
|
||||
if (!taskNamesAsList.contains(taskExecutionMapEntry.getValue().getTaskName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final TaskExecution tempTaskExecution = tempTaskExecutions
|
||||
.get(taskExecutionMapEntry.getValue().getTaskName());
|
||||
if (tempTaskExecution == null
|
||||
|| tempTaskExecution.getStartTime()
|
||||
.before(taskExecutionMapEntry.getValue().getStartTime())
|
||||
|| (tempTaskExecution.getStartTime()
|
||||
.equals(taskExecutionMapEntry.getValue().getStartTime())
|
||||
&& tempTaskExecution.getExecutionId() < taskExecutionMapEntry
|
||||
.getValue().getExecutionId())) {
|
||||
|| tempTaskExecution.getStartTime().before(taskExecutionMapEntry.getValue().getStartTime())
|
||||
|| (tempTaskExecution.getStartTime().equals(taskExecutionMapEntry.getValue().getStartTime())
|
||||
&& tempTaskExecution.getExecutionId() < taskExecutionMapEntry.getValue()
|
||||
.getExecutionId())) {
|
||||
tempTaskExecutions.put(taskExecutionMapEntry.getValue().getTaskName(),
|
||||
taskExecutionMapEntry.getValue());
|
||||
}
|
||||
}
|
||||
final List<TaskExecution> latestTaskExecutions = new ArrayList<>(
|
||||
tempTaskExecutions.values());
|
||||
final List<TaskExecution> latestTaskExecutions = new ArrayList<>(tempTaskExecutions.values());
|
||||
Collections.sort(latestTaskExecutions, new TaskExecutionComparator());
|
||||
return latestTaskExecutions;
|
||||
}
|
||||
@@ -329,8 +303,7 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
@Override
|
||||
public TaskExecution getLatestTaskExecutionForTaskName(String taskName) {
|
||||
Assert.hasText(taskName, "The task name must not be empty.");
|
||||
final List<TaskExecution> taskExecutions = this
|
||||
.getLatestTaskExecutionsByTaskNames(taskName);
|
||||
final List<TaskExecution> taskExecutions = this.getLatestTaskExecutionsByTaskNames(taskName);
|
||||
if (taskExecutions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -339,25 +312,19 @@ public class MapTaskExecutionDao implements TaskExecutionDao {
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Only expected a single TaskExecution but received "
|
||||
+ taskExecutions.size());
|
||||
"Only expected a single TaskExecution but received " + taskExecutions.size());
|
||||
}
|
||||
}
|
||||
|
||||
private static class TaskExecutionComparator
|
||||
implements Comparator<TaskExecution>, Serializable {
|
||||
private static class TaskExecutionComparator implements Comparator<TaskExecution>, Serializable {
|
||||
|
||||
@Override
|
||||
public int compare(TaskExecution firstTaskExecution,
|
||||
TaskExecution secondTaskExecution) {
|
||||
if (firstTaskExecution.getStartTime()
|
||||
.equals(secondTaskExecution.getStartTime())) {
|
||||
return Long.compare(firstTaskExecution.getExecutionId(),
|
||||
secondTaskExecution.getExecutionId());
|
||||
public int compare(TaskExecution firstTaskExecution, TaskExecution secondTaskExecution) {
|
||||
if (firstTaskExecution.getStartTime().equals(secondTaskExecution.getStartTime())) {
|
||||
return Long.compare(firstTaskExecution.getExecutionId(), secondTaskExecution.getExecutionId());
|
||||
}
|
||||
else {
|
||||
return secondTaskExecution.getStartTime()
|
||||
.compareTo(firstTaskExecution.getStartTime());
|
||||
return secondTaskExecution.getStartTime().compareTo(firstTaskExecution.getStartTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ public interface TaskExecutionDao {
|
||||
* @param externalExecutionId id assigned to the task by the platform
|
||||
* @return A fully qualified {@link TaskExecution} instance.
|
||||
*/
|
||||
TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId);
|
||||
TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Save a new {@link TaskExecution}.
|
||||
@@ -55,8 +55,8 @@ public interface TaskExecutionDao {
|
||||
* @return A fully qualified {@link TaskExecution} instance.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
TaskExecution createTaskExecution(String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId, Long parentExecutionId);
|
||||
TaskExecution createTaskExecution(String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as started.
|
||||
@@ -69,8 +69,8 @@ public interface TaskExecutionDao {
|
||||
* start.
|
||||
* @since 1.1.0
|
||||
*/
|
||||
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId);
|
||||
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as started.
|
||||
@@ -84,8 +84,8 @@ public interface TaskExecutionDao {
|
||||
* start.
|
||||
* @since 1.2.0
|
||||
*/
|
||||
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime,
|
||||
List<String> arguments, String externalExecutionId, Long parentExecutionId);
|
||||
TaskExecution startTaskExecution(long executionId, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution} to mark it as completed.
|
||||
@@ -96,8 +96,8 @@ public interface TaskExecutionDao {
|
||||
* @param errorMessage error information available upon failure of a task.
|
||||
* @since 1.1.0
|
||||
*/
|
||||
void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage, String errorMessage);
|
||||
void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage,
|
||||
String errorMessage);
|
||||
|
||||
/**
|
||||
* Update and existing {@link TaskExecution}.
|
||||
@@ -106,8 +106,7 @@ public interface TaskExecutionDao {
|
||||
* @param endTime the time the task completed.
|
||||
* @param exitMessage the message assigned to the task upon completion.
|
||||
*/
|
||||
void completeTaskExecution(long executionId, Integer exitCode, Date endTime,
|
||||
String exitMessage);
|
||||
void completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage);
|
||||
|
||||
/**
|
||||
* Retrieves a task execution from the task repository.
|
||||
|
||||
@@ -144,13 +144,11 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi
|
||||
sql.append(" WHERE ").append(this.whereClause);
|
||||
}
|
||||
List<String> namedParameters = new ArrayList<>();
|
||||
this.parameterCount = JdbcParameterUtils
|
||||
.countParameterPlaceholders(sql.toString(), namedParameters);
|
||||
this.parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql.toString(), namedParameters);
|
||||
if (namedParameters.size() > 0) {
|
||||
if (this.parameterCount != namedParameters.size()) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"You can't use both named parameters and classic \"?\" placeholders: "
|
||||
+ sql);
|
||||
"You can't use both named parameters and classic \"?\" placeholders: " + sql);
|
||||
}
|
||||
this.usingNamedParameters = true;
|
||||
}
|
||||
@@ -159,8 +157,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi
|
||||
private String removeKeyWord(String keyWord, String clause) {
|
||||
String temp = clause.trim();
|
||||
String keyWordString = keyWord + " ";
|
||||
if (temp.toLowerCase().startsWith(keyWordString)
|
||||
&& temp.length() > keyWordString.length()) {
|
||||
if (temp.toLowerCase().startsWith(keyWordString) && temp.length() > keyWordString.length()) {
|
||||
return temp.substring(keyWordString.length());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -32,17 +32,15 @@ public class Db2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
long offset = pageable.getOffset() + 1;
|
||||
return generateRowNumSqlQueryWithNesting(getSelectClause(), false,
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize()));
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize()));
|
||||
}
|
||||
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause,
|
||||
boolean remainingPageQuery, String rowNumClause) {
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause, boolean remainingPageQuery,
|
||||
String rowNumClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(selectClause).append(" FROM (SELECT ")
|
||||
.append(selectClause).append(", ")
|
||||
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());
|
||||
sql.append(" FROM (SELECT ").append(selectClause).append(" FROM ").append(this.getFromClause());
|
||||
SqlPagingQueryUtils.buildWhereClause(this, remainingPageQuery, sql);
|
||||
sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
|
||||
sql.append(")) WHERE ").append(rowNumClause);
|
||||
|
||||
@@ -29,10 +29,8 @@ 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,9 +29,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,17 +31,15 @@ public class OraclePagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
long offset = pageable.getOffset() + 1;
|
||||
return generateRowNumSqlQueryWithNesting(getSelectClause(), false,
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < "
|
||||
+ (offset + pageable.getPageSize()));
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize()));
|
||||
}
|
||||
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause,
|
||||
boolean remainingPageQuery, String rowNumClause) {
|
||||
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(" FROM (SELECT ").append(selectClause).append(" FROM ")
|
||||
.append(this.getFromClause());
|
||||
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));
|
||||
sql.append(")) WHERE ").append(rowNumClause);
|
||||
|
||||
@@ -29,8 +29,7 @@ public class PostgresPagingQueryProvider extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
String limitClause = new StringBuilder().append("LIMIT ")
|
||||
.append(pageable.getPageSize()).append(" OFFSET ")
|
||||
String limitClause = new StringBuilder().append("LIMIT ").append(pageable.getPageSize()).append(" OFFSET ")
|
||||
.append(pageable.getOffset()).toString();
|
||||
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, limitClause);
|
||||
}
|
||||
|
||||
@@ -47,8 +47,7 @@ import static org.springframework.cloud.task.repository.support.DatabaseType.SQL
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class SqlPagingQueryProviderFactoryBean
|
||||
implements FactoryBean<PagingQueryProvider> {
|
||||
public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQueryProvider> {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
@@ -134,20 +133,16 @@ public class SqlPagingQueryProviderFactoryBean
|
||||
|
||||
DatabaseType type;
|
||||
try {
|
||||
type = this.databaseType != null
|
||||
? DatabaseType.valueOf(this.databaseType.toUpperCase())
|
||||
type = this.databaseType != null ? DatabaseType.valueOf(this.databaseType.toUpperCase())
|
||||
: DatabaseType.fromMetaData(this.dataSource);
|
||||
}
|
||||
catch (MetaDataAccessException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not inspect meta data for database type. You have to supply it explicitly.",
|
||||
e);
|
||||
"Could not inspect meta data for database type. You have to supply it explicitly.", e);
|
||||
}
|
||||
|
||||
AbstractSqlPagingQueryProvider provider = this.providers.get(type);
|
||||
Assert.state(provider != null,
|
||||
"Should not happen: missing PagingQueryProvider for DatabaseType="
|
||||
+ type);
|
||||
Assert.state(provider != null, "Should not happen: missing PagingQueryProvider for DatabaseType=" + type);
|
||||
|
||||
provider.setFromClause(this.fromClause);
|
||||
provider.setWhereClause(this.whereClause);
|
||||
|
||||
@@ -37,13 +37,11 @@ public final class SqlPagingQueryUtils {
|
||||
* @param limitClause the implementation specific top clause to be used
|
||||
* @return the generated query
|
||||
*/
|
||||
public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider,
|
||||
String limitClause) {
|
||||
public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider, String limitClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(provider.getSelectClause());
|
||||
sql.append(" FROM ").append(provider.getFromClause());
|
||||
sql.append(provider.getWhereClause() == null ? ""
|
||||
: " WHERE " + provider.getWhereClause());
|
||||
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
|
||||
sql.append(" ORDER BY ").append(buildSortClause(provider));
|
||||
sql.append(" ").append(limitClause);
|
||||
|
||||
@@ -57,14 +55,11 @@ public final class SqlPagingQueryUtils {
|
||||
* @param topClause the implementation specific top clause to be used
|
||||
* @return the generated query
|
||||
*/
|
||||
public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider,
|
||||
String topClause) {
|
||||
public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider, String topClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(topClause).append(" ")
|
||||
.append(provider.getSelectClause());
|
||||
sql.append("SELECT ").append(topClause).append(" ").append(provider.getSelectClause());
|
||||
sql.append(" FROM ").append(provider.getFromClause());
|
||||
sql.append(provider.getWhereClause() == null ? ""
|
||||
: " WHERE " + provider.getWhereClause());
|
||||
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
|
||||
sql.append(" ORDER BY ").append(buildSortClause(provider));
|
||||
|
||||
return sql.toString();
|
||||
@@ -76,8 +71,8 @@ public final class SqlPagingQueryUtils {
|
||||
* @param remainingPageQuery if true assumes more will be appended to where clause
|
||||
* @param sql the sql statement to be appended.
|
||||
*/
|
||||
public static void buildWhereClause(AbstractSqlPagingQueryProvider provider,
|
||||
boolean remainingPageQuery, StringBuilder sql) {
|
||||
public static void buildWhereClause(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery,
|
||||
StringBuilder sql) {
|
||||
if (remainingPageQuery) {
|
||||
sql.append(" WHERE ");
|
||||
if (provider.getWhereClause() != null) {
|
||||
@@ -87,8 +82,7 @@ public final class SqlPagingQueryUtils {
|
||||
}
|
||||
}
|
||||
else {
|
||||
sql.append(provider.getWhereClause() == null ? ""
|
||||
: " WHERE " + provider.getWhereClause());
|
||||
sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,14 @@ public class SqlServerPagingQueryProvider extends AbstractSqlPagingQueryProvider
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
long offset = pageable.getOffset() + 1;
|
||||
return generateRowNumSqlQueryWithNesting(getSelectClause(), false,
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < "
|
||||
+ (offset + pageable.getPageSize()));
|
||||
"TMP_ROW_NUM >= " + offset + " AND TMP_ROW_NUM < " + (offset + pageable.getPageSize()));
|
||||
}
|
||||
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause,
|
||||
boolean remainingPageQuery, String rowNumClause) {
|
||||
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))
|
||||
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 ");
|
||||
|
||||
@@ -109,24 +109,22 @@ public enum DatabaseType {
|
||||
* @return DatabaseType The database type associated with the datasource.
|
||||
* @throws MetaDataAccessException thrown if failure occurs on metadata lookup.
|
||||
*/
|
||||
public static DatabaseType fromMetaData(DataSource dataSource)
|
||||
throws SQLException, MetaDataAccessException {
|
||||
String databaseProductName = JdbcUtils
|
||||
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
|
||||
public static DatabaseType fromMetaData(DataSource dataSource) throws SQLException, MetaDataAccessException {
|
||||
String databaseProductName = JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
|
||||
|
||||
@Override
|
||||
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
|
||||
return dbmd.getDatabaseProductName();
|
||||
}
|
||||
}).toString();
|
||||
if (StringUtils.hasText(databaseProductName)
|
||||
&& !databaseProductName.equals("DB2/Linux")
|
||||
@Override
|
||||
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
|
||||
return dbmd.getDatabaseProductName();
|
||||
}
|
||||
}).toString();
|
||||
if (StringUtils.hasText(databaseProductName) && !databaseProductName.equals("DB2/Linux")
|
||||
&& databaseProductName.startsWith("DB2")) {
|
||||
String databaseProductVersion = JdbcUtils
|
||||
.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() {
|
||||
|
||||
@Override
|
||||
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
|
||||
public Object processMetaData(DatabaseMetaData dbmd)
|
||||
throws SQLException, MetaDataAccessException {
|
||||
return dbmd.getDatabaseProductVersion();
|
||||
}
|
||||
}).toString();
|
||||
@@ -139,8 +137,7 @@ public enum DatabaseType {
|
||||
}
|
||||
else if (databaseProductName.indexOf("AS") != -1
|
||||
&& (databaseProductVersion.startsWith("QSQ") || databaseProductVersion
|
||||
.substring(databaseProductVersion.indexOf('V'))
|
||||
.matches("V\\dR\\d[mM]\\d"))) {
|
||||
.substring(databaseProductVersion.indexOf('V')).matches("V\\dR\\d[mM]\\d"))) {
|
||||
databaseProductName = "DB2AS400";
|
||||
}
|
||||
else {
|
||||
@@ -164,8 +161,7 @@ public enum DatabaseType {
|
||||
productName = "MySQL";
|
||||
}
|
||||
if (!dbNameMap.containsKey(productName)) {
|
||||
throw new IllegalArgumentException(
|
||||
"DatabaseType not found for product name: [" + productName + "]");
|
||||
throw new IllegalArgumentException("DatabaseType not found for product name: [" + productName + "]");
|
||||
}
|
||||
else {
|
||||
return dbNameMap.get(productName);
|
||||
|
||||
@@ -39,8 +39,7 @@ public class SimpleTaskExplorer implements TaskExplorer {
|
||||
private TaskExecutionDao taskExecutionDao;
|
||||
|
||||
public SimpleTaskExplorer(TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean) {
|
||||
Assert.notNull(taskExecutionDaoFactoryBean,
|
||||
"taskExecutionDaoFactoryBean must not be null");
|
||||
Assert.notNull(taskExecutionDaoFactoryBean, "taskExecutionDaoFactoryBean must not be null");
|
||||
|
||||
try {
|
||||
this.taskExecutionDao = taskExecutionDaoFactoryBean.getObject();
|
||||
@@ -56,8 +55,7 @@ public class SimpleTaskExplorer implements TaskExplorer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName,
|
||||
Pageable pageable) {
|
||||
public Page<TaskExecution> findRunningTaskExecutions(String taskName, Pageable pageable) {
|
||||
return this.taskExecutionDao.findRunningTaskExecutions(taskName, pageable);
|
||||
}
|
||||
|
||||
@@ -82,8 +80,7 @@ public class SimpleTaskExplorer implements TaskExplorer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName,
|
||||
Pageable pageable) {
|
||||
public Page<TaskExecution> findTaskExecutionsByName(String taskName, Pageable pageable) {
|
||||
return this.taskExecutionDao.findTaskExecutionsByName(taskName, pageable);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ public class SimpleTaskNameResolver implements TaskNameResolver, ApplicationCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.context = applicationContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,19 +65,15 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
|
||||
private int maxErrorMessageSize = MAX_ERROR_MESSAGE_SIZE;
|
||||
|
||||
public SimpleTaskRepository(
|
||||
FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean) {
|
||||
Assert.notNull(taskExecutionDaoFactoryBean,
|
||||
"A FactoryBean that provides a TaskExecutionDao is required");
|
||||
public SimpleTaskRepository(FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean) {
|
||||
Assert.notNull(taskExecutionDaoFactoryBean, "A FactoryBean that provides a TaskExecutionDao is required");
|
||||
|
||||
this.taskExecutionDaoFactoryBean = taskExecutionDaoFactoryBean;
|
||||
}
|
||||
|
||||
public SimpleTaskRepository(FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean,
|
||||
Integer maxExitMessageSize, Integer maxTaskNameSize,
|
||||
Integer maxErrorMessageSize) {
|
||||
Assert.notNull(taskExecutionDaoFactoryBean,
|
||||
"A FactoryBean that provides a TaskExecutionDao is required");
|
||||
public SimpleTaskRepository(FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean, Integer maxExitMessageSize,
|
||||
Integer maxTaskNameSize, Integer maxErrorMessageSize) {
|
||||
Assert.notNull(taskExecutionDaoFactoryBean, "A FactoryBean that provides a TaskExecutionDao is required");
|
||||
if (maxTaskNameSize != null) {
|
||||
this.maxTaskNameSize = maxTaskNameSize;
|
||||
}
|
||||
@@ -91,24 +87,21 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode,
|
||||
Date endTime, String exitMessage) {
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage) {
|
||||
return completeTaskExecution(executionId, exitCode, endTime, exitMessage, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode,
|
||||
Date endTime, String exitMessage, String errorMessage) {
|
||||
public TaskExecution completeTaskExecution(long executionId, Integer exitCode, Date endTime, String exitMessage,
|
||||
String errorMessage) {
|
||||
initialize();
|
||||
|
||||
validateCompletedTaskExitInformation(executionId, exitCode, endTime);
|
||||
exitMessage = trimMessage(exitMessage, this.maxExitMessageSize);
|
||||
errorMessage = trimMessage(errorMessage, this.maxErrorMessageSize);
|
||||
this.taskExecutionDao.completeTaskExecution(executionId, exitCode, endTime,
|
||||
exitMessage, errorMessage);
|
||||
logger.debug("Updating: TaskExecution with executionId=" + executionId
|
||||
+ " with the following {" + "exitCode=" + exitCode + ", endTime="
|
||||
+ endTime + ", exitMessage='" + exitMessage + '\'' + ", errorMessage='"
|
||||
this.taskExecutionDao.completeTaskExecution(executionId, exitCode, endTime, exitMessage, errorMessage);
|
||||
logger.debug("Updating: TaskExecution with executionId=" + executionId + " with the following {" + "exitCode="
|
||||
+ exitCode + ", endTime=" + endTime + ", exitMessage='" + exitMessage + '\'' + ", errorMessage='"
|
||||
+ errorMessage + '\'' + '}');
|
||||
|
||||
return this.taskExecutionDao.getTaskExecution(executionId);
|
||||
@@ -118,9 +111,8 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
public TaskExecution createTaskExecution(TaskExecution taskExecution) {
|
||||
initialize();
|
||||
validateCreateInformation(taskExecution);
|
||||
TaskExecution daoTaskExecution = this.taskExecutionDao.createTaskExecution(
|
||||
taskExecution.getTaskName(), taskExecution.getStartTime(),
|
||||
taskExecution.getArguments(), taskExecution.getExternalExecutionId(),
|
||||
TaskExecution daoTaskExecution = this.taskExecutionDao.createTaskExecution(taskExecution.getTaskName(),
|
||||
taskExecution.getStartTime(), taskExecution.getArguments(), taskExecution.getExternalExecutionId(),
|
||||
taskExecution.getParentExecutionId());
|
||||
logger.debug("Creating: " + taskExecution.toString());
|
||||
return daoTaskExecution;
|
||||
@@ -129,8 +121,8 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
@Override
|
||||
public TaskExecution createTaskExecution(String name) {
|
||||
initialize();
|
||||
TaskExecution taskExecution = this.taskExecutionDao.createTaskExecution(name,
|
||||
null, Collections.<String>emptyList(), null);
|
||||
TaskExecution taskExecution = this.taskExecutionDao.createTaskExecution(name, null,
|
||||
Collections.<String>emptyList(), null);
|
||||
logger.debug("Creating: " + taskExecution.toString());
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -141,10 +133,9 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId) {
|
||||
return startTaskExecution(executionid, taskName, startTime, arguments,
|
||||
externalExecutionId, null);
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId) {
|
||||
return startTaskExecution(executionid, taskName, startTime, arguments, externalExecutionId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,13 +145,11 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName,
|
||||
Date startTime, List<String> arguments, String externalExecutionId,
|
||||
Long parentExecutionId) {
|
||||
public TaskExecution startTaskExecution(long executionid, String taskName, Date startTime, List<String> arguments,
|
||||
String externalExecutionId, Long parentExecutionId) {
|
||||
initialize();
|
||||
TaskExecution taskExecution = this.taskExecutionDao.startTaskExecution(
|
||||
executionid, taskName, startTime, arguments, externalExecutionId,
|
||||
parentExecutionId);
|
||||
TaskExecution taskExecution = this.taskExecutionDao.startTaskExecution(executionid, taskName, startTime,
|
||||
arguments, externalExecutionId, parentExecutionId);
|
||||
logger.debug("Starting: " + taskExecution.toString());
|
||||
return taskExecution;
|
||||
}
|
||||
@@ -181,8 +170,7 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
this.initialized = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to create the TaskExecutionDao",
|
||||
e);
|
||||
throw new IllegalStateException("Unable to create the TaskExecutionDao", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,18 +180,14 @@ public class SimpleTaskRepository implements TaskRepository {
|
||||
* @param taskExecution task execution to validate
|
||||
*/
|
||||
private void validateCreateInformation(TaskExecution taskExecution) {
|
||||
Assert.notNull(taskExecution.getStartTime(),
|
||||
"TaskExecution start time cannot be null.");
|
||||
Assert.notNull(taskExecution.getStartTime(), "TaskExecution start time cannot be null.");
|
||||
|
||||
if (taskExecution.getTaskName() != null
|
||||
&& taskExecution.getTaskName().length() > this.maxTaskNameSize) {
|
||||
throw new IllegalArgumentException(
|
||||
"TaskName length exceeds " + this.maxTaskNameSize + " characters");
|
||||
if (taskExecution.getTaskName() != null && taskExecution.getTaskName().length() > this.maxTaskNameSize) {
|
||||
throw new IllegalArgumentException("TaskName length exceeds " + this.maxTaskNameSize + " characters");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCompletedTaskExitInformation(long executionId, Integer exitCode,
|
||||
Date endTime) {
|
||||
private void validateCompletedTaskExitInformation(long executionId, Integer exitCode, Date endTime) {
|
||||
Assert.notNull(exitCode, "exitCode should not be null");
|
||||
Assert.isTrue(exitCode >= 0, "exit code must be greater than or equal to zero");
|
||||
Assert.notNull(endTime, "TaskExecution endTime cannot be null.");
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.jdbc.support.incrementer.AbstractSequenceMaxValueIncr
|
||||
|
||||
/**
|
||||
* Incrementer using SQL Server's sequence.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @since 2.3.2
|
||||
*/
|
||||
@@ -30,8 +31,10 @@ public class SqlServerSequenceMaxValueIncrementer extends AbstractSequenceMaxVal
|
||||
SqlServerSequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) {
|
||||
super(dataSource, incrementerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSequenceQuery() {
|
||||
return "select next value for " + getIncrementerName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean<TaskExecutionDao
|
||||
String incrementerName = this.tablePrefix + "SEQ";
|
||||
DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(
|
||||
dataSource);
|
||||
DataFieldMaxValueIncrementer incrementer = incrementerFactory
|
||||
.getIncrementer(databaseType, incrementerName);
|
||||
DataFieldMaxValueIncrementer incrementer = incrementerFactory.getIncrementer(databaseType,
|
||||
incrementerName);
|
||||
if (!isSqlServerTableSequenceAvailable(incrementerName)) {
|
||||
incrementer = new SqlServerSequenceMaxValueIncrementer(dataSource, this.tablePrefix + "SEQ");
|
||||
}
|
||||
@@ -135,8 +135,8 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean<TaskExecutionDao
|
||||
catch (SQLException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
((JdbcTaskExecutionDao) this.dao).setTaskIncrementer(incrementerFactory
|
||||
.getIncrementer(databaseType, this.tablePrefix + "SEQ"));
|
||||
((JdbcTaskExecutionDao) this.dao)
|
||||
.setTaskIncrementer(incrementerFactory.getIncrementer(databaseType, this.tablePrefix + "SEQ"));
|
||||
}
|
||||
|
||||
private boolean isSqlServerTableSequenceAvailable(String incrementerName) {
|
||||
|
||||
@@ -84,9 +84,7 @@ public final class TaskRepositoryInitializer implements InitializingBean {
|
||||
|
||||
private String getDatabaseType(DataSource dataSource) {
|
||||
try {
|
||||
return JdbcUtils
|
||||
.commonDatabaseName(DatabaseType.fromMetaData(dataSource).toString())
|
||||
.toLowerCase();
|
||||
return JdbcUtils.commonDatabaseName(DatabaseType.fromMetaData(dataSource).toString()).toLowerCase();
|
||||
}
|
||||
catch (MetaDataAccessException ex) {
|
||||
throw new IllegalStateException("Unable to detect database type", ex);
|
||||
@@ -99,10 +97,9 @@ public final class TaskRepositoryInitializer implements InitializingBean {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
boolean isInitializeEnabled = (this.taskProperties.isInitializeEnabled() != null)
|
||||
? this.taskProperties.isInitializeEnabled()
|
||||
: this.taskInitializationEnabled;
|
||||
if (this.dataSource != null && isInitializeEnabled && this.taskProperties
|
||||
.getTablePrefix().equals(TaskProperties.DEFAULT_TABLE_PREFIX)) {
|
||||
? this.taskProperties.isInitializeEnabled() : this.taskInitializationEnabled;
|
||||
if (this.dataSource != null && isInitializeEnabled
|
||||
&& this.taskProperties.getTablePrefix().equals(TaskProperties.DEFAULT_TABLE_PREFIX)) {
|
||||
String platform = getDatabaseType(this.dataSource);
|
||||
if ("hsql".equals(platform)) {
|
||||
platform = "hsqldb";
|
||||
@@ -124,8 +121,7 @@ public final class TaskRepositoryInitializer implements InitializingBean {
|
||||
schemaLocation = schemaLocation.replace("@@platform@@", platform);
|
||||
populator.addScript(this.resourceLoader.getResource(schemaLocation));
|
||||
populator.setContinueOnError(true);
|
||||
logger.debug(
|
||||
String.format("Initializing task schema for %s database", platform));
|
||||
logger.debug(String.format("Initializing task schema for %s database", platform));
|
||||
DatabasePopulatorUtils.execute(populator, this.dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,19 +40,15 @@ public class SimpleSingleTaskAutoConfigurationTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
|
||||
applicationContextRunner.run((context) -> {
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context
|
||||
.getBean(SingleInstanceTaskListener.class);
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
assertThat(singleInstanceTaskListener).as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
assertThat(SingleInstanceTaskListener.class).isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -41,20 +41,16 @@ public class SimpleSingleTaskAutoConfigurationWithDataSourceTests {
|
||||
public void testConfiguration() {
|
||||
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.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);
|
||||
SingleInstanceTaskListener singleInstanceTaskListener = context.getBean(SingleInstanceTaskListener.class);
|
||||
|
||||
assertThat(singleInstanceTaskListener)
|
||||
.as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
assertThat(singleInstanceTaskListener).as("singleInstanceTaskListener should not be null").isNotNull();
|
||||
|
||||
assertThat(SingleInstanceTaskListener.class)
|
||||
.isEqualTo(singleInstanceTaskListener.getClass());
|
||||
assertThat(SingleInstanceTaskListener.class).isEqualTo(singleInstanceTaskListener.getClass());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,10 +62,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);
|
||||
@@ -78,8 +76,7 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testAutoConfigurationDisabled() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
|
||||
Executable executable = () -> {
|
||||
@@ -87,17 +84,16 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
context.getBean(TaskRepository.class);
|
||||
});
|
||||
};
|
||||
verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying "
|
||||
+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' "
|
||||
+ "available", executable);
|
||||
verifyExceptionThrown(
|
||||
NoSuchBeanDefinitionException.class, "No qualifying "
|
||||
+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' " + "available",
|
||||
executable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withConfiguration(
|
||||
AutoConfigurations.of(EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
applicationContextRunner.run((context) -> {
|
||||
@@ -108,14 +104,12 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testRepositoryInitializedWithLazyInitialization() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withInitializer((context) -> context
|
||||
.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()))
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner().withInitializer(
|
||||
(context) -> context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()))
|
||||
.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);
|
||||
@@ -125,47 +119,42 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRepositoryNotInitialized() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
|
||||
.withConfiguration(AutoConfigurations.of(EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
|
||||
SingleTaskConfiguration.class))
|
||||
.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
|
||||
.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");
|
||||
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class,
|
||||
applicationContextRunner);
|
||||
verifyExceptionThrownDefaultExecutable(ApplicationContextException.class, applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleConfigurers() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.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",
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
applicationContextRunner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDataSources() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
PropertyPlaceholderAutoConfiguration.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",
|
||||
"Error creating bean " + "with name 'simpleTaskAutoConfiguration': Invocation of init method failed",
|
||||
applicationContextRunner);
|
||||
|
||||
}
|
||||
|
||||
public void verifyExceptionThrownDefaultExecutable(Class classToCheck, ApplicationContextRunner applicationContextRunner) {
|
||||
public void verifyExceptionThrownDefaultExecutable(Class classToCheck,
|
||||
ApplicationContextRunner applicationContextRunner) {
|
||||
Executable executable = () -> {
|
||||
applicationContextRunner.run((context) -> {
|
||||
Throwable expectedException = context.getStartupFailure();
|
||||
@@ -188,10 +177,8 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
verifyExceptionThrown(classToCheck, message, executable);
|
||||
}
|
||||
|
||||
public void verifyExceptionThrown(Class classToCheck, String message,
|
||||
Executable executable) {
|
||||
assertThatExceptionOfType(classToCheck).isThrownBy(executable::execute)
|
||||
.withMessage(message);
|
||||
public void verifyExceptionThrown(Class classToCheck, String message, Executable executable) {
|
||||
assertThatExceptionOfType(classToCheck).isThrownBy(executable::execute).withMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,16 +187,13 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
*/
|
||||
@Test
|
||||
public void testWithDataSourceProxy() {
|
||||
ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.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);
|
||||
SimpleTaskAutoConfiguration taskConfiguration = context.getBean(SimpleTaskAutoConfiguration.class);
|
||||
assertThat(taskConfiguration).isNotNull();
|
||||
assertThat(taskConfiguration.taskExplorer()).isNotNull();
|
||||
});
|
||||
@@ -255,10 +239,9 @@ public class SimpleTaskAutoConfigurationTests {
|
||||
public BeanDefinitionHolder proxyDataSource() {
|
||||
GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
|
||||
proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(
|
||||
proxyBeanDefinition, "dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource,
|
||||
(BeanDefinitionRegistry) this.context.getBeanFactory(), true);
|
||||
BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(proxyBeanDefinition, "dataSource2");
|
||||
ScopedProxyUtils.createScopedProxy(myDataSource, (BeanDefinitionRegistry) this.context.getBeanFactory(),
|
||||
true);
|
||||
return myDataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,17 +72,16 @@ public class TaskCoreTests {
|
||||
@Test
|
||||
public void successfulTaskTest(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(TaskConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,76 +89,63 @@ public class TaskCoreTests {
|
||||
*/
|
||||
@Test
|
||||
public void successfulTaskTestWithAnnotation(CapturedOutput capturedOutput) {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskConfigurationWithAnotation.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
this.applicationContext = SpringApplication.run(TaskConfigurationWithAnotation.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).isTrue();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(SUCCESS_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionTaskTest(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
this.applicationContext = SpringApplication.run(TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false");
|
||||
}
|
||||
catch (IllegalStateException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown")
|
||||
.isTrue();
|
||||
assertThat(exceptionFired).as("An IllegalStateException should have been thrown").isTrue();
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE))
|
||||
.as("Test results do not show create task message: " + output).isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE))
|
||||
.as("Test results do not show success message: " + output).isTrue();
|
||||
assertThat(output.contains(EXCEPTION_EXIT_CODE_MESSAGE))
|
||||
.as("Test results have incorrect exit code: " + output).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();
|
||||
assertThat(output.contains(CREATE_TASK_MESSAGE)).as("Test results do not show create task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(UPDATE_TASK_MESSAGE)).as("Test results do not show success message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains(EXCEPTION_EXIT_CODE_MESSAGE)).as("Test results have incorrect exit code: " + output)
|
||||
.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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidExecutionId(CapturedOutput capturedOutput) {
|
||||
boolean exceptionFired = false;
|
||||
try {
|
||||
this.applicationContext = SpringApplication.run(
|
||||
TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false",
|
||||
"--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false",
|
||||
"--spring.cloud.task.executionid=55");
|
||||
this.applicationContext = SpringApplication.run(TaskExceptionConfiguration.class,
|
||||
"--spring.cloud.task.closecontext.enable=false", "--spring.cloud.task.name=" + TASK_NAME,
|
||||
"--spring.main.web-environment=false", "--spring.cloud.task.executionid=55");
|
||||
}
|
||||
catch (ApplicationContextException exception) {
|
||||
exceptionFired = true;
|
||||
}
|
||||
assertThat(exceptionFired)
|
||||
.as("An ApplicationContextException should have been thrown").isTrue();
|
||||
assertThat(exceptionFired).as("An ApplicationContextException should have been thrown").isTrue();
|
||||
|
||||
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
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -174,8 +160,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskConfigurationWithAnotation {
|
||||
|
||||
@Bean
|
||||
@@ -190,8 +175,7 @@ public class TaskCoreTests {
|
||||
}
|
||||
|
||||
@EnableTask
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class })
|
||||
@ImportAutoConfiguration({ SimpleTaskAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
public static class TaskExceptionConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -43,8 +43,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class })
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class, EmbeddedDataSourceConfiguration.class })
|
||||
@DirtiesContext
|
||||
public class TaskRepositoryInitializerDefaultTaskConfigurerTests {
|
||||
|
||||
|
||||
@@ -44,9 +44,8 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(
|
||||
classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class })
|
||||
@ContextConfiguration(classes = { SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class, DefaultTaskConfigurer.class })
|
||||
public class TaskRepositoryInitializerNoDataSourceTaskConfigurerTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user