diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java index 4bfd2f19b..bba4180b8 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/AbstractBatchConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ import org.springframework.util.Assert; @Import(ScopeConfiguration.class) public abstract class AbstractBatchConfiguration implements ImportAware, InitializingBean { - @Autowired(required = false) + @Autowired private DataSource dataSource; private BatchConfigurer configurer; @@ -103,22 +103,15 @@ public abstract class AbstractBatchConfiguration implements ImportAware, Initial this.stepBuilderFactory = new StepBuilderFactory(jobRepository(), transactionManager()); } - protected BatchConfigurer getConfigurer(Collection configurers) throws Exception { + protected BatchConfigurer getConfigurer(Collection configurers) { if (this.configurer != null) { return this.configurer; } if (configurers == null || configurers.isEmpty()) { - if (dataSource == null) { - DefaultBatchConfigurer configurer = new DefaultBatchConfigurer(); - configurer.initialize(); - this.configurer = configurer; - return configurer; - } else { - DefaultBatchConfigurer configurer = new DefaultBatchConfigurer(dataSource); - configurer.initialize(); - this.configurer = configurer; - return configurer; - } + DefaultBatchConfigurer configurer = new DefaultBatchConfigurer(this.dataSource); + configurer.initialize(); + this.configurer = configurer; + return configurer; } if (configurers.size() > 1) { throw new IllegalStateException( diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java index 4d99ddf1e..986419fee 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,27 +18,20 @@ package org.springframework.batch.core.configuration.annotation; import javax.annotation.PostConstruct; import javax.sql.DataSource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.batch.core.configuration.BatchConfigurationException; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.explore.support.JobExplorerFactoryBean; -import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.util.Assert; @Component public class DefaultBatchConfigurer implements BatchConfigurer { - private static final Log logger = LogFactory.getLog(DefaultBatchConfigurer.class); private DataSource dataSource; private PlatformTransactionManager transactionManager; @@ -47,28 +40,39 @@ public class DefaultBatchConfigurer implements BatchConfigurer { private JobExplorer jobExplorer; /** - * Sets the dataSource. If the {@link DataSource} has been set once, all future - * values are passed are ignored (to prevent {@code}@Autowired{@code} from overwriting - * the value). + * Sets the dataSource. * - * @param dataSource The data source to use + * @param dataSource The data source to use. Must not be {@code null}. */ - @Autowired(required = false) public void setDataSource(DataSource dataSource) { - if(this.dataSource == null) { - this.dataSource = dataSource; - } - - if(getTransactionManager() == null) { - logger.warn("No transaction manager was provided, using a DataSourceTransactionManager"); - this.transactionManager = new DataSourceTransactionManager(this.dataSource); - } + Assert.notNull(dataSource, "DataSource must not be null"); + this.dataSource = dataSource; } - protected DefaultBatchConfigurer() {} + public DataSource getDataSource() { + return this.dataSource; + } + /** + * Create a new {@link DefaultBatchConfigurer} with the passed datasource. This constructor + * will configure a default {@link DataSourceTransactionManager}. + * + * @param dataSource to use for the job repository and job explorer + */ public DefaultBatchConfigurer(DataSource dataSource) { - setDataSource(dataSource); + this(dataSource, new DataSourceTransactionManager(dataSource)); + } + + /** + * Create a new {@link DefaultBatchConfigurer} with the passed datasource and transaction manager. + * @param dataSource to use for the job repository and job explorer + * @param transactionManager to use for the job repository + */ + public DefaultBatchConfigurer(DataSource dataSource, PlatformTransactionManager transactionManager) { + Assert.notNull(dataSource, "DataSource must not be null"); + Assert.notNull(transactionManager, "transactionManager must not be null"); + this.dataSource = dataSource; + this.transactionManager = transactionManager; } @Override @@ -94,26 +98,8 @@ public class DefaultBatchConfigurer implements BatchConfigurer { @PostConstruct public void initialize() { try { - if(dataSource == null) { - logger.warn("No datasource was provided...using a Map based JobRepository"); - - if(getTransactionManager() == null) { - logger.warn("No transaction manager was provided, using a ResourcelessTransactionManager"); - this.transactionManager = new ResourcelessTransactionManager(); - } - - MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(getTransactionManager()); - jobRepositoryFactory.afterPropertiesSet(); - this.jobRepository = jobRepositoryFactory.getObject(); - - MapJobExplorerFactoryBean jobExplorerFactory = new MapJobExplorerFactoryBean(jobRepositoryFactory); - jobExplorerFactory.afterPropertiesSet(); - this.jobExplorer = jobExplorerFactory.getObject(); - } else { - this.jobRepository = createJobRepository(); - this.jobExplorer = createJobExplorer(); - } - + this.jobRepository = createJobRepository(); + this.jobExplorer = createJobExplorer(); this.jobLauncher = createJobLauncher(); } catch (Exception e) { throw new BatchConfigurationException(e); @@ -122,14 +108,14 @@ public class DefaultBatchConfigurer implements BatchConfigurer { protected JobLauncher createJobLauncher() throws Exception { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); - jobLauncher.setJobRepository(jobRepository); + jobLauncher.setJobRepository(this.jobRepository); jobLauncher.afterPropertiesSet(); return jobLauncher; } protected JobRepository createJobRepository() throws Exception { JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); - factory.setDataSource(dataSource); + factory.setDataSource(this.dataSource); factory.setTransactionManager(getTransactionManager()); factory.afterPropertiesSet(); return factory.getObject(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java index 91b06ef66..f86b41ac9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,9 +85,7 @@ import org.springframework.transaction.PlatformTransactionManager; * } * * - * If a user does not provide a {@link javax.sql.DataSource} within the context, a Map based - * {@link org.springframework.batch.core.repository.JobRepository} will be used. If multiple - * {@link javax.sql.DataSource}s are defined in the context, the one annotated with + * If multiple {@link javax.sql.DataSource}s are defined in the context, the one annotated with * {@link org.springframework.context.annotation.Primary} will be used (Note that if none * of them is annotated with {@link org.springframework.context.annotation.Primary}, the one * named dataSource will be used if any, otherwise a {@link UnsatisfiedDependencyException} @@ -111,14 +109,8 @@ import org.springframework.transaction.PlatformTransactionManager; * job repository and transaction manager into every step * * - * The transaction manager provided by this annotation will be of type: - * - * + * The transaction manager provided by this annotation will be of type {@link org.springframework.jdbc.datasource.DataSourceTransactionManager} + * configured with the {@link javax.sql.DataSource} provided within the context. * * In order to use a custom transaction manager, a custom {@link BatchConfigurer} should be provided. For example: * diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/AbstractJobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/AbstractJobExplorerFactoryBean.java index e7d3a8ed0..c4918d736 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/AbstractJobExplorerFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/AbstractJobExplorerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,9 @@ import org.springframework.beans.factory.FactoryBean; * object implementations. * * @see JobExplorerFactoryBean - * @see MapJobExplorerFactoryBean * * @author Dave Syer + * @author Mahmoud Ben Hassine * @since 2.0 */ public abstract class AbstractJobExplorerFactoryBean implements FactoryBean { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBean.java deleted file mode 100644 index 383a1e885..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBean.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2006-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.explore.support; - -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.repository.dao.ExecutionContextDao; -import org.springframework.batch.core.repository.dao.JobExecutionDao; -import org.springframework.batch.core.repository.dao.JobInstanceDao; -import org.springframework.batch.core.repository.dao.StepExecutionDao; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; - -/** - * A {@link FactoryBean} that automates the creation of a - * {@link SimpleJobExplorer} using in-memory DAO implementations. - * - * @author Dave Syer - * @author Mahmoud Ben Hassine - * @since 2.0 - * - * @deprecated as of v4.3 in favor of using the {@link JobExplorerFactoryBean} - * with an in-memory database. Scheduled for removal in v5.0. - */ -@Deprecated -public class MapJobExplorerFactoryBean extends AbstractJobExplorerFactoryBean implements InitializingBean { - - private MapJobRepositoryFactoryBean repositoryFactory; - - /** - * Create an instance with the provided {@link MapJobRepositoryFactoryBean} - * as a source of Dao instances. - * @param repositoryFactory provides the used {@link org.springframework.batch.core.repository.JobRepository} - */ - public MapJobExplorerFactoryBean(MapJobRepositoryFactoryBean repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - /** - * Create a factory with no {@link MapJobRepositoryFactoryBean}. It must be - * injected as a property. - */ - public MapJobExplorerFactoryBean() { - } - - /** - * The repository factory that can be used to create daos for the explorer. - * - * @param repositoryFactory a {@link MapJobExplorerFactoryBean} - */ - public void setRepositoryFactory(MapJobRepositoryFactoryBean repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - /** - * @throws Exception thrown if error occurs. - * - * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() - */ - @Override - public void afterPropertiesSet() throws Exception { - Assert.state(repositoryFactory != null, "A MapJobRepositoryFactoryBean must be provided"); - repositoryFactory.afterPropertiesSet(); - } - - @Override - protected JobExecutionDao createJobExecutionDao() throws Exception { - return repositoryFactory.getJobExecutionDao(); - } - - @Override - protected JobInstanceDao createJobInstanceDao() throws Exception { - return repositoryFactory.getJobInstanceDao(); - } - - @Override - protected StepExecutionDao createStepExecutionDao() throws Exception { - return repositoryFactory.getStepExecutionDao(); - } - - @Override - protected ExecutionContextDao createExecutionContextDao() throws Exception { - return repositoryFactory.getExecutionContextDao(); - } - - @Override - public JobExplorer getObject() throws Exception { - return new SimpleJobExplorer(createJobInstanceDao(), createJobExecutionDao(), createStepExecutionDao(), - createExecutionContextDao()); - } - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java deleted file mode 100644 index 399f39a66..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapExecutionContextDao.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright 2006-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.repository.dao; - -import java.io.Serializable; -import java.util.Collection; -import java.util.concurrent.ConcurrentMap; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; -import org.springframework.util.Assert; -import org.springframework.util.SerializationUtils; - -/** - * In-memory implementation of {@link ExecutionContextDao} backed by maps. - * - * @author Robert Kasanicky - * @author Dave Syer - * @author David Turanski - * @author Mahmoud Ben Hassine - * - * @deprecated as of v4.3 in favor of using the {@link JdbcExecutionContextDao} - * with an in-memory database. Scheduled for removal in v5.0. - */ -@SuppressWarnings("serial") -@Deprecated -public class MapExecutionContextDao implements ExecutionContextDao { - - private final ConcurrentMap contexts = TransactionAwareProxyFactory - .createAppendOnlyTransactionalMap(); - - private static final class ContextKey implements Comparable, Serializable { - - private static enum Type { STEP, JOB; } - - private final Type type; - private final long id; - - private ContextKey(Type type, long id) { - if(type == null) { - throw new IllegalStateException("Need a non-null type for a context"); - } - this.type = type; - this.id = id; - } - - @Override - public int compareTo(ContextKey them) { - if(them == null) { - return 1; - } - final int idCompare = Long.compare(this.id, them.id); - if(idCompare != 0) { - return idCompare; - } - final int typeCompare = this.type.compareTo(them.type); - if(typeCompare != 0) { - return typeCompare; - } - return 0; - } - - @Override - public boolean equals(Object them) { - if(them == null) { - return false; - } - if(them instanceof ContextKey) { - return this.equals((ContextKey)them); - } - return false; - } - - public boolean equals(ContextKey them) { - if(them == null) { - return false; - } - return this.id == them.id && this.type.equals(them.type); - } - - @Override - public int hashCode() { - int value = (int)(id^(id>>>32)); - switch(type) { - case STEP: return value; - case JOB: return ~value; - default: throw new IllegalStateException("Unknown type encountered in switch: " + type); - } - } - - public static ContextKey step(long id) { return new ContextKey(Type.STEP, id); } - - public static ContextKey job(long id) { return new ContextKey(Type.JOB, id); } - } - - public void clear() { - contexts.clear(); - } - - private static ExecutionContext copy(ExecutionContext original) { - return (ExecutionContext) SerializationUtils.deserialize(SerializationUtils.serialize(original)); - } - - @Override - public ExecutionContext getExecutionContext(StepExecution stepExecution) { - return copy(contexts.get(ContextKey.step(stepExecution.getId()))); - } - - @Override - public void updateExecutionContext(StepExecution stepExecution) { - ExecutionContext executionContext = stepExecution.getExecutionContext(); - if (executionContext != null) { - contexts.put(ContextKey.step(stepExecution.getId()), copy(executionContext)); - } - } - - @Override - public ExecutionContext getExecutionContext(JobExecution jobExecution) { - return copy(contexts.get(ContextKey.job(jobExecution.getId()))); - } - - @Override - public void updateExecutionContext(JobExecution jobExecution) { - ExecutionContext executionContext = jobExecution.getExecutionContext(); - if (executionContext != null) { - contexts.put(ContextKey.job(jobExecution.getId()), copy(executionContext)); - } - } - - @Override - public void saveExecutionContext(JobExecution jobExecution) { - updateExecutionContext(jobExecution); - } - - @Override - public void saveExecutionContext(StepExecution stepExecution) { - updateExecutionContext(stepExecution); - } - - - @Override - public void saveExecutionContexts(Collection stepExecutions) { - Assert.notNull(stepExecutions,"Attempt to save a null collection of step executions"); - for (StepExecution stepExecution: stepExecutions) { - saveExecutionContext(stepExecution); - saveExecutionContext(stepExecution.getJobExecution()); - } - } - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java deleted file mode 100644 index 570ecbee5..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2006-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.repository.dao; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; -import org.springframework.util.SerializationUtils; - -/** - * In-memory implementation of {@link JobExecutionDao}. - * - * @deprecated as of v4.3 in favor of using the {@link JdbcJobExecutionDao} - * with an in-memory database. Scheduled for removal in v5.0. - */ -@Deprecated -public class MapJobExecutionDao implements JobExecutionDao { - - // JDK6 Make this into a ConcurrentSkipListMap: adds and removes tend to be very near the front or back - private final ConcurrentMap executionsById = new ConcurrentHashMap<>(); - - private final AtomicLong currentId = new AtomicLong(0L); - - public void clear() { - executionsById.clear(); - } - - private static JobExecution copy(JobExecution original) { - JobExecution copy = (JobExecution) SerializationUtils.deserialize(SerializationUtils.serialize(original)); - return copy; - } - - @Override - public void saveJobExecution(JobExecution jobExecution) { - Assert.isTrue(jobExecution.getId() == null, "jobExecution id is not null"); - Long newId = currentId.getAndIncrement(); - jobExecution.setId(newId); - jobExecution.incrementVersion(); - executionsById.put(newId, copy(jobExecution)); - } - - @Override - public List findJobExecutions(JobInstance jobInstance) { - List executions = new ArrayList<>(); - for (JobExecution exec : executionsById.values()) { - if (exec.getJobInstance().equals(jobInstance)) { - executions.add(copy(exec)); - } - } - Collections.sort(executions, new Comparator() { - - @Override - public int compare(JobExecution e1, JobExecution e2) { - long result = (e1.getId() - e2.getId()); - if (result > 0) { - return -1; - } - else if (result < 0) { - return 1; - } - else { - return 0; - } - } - }); - return executions; - } - - @Override - public void updateJobExecution(JobExecution jobExecution) { - Long id = jobExecution.getId(); - Assert.notNull(id, "JobExecution is expected to have an id (should be saved already)"); - JobExecution persistedExecution = executionsById.get(id); - Assert.notNull(persistedExecution, "JobExecution must already be saved"); - - synchronized (jobExecution) { - if (!persistedExecution.getVersion().equals(jobExecution.getVersion())) { - throw new OptimisticLockingFailureException("Attempt to update job execution id=" + id - + " with wrong version (" + jobExecution.getVersion() + "), where current version is " - + persistedExecution.getVersion()); - } - jobExecution.incrementVersion(); - executionsById.put(id, copy(jobExecution)); - } - } - - @Nullable - @Override - public JobExecution getLastJobExecution(@Nullable JobInstance jobInstance) { - JobExecution lastExec = null; - for (JobExecution exec : executionsById.values()) { - if (!exec.getJobInstance().equals(jobInstance)) { - continue; - } - if (lastExec == null) { - lastExec = exec; - } - if (lastExec.getCreateTime().before(exec.getCreateTime())) { - lastExec = exec; - } - } - return copy(lastExec); - } - - /* - * (non-Javadoc) - * - * @see org.springframework.batch.core.repository.dao.JobExecutionDao# - * findRunningJobExecutions(java.lang.String) - */ - @Override - public Set findRunningJobExecutions(String jobName) { - Set result = new HashSet<>(); - for (JobExecution exec : executionsById.values()) { - if (!exec.getJobInstance().getJobName().equals(jobName) || !exec.isRunning()) { - continue; - } - result.add(copy(exec)); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see - * org.springframework.batch.core.repository.dao.JobExecutionDao#getJobExecution - * (java.lang.Long) - */ - @Override - @Nullable - public JobExecution getJobExecution(Long executionId) { - return copy(executionsById.get(executionId)); - } - - @Override - public void synchronizeStatus(JobExecution jobExecution) { - JobExecution saved = getJobExecution(jobExecution.getId()); - if (saved.getVersion().intValue() != jobExecution.getVersion().intValue()) { - jobExecution.upgradeStatus(saved.getStatus()); - jobExecution.setVersion(saved.getVersion()); - } - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java deleted file mode 100644 index f879549e9..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2006-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.repository.dao; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.batch.core.DefaultJobKeyGenerator; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobKeyGenerator; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.launch.NoSuchJobException; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; - -/** - * In-memory implementation of {@link JobInstanceDao}. - * - * @deprecated as of v4.3 in favor of using the {@link JdbcJobInstanceDao} - * with an in-memory database. Scheduled for removal in v5.0. - */ -@Deprecated -public class MapJobInstanceDao implements JobInstanceDao { - private static final String STAR_WILDCARD = "\\*"; - private static final String STAR_WILDCARD_PATTERN = ".*"; - - // JDK6 Make a ConcurrentSkipListSet: tends to add on end - private final Map jobInstances = new ConcurrentHashMap<>(); - - private JobKeyGenerator jobKeyGenerator = new DefaultJobKeyGenerator(); - - private final AtomicLong currentId = new AtomicLong(0L); - - public void clear() { - jobInstances.clear(); - } - - @Override - public JobInstance createJobInstance(String jobName, JobParameters jobParameters) { - - Assert.state(getJobInstance(jobName, jobParameters) == null, "JobInstance must not already exist"); - - JobInstance jobInstance = new JobInstance(currentId.getAndIncrement(), jobName); - jobInstance.incrementVersion(); - jobInstances.put(jobName + "|" + jobKeyGenerator.generateKey(jobParameters), jobInstance); - - return jobInstance; - } - - @Override - @Nullable - public JobInstance getJobInstance(String jobName, JobParameters jobParameters) { - return jobInstances.get(jobName + "|" + jobKeyGenerator.generateKey(jobParameters)); - } - - @Override - @Nullable - public JobInstance getJobInstance(@Nullable Long instanceId) { - for (Map.Entry instanceEntry : jobInstances.entrySet()) { - JobInstance instance = instanceEntry.getValue(); - if (instance.getId().equals(instanceId)) { - return instance; - } - } - return null; - } - - @Override - public List getJobNames() { - List result = new ArrayList<>(); - for (Map.Entry instanceEntry : jobInstances.entrySet()) { - result.add(instanceEntry.getValue().getJobName()); - } - Collections.sort(result); - return result; - } - - @Override - public List getJobInstances(String jobName, int start, int count) { - List result = new ArrayList<>(); - for (Map.Entry instanceEntry : jobInstances.entrySet()) { - JobInstance instance = instanceEntry.getValue(); - if (instance.getJobName().equals(jobName)) { - result.add(instance); - } - } - - sortDescending(result); - - return subset(result, start, count); - } - - @Override - @Nullable - public JobInstance getLastJobInstance(String jobName) { - List jobInstances = getJobInstances(jobName, 0, 1); - return jobInstances.isEmpty() ? null : jobInstances.get(0); - } - - @Override - @Nullable - public JobInstance getJobInstance(JobExecution jobExecution) { - return jobExecution.getJobInstance(); - } - - @Override - public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { - int count = 0; - - for (Map.Entry instanceEntry : jobInstances.entrySet()) { - String key = instanceEntry.getKey(); - String curJobName = key.substring(0, key.lastIndexOf("|")); - - if(curJobName.equals(jobName)) { - count++; - } - } - - if(count == 0) { - throw new NoSuchJobException("No job instances for job name " + jobName + " were found"); - } else { - return count; - } - } - - @Override - public List findJobInstancesByName(String jobName, int start, int count) { - List result = new ArrayList<>(); - String convertedJobName = jobName.replaceAll(STAR_WILDCARD, STAR_WILDCARD_PATTERN); - - for (Map.Entry instanceEntry : jobInstances.entrySet()) { - JobInstance instance = instanceEntry.getValue(); - - if(instance.getJobName().matches(convertedJobName)) { - result.add(instance); - } - } - - sortDescending(result); - - return subset(result, start, count); - } - - private void sortDescending(List result) { - Collections.sort(result, new Comparator() { - @Override - public int compare(JobInstance o1, JobInstance o2) { - return Long.signum(o2.getId() - o1.getId()); - } - }); - } - - private List subset(List jobInstances, int start, int count) { - int startIndex = Math.min(start, jobInstances.size()); - int endIndex = Math.min(start + count, jobInstances.size()); - - return jobInstances.subList(startIndex, endIndex); - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java deleted file mode 100644 index 2e3bed246..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2006-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.dao; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; - -import org.springframework.batch.core.Entity; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.StepExecution; -import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; -import org.springframework.util.SerializationUtils; - -/** - * In-memory implementation of {@link StepExecutionDao}. - * - * @deprecated as of v4.3 in favor of using the {@link JdbcStepExecutionDao} - * with an in-memory database. Scheduled for removal in v5.0. - */ -@Deprecated -public class MapStepExecutionDao implements StepExecutionDao { - - private Map> executionsByJobExecutionId = new ConcurrentHashMap<>(); - - private Map executionsByStepExecutionId = new ConcurrentHashMap<>(); - - private AtomicLong currentId = new AtomicLong(); - - public void clear() { - executionsByJobExecutionId.clear(); - executionsByStepExecutionId.clear(); - } - - private static StepExecution copy(StepExecution original) { - return (StepExecution) SerializationUtils.deserialize(SerializationUtils.serialize(original)); - } - - private static void copy(final StepExecution sourceExecution, final StepExecution targetExecution) { - // Cheaper than full serialization is a reflective field copy, which is - // fine for volatile storage - ReflectionUtils.doWithFields(StepExecution.class, new ReflectionUtils.FieldCallback() { - @Override - public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { - field.setAccessible(true); - field.set(targetExecution, field.get(sourceExecution)); - } - }, ReflectionUtils.COPYABLE_FIELDS); - } - - @Override - public void saveStepExecution(StepExecution stepExecution) { - - Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); - Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); - Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); - - Map executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); - if (executions == null) { - executions = new ConcurrentHashMap<>(); - executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); - } - - stepExecution.setId(currentId.incrementAndGet()); - stepExecution.incrementVersion(); - StepExecution copy = copy(stepExecution); - executions.put(stepExecution.getId(), copy); - executionsByStepExecutionId.put(stepExecution.getId(), copy); - - } - - @Override - public void updateStepExecution(StepExecution stepExecution) { - - Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); - - Map executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); - Assert.notNull(executions, "step executions for given job execution are expected to be already saved"); - - final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId()); - Assert.notNull(persistedExecution, "step execution is expected to be already saved"); - - synchronized (stepExecution) { - if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) { - throw new OptimisticLockingFailureException("Attempt to update step execution id=" - + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() - + "), where current version is " + persistedExecution.getVersion()); - } - - stepExecution.incrementVersion(); - StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution()); - copy(stepExecution, copy); - executions.put(stepExecution.getId(), copy); - executionsByStepExecutionId.put(stepExecution.getId(), copy); - } - } - - @Override - @Nullable - public StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId) { - return executionsByStepExecutionId.get(stepExecutionId); - } - - @Override - public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) { - StepExecution latest = null; - for (StepExecution stepExecution : executionsByStepExecutionId.values()) { - if (!stepExecution.getStepName().equals(stepName) - || stepExecution.getJobExecution().getJobInstance().getInstanceId() != jobInstance.getInstanceId()) { - continue; - } - if (latest == null) { - latest = stepExecution; - } - if (latest.getStartTime().getTime() < stepExecution.getStartTime().getTime()) { - latest = stepExecution; - } - // Use step execution ID as the tie breaker if start time is identical - if (latest.getStartTime().getTime() == stepExecution.getStartTime().getTime() && - latest.getId() < stepExecution.getId()) { - latest = stepExecution; - } - } - return latest; - } - - @Override - public void addStepExecutions(JobExecution jobExecution) { - Map executions = executionsByJobExecutionId.get(jobExecution.getId()); - if (executions == null || executions.isEmpty()) { - return; - } - List result = new ArrayList<>(executions.values()); - Collections.sort(result, new Comparator() { - - @Override - public int compare(Entity o1, Entity o2) { - return Long.signum(o2.getId() - o1.getId()); - } - }); - - List copy = new ArrayList<>(result.size()); - for (StepExecution exec : result) { - copy.add(copy(exec)); - } - jobExecution.addStepExecutions(copy); - } - - @Override - public void saveStepExecutions(Collection stepExecutions) { - Assert.notNull(stepExecutions,"Attempt to save an null collect of step executions"); - for (StepExecution stepExecution: stepExecutions) { - saveStepExecution(stepExecution); - } - } - - @Override - public int countStepExecutions(JobInstance jobInstance, String stepName) { - int count = 0; - - for (StepExecution stepExecution : executionsByStepExecutionId.values()) { - if (stepExecution.getStepName().equals(stepName) && stepExecution.getJobExecution().getJobInstance() - .getInstanceId() == jobInstance.getInstanceId()) { - count++; - } - } - return count; - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java index 67fac0007..36d30ef54 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java @@ -44,7 +44,6 @@ import org.springframework.util.Assert; * object implementations. * * @see JobRepositoryFactoryBean - * @see MapJobRepositoryFactoryBean * * @author Ben Hale * @author Lucas Ward @@ -155,18 +154,6 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean clazz) throws Exception { - GenericApplicationContext context = new AnnotationConfigApplicationContext(clazz); - this.jobLauncher = context.getBean(JobLauncher.class); - this.jobRepository = context.getBean(JobRepository.class); - this.job = context.getBean(Job.class); - this.jobExplorer = context.getBean(JobExplorer.class); - - JobExecution jobExecution = jobLauncher.run(job, new JobParameters()); - assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); - JobExecution repositoryJobExecution = jobRepository.getLastJobExecution(job.getName(), new JobParameters()); - assertEquals(jobExecution.getId(), repositoryJobExecution.getId()); - assertEquals("job", jobExplorer.getJobNames().iterator().next()); - context.close(); - } - - public static class InvalidBatchConfiguration extends HsqlBatchConfiguration { - - @Bean - DataSource dataSource2() { - return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder().setName("badDatabase").build()); - } - } - - public static class ValidBatchConfigurationWithPrimaryDataSource extends HsqlBatchConfiguration { - - @Primary - @Bean - DataSource dataSource2() { - return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder(). - setName("dataSource2"). - addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"). - addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql"). - build()); - } - } - - public static class ValidBatchConfigurationWithoutPrimaryDataSource extends HsqlBatchConfiguration { - - @Bean - DataSource dataSource() { // will be autowired by name - return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder(). - setName("dataSource"). - addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"). - addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql"). - build()); - } - } - - public static class HsqlBatchConfiguration extends MapRepositoryBatchConfiguration { - - @Bean - DataSource dataSource1() { - return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder(). - setName("dataSource1"). - addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"). - addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql"). - build()); - } - } - - @Component - @EnableBatchProcessing - public static class MapRepositoryBatchConfiguration { - @Autowired - JobBuilderFactory jobFactory; - - @Autowired - StepBuilderFactory stepFactory; - - @Bean - Step step1 () { - return stepFactory.get("step1").tasklet(new Tasklet() { - @Nullable - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - return RepeatStatus.FINISHED; - } - }).build(); - } - - @Bean - Job job() { - return jobFactory.get("job").start(step1()).build(); - } - } -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java index 825c125e0..5eccd96e2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithBatchConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,9 @@ import javax.sql.DataSource; import org.junit.Assert; import org.junit.Test; +import org.springframework.batch.core.configuration.BatchConfigurationException; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -35,24 +36,9 @@ import org.springframework.transaction.PlatformTransactionManager; */ public class TransactionManagerConfigurationWithBatchConfigurerTests extends TransactionManagerConfigurationTests { - @Test - public void testConfigurationWithNoDataSourceAndNoTransactionManager() throws Exception { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndNoTransactionManager.class); - BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class); - - PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager(); - Assert.assertTrue(platformTransactionManager instanceof ResourcelessTransactionManager); - Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)), platformTransactionManager); - } - - @Test - public void testConfigurationWithNoDataSourceAndTransactionManager() throws Exception { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndTransactionManager.class); - BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class); - - PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager(); - Assert.assertSame(transactionManager, platformTransactionManager); - Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)), transactionManager); + @Test(expected = UnsatisfiedDependencyException.class) + public void testConfigurationWithNoDataSourceAndNoTransactionManager() { + new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndNoTransactionManager.class); } @Test @@ -79,29 +65,6 @@ public class TransactionManagerConfigurationWithBatchConfigurerTests extends Tra @EnableBatchProcessing public static class BatchConfigurationWithNoDataSourceAndNoTransactionManager { - @Bean - public BatchConfigurer batchConfigurer() { - return new DefaultBatchConfigurer(); - } - } - - @EnableBatchProcessing - public static class BatchConfigurationWithNoDataSourceAndTransactionManager { - - @Bean - public PlatformTransactionManager transactionManager() { - return transactionManager; - } - - @Bean - public BatchConfigurer batchConfigurer() { - return new DefaultBatchConfigurer() { - @Override - public PlatformTransactionManager getTransactionManager() { - return transactionManager(); - } - }; - } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java index a2fb3860b..c2a3eb1d9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/annotation/TransactionManagerConfigurationWithoutBatchConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.junit.Test; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -36,24 +37,14 @@ import org.springframework.transaction.PlatformTransactionManager; */ public class TransactionManagerConfigurationWithoutBatchConfigurerTests extends TransactionManagerConfigurationTests { - @Test - public void testConfigurationWithNoDataSourceAndNoTransactionManager() throws Exception { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndNoTransactionManager.class); - Assert.assertTrue(applicationContext.containsBean("transactionManager")); - PlatformTransactionManager platformTransactionManager = applicationContext.getBean(PlatformTransactionManager.class); - Object targetObject = AopTestUtils.getTargetObject(platformTransactionManager); - Assert.assertTrue(targetObject instanceof ResourcelessTransactionManager); - Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)), targetObject); + @Test(expected = UnsatisfiedDependencyException.class) + public void testConfigurationWithNoDataSourceAndNoTransactionManager() { + new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndNoTransactionManager.class); } - @Test - public void testConfigurationWithNoDataSourceAndTransactionManager() throws Exception { - ApplicationContext applicationContext = new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndTransactionManager.class); - PlatformTransactionManager platformTransactionManager = applicationContext.getBean(PlatformTransactionManager.class); - Assert.assertSame(transactionManager, platformTransactionManager); - // In this case, the supplied transaction manager won't be used by batch and a ResourcelessTransactionManager will be used instead. - // The user has to provide a custom BatchConfigurer. - Assert.assertTrue(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)) instanceof ResourcelessTransactionManager); + @Test(expected = UnsatisfiedDependencyException.class) + public void testConfigurationWithNoDataSourceAndTransactionManager() { + new AnnotationConfigApplicationContext(BatchConfigurationWithNoDataSourceAndTransactionManager.class); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java index ac600c499..0869f4a96 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/AbstractJobParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,13 +27,13 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import static org.junit.Assert.fail; /** * @author Dan Garrette + * @author Mahmoud Ben Hassine * @since 2.0 */ public abstract class AbstractJobParserTests { @@ -44,15 +44,11 @@ public abstract class AbstractJobParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - @Autowired protected ArrayList stepNamesList = new ArrayList<>(); @Before public void setUp() { - mapJobRepositoryFactoryBean.clear(); stepNamesList.clear(); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java index ad3d8ec22..90711e18d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowJobParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -30,7 +29,6 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -39,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -64,14 +63,6 @@ public class FlowJobParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testFlowJob() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java index 9bc05c7e7..591b49626 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/FlowStepParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -32,7 +31,6 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.JobExecutionDecider; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.lang.Nullable; @@ -41,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -66,14 +65,6 @@ public class FlowStepParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testFlowStep() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java index 108e58c12..b650c4072 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/JobStepParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.List; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -30,7 +29,6 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -39,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -56,14 +55,6 @@ public class JobStepParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testFlowStep() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java index f92e0d3b3..31bbdc399 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/NamespacePrefixedJobParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.batch.core.configuration.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -26,7 +25,6 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -35,6 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -48,14 +47,6 @@ public class NamespacePrefixedJobParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testNoopJob() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java index bba6bdfed..df171f6ac 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,6 @@ import org.springframework.batch.core.partition.support.PartitionStep; import org.springframework.batch.core.partition.support.StepExecutionAggregator; import org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; @@ -86,9 +85,6 @@ public class PartitionStepParserTests implements ApplicationContextAware { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - private ApplicationContext applicationContext; private List savedStepNames = new ArrayList<>(); @@ -101,7 +97,6 @@ public class PartitionStepParserTests implements ApplicationContextAware { @Before public void setUp() { nameStoringTasklet.setStepNamesList(savedStepNames); - mapJobRepositoryFactoryBean.clear(); } @SuppressWarnings("unchecked") diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java index 33aa60235..c9b3ff1cf 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithFlowParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.JobExecutionDecider; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.lang.Nullable; @@ -43,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer * @author Josh Long + * @author Mahmoud Ben Hassine */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -59,15 +59,11 @@ public class PartitionStepWithFlowParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - private List savedStepNames = new ArrayList<>(); @Before public void setUp() { nameStoringTasklet.setStepNamesList(savedStepNames); - mapJobRepositoryFactoryBean.clear(); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java index efdd79419..659cfb402 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithLateBindingParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -40,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer * @author Josh Long + * @author Mahmoud Ben Hassine */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -56,15 +56,11 @@ public class PartitionStepWithLateBindingParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - private List savedStepNames = new ArrayList<>(); @Before public void setUp() { nameStoringTasklet.setStepNamesList(savedStepNames); - mapJobRepositoryFactoryBean.clear(); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java index 37c5b4355..f5484d26b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.batch.core.configuration.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -26,7 +25,6 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -34,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -46,14 +45,6 @@ public class PartitionStepWithNonDefaultTransactionManagerParserTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testDefaultHandlerStep() throws Exception { assertNotNull(job); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java index c3db493b8..f1b7d770f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepParserTests.java @@ -55,6 +55,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.dao.DeadlockLoserDataAccessException; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.retry.RetryListener; import org.springframework.retry.listener.RetryListenerSupport; import org.springframework.test.util.ReflectionTestUtils; @@ -65,6 +66,7 @@ import org.springframework.transaction.interceptor.DefaultTransactionAttribute; /** * @author Thomas Risberg * @author Dan Garrette + * @author Mahmoud Ben Hassine */ public class StepParserTests { @@ -297,7 +299,7 @@ public class StepParserTests { public void testTransactionManagerDefaults() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; - assertTrue(getTransactionManager("defaultTxMgrStep", ctx) instanceof ResourcelessTransactionManager); + assertTrue(getTransactionManager("defaultTxMgrStep", ctx) instanceof DataSourceTransactionManager); assertDummyTransactionManager("specifiedTxMgrStep", "dummyTxMgr", ctx); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests.java index 890bdcd2f..d5791af48 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @@ -35,6 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -52,14 +52,6 @@ public class TaskletParserAdapterTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testTaskletRef() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests.java index 5cce10ac8..63f1b5d3e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.batch.core.configuration.xml; import java.lang.reflect.Field; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; @@ -27,7 +26,6 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.job.flow.FlowJob; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.batch.core.test.namespace.config.DummyNamespaceHandler; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +40,7 @@ import static org.junit.Assert.*; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ @ContextConfiguration @@ -72,14 +71,6 @@ public class TaskletParserBeanPropertiesTests { @Autowired private JobRepository jobRepository; - @Autowired - private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean; - - @Before - public void setUp() { - mapJobRepositoryFactoryBean.clear(); - } - @Test public void testTaskletRef() throws Exception { assertNotNull(job1); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBeanTests.java deleted file mode 100644 index 9ceb07593..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerFactoryBeanTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.explore.support; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; - -import java.util.Date; - -/** - * Tests for {@link MapJobExplorerFactoryBean}. - */ -public class MapJobExplorerFactoryBeanTests { - - /** - * Use the factory to create repository and check the explorer remembers - * created executions. - */ - @Test - public void testCreateExplorer() throws Exception { - - MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean(); - JobRepository jobRepository = repositoryFactory.getObject(); - JobExecution jobExecution = jobRepository.createJobExecution("foo", new JobParameters()); - - //simulating a running job execution - jobExecution.setStartTime(new Date()); - jobRepository.update(jobExecution); - - MapJobExplorerFactoryBean tested = new MapJobExplorerFactoryBean(repositoryFactory); - tested.afterPropertiesSet(); - - JobExplorer explorer = tested.getObject(); - - assertEquals(1, explorer.findRunningJobExecutions("foo").size()); - - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerIntegrationTests.java deleted file mode 100644 index 3fcc0ddef..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/MapJobExplorerIntegrationTests.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2006-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.explore.support; - -import org.junit.Test; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.StepContribution; -import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.job.SimpleJob; -import org.springframework.batch.core.launch.support.SimpleJobLauncher; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.core.step.tasklet.TaskletStep; -import org.springframework.batch.repeat.RepeatStatus; -import org.springframework.core.task.SimpleAsyncTaskExecutor; -import org.springframework.lang.Nullable; - -import java.util.Set; - -import static org.junit.Assert.assertEquals; - -/** - * @author Dave Syer - * - */ -public class MapJobExplorerIntegrationTests { - - private boolean block = true; - - @Test - public void testRunningJobExecution() throws Exception { - - SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); - MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean(); - repositoryFactory.afterPropertiesSet(); - JobRepository jobRepository = repositoryFactory.getObject(); - jobLauncher.setJobRepository(jobRepository); - jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor()); - jobLauncher.afterPropertiesSet(); - - SimpleJob job = new SimpleJob("job"); - TaskletStep step = new TaskletStep("step"); - step.setTasklet(new Tasklet() { - @Nullable - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - while (block) { - Thread.sleep(100L); - } - return RepeatStatus.FINISHED; - } - }); - step.setTransactionManager(repositoryFactory.getTransactionManager()); - step.setJobRepository(jobRepository); - step.afterPropertiesSet(); - job.addStep(step); - job.setJobRepository(jobRepository); - job.afterPropertiesSet(); - - jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters()); - - Thread.sleep(500L); - JobExplorer explorer = new MapJobExplorerFactoryBean(repositoryFactory).getObject(); - Set executions = explorer.findRunningJobExecutions("job"); - assertEquals(1, executions.size()); - assertEquals(1, executions.iterator().next().getStepExecutions().size()); - - block = false; - - } -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java index 574f0e3c4..c477ecdf6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/ExtendedAbstractJobTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,11 @@ import org.springframework.batch.core.JobParametersInvalidException; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import java.util.Collection; @@ -52,7 +55,14 @@ public class ExtendedAbstractJobTests { @Before public void setUp() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); jobRepository = factory.getObject(); job = new StubJob("job", jobRepository); } @@ -166,13 +176,10 @@ public class ExtendedAbstractJobTests { } } - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); - factory.afterPropertiesSet(); - JobRepository repository = factory.getObject(); - job.setJobRepository(repository); + job.setJobRepository(this.jobRepository); job.setRestartable(true); - JobExecution execution = repository.createJobExecution("testHandleStepJob", new JobParameters()); + JobExecution execution = this.jobRepository.createJobExecution("testHandleStepJob", new JobParameters()); job.handleStep(new StubStep(), execution); assertEquals(StubStep.value, execution.getExecutionContext().get(StubStep.key)); @@ -180,9 +187,9 @@ public class ExtendedAbstractJobTests { // simulate restart and check the job execution context's content survives execution.setEndTime(new Date()); execution.setStatus(BatchStatus.FAILED); - repository.update(execution); + this.jobRepository.update(execution); - JobExecution restarted = repository.createJobExecution("testHandleStepJob", new JobParameters()); + JobExecution restarted = this.jobRepository.createJobExecution("testHandleStepJob", new JobParameters()); assertEquals(StubStep.value, restarted.getExecutionContext().get(StubStep.key)); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobFailureTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobFailureTests.java index 2a1043aa9..600fb75bc 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobFailureTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobFailureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,14 +29,18 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; /** * Test suite for various failure scenarios during job processing. * * @author Lucas Ward * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class SimpleJobFailureTests { @@ -47,7 +51,15 @@ public class SimpleJobFailureTests { @Before public void init() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + JobRepository jobRepository = factory.getObject(); job.setJobRepository(jobRepository); execution = jobRepository.createJobExecution("job", new JobParameters()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index f8ecb0c44..b4961f81a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,23 +45,32 @@ import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; +import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.explore.support.JobExplorerFactoryBean; import org.springframework.batch.core.listener.JobExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.dao.ExecutionContextDao; +import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; +import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao; +import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao; +import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao; +import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao; import org.springframework.batch.core.repository.dao.JobExecutionDao; import org.springframework.batch.core.repository.dao.JobInstanceDao; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; import org.springframework.batch.core.repository.dao.StepExecutionDao; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.item.ExecutionContext; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer; /** - * Tests for DefaultJobLifecycle. MapJobDao and MapStepExecutionDao are used - * instead of a mock repository to test that status is being stored correctly. + * Tests for DefaultJobLifecycle. * * @author Lucas Ward * @author Will Schipp @@ -71,13 +80,7 @@ public class SimpleJobTests { private JobRepository jobRepository; - private JobInstanceDao jobInstanceDao; - - private JobExecutionDao jobExecutionDao; - - private StepExecutionDao stepExecutionDao; - - private ExecutionContextDao ecDao; + private JobExplorer jobExplorer; private List list = new ArrayList<>(); @@ -100,11 +103,21 @@ public class SimpleJobTests { @Before public void setUp() throws Exception { - jobInstanceDao = new MapJobInstanceDao(); - jobExecutionDao = new MapJobExecutionDao(); - stepExecutionDao = new MapStepExecutionDao(); - ecDao = new MapExecutionContextDao(); - jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, ecDao); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + this.jobRepository = repositoryFactoryBean.getObject(); + JobExplorerFactoryBean explorerFactoryBean = new JobExplorerFactoryBean(); + explorerFactoryBean.setDataSource(embeddedDatabase); + explorerFactoryBean.afterPropertiesSet(); + this.jobExplorer = explorerFactoryBean.getObject(); job = new SimpleJob(); job.setJobRepository(jobRepository); @@ -528,9 +541,8 @@ public class SimpleJobTests { * Check JobRepository to ensure status is being saved. */ private void checkRepository(BatchStatus status, ExitStatus exitStatus) { - assertEquals(jobInstance, jobInstanceDao.getJobInstance(job.getName(), jobParameters)); - // because map DAO stores in memory, it can be checked directly - JobExecution jobExecution = jobExecutionDao.findJobExecutions(jobInstance).get(0); + assertEquals(jobInstance, this.jobRepository.getLastJobExecution(job.getName(), jobParameters).getJobInstance()); + JobExecution jobExecution = this.jobExplorer.getJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), jobExecution.getJobId()); assertEquals(status, jobExecution.getStatus()); if (exitStatus != null) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleStepHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleStepHandlerTests.java index ee5ec3e3e..634b8b61a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleStepHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleStepHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,15 @@ import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class SimpleStepHandlerTests { @@ -44,8 +48,15 @@ public class SimpleStepHandlerTests { @Before public void setUp() throws Exception { - MapJobRepositoryFactoryBean jobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(); - jobRepository = jobRepositoryFactoryBean.getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + jobRepository = factory.getObject(); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); stepHandler = new SimpleStepHandler(jobRepository); stepHandler.afterPropertiesSet(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowBuilderTests.java index 1fc4cd4fa..2c90af41b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import org.springframework.batch.core.job.flow.Flow; import org.springframework.batch.core.job.flow.FlowExecution; import org.springframework.batch.core.job.flow.JobFlowExecutor; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.step.JobRepositorySupport; import org.springframework.batch.core.step.StepSupport; import static org.junit.Assert.assertEquals; @@ -38,6 +38,7 @@ import static org.junit.Assert.assertEquals; /** * @author Dave Syer * @author Michael Minella + * @author Mahmoud Ben Hassine * */ public class FlowBuilderTests { @@ -45,7 +46,7 @@ public class FlowBuilderTests { @Test public void test() throws Exception { FlowBuilder builder = new FlowBuilder<>("flow"); - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); + JobRepository jobRepository = new JobRepositorySupport(); JobExecution execution = jobRepository.createJobExecution("foo", new JobParameters()); builder.start(new StepSupport("step") { @Override @@ -58,7 +59,7 @@ public class FlowBuilderTests { @Test public void testTransitionOrdering() throws Exception { FlowBuilder builder = new FlowBuilder<>("transitionsFlow"); - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); + JobRepository jobRepository = new JobRepositorySupport(); JobExecution execution = jobRepository.createJobExecution("foo", new JobParameters()); StepSupport stepA = new StepSupport("stepA") { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java index 2aa469e85..12d67c6e6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/FlowJobBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ package org.springframework.batch.core.job.builder; import java.util.Arrays; +import javax.sql.DataSource; + import static org.junit.Assert.assertEquals; import org.junit.Before; @@ -40,7 +42,7 @@ import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.JobExecutionDecider; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.item.support.ListItemReader; import org.springframework.beans.factory.annotation.Value; @@ -49,6 +51,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; /** @@ -104,7 +109,15 @@ public class FlowJobBuilderTests { @Before public void init() throws Exception { - jobRepository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + jobRepository = factory.getObject(); execution = jobRepository.createJobExecution("flow", new JobParameters()); } @@ -293,6 +306,15 @@ public class FlowJobBuilderTests { .build() .build(); } + + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java index 9bbd3e8aa..a7873b9b9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/builder/JobBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.springframework.batch.core.job.builder; +import javax.sql.DataSource; + import org.junit.Assert; import org.junit.Test; @@ -34,6 +36,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import static org.junit.Assert.assertEquals; @@ -74,6 +77,15 @@ public class JobBuilderTests { .build()) .build(); } + + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } } static class InterfaceBasedJobExecutionListener implements JobExecutionListener { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobFailureTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobFailureTests.java index 9bd7e3108..193bf07ad 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobFailureTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobFailureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2014 the original author or authors. + * Copyright 2010-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,14 +34,18 @@ import org.springframework.batch.core.job.flow.support.StateTransition; import org.springframework.batch.core.job.flow.support.state.EndState; import org.springframework.batch.core.job.flow.support.state.StepState; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; /** * Test suite for various failure scenarios during job processing. * * @author Lucas Ward * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class FlowJobFailureTests { @@ -52,7 +56,15 @@ public class FlowJobFailureTests { @Before public void init() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + JobRepository jobRepository = factory.getObject(); job.setJobRepository(jobRepository); execution = jobRepository.createJobExecution("job", new JobParameters()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java index d253fc54a..466d7e130 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.core.explore.support.JobExplorerFactoryBean; import org.springframework.batch.core.job.flow.support.DefaultStateTransitionComparator; import org.springframework.batch.core.job.flow.support.SimpleFlow; import org.springframework.batch.core.job.flow.support.StateTransition; @@ -38,9 +40,11 @@ import org.springframework.batch.core.jsr.partition.JsrPartitionHandler; import org.springframework.batch.core.jsr.step.PartitionStep; import org.springframework.batch.core.jsr.partition.JsrStepExecutionSplitter; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.dao.JobExecutionDao; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import java.util.ArrayList; @@ -56,6 +60,7 @@ import static org.junit.Assert.fail; /** * @author Dave Syer * @author Michael Minella + * @author Mahmoud Ben Hassine * */ public class FlowJobTests { @@ -66,18 +71,28 @@ public class FlowJobTests { private JobRepository jobRepository; - private boolean fail = false; + private JobExplorer jobExplorer; - private JobExecutionDao jobExecutionDao; + private boolean fail = false; @Before public void setUp() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); factory.afterPropertiesSet(); - jobExecutionDao = factory.getJobExecutionDao(); - jobRepository = factory.getObject(); - job.setJobRepository(jobRepository); - jobExecution = jobRepository.createJobExecution("job", new JobParameters()); + this.jobRepository = factory.getObject(); + job.setJobRepository(this.jobRepository); + this.jobExecution = this.jobRepository.createJobExecution("job", new JobParameters()); + + JobExplorerFactoryBean explorerFactoryBean = new JobExplorerFactoryBean(); + explorerFactoryBean.setDataSource(embeddedDatabase); + explorerFactoryBean.afterPropertiesSet(); + this.jobExplorer = explorerFactoryBean.getObject(); } @Test @@ -743,9 +758,8 @@ public class FlowJobTests { } private void checkRepository(BatchStatus status, ExitStatus exitStatus) { - // because map dao stores in memory, it can be checked directly - JobInstance jobInstance = jobExecution.getJobInstance(); - JobExecution other = jobExecutionDao.findJobExecutions(jobInstance).get(0); + JobInstance jobInstance = this.jobExecution.getJobInstance(); + JobExecution other = this.jobExplorer.getJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), other.getJobId()); assertEquals(status, other.getStatus()); if (exitStatus != null) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowStepTests.java index b953df51e..fb933c3db 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowStepTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,15 @@ import org.springframework.batch.core.job.flow.support.StateTransition; import org.springframework.batch.core.job.flow.support.state.EndState; import org.springframework.batch.core.job.flow.support.state.StepState; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class FlowStepTests { @@ -49,7 +53,15 @@ public class FlowStepTests { @Before public void setUp() throws Exception { - jobRepository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean(); + jobRepositoryFactoryBean.setDataSource(embeddedDatabase); + jobRepositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + jobRepositoryFactoryBean.afterPropertiesSet(); + jobRepository = jobRepositoryFactoryBean.getObject(); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/JsrFlowJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/JsrFlowJobTests.java index 38f7b1aea..821c27d12 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/JsrFlowJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/job/flow/JsrFlowJobTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.explore.JobExplorer; -import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; +import org.springframework.batch.core.explore.support.JobExplorerFactoryBean; import org.springframework.batch.core.job.flow.Flow; import org.springframework.batch.core.job.flow.FlowExecutionStatus; import org.springframework.batch.core.job.flow.FlowExecutor; @@ -43,9 +43,11 @@ import org.springframework.batch.core.job.flow.support.state.StepState; import org.springframework.batch.core.jsr.JsrStepExecution; import org.springframework.batch.core.jsr.job.flow.support.JsrFlow; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.dao.JobExecutionDao; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import javax.batch.api.Decider; @@ -62,6 +64,7 @@ import static org.junit.Assert.fail; /** * @author Dave Syer * @author Michael Minella + * @author Mahmoud Ben Hassine */ public class JsrFlowJobTests { @@ -75,19 +78,23 @@ public class JsrFlowJobTests { private boolean fail = false; - private JobExecutionDao jobExecutionDao; - @Before public void setUp() throws Exception { job = new JsrFlowJob(); - MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(); - jobRepositoryFactory.afterPropertiesSet(); - jobExecutionDao = jobRepositoryFactory.getJobExecutionDao(); - jobRepository = jobRepositoryFactory.getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + jobRepository = factory.getObject(); job.setJobRepository(jobRepository); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); - MapJobExplorerFactoryBean jobExplorerFactory = new MapJobExplorerFactoryBean(jobRepositoryFactory); + JobExplorerFactoryBean jobExplorerFactory = new JobExplorerFactoryBean(); + jobExplorerFactory.setDataSource(embeddedDatabase); jobExplorerFactory.afterPropertiesSet(); jobExplorer = jobExplorerFactory.getObject(); job.setJobExplorer(jobExplorer); @@ -751,9 +758,8 @@ public class JsrFlowJobTests { } private void checkRepository(BatchStatus status, ExitStatus exitStatus) { - // because map DAO stores in memory, it can be checked directly JobInstance jobInstance = jobExecution.getJobInstance(); - JobExecution other = jobExecutionDao.findJobExecutions(jobInstance).get(0); + JobExecution other = jobExplorer.getJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), other.getJobId()); assertEquals(status, other.getStatus()); if (exitStatus != null) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java index ad6037396..dcc553abb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/partition/JsrPartitionHandlerTests.java @@ -27,9 +27,12 @@ import org.springframework.batch.core.jsr.AbstractJsrTestCase; import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext; import org.springframework.batch.core.jsr.step.batchlet.BatchletSupport; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.JobRepositorySupport; import org.springframework.batch.core.step.StepSupport; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.util.StopWatch; import javax.batch.api.BatchProperty; @@ -56,7 +59,7 @@ import static org.junit.Assert.fail; public class JsrPartitionHandlerTests extends AbstractJsrTestCase { private JsrPartitionHandler handler; - private JobRepository repository = new JobRepositorySupport(); + private JobRepository repository; private StepExecution stepExecution; private AtomicInteger count; private BatchPropertyContext propertyContext; @@ -82,7 +85,15 @@ public class JsrPartitionHandlerTests extends AbstractJsrTestCase { }); propertyContext = new BatchPropertyContext(); handler.setPropertyContext(propertyContext); - repository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + repository = factory.getObject(); handler.setJobRepository(repository); MyPartitionReducer.reset(); CountingPartitionCollector.reset(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrChunkProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrChunkProcessorTests.java index 72214df7b..194f16423 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrChunkProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrChunkProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,12 +37,15 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; public class JsrChunkProcessorTests { @@ -71,7 +74,15 @@ public class JsrChunkProcessorTests { builder = new JsrSimpleStepBuilder<>(new StepBuilder("step1")); builder.setBatchPropertyContext(new BatchPropertyContext()); - repository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + repository = factory.getObject(); builder.repository(repository); builder.transactionManager(new ResourcelessTransactionManager()); stepExecution = null; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrFaultTolerantChunkProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrFaultTolerantChunkProcessorTests.java index 95c530af0..375678c6e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrFaultTolerantChunkProcessorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/item/JsrFaultTolerantChunkProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2019 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,12 +39,15 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; public class JsrFaultTolerantChunkProcessorTests { @@ -73,7 +76,15 @@ public class JsrFaultTolerantChunkProcessorTests { builder = new JsrFaultTolerantStepBuilder<>(new StepBuilder("step1")); builder.setBatchPropertyContext(new BatchPropertyContext()); - repository = new MapJobRepositoryFactoryBean().getObject(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); + repository = factory.getObject(); builder.repository(repository); builder.transactionManager(new ResourcelessTransactionManager()); stepExecution = null; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java index 42b6fcadb..9193efcae 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ItemListenerErrorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2015-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals; import java.util.Collections; import java.util.List; +import javax.sql.DataSource; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,6 +45,7 @@ import org.springframework.batch.item.support.ListItemReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -151,6 +154,15 @@ public class ItemListenerErrorTests { .build(); } + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } + @Bean public FailingListener itemListener() { return new FailingListener(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java index 2c6883e07..116bc024b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,12 +32,16 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.partition.PartitionHandler; import org.springframework.batch.core.partition.StepExecutionSplitter; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import static org.junit.Assert.assertEquals; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class PartitionStepTests { @@ -48,7 +52,14 @@ public class PartitionStepTests { @Before public void setUp() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); jobRepository = factory.getObject(); step.setJobRepository(jobRepository); step.setName("partitioned"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/RemoteStepExecutionAggregatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/RemoteStepExecutionAggregatorTests.java index 653b655d8..447007a84 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/RemoteStepExecutionAggregatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/RemoteStepExecutionAggregatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,12 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean; +import org.springframework.batch.core.explore.support.JobExplorerFactoryBean; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import java.util.Arrays; import java.util.Collections; @@ -45,9 +48,19 @@ public class RemoteStepExecutionAggregatorTests { @Before public void init() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); JobRepository jobRepository = factory.getObject(); - aggregator.setJobExplorer(new MapJobExplorerFactoryBean(factory).getObject()); + JobExplorerFactoryBean explorerFactoryBean = new JobExplorerFactoryBean(); + explorerFactoryBean.setDataSource(embeddedDatabase); + explorerFactoryBean.afterPropertiesSet(); + aggregator.setJobExplorer(explorerFactoryBean.getObject()); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); result = jobExecution.createStepExecution("aggregate"); stepExecution1 = jobExecution.createStepExecution("foo:1"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java index a39d7e699..e03b162e4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,12 @@ import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.step.tasklet.TaskletStep; import org.springframework.batch.item.ExecutionContext; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -52,7 +55,14 @@ public class SimpleStepExecutionSplitterTests { @Before public void setUp() throws Exception { step = new TaskletStep("step"); - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); jobRepository = factory.getObject(); stepExecution = jobRepository.createJobExecution("job", new JobParameters()).createStepExecution("bar"); jobRepository.add(stepExecution); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java deleted file mode 100644 index effdd0b2e..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapExecutionContextDaoTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008-2012 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.dao; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.junit.runners.JUnit4; -import org.junit.runner.RunWith; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.ExecutionContext; - -/** - * Tests for {@link MapExecutionContextDao}. - */ -@RunWith(JUnit4.class) -public class MapExecutionContextDaoTests extends AbstractExecutionContextDaoTests { - - @Override - protected JobInstanceDao getJobInstanceDao() { - return new MapJobInstanceDao(); - } - - @Override - protected JobExecutionDao getJobExecutionDao() { - return new MapJobExecutionDao(); - } - - @Override - protected StepExecutionDao getStepExecutionDao() { - return new MapStepExecutionDao(); - } - - @Override - protected ExecutionContextDao getExecutionContextDao() { - return new MapExecutionContextDao(); - } - - @Test - public void testSaveBothJobAndStepContextWithSameId() throws Exception { - MapExecutionContextDao tested = new MapExecutionContextDao(); - JobExecution jobExecution = new JobExecution(1L); - StepExecution stepExecution = new StepExecution("stepName", jobExecution, 1L); - - assertTrue(stepExecution.getId() == jobExecution.getId()); - - jobExecution.getExecutionContext().put("type", "job"); - stepExecution.getExecutionContext().put("type", "step"); - assertTrue(!jobExecution.getExecutionContext().get("type").equals(stepExecution.getExecutionContext().get("type"))); - assertEquals("job", jobExecution.getExecutionContext().get("type")); - assertEquals("step", stepExecution.getExecutionContext().get("type")); - - tested.saveExecutionContext(jobExecution); - tested.saveExecutionContext(stepExecution); - - ExecutionContext jobCtx = tested.getExecutionContext(jobExecution); - ExecutionContext stepCtx = tested.getExecutionContext(stepExecution); - - assertEquals("job", jobCtx.get("type")); - assertEquals("step", stepCtx.get("type")); - } - - @Test - public void testPersistentCopy() throws Exception { - MapExecutionContextDao tested = new MapExecutionContextDao(); - JobExecution jobExecution = new JobExecution((long)1); - StepExecution stepExecution = new StepExecution("stepName", jobExecution, 123L); - assertTrue(stepExecution.getExecutionContext().isEmpty()); - - tested.updateExecutionContext(stepExecution); - stepExecution.getExecutionContext().put("key","value"); - - ExecutionContext retrieved = tested.getExecutionContext(stepExecution); - assertTrue(retrieved.isEmpty()); - - tested.updateExecutionContext(jobExecution); - jobExecution.getExecutionContext().put("key", "value"); - retrieved = tested.getExecutionContext(jobExecution); - assertTrue(retrieved.isEmpty()); - } - -} - diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java deleted file mode 100644 index 27abba477..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobExecutionDaoTests.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.dao; - -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import java.util.Collections; -import java.util.Date; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameters; - -@RunWith(JUnit4.class) -public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests { - - @Override - protected JobExecutionDao getJobExecutionDao() { - return new MapJobExecutionDao(); - } - - @Override - protected JobInstanceDao getJobInstanceDao() { - return new MapJobInstanceDao(); - } - - /** - * Modifications to saved entity do not affect the persisted object. - */ - @Test - public void testPersistentCopy() { - JobExecutionDao tested = new MapJobExecutionDao(); - JobExecution jobExecution = new JobExecution(new JobInstance((long) 1, "mapJob"), new JobParameters()); - - assertNull(jobExecution.getStartTime()); - tested.saveJobExecution(jobExecution); - jobExecution.setStartTime(new Date()); - - JobExecution retrieved = tested.getJobExecution(jobExecution.getId()); - assertNull(retrieved.getStartTime()); - - tested.updateJobExecution(jobExecution); - jobExecution.setEndTime(new Date()); - assertNull(retrieved.getEndTime()); - - } - - /** - * Verify that the ids are properly generated even under heavy concurrent load - */ - @Test - public void testConcurrentSaveJobExecution() throws Exception { - final int iterations = 100; - - // Object under test - final JobExecutionDao tested = new MapJobExecutionDao(); - - // Support objects for this testing - final CountDownLatch latch = new CountDownLatch(1); - final SortedSet ids = Collections.synchronizedSortedSet(new TreeSet<>()); // TODO Change to SkipList w/JDK6 - final AtomicReference exception = new AtomicReference<>(null); - - // Implementation of the high-concurrency code - final Runnable codeUnderTest = new Runnable() { - @Override - public void run() { - try { - JobExecution jobExecution = new JobExecution(new JobInstance((long) -1, "mapJob"), new JobParameters()); - latch.await(); - tested.saveJobExecution(jobExecution); - ids.add(jobExecution.getId()); - } catch(Exception e) { - exception.set(e); - } - } - }; - - // Create the threads - final Thread[] threads = new Thread[iterations]; - for(int i = 0; i < iterations; i++) { - Thread t = new Thread(codeUnderTest, "Map Job Thread #" + (i+1)); - t.setPriority(Thread.MAX_PRIORITY); - t.setDaemon(true); - t.start(); - Thread.yield(); - threads[i] = t; - } - - // Let the high concurrency abuse begin! - do { latch.countDown(); } while(latch.getCount() > 0); - for(Thread t : threads) { t.join(); } - - // Ensure no general exceptions arose - if(exception.get() != null) { - throw new RuntimeException("Exception occurred under high concurrency usage", exception.get()); - } - - // Validate the ids: we'd expect one of these three things to fail - if(ids.size() < iterations) { - fail("Duplicate id generated during high concurrency usage"); - } - if(ids.first() < 0) { - fail("Generated an id less than zero during high concurrency usage: " + ids.first()); - } - if(ids.last() > iterations) { - fail("Generated an id larger than expected during high concurrency usage: " + ids.last()); - } - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java deleted file mode 100644 index 668769e08..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapJobInstanceDaoTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2008-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.dao; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.springframework.batch.core.JobInstance; -import org.springframework.batch.core.JobParameters; - -import java.util.List; - -import static org.junit.Assert.assertTrue; - -@RunWith(JUnit4.class) -public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests { - - @Override - protected JobInstanceDao getJobInstanceDao() { - return new MapJobInstanceDao(); - } - - @Test - public void testWildcardPrefix() { - MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao(); - mapJobInstanceDao.createJobInstance("testJob", new JobParameters()); - mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters()); - List jobInstances = mapJobInstanceDao.findJobInstancesByName("*Job", 0, 2); - assertTrue("Invalid matching job instances found, expected 1, got: " + jobInstances.size(), jobInstances.size() == 1); - } - - @Test - public void testWildcardSuffix() { - MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao(); - mapJobInstanceDao.createJobInstance("testJob", new JobParameters()); - mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters()); - List jobInstances = mapJobInstanceDao.findJobInstancesByName("Job*", 0, 2); - assertTrue("No matching job instances found, expected 1, got: " + jobInstances.size(), jobInstances.size() == 1); - } - - @Test - public void testWildcardRange() { - MapJobInstanceDao mapJobInstanceDao = new MapJobInstanceDao(); - mapJobInstanceDao.createJobInstance("testJob", new JobParameters()); - mapJobInstanceDao.createJobInstance("Jobtest", new JobParameters()); - List jobInstances = mapJobInstanceDao.findJobInstancesByName("*Job*", 0, 2); - assertTrue("No matching job instances found, expected 2, got: " + jobInstances.size(), jobInstances.size() == 2); - } -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java deleted file mode 100644 index 7511cd295..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/MapStepExecutionDaoTests.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2008-2020 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.dao; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.Date; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.SimpleJobRepository; - -@RunWith(JUnit4.class) -public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests { - - @Override - protected StepExecutionDao getStepExecutionDao() { - return new MapStepExecutionDao(); - } - - @Override - protected JobRepository getJobRepository() { - return new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), new MapStepExecutionDao(), - new MapExecutionContextDao()); - } - - /** - * Modifications to saved entity do not affect the persisted object. - */ - @Test - public void testPersistentCopy() { - StepExecutionDao tested = new MapStepExecutionDao(); - JobExecution jobExecution = new JobExecution(77L); - StepExecution stepExecution = new StepExecution("stepName", jobExecution); - - assertNull(stepExecution.getEndTime()); - tested.saveStepExecution(stepExecution); - stepExecution.setEndTime(new Date()); - - StepExecution retrieved = tested.getStepExecution(jobExecution, stepExecution.getId()); - assertNull(retrieved.getEndTime()); - - stepExecution.setEndTime(null); - tested.updateStepExecution(stepExecution); - stepExecution.setEndTime(new Date()); - - StepExecution stored = tested.getStepExecution(jobExecution, stepExecution.getId()); - assertNull(stored.getEndTime()); - } - - @Test - public void testAddStepExecutions() { - StepExecutionDao tested = new MapStepExecutionDao(); - - JobExecution jobExecution = new JobExecution(88L); - - // Create step execution with status STARTED - StepExecution stepExecution = new StepExecution("Step one", jobExecution); - stepExecution.setStatus(BatchStatus.STARTED); - - // Save and check id - tested.saveStepExecution(stepExecution); - assertNotNull(stepExecution.getId()); - - // Job execution instance doesn't contain step execution instances - assertEquals(0, jobExecution.getStepExecutions().size()); - - // Load all execution steps and check - tested.addStepExecutions(jobExecution); - assertEquals(1, jobExecution.getStepExecutions().size()); - - // Check the first (and only) step execution instance of the job instance - StepExecution jobStepExecution = jobExecution.getStepExecutions().iterator().next(); - assertEquals(BatchStatus.STARTED, jobStepExecution.getStatus()); - assertEquals(stepExecution.getId(), jobStepExecution.getId()); - - // Load the step execution instance from the repository and check is it the same - StepExecution repoStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId()); - assertEquals(stepExecution.getId(), repoStepExecution.getId()); - assertEquals(BatchStatus.STARTED, repoStepExecution.getStatus()); - - // Update the step execution instance - repoStepExecution.setStatus(BatchStatus.COMPLETED); - - // Update the step execution in the repository and check - tested.updateStepExecution(repoStepExecution); - StepExecution updatedStepExecution = tested.getStepExecution(jobExecution, stepExecution.getId()); - assertEquals(stepExecution.getId(), updatedStepExecution.getId()); - assertEquals(BatchStatus.COMPLETED, updatedStepExecution.getStatus()); - - // Now, add step executions from the repository and check - tested.addStepExecutions(jobExecution); - - jobStepExecution = jobExecution.getStepExecutions().iterator().next(); - assertEquals(1, jobExecution.getStepExecutions().size()); - assertEquals(stepExecution.getId(), jobStepExecution.getId()); - assertEquals(BatchStatus.COMPLETED, jobStepExecution.getStatus()); - } - - @Test - public void testCountStepExecutions() { - // Given - StepExecutionDao tested = new MapStepExecutionDao(); - JobExecution jobExecution = new JobExecution(jobInstance, 88L, null, null); - - StepExecution firstStepExecution = new StepExecution("Step one", jobExecution); - firstStepExecution.setStatus(BatchStatus.STARTED); - - tested.saveStepExecution(firstStepExecution); - - StepExecution secondStepExecution = new StepExecution("Step two", jobExecution); - secondStepExecution.setStatus(BatchStatus.STARTED); - - tested.saveStepExecution(secondStepExecution); - - // When - int result = tested.countStepExecutions(jobInstance, firstStepExecution.getStepName()); - - // Then - assertEquals(1, result); - } -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MapJobRepositoryFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MapJobRepositoryFactoryBeanTests.java deleted file mode 100644 index 6eff4b12a..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MapJobRepositoryFactoryBeanTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2008-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.repository.support; - -import org.junit.Test; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.job.JobSupport; -import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; -import org.springframework.batch.core.repository.JobRepository; - -import java.util.Date; - -import static org.junit.Assert.fail; - -/** - * Tests for {@link MapJobRepositoryFactoryBean}. - */ -public class MapJobRepositoryFactoryBeanTests { - - private MapJobRepositoryFactoryBean tested = new MapJobRepositoryFactoryBean(); - - /** - * Use the factory to create repository and check the repository remembers - * created executions. - */ - @Test - public void testCreateRepository() throws Exception { - tested.afterPropertiesSet(); - JobRepository repository = tested.getObject(); - Job job = new JobSupport("jobName"); - JobParameters jobParameters = new JobParameters(); - - JobExecution jobExecution = repository.createJobExecution(job.getName(), jobParameters); - - // simulate a running execution - jobExecution.setStartTime(new Date()); - repository.update(jobExecution); - - try { - repository.createJobExecution(job.getName(), jobParameters); - fail("Expected JobExecutionAlreadyRunningException"); - } - catch (JobExecutionAlreadyRunningException e) { - // expected - } - } -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java index 5a171ccf0..8ad0e6c91 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.List; import java.util.function.Function; +import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; @@ -41,12 +42,15 @@ import org.springframework.batch.core.configuration.xml.DummyItemReader; import org.springframework.batch.core.configuration.xml.DummyItemWriter; import org.springframework.batch.core.job.SimpleJob; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.item.support.ListItemWriter; import org.springframework.batch.item.support.PassThroughItemProcessor; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; @@ -61,9 +65,24 @@ import static org.junit.Assert.assertEquals; */ public class StepBuilderTests { + private JobRepository jobRepository; + + @Before + public void setUp() throws Exception { + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(transactionManager); + factory.afterPropertiesSet(); + this.jobRepository = factory.getObject(); + } + @Test public void test() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution( "step"); jobRepository.add(execution); @@ -76,7 +95,6 @@ public class StepBuilderTests { @Test public void testListeners() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -98,7 +116,6 @@ public class StepBuilderTests { @Test public void testAnnotationBasedChunkListenerForTaskletStep() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -115,7 +132,6 @@ public class StepBuilderTests { @Test public void testAnnotationBasedChunkListenerForSimpleTaskletStep() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -134,7 +150,6 @@ public class StepBuilderTests { @Test public void testAnnotationBasedChunkListenerForFaultTolerantTaskletStep() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -154,7 +169,6 @@ public class StepBuilderTests { @Test public void testAnnotationBasedChunkListenerForJobStepBuilder() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -175,7 +189,6 @@ public class StepBuilderTests { @Test public void testItemListeners() throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -218,7 +231,6 @@ public class StepBuilderTests { } private void assertStepFunctions(boolean faultTolerantStep) throws Exception { - JobRepository jobRepository = new MapJobRepositoryFactoryBean().getObject(); StepExecution execution = jobRepository.createJobExecution("foo", new JobParameters()).createStepExecution("step"); jobRepository.add(execution); PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java index 7c20b5e0c..8a2a4bdd9 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRetryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,10 +37,13 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.listener.SkipListenerSupport; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; +import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao; +import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao; +import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao; +import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean; @@ -53,9 +56,16 @@ import org.springframework.batch.item.support.AbstractItemCountingItemStreamItem import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer; import org.springframework.lang.Nullable; import org.springframework.retry.policy.MapRetryContextCache; import org.springframework.retry.policy.SimpleRetryPolicy; +import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.StringUtils; @@ -64,6 +74,7 @@ import static org.junit.Assert.assertTrue; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class FaultTolerantStepFactoryBeanRetryTests { @@ -85,9 +96,7 @@ public class FaultTolerantStepFactoryBeanRetryTests { boolean fail = false; - private SimpleJobRepository repository = new SimpleJobRepository( - new MapJobInstanceDao(), new MapJobExecutionDao(), - new MapStepExecutionDao(), new MapExecutionContextDao()); + private JobRepository repository; JobExecution jobExecution; @@ -102,6 +111,18 @@ public class FaultTolerantStepFactoryBeanRetryTests { @Before public void setUp() throws Exception { + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + repository = repositoryFactoryBean.getObject(); + factory = new FaultTolerantStepFactoryBean<>(); factory.setBeanName("step"); @@ -109,7 +130,7 @@ public class FaultTolerantStepFactoryBeanRetryTests { new ArrayList<>())); factory.setItemWriter(writer); factory.setJobRepository(repository); - factory.setTransactionManager(new ResourcelessTransactionManager()); + factory.setTransactionManager(transactionManager); factory.setRetryableExceptionClasses(getExceptionMap(Exception.class)); factory.setCommitInterval(1); // trivial by default diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRollbackTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRollbackTests.java index d94d420f7..b9501bc3e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRollbackTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanRollbackTests.java @@ -37,7 +37,7 @@ import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.FatalStepExecutionException; import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean; @@ -46,6 +46,9 @@ import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.transaction.interceptor.RollbackRuleAttribute; import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute; import org.springframework.transaction.interceptor.TransactionAttribute; @@ -106,8 +109,13 @@ public class FaultTolerantStepFactoryBeanRollbackTests { factory.setSkippableExceptionClasses(getExceptionMap(Exception.class)); - MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean(); - repositoryFactory.setTransactionManager(transactionManager); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean repositoryFactory = new JobRepositoryFactoryBean(); + repositoryFactory.setDataSource(embeddedDatabase); + repositoryFactory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); repositoryFactory.afterPropertiesSet(); repository = repositoryFactory.getObject(); factory.setJobRepository(repository); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java index 2913ae38c..96865bebf 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/FaultTolerantStepFactoryBeanTests.java @@ -45,7 +45,7 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepListener; import org.springframework.batch.core.listener.SkipListenerSupport; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean; import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy; @@ -63,8 +63,10 @@ import org.springframework.batch.item.UnexpectedInputException; import org.springframework.batch.item.WriteFailedException; import org.springframework.batch.item.WriterNotOpenException; import org.springframework.batch.item.support.AbstractItemStreamItemReader; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.FactoryBean; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; import org.springframework.test.util.ReflectionTestUtils; @@ -108,10 +110,17 @@ public class FaultTolerantStepFactoryBeanTests { @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb-extended.sql") + .generateUniqueName(true) + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + factory = new FaultTolerantStepFactoryBean<>(); factory.setBeanName("stepName"); - factory.setTransactionManager(new ResourcelessTransactionManager()); + factory.setTransactionManager(transactionManager); factory.setCommitInterval(2); reader.clear(); @@ -127,9 +136,12 @@ public class FaultTolerantStepFactoryBeanTests { factory .setSkippableExceptionClasses(getExceptionMap(SkippableException.class, SkippableRuntimeException.class)); - MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean(); - repositoryFactory.afterPropertiesSet(); - repository = repositoryFactory.getObject(); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.setMaxVarCharLength(10000); + repositoryFactoryBean.afterPropertiesSet(); + repository = repositoryFactoryBean.getObject(); factory.setJobRepository(repository); jobExecution = repository.createJobExecution("skipJob", new JobParameters()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java index 4cdd686f8..7fc8d932c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java @@ -42,10 +42,13 @@ import org.springframework.batch.core.StepListener; import org.springframework.batch.core.job.SimpleJob; import org.springframework.batch.core.listener.ItemListenerSupport; import org.springframework.batch.core.listener.StepListenerSupport; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; +import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao; +import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao; +import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao; +import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.AbstractStep; @@ -58,6 +61,12 @@ import org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.task.SimpleAsyncTaskExecutor; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer; import org.springframework.lang.Nullable; /** @@ -67,8 +76,7 @@ public class SimpleStepFactoryBeanTests { private List listened = new ArrayList<>(); - private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), - new MapStepExecutionDao(), new MapExecutionContextDao()); + private JobRepository repository; private List written = new ArrayList<>(); @@ -85,6 +93,18 @@ public class SimpleStepFactoryBeanTests { @Before public void setUp() throws Exception { + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + repository = repositoryFactoryBean.getObject(); + job.setJobRepository(repository); job.setBeanName("simpleJob"); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java index c467cb333..f3d9f9260 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/job/JobStepTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,14 +29,18 @@ import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.job.JobSupport; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.ExecutionContext; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public class JobStepTests { @@ -50,7 +54,14 @@ public class JobStepTests { @Before public void setUp() throws Exception { step.setName("step"); - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); + factory.setDataSource(embeddedDatabase); + factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase)); + factory.afterPropertiesSet(); jobRepository = factory.getObject(); step.setJobRepository(jobRepository); JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java index 19106578e..c88ddc8f7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java @@ -23,7 +23,10 @@ import static org.junit.Assert.assertTrue; import java.util.List; import java.util.concurrent.Semaphore; +import javax.sql.DataSource; + import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; @@ -35,18 +38,19 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; -import org.springframework.batch.core.repository.support.SimpleJobRepository; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; +import org.springframework.transaction.PlatformTransactionManager; +// FIXME This test fails with an embedded database. Need to check if the datasource should be configured with mvcc enabled +@Ignore public class StepExecutorInterruptionTests { private TaskletStep step; @@ -59,10 +63,21 @@ public class StepExecutorInterruptionTests { private JobRepository jobRepository; + private PlatformTransactionManager transactionManager; + @Before public void setUp() throws Exception { - jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), - new MapStepExecutionDao(), new MapExecutionContextDao()); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + this.transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(this.transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + jobRepository = repositoryFactoryBean.getObject(); } private void configureStep(TaskletStep step) throws JobExecutionAlreadyRunningException, JobRestartException, @@ -74,7 +89,7 @@ public class StepExecutorInterruptionTests { job.setBeanName("testJob"); jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters()); step.setJobRepository(jobRepository); - step.setTransactionManager(new ResourcelessTransactionManager()); + step.setTransactionManager(this.transactionManager); itemWriter = new ItemWriter() { @Override public void write(List item) throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java index 8fca070f5..fb61cbe2f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,12 @@ import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.job.JobSupport; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; +import org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer; +import org.springframework.batch.core.repository.dao.JdbcExecutionContextDao; +import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao; +import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao; +import org.springframework.batch.core.repository.dao.JdbcStepExecutionDao; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.JobRepositorySupport; @@ -63,6 +65,12 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer; import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionException; import org.springframework.transaction.interceptor.DefaultTransactionAttribute; @@ -230,10 +238,18 @@ public class TaskletStepTests { @Test public void testRepository() throws Exception { - - SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), - new MapStepExecutionDao(), new MapExecutionContextDao()); + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + JobRepository repository = repositoryFactoryBean.getObject(); step.setJobRepository(repository); + step.setTransactionManager(transactionManager); JobExecution jobExecution = repository.createJobExecution(job.getName(), jobParameters); StepExecution stepExecution = new StepExecution(step.getName(), jobExecution); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java index 088d73a02..b969dc222 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/concurrent/ConcurrentTransactionTests.java @@ -45,11 +45,13 @@ import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.jdbc.datasource.embedded.ConnectionProperties; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurer; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; @@ -86,6 +88,7 @@ public class ConcurrentTransactionTests { @Configuration @EnableBatchProcessing + @Import(DataSourceConfiguration.class) public static class ConcurrentJobConfiguration extends DefaultBatchConfigurer { @Autowired @@ -94,64 +97,15 @@ public class ConcurrentTransactionTests { @Autowired private StepBuilderFactory stepBuilderFactory; + public ConcurrentJobConfiguration(DataSource dataSource) { + super(dataSource); + } + @Bean public TaskExecutor taskExecutor() { return new SimpleAsyncTaskExecutor(); } - /** - * This datasource configuration configures the HSQLDB instance using MVCC. When - * configured using the default behavior, transaction serialization errors are - * thrown (default configuration example below). - * - * return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder(). - * addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"). - * addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql"). - * build()); - - * @return - */ - @Bean - DataSource dataSource() { - ResourceLoader defaultResourceLoader = new DefaultResourceLoader(); - EmbeddedDatabaseFactory embeddedDatabaseFactory = new EmbeddedDatabaseFactory(); - embeddedDatabaseFactory.setDatabaseConfigurer(new EmbeddedDatabaseConfigurer() { - - @Override - @SuppressWarnings("unchecked") - public void configureConnectionProperties(ConnectionProperties properties, String databaseName) { - try { - properties.setDriverClass((Class) ClassUtils.forName("org.hsqldb.jdbcDriver", this.getClass().getClassLoader())); - } - catch (Exception e) { - e.printStackTrace(); - } - properties.setUrl("jdbc:hsqldb:mem:" + databaseName + ";hsqldb.tx=mvcc"); - properties.setUsername("sa"); - properties.setPassword(""); - } - - @Override - public void shutdown(DataSource dataSource, String databaseName) { - try { - Connection connection = dataSource.getConnection(); - Statement stmt = connection.createStatement(); - stmt.execute("SHUTDOWN"); - } - catch (SQLException ex) { - } - } - }); - - ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); - databasePopulator.addScript(defaultResourceLoader.getResource("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")); - databasePopulator.addScript(defaultResourceLoader.getResource("classpath:org/springframework/batch/core/schema-hsqldb.sql")); - embeddedDatabaseFactory.setDatabasePopulator(databasePopulator); - embeddedDatabaseFactory.setGenerateUniqueDatabaseName(true); - - return embeddedDatabaseFactory.getDatabase(); - } - @Bean public Flow flow() { return new FlowBuilder("flow") @@ -216,11 +170,67 @@ public class ConcurrentTransactionTests { @Override protected JobRepository createJobRepository() throws Exception { JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); - factory.setDataSource(dataSource()); + factory.setDataSource(getDataSource()); factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED"); factory.setTransactionManager(getTransactionManager()); factory.afterPropertiesSet(); return factory.getObject(); } } + + @Configuration + static class DataSourceConfiguration { + /** + * This datasource configuration configures the HSQLDB instance using MVCC. When + * configured using the default behavior, transaction serialization errors are + * thrown (default configuration example below). + * + * return new PooledEmbeddedDataSource(new EmbeddedDatabaseBuilder(). + * addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql"). + * addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql"). + * build()); + + * @return + */ + @Bean + DataSource dataSource() { + ResourceLoader defaultResourceLoader = new DefaultResourceLoader(); + EmbeddedDatabaseFactory embeddedDatabaseFactory = new EmbeddedDatabaseFactory(); + embeddedDatabaseFactory.setDatabaseConfigurer(new EmbeddedDatabaseConfigurer() { + + @Override + @SuppressWarnings("unchecked") + public void configureConnectionProperties(ConnectionProperties properties, String databaseName) { + try { + properties.setDriverClass((Class) ClassUtils.forName("org.hsqldb.jdbcDriver", this.getClass().getClassLoader())); + } + catch (Exception e) { + e.printStackTrace(); + } + properties.setUrl("jdbc:hsqldb:mem:" + databaseName + ";hsqldb.tx=mvcc"); + properties.setUsername("sa"); + properties.setPassword(""); + } + + @Override + public void shutdown(DataSource dataSource, String databaseName) { + try { + Connection connection = dataSource.getConnection(); + Statement stmt = connection.createStatement(); + stmt.execute("SHUTDOWN"); + } + catch (SQLException ex) { + } + } + }); + + ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); + databasePopulator.addScript(defaultResourceLoader.getResource("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql")); + databasePopulator.addScript(defaultResourceLoader.getResource("classpath:org/springframework/batch/core/schema-hsqldb.sql")); + embeddedDatabaseFactory.setDatabasePopulator(databasePopulator); + embeddedDatabaseFactory.setGenerateUniqueDatabaseName(true); + + return embeddedDatabaseFactory.getDatabase(); + } + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/ConcurrentMapExecutionContextDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/ConcurrentMapExecutionContextDaoTests.java deleted file mode 100644 index fc1d42194..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/ConcurrentMapExecutionContextDaoTests.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2006-2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.test.repository; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.junit.Test; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; -import org.springframework.util.Assert; - -/** - * @author Dave Syer - * - */ -public class ConcurrentMapExecutionContextDaoTests { - - private MapExecutionContextDao dao = new MapExecutionContextDao(); - - private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); - - @Test - public void testSaveUpdate() throws Exception { - StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); - stepExecution.setId(123L); - stepExecution.getExecutionContext().put("foo", "bar"); - dao.saveExecutionContext(stepExecution); - ExecutionContext executionContext = dao.getExecutionContext(stepExecution); - assertEquals("bar", executionContext.get("foo")); - } - - @Test - public void testTransactionalSaveUpdate() throws Exception { - final StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); - stepExecution.setId(123L); - new TransactionTemplate(transactionManager).execute(new TransactionCallback() { - @Override - public Void doInTransaction(TransactionStatus status) { - stepExecution.getExecutionContext().put("foo", "bar"); - dao.saveExecutionContext(stepExecution); - return null; - } - }); - ExecutionContext executionContext = dao.getExecutionContext(stepExecution); - assertEquals("bar", executionContext.get("foo")); - - } - - @Test - public void testConcurrentTransactionalSaveUpdate() throws Exception { - - ExecutorService executor = Executors.newFixedThreadPool(3); - CompletionService completionService = new ExecutorCompletionService<>(executor); - - final int outerMax = 10; - final int innerMax = 100; - - for (int i = 0; i < outerMax; i++) { - - final StepExecution stepExecution1 = new StepExecution("step", new JobExecution(11L)); - stepExecution1.setId(123L + i); - final StepExecution stepExecution2 = new StepExecution("step", new JobExecution(11L)); - stepExecution2.setId(1234L + i); - - completionService.submit(new Callable() { - @Override - public StepExecution call() throws Exception { - for (int i = 0; i < innerMax; i++) { - String value = "bar" + i; - saveAndAssert(stepExecution1, value); - } - return stepExecution1; - } - }); - - completionService.submit(new Callable() { - @Override - public StepExecution call() throws Exception { - for (int i = 0; i < innerMax; i++) { - String value = "spam" + i; - saveAndAssert(stepExecution2, value); - } - return stepExecution2; - } - }); - - completionService.take().get(); - completionService.take().get(); - - } - - executor.shutdown(); - - } - - private void saveAndAssert(final StepExecution stepExecution, final String value) { - - new TransactionTemplate(transactionManager).execute(new TransactionCallback() { - @Override - public Void doInTransaction(TransactionStatus status) { - stepExecution.getExecutionContext().put("foo", value); - dao.saveExecutionContext(stepExecution); - return null; - } - }); - - ExecutionContext executionContext = dao.getExecutionContext(stepExecution); - Assert.state(executionContext != null, "Lost insert: null executionContext at value=" + value); - String foo = executionContext.getString("foo"); - Assert.state(value.equals(foo), "Lost update: wrong value=" + value + " (found " + foo + ") for id=" - + stepExecution.getId()); - - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanRollbackTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanRollbackTests.java deleted file mode 100644 index 9cb8e663c..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanRollbackTests.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright 2010-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.test.step; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; - -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean; -import org.springframework.batch.item.ItemProcessor; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.lang.Nullable; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.util.Assert; - -import static org.junit.Assert.assertEquals; - -/** - * Tests for {@link FaultTolerantStepFactoryBean}. - */ -public class MapRepositoryFaultTolerantStepFactoryBeanRollbackTests { - - private static final int MAX_COUNT = 1000; - - private final Log logger = LogFactory.getLog(getClass()); - - private FaultTolerantStepFactoryBean factory; - - private SkipReaderStub reader; - - private SkipProcessorStub processor; - - private SkipWriterStub writer; - - private JobExecution jobExecution; - - private StepExecution stepExecution; - - private JobRepository repository; - - private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); - - @SuppressWarnings("unchecked") - @Before - public void setUp() throws Exception { - - reader = new SkipReaderStub(); - writer = new SkipWriterStub(); - processor = new SkipProcessorStub(); - - factory = new FaultTolerantStepFactoryBean<>(); - - factory.setTransactionManager(transactionManager); - factory.setBeanName("stepName"); - factory.setCommitInterval(3); - ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); - taskExecutor.setCorePoolSize(3); - taskExecutor.setMaxPoolSize(6); - taskExecutor.setQueueCapacity(0); - taskExecutor.afterPropertiesSet(); - factory.setTaskExecutor(taskExecutor); - - factory.setSkipLimit(10); - factory.setSkippableExceptionClasses(getExceptionMap(Exception.class)); - - } - - @Test - public void testUpdatesNoRollback() throws Exception { - - writer.write(Arrays.asList("foo", "bar")); - processor.process("spam"); - assertEquals(2, writer.getWritten().size()); - assertEquals(1, processor.getProcessed().size()); - - writer.clear(); - processor.clear(); - assertEquals(0, processor.getProcessed().size()); - - } - - @Test - public void testMultithreadedSkipInWrite() throws Throwable { - - for (int i = 0; i < MAX_COUNT; i++) { - - if (i%100==0) { - logger.info("Starting step: "+i); - repository = new MapJobRepositoryFactoryBean(transactionManager).getObject(); - factory.setJobRepository(repository); - jobExecution = repository.createJobExecution("vanillaJob", new JobParameters()); - } - - reader.clear(); - reader.setItems("1", "2", "3", "4", "5"); - factory.setItemReader(reader); - writer.clear(); - factory.setItemWriter(writer); - processor.clear(); - factory.setItemProcessor(processor); - - writer.setFailures("1", "2", "3", "4", "5"); - - try { - - Step step = factory.getObject(); - - stepExecution = jobExecution.createStepExecution(factory.getName()); - repository.add(stepExecution); - step.execute(stepExecution); - assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); - - assertEquals(5, stepExecution.getSkipCount()); - List processed = new ArrayList<>(processor.getProcessed()); - Collections.sort(processed); - assertEquals("[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]", processed.toString()); - - } - catch (Throwable e) { - logger.info("Failed on iteration " + i + " of " + MAX_COUNT); - throw e; - } - - } - - } - - private static class SkipReaderStub implements ItemReader { - - private String[] items; - - private int counter = -1; - - public SkipReaderStub() throws Exception { - super(); - } - - public void setItems(String... items) { - Assert.isTrue(counter < 0, "Items cannot be set once reading has started"); - this.items = items; - } - - public void clear() { - counter = -1; - } - - @Nullable - @Override - public synchronized String read() throws Exception { - counter++; - if (counter >= items.length) { - return null; - } - return items[counter]; - } - } - - private static class SkipWriterStub implements ItemWriter { - - private final Log logger = LogFactory.getLog(getClass()); - - private List written = new CopyOnWriteArrayList<>(); - - private Collection failures = Collections.emptySet(); - - public void setFailures(String... failures) { - this.failures = Arrays.asList(failures); - } - - public List getWritten() { - return written; - } - - public void clear() { - written.clear(); - } - - @Override - public void write(List items) throws Exception { - for (String item : items) { - logger.trace("Writing: "+item); - written.add(item); - checkFailure(item); - } - } - - private void checkFailure(String item) { - if (failures.contains(item)) { - throw new RuntimeException("Planned failure"); - } - } - } - - private static class SkipProcessorStub implements ItemProcessor { - - private final Log logger = LogFactory.getLog(getClass()); - - private List processed = new CopyOnWriteArrayList<>(); - - public List getProcessed() { - return processed; - } - - public void clear() { - processed.clear(); - } - - @Nullable - @Override - public String process(String item) throws Exception { - processed.add(item); - logger.debug("Processed item: "+item); - return item; - } - } - - @SuppressWarnings("unchecked") - private Map, Boolean> getExceptionMap(Class... args) { - Map, Boolean> map = new HashMap<>(); - for (Class arg : args) { - map.put(arg, true); - } - return map; - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanTests.java deleted file mode 100644 index 838f49300..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/MapRepositoryFaultTolerantStepFactoryBeanTests.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright 2010-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.core.test.step; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Before; -import org.junit.Test; -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; -import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean; -import org.springframework.batch.item.ItemProcessor; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.ParseException; -import org.springframework.batch.item.UnexpectedInputException; -import org.springframework.batch.support.transaction.ResourcelessTransactionManager; -import org.springframework.lang.Nullable; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.util.Assert; - -/** - * Tests for {@link FaultTolerantStepFactoryBean}. - */ -public class MapRepositoryFaultTolerantStepFactoryBeanTests { - - private static final int MAX_COUNT = 1000; - - private final Log logger = LogFactory.getLog(getClass()); - - private FaultTolerantStepFactoryBean factory; - - private SkipReaderStub reader; - - private SkipProcessorStub processor; - - private SkipWriterStub writer; - - private JobExecution jobExecution; - - private StepExecution stepExecution; - - private JobRepository repository; - - private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); - - @Before - public void setUp() throws Exception { - - reader = new SkipReaderStub(); - writer = new SkipWriterStub(); - processor = new SkipProcessorStub(); - - factory = new FaultTolerantStepFactoryBean<>(); - - factory.setBeanName("stepName"); - factory.setTransactionManager(transactionManager); - factory.setCommitInterval(3); - ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); - taskExecutor.setCorePoolSize(3); - taskExecutor.setMaxPoolSize(6); - taskExecutor.setQueueCapacity(0); - taskExecutor.afterPropertiesSet(); - factory.setTaskExecutor(taskExecutor); - - } - - @Test - public void testUpdatesNoRollback() throws Exception { - - writer.write(Arrays.asList("foo", "bar")); - processor.process("spam"); - assertEquals(2, writer.getWritten().size()); - assertEquals(1, processor.getProcessed().size()); - - writer.clear(); - processor.clear(); - assertEquals(0, processor.getProcessed().size()); - - } - - @Test - public void testMultithreadedSunnyDay() throws Throwable { - - for (int i = 0; i < MAX_COUNT; i++) { - - if (i%100==0) { - logger.info("Starting step: "+i); - repository = new MapJobRepositoryFactoryBean(transactionManager).getObject(); - factory.setJobRepository(repository); - jobExecution = repository.createJobExecution("vanillaJob", new JobParameters()); - } - - reader.clear(); - reader.setItems("1", "2", "3", "4", "5"); - factory.setItemReader(reader); - writer.clear(); - factory.setItemWriter(writer); - processor.clear(); - factory.setItemProcessor(processor); - - try { - - Step step = factory.getObject(); - - stepExecution = jobExecution.createStepExecution(factory.getName()); - repository.add(stepExecution); - step.execute(stepExecution); - assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); - - List committed = new ArrayList<>(writer.getWritten()); - Collections.sort(committed); - assertEquals("[1, 2, 3, 4, 5]", committed.toString()); - List processed = new ArrayList<>(processor.getProcessed()); - Collections.sort(processed); - assertEquals("[1, 2, 3, 4, 5]", processed.toString()); - assertEquals(0, stepExecution.getSkipCount()); - - } - catch (Throwable e) { - logger.info("Failed on iteration " + i + " of " + MAX_COUNT); - throw e; - } - - } - - } - - private static class SkipReaderStub implements ItemReader { - - private String[] items; - - private int counter = -1; - - public SkipReaderStub() throws Exception { - super(); - } - - public void setItems(String... items) { - Assert.isTrue(counter < 0, "Items cannot be set once reading has started"); - this.items = items; - } - - public void clear() { - counter = -1; - } - - @Nullable - @Override - public synchronized String read() throws Exception, UnexpectedInputException, ParseException { - counter++; - if (counter >= items.length) { - return null; - } - String item = items[counter]; - return item; - } - } - - private static class SkipWriterStub implements ItemWriter { - - private List written = new CopyOnWriteArrayList<>(); - - private Collection failures = Collections.emptySet(); - - public List getWritten() { - return written; - } - - public void clear() { - written.clear(); - } - - @Override - public void write(List items) throws Exception { - for (String item : items) { - written.add(item); - checkFailure(item); - } - } - - private void checkFailure(String item) { - if (failures.contains(item)) { - throw new RuntimeException("Planned failure"); - } - } - } - - private static class SkipProcessorStub implements ItemProcessor { - - private final Log logger = LogFactory.getLog(getClass()); - - private List processed = new CopyOnWriteArrayList<>(); - - public List getProcessed() { - return processed; - } - - public void clear() { - processed.clear(); - } - - @Nullable - @Override - public String process(String item) throws Exception { - processed.add(item); - logger.debug("Processed item: "+item); - return item; - } - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests.java deleted file mode 100644 index 55adf0841..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2006-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.core.test.step; - -import static org.junit.Assert.assertEquals; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Test; -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.StepContribution; -import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.core.scope.context.ChunkContext; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.RepeatStatus; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.lang.Nullable; - -/** - * @author Dave Syer - * - */ -public class SplitJobMapRepositoryIntegrationTests { - - private static final int MAX_COUNT = 1000; - - /** Logger */ - private final Log logger = LogFactory.getLog(getClass()); - - @SuppressWarnings("resource") - @Test - public void testMultithreadedSplit() throws Throwable { - - JobLauncher jobLauncher = null; - Job job = null; - - ClassPathXmlApplicationContext context = null; - - for (int i = 0; i < MAX_COUNT; i++) { - - if (i % 100 == 0) { - if (context!=null) { - context.close(); - } - logger.info("Starting job: " + i); - context = new ClassPathXmlApplicationContext(getClass().getSimpleName() - + "-context.xml", getClass()); - jobLauncher = context.getBean("jobLauncher", JobLauncher.class); - job = context.getBean("job", Job.class); - } - - try { - JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("count", (long) i) - .toJobParameters()); - assertEquals(BatchStatus.COMPLETED, execution.getStatus()); - } - catch (Throwable e) { - logger.info("Failed on iteration " + i + " of " + MAX_COUNT); - throw e; - } - - } - - } - - public static class CountingTasklet implements Tasklet { - - private int maxCount = 10; - - private AtomicInteger count = new AtomicInteger(0); - - @Nullable - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - contribution.incrementReadCount(); - contribution.incrementWriteCount(1); - return RepeatStatus.continueIf(count.incrementAndGet() < maxCount); - } - - } - -} diff --git a/spring-batch-core/src/test/resources/applicationContext-test2.xml b/spring-batch-core/src/test/resources/applicationContext-test2.xml index 8ee9f5826..720f7b7e5 100644 --- a/spring-batch-core/src/test/resources/applicationContext-test2.xml +++ b/spring-batch-core/src/test/resources/applicationContext-test2.xml @@ -1,8 +1,9 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -50,11 +51,18 @@ - - + + + + + + + + + - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml index f17e2c8c7..56e4591f9 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/support/JobRegistryIntegrationTests-context.xml @@ -1,9 +1,9 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -15,9 +15,22 @@ - + - + + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml index 1e001f6b4..08cd54db8 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml @@ -2,11 +2,11 @@ + https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -16,8 +16,18 @@ - - + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml index 36d951914..8ac6dd848 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml @@ -1,13 +1,26 @@ - + - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml index 90e1746c2..6db85d627 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRegistryJobParserTests-context.xml @@ -1,17 +1,23 @@ + xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - - + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobStepParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobStepParserTests-context.xml index 74d96655b..53b3ff8a4 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobStepParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobStepParserTests-context.xml @@ -1,8 +1,9 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd"> diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml index abc7f1ba5..dfd73e988 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/PartitionStepWithNonDefaultTransactionManagerParserTests-context.xml @@ -1,7 +1,9 @@ + xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -15,15 +17,22 @@ - + - - + + + + + + + + + - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml index aa5e5a489..062ef87dd 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/RepositoryJobParserTests-context.xml @@ -1,16 +1,30 @@ - + - - - + + + + + + + + + + + + + + + - + @@ -20,7 +34,7 @@ - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml index 6fbfecbc9..d88d1f392 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml @@ -1,8 +1,10 @@ - + @@ -46,10 +48,17 @@ - + - - + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml index f5ed35abd..b599f12e0 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserAdapterTests-context.xml @@ -1,8 +1,11 @@ - + @@ -20,10 +23,17 @@ - + - - + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml index 955ed1755..fe9d38c26 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletParserBeanPropertiesTests-context.xml @@ -1,11 +1,13 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:p="http://www.springframework.org/schema/p" + xmlns:test="http://www.springframework.org/schema/batch/test" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -35,10 +37,17 @@ - + - - + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTest-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTest-context.xml index 68eac8593..388134b3d 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTest-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTest-context.xml @@ -1,11 +1,22 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:batch="http://www.springframework.org/schema/batch" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + + + + + + + + + + + + @@ -40,6 +51,4 @@ - - diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml index 7264a16f8..9c082fd99 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/common-context.xml @@ -1,15 +1,23 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xmlns:batch="http://www.springframework.org/schema/batch" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - - + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ChunkListenerParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ChunkListenerParsingTests-context.xml index 839225487..1fcdc3f79 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ChunkListenerParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ChunkListenerParsingTests-context.xml @@ -1,10 +1,11 @@ + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -39,16 +40,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests-context.xml index 4e36f93c0..0e2ebc00e 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/CustomWiredJsrJobOperatorTests-context.xml @@ -1,16 +1,24 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - - + + + + + + + - - + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ItemListenerParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ItemListenerParsingTests-context.xml index b1a5ee0a4..1303dc941 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ItemListenerParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/ItemListenerParsingTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -38,16 +39,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobListenerParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobListenerParsingTests-context.xml index 8d4fb3898..5114f7b1f 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobListenerParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobListenerParsingTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -17,16 +18,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobPropertySubstitutionTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobPropertySubstitutionTests-context.xml index f75bcefd0..781224fcb 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobPropertySubstitutionTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/JobPropertySubstitutionTests-context.xml @@ -1,9 +1,10 @@ + http://xmlns.jcp.org/xml/ns/javaee https://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -35,16 +36,25 @@ - - - + - - + + + + + + + + + + + + + + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -17,16 +18,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTestBase-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTestBase-context.xml index 803f12b0f..19d89a624 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTestBase-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/RetryListenerTestBase-context.xml @@ -1,8 +1,9 @@ + http://xmlns.jcp.org/xml/ns/javaee https://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -22,15 +23,24 @@ - - - + - - - + + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleItemBasedJobParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleItemBasedJobParsingTests-context.xml index 493574fea..f5456637d 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleItemBasedJobParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleItemBasedJobParsingTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -36,16 +37,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleJobParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleJobParsingTests-context.xml index ef6ac6547..fec01304c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleJobParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/SimpleJobParsingTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -17,16 +18,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/StepListenerParsingTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/StepListenerParsingTests-context.xml index 23a6c891a..5358f44d7 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/StepListenerParsingTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/StepListenerParsingTests-context.xml @@ -1,9 +1,10 @@ + http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -26,16 +27,25 @@ - - - + - - + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/default-split-task-executor-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/default-split-task-executor-context.xml index f712b4ff2..06eb66fa8 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/default-split-task-executor-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/default-split-task-executor-context.xml @@ -2,10 +2,11 @@ + http://xmlns.jcp.org/xml/ns/javaee https://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -55,13 +56,22 @@ - + - - - + + + + - + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/user-specified-split-task-executor-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/user-specified-split-task-executor-context.xml index 4902f1c4b..2c6c74775 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/user-specified-split-task-executor-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/jsr/configuration/xml/user-specified-split-task-executor-context.xml @@ -2,10 +2,11 @@ + http://xmlns.jcp.org/xml/ns/javaee https://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd"> @@ -55,13 +56,22 @@ - + - - - + + + + - + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/schema-hsqldb-extended.sql b/spring-batch-core/src/test/resources/org/springframework/batch/core/schema-hsqldb-extended.sql new file mode 100644 index 000000000..4612aec20 --- /dev/null +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/schema-hsqldb-extended.sql @@ -0,0 +1,91 @@ +-- This schema is the same as the default hsqdl DDL script +-- except it has larger column length for the exit code of +-- step/job executions. This is required in some tests as we +-- store and verify the stack traces of failure exceptions, +-- which could be larger than the default 2500 characters. + +CREATE TABLE BATCH_JOB_INSTANCE ( + JOB_INSTANCE_ID BIGINT IDENTITY NOT NULL PRIMARY KEY , + VERSION BIGINT , + JOB_NAME VARCHAR(100) NOT NULL, + JOB_KEY VARCHAR(32) NOT NULL, + constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) +) ; + +CREATE TABLE BATCH_JOB_EXECUTION ( + JOB_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY , + VERSION BIGINT , + JOB_INSTANCE_ID BIGINT NOT NULL, + CREATE_TIME TIMESTAMP NOT NULL, + START_TIME TIMESTAMP DEFAULT NULL , + END_TIME TIMESTAMP DEFAULT NULL , + STATUS VARCHAR(10) , + EXIT_CODE VARCHAR(10000) , + EXIT_MESSAGE VARCHAR(10000) , + LAST_UPDATED TIMESTAMP, + JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL, + constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) +) ; + +CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( + JOB_EXECUTION_ID BIGINT NOT NULL , + TYPE_CD VARCHAR(6) NOT NULL , + KEY_NAME VARCHAR(100) NOT NULL , + STRING_VAL VARCHAR(250) , + DATE_VAL TIMESTAMP DEFAULT NULL , + LONG_VAL BIGINT , + DOUBLE_VAL DOUBLE PRECISION , + IDENTIFYING CHAR(1) NOT NULL , + constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION ( + STEP_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY , + VERSION BIGINT NOT NULL, + STEP_NAME VARCHAR(100) NOT NULL, + JOB_EXECUTION_ID BIGINT NOT NULL, + START_TIME TIMESTAMP NOT NULL , + END_TIME TIMESTAMP DEFAULT NULL , + STATUS VARCHAR(10) , + COMMIT_COUNT BIGINT , + READ_COUNT BIGINT , + FILTER_COUNT BIGINT , + WRITE_COUNT BIGINT , + READ_SKIP_COUNT BIGINT , + WRITE_SKIP_COUNT BIGINT , + PROCESS_SKIP_COUNT BIGINT , + ROLLBACK_COUNT BIGINT , + EXIT_CODE VARCHAR(10000) , + EXIT_MESSAGE VARCHAR(10000) , + LAST_UPDATED TIMESTAMP, + constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( + STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(10000) NOT NULL, + SERIALIZED_CONTEXT LONGVARCHAR , + constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( + JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(10000) NOT NULL, + SERIALIZED_CONTEXT LONGVARCHAR , + constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( + ID BIGINT IDENTITY +); +CREATE TABLE BATCH_JOB_EXECUTION_SEQ ( + ID BIGINT IDENTITY +); +CREATE TABLE BATCH_JOB_SEQ ( + ID BIGINT IDENTITY +); diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml index d1b492e21..aff03495c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml @@ -1,12 +1,23 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml index ef158c121..926ed044c 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartInPriorStepTests-context.xml @@ -1,11 +1,12 @@ + https://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -73,9 +74,18 @@ - + - + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml index 5fc49141e..18e2ae81a 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/RestartLoopTests-context.xml @@ -1,8 +1,9 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -22,12 +23,19 @@ - + - - + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml index 9f84a00a6..d3b314018 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/FaultTolerantExceptionClassesTests-context.xml @@ -1,9 +1,10 @@ + xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -144,10 +145,17 @@ - - + + + + + + + + + - + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTest-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTest-context.xml index bac1b4832..4223bf7a3 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTest-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/item/ScriptItemProcessorTest-context.xml @@ -2,10 +2,10 @@ + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -15,11 +15,22 @@ - + - + + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml index e91bb0e17..c9ecc60cc 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/step/skip/ReprocessExceptionTests-context.xml @@ -1,8 +1,10 @@ + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -42,6 +44,16 @@ - - + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests-context.xml deleted file mode 100644 index 2fd345bb2..000000000 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/test/step/SplitJobMapRepositoryIntegrationTests-context.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-batch-core/src/test/resources/simple-job-launcher-context.xml b/spring-batch-core/src/test/resources/simple-job-launcher-context.xml index 7946b246b..a07abfe0f 100644 --- a/spring-batch-core/src/test/resources/simple-job-launcher-context.xml +++ b/spring-batch-core/src/test/resources/simple-job-launcher-context.xml @@ -19,10 +19,6 @@ class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" /> - - - - ----- - -[role="javaContent"] -The following example shows the inclusion of `MapJobRepositoryFactoryBean` in Java: - -.Java Configuration -[source, java, role="javaContent"] ----- -// This would reside in your BatchConfigurer implementation -@Override -protected JobRepository createJobRepository() throws Exception { - MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); - factory.setTransactionManager(transactionManager); - return factory.getObject(); -} - ----- - -Note that the in-memory repository is volatile and so does not allow restart between JVM -instances. It also cannot guarantee that two job instances with the same parameters are -launched simultaneously, and is not suitable for use in a multi-threaded Job, or a locally -partitioned `Step`. So use the database version of the repository wherever you need those -features. - -However it does require a transaction manager to be defined because there are rollback -semantics within the repository, and because the business logic might still be -transactional (such as RDBMS access). For testing purposes many people find the -`ResourcelessTransactionManager` useful. - - - [[nonStandardDatabaseTypesInRepository]] ==== Non-standard Database Types in a Repository diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java index 30e934a85..c659b1f38 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java @@ -1,3 +1,18 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.batch.integration.chunk; import java.util.Arrays; @@ -19,11 +34,9 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.job.SimpleJob; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; +import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.core.repository.dao.MapExecutionContextDao; -import org.springframework.batch.core.repository.dao.MapJobExecutionDao; -import org.springframework.batch.core.repository.dao.MapJobInstanceDao; -import org.springframework.batch.core.repository.dao.MapStepExecutionDao; +import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.factory.SimpleStepFactoryBean; import org.springframework.batch.item.ExecutionContext; @@ -32,6 +45,12 @@ import org.springframework.batch.support.transaction.ResourcelessTransactionMana import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.core.MessagingTemplate; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.HsqlSequenceMaxValueIncrementer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; @@ -59,17 +78,24 @@ public class ChunkMessageItemWriterIntegrationTests { private final SimpleStepFactoryBean factory = new SimpleStepFactoryBean<>(); - private SimpleJobRepository jobRepository; + private JobRepository jobRepository; private static long jobCounter; @Before - public void setUp() { - - jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), - new MapStepExecutionDao(), new MapExecutionContextDao()); + public void setUp() throws Exception { + EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .build(); + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase); + JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean(); + repositoryFactoryBean.setDataSource(embeddedDatabase); + repositoryFactoryBean.setTransactionManager(transactionManager); + repositoryFactoryBean.afterPropertiesSet(); + jobRepository = repositoryFactoryBean.getObject(); factory.setJobRepository(jobRepository); - factory.setTransactionManager(new ResourcelessTransactionManager()); + factory.setTransactionManager(transactionManager); factory.setBeanName("step"); factory.setItemWriter(writer); factory.setCommitInterval(4); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTest.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTest.java index 944e72dd4..50b80dcc7 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTest.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingManagerStepBuilderTest.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +import javax.sql.DataSource; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,10 +47,12 @@ import org.springframework.batch.item.support.CompositeItemStream; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.MessagingTemplate; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.lang.Nullable; import org.springframework.messaging.PollableChannel; import org.springframework.retry.RetryListener; @@ -337,5 +341,14 @@ public class RemoteChunkingManagerStepBuilderTest { @EnableBatchProcessing public static class BatchConfiguration { + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } + } } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/JobLauncherParserTestsConfiguration.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/JobLauncherParserTestsConfiguration.java index 2cde85f30..79639234a 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/JobLauncherParserTestsConfiguration.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/config/xml/JobLauncherParserTestsConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -12,12 +12,17 @@ */ package org.springframework.batch.integration.config.xml; +import javax.sql.DataSource; + import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; /** * * @author Gunnar Hillert + * @author Mahmoud Ben Hassine * @since 1.3 * */ @@ -25,4 +30,13 @@ import org.springframework.context.annotation.Configuration; @EnableBatchProcessing public class JobLauncherParserTestsConfiguration { + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } + } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningMasterStepBuilderTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningMasterStepBuilderTests.java index 0e95cda87..cedd3e1fb 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningMasterStepBuilderTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/RemotePartitioningMasterStepBuilderTests.java @@ -16,6 +16,8 @@ package org.springframework.batch.integration.partition; +import javax.sql.DataSource; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,10 +30,12 @@ import org.springframework.batch.core.partition.support.Partitioner; import org.springframework.batch.core.partition.support.StepExecutionAggregator; import org.springframework.batch.core.repository.JobRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.MessagingTemplate; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -238,5 +242,14 @@ public class RemotePartitioningMasterStepBuilderTests { @EnableBatchProcessing public static class BatchConfiguration { + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder() + .addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql") + .addScript("/org/springframework/batch/core/schema-hsqldb.sql") + .generateUniqueName(true) + .build(); + } + } } diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepIntegrationTests-context.xml index c97a55007..819f7d30b 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepIntegrationTests-context.xml @@ -1,15 +1,17 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:integration="http://www.springframework.org/schema/integration" + xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd + http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd + http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -74,12 +76,19 @@ - + - - + + + + + + + + + diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepJmsIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepJmsIntegrationTests-context.xml index b27846f9e..0e203f015 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepJmsIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkFaultTolerantStepJmsIntegrationTests-context.xml @@ -3,12 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:integration="http://www.springframework.org/schema/integration" xmlns:int-jms="http://www.springframework.org/schema/integration/jms" - xmlns:jms="http://www.springframework.org/schema/jms" + xmlns:jms="http://www.springframework.org/schema/jms" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xmlns:batch="http://www.springframework.org/schema/batch" xsi:schemaLocation="http://www.springframework.org/schema/jms https://www.springframework.org/schema/jms/spring-jms.xsd http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/jms https://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd"> + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -104,12 +105,19 @@ - + - - + + + + + + + + + diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkStepIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkStepIntegrationTests-context.xml index 2bfad626c..7095efc3d 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkStepIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/chunk/RemoteChunkStepIntegrationTests-context.xml @@ -1,13 +1,15 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:integration="http://www.springframework.org/schema/integration" + xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:context="http://www.springframework.org/schema/context" + xmlns:task="http://www.springframework.org/schema/task" xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd + http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.2.xsd + http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> @@ -59,10 +61,21 @@ - + - - + + + + + + + + + + + + + diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/JmsIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/JmsIntegrationTests-context.xml index bc7725d8b..af7f911ff 100755 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/JmsIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/JmsIntegrationTests-context.xml @@ -42,10 +42,6 @@ - - - - diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/PollingIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/PollingIntegrationTests-context.xml index 9a27c72fe..e255e9dce 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/PollingIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/PollingIntegrationTests-context.xml @@ -23,10 +23,6 @@ - - - - diff --git a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/VanillaIntegrationTests-context.xml b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/VanillaIntegrationTests-context.xml index 0e6a95c63..55fb1a444 100644 --- a/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/VanillaIntegrationTests-context.xml +++ b/spring-batch-integration/src/test/resources/org/springframework/batch/integration/partition/VanillaIntegrationTests-context.xml @@ -31,10 +31,6 @@ - - - - diff --git a/spring-batch-integration/src/test/resources/simple-job-launcher-context.xml b/spring-batch-integration/src/test/resources/simple-job-launcher-context.xml index 06dce322d..1373b6640 100644 --- a/spring-batch-integration/src/test/resources/simple-job-launcher-context.xml +++ b/spring-batch-integration/src/test/resources/simple-job-launcher-context.xml @@ -1,16 +1,28 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:batch="http://www.springframework.org/schema/batch" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - - + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml index 38bfb7311..d6fc99a56 100644 --- a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml @@ -20,10 +20,6 @@ p:isolationLevelForCreate = "${batch.isolationlevel}" p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:lobHandler-ref="lobHandler"/> - - + xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:batch="http://www.springframework.org/schema/batch" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + + + + + + + + diff --git a/spring-batch-test/src/test/resources/org/springframework/batch/test/StepScopeTestExecutionListenerIntegrationTests-context.xml b/spring-batch-test/src/test/resources/org/springframework/batch/test/StepScopeTestExecutionListenerIntegrationTests-context.xml index 9f7a71c64..2162005ff 100644 --- a/spring-batch-test/src/test/resources/org/springframework/batch/test/StepScopeTestExecutionListenerIntegrationTests-context.xml +++ b/spring-batch-test/src/test/resources/org/springframework/batch/test/StepScopeTestExecutionListenerIntegrationTests-context.xml @@ -1,11 +1,22 @@ + xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:batch="http://www.springframework.org/schema/batch" + xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> - + - + + + + + + + + + +