BATCH-1450: make Maps in Daos local not global

This commit is contained in:
dsyer
2009-11-26 08:57:22 +00:00
parent 2cced977ec
commit b6ea930f28
39 changed files with 162 additions and 186 deletions

View File

@@ -117,6 +117,7 @@ public class CoreNamespacePostProcessor implements BeanPostProcessor, BeanFactor
* @param bean
* @return
*/
@SuppressWarnings("unchecked")
private Object injectDefaults(Object bean) {
if (bean instanceof JobParserJobFactoryBean) {
JobParserJobFactoryBean fb = (JobParserJobFactoryBean) bean;

View File

@@ -19,12 +19,11 @@ package org.springframework.batch.core.explore.support;
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.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.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
@@ -33,26 +32,53 @@ import org.springframework.beans.factory.FactoryBean;
* @author Dave Syer
* @since 2.0
*/
public class MapJobExplorerFactoryBean extends AbstractJobExplorerFactoryBean {
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
*/
public MapJobExplorerFactoryBean(MapJobRepositoryFactoryBean repositoryFactory) {
this.repositoryFactory = repositoryFactory;
}
/**
* Create a factory with no {@link MapJobRepositoryFactoryBean}. It must be
* injected as a property.
*/
public MapJobExplorerFactoryBean() {
}
/**
* @throws Exception
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.state(repositoryFactory!=null, "A MapJobExplorerFactoryBean must be provided");
repositoryFactory.afterPropertiesSet();
}
@Override
protected JobExecutionDao createJobExecutionDao() throws Exception {
return new MapJobExecutionDao();
return repositoryFactory.getJobExecutionDao();
}
@Override
protected JobInstanceDao createJobInstanceDao() throws Exception {
return new MapJobInstanceDao();
return repositoryFactory.getJobInstanceDao();
}
@Override
protected StepExecutionDao createStepExecutionDao() throws Exception {
return new MapStepExecutionDao();
return repositoryFactory.getStepExecutionDao();
}
@Override
protected ExecutionContextDao createExecutionContextDao() throws Exception {
return new MapExecutionContextDao();
return repositoryFactory.getExecutionContextDao();
}
public Object getObject() throws Exception {

View File

@@ -32,13 +32,13 @@ import org.springframework.batch.support.transaction.TransactionAwareProxyFactor
*/
public class MapExecutionContextDao implements ExecutionContextDao {
private static Map<Long, ExecutionContext> contextsByStepExecutionId = TransactionAwareProxyFactory
private Map<Long, ExecutionContext> contextsByStepExecutionId = TransactionAwareProxyFactory
.createTransactionalMap();
private static Map<Long, ExecutionContext> contextsByJobExecutionId = TransactionAwareProxyFactory
private Map<Long, ExecutionContext> contextsByJobExecutionId = TransactionAwareProxyFactory
.createTransactionalMap();
public static void clear() {
public void clear() {
contextsByJobExecutionId.clear();
contextsByStepExecutionId.clear();
}

View File

@@ -36,11 +36,11 @@ import org.springframework.util.Assert;
*/
public class MapJobExecutionDao implements JobExecutionDao {
private static Map<Long, JobExecution> executionsById = TransactionAwareProxyFactory.createTransactionalMap();
private Map<Long, JobExecution> executionsById = TransactionAwareProxyFactory.createTransactionalMap();
private static long currentId = 0;
private long currentId = 0;
public static void clear() {
public void clear() {
executionsById.clear();
}

View File

@@ -33,11 +33,11 @@ import org.springframework.util.Assert;
*/
public class MapJobInstanceDao implements JobInstanceDao {
private static Collection<JobInstance> jobInstances = TransactionAwareProxyFactory.createTransactionalSet();
private Collection<JobInstance> jobInstances = TransactionAwareProxyFactory.createTransactionalSet();
private static long currentId = 0;
private long currentId = 0;
public static void clear() {
public void clear() {
jobInstances.clear();
}

View File

@@ -34,15 +34,15 @@ import org.springframework.util.Assert;
*/
public class MapStepExecutionDao implements StepExecutionDao {
private static Map<Long, Map<Long, StepExecution>> executionsByJobExecutionId = TransactionAwareProxyFactory
private Map<Long, Map<Long, StepExecution>> executionsByJobExecutionId = TransactionAwareProxyFactory
.createTransactionalMap();
private static Map<Long, StepExecution> executionsByStepExecutionId = TransactionAwareProxyFactory
private Map<Long, StepExecution> executionsByStepExecutionId = TransactionAwareProxyFactory
.createTransactionalMap();
private static long currentId = 0;
private long currentId = 0;
public static void clear() {
public void clear() {
executionsByJobExecutionId.clear();
executionsByStepExecutionId.clear();
}

View File

@@ -113,20 +113,32 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean, I
this.transactionManager = transactionManager;
}
/**
* The transaction manager used in this factory. Useful to inject into steps
* and jobs, to ensure that they are using the same instance.
*
* @return the transactionManager
*/
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
private void initializeProxy() throws Exception {
proxyFactory = new ProxyFactory();
TransactionInterceptor advice = new TransactionInterceptor(transactionManager, PropertiesConverter
.stringToProperties("create*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate
+ "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate
+ "\n*=PROPAGATION_REQUIRED"));
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(advice);
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.addMethodName("*");
advisor.setPointcut(pointcut);
proxyFactory.addAdvisor(advisor);
proxyFactory.setProxyTargetClass(false);
proxyFactory.addInterface(JobRepository.class);
proxyFactory.setTarget(getTarget());
if (proxyFactory == null) {
proxyFactory = new ProxyFactory();
TransactionInterceptor advice = new TransactionInterceptor(transactionManager, PropertiesConverter
.stringToProperties("create*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate
+ "\ngetLastJobExecution*=PROPAGATION_REQUIRES_NEW," + isolationLevelForCreate
+ "\n*=PROPAGATION_REQUIRED"));
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(advice);
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.addMethodName("*");
advisor.setPointcut(pointcut);
proxyFactory.addAdvisor(advisor);
proxyFactory.setProxyTargetClass(false);
proxyFactory.addInterface(JobRepository.class);
proxyFactory.setTarget(getTarget());
}
}
public void afterPropertiesSet() throws Exception {

View File

@@ -26,6 +26,7 @@ import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
import org.springframework.batch.core.repository.dao.StepExecutionDao;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
/**
* A {@link FactoryBean} that automates the creation of a
@@ -33,7 +34,7 @@ import org.springframework.beans.factory.FactoryBean;
* implementations. This repository is only really intended for use in testing
* and rapid prototyping. In such settings you might find that
* {@link ResourcelessTransactionManager} is useful (as long as your business
* logic does not use a relational database). Not suited for use in
* logic does not use a relational database). Not suited for use in
* multi-threaded jobs with splits, although it should be safe to use in a
* multi-threaded step.
*
@@ -41,35 +42,79 @@ import org.springframework.beans.factory.FactoryBean;
*/
public class MapJobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean {
private MapJobExecutionDao jobExecutionDao;
private MapJobInstanceDao jobInstanceDao;
private MapStepExecutionDao stepExecutionDao;
private MapExecutionContextDao executionContextDao;
/**
* Create a new instance with a {@link ResourcelessTransactionManager}.
*/
public MapJobRepositoryFactoryBean() {
this(new ResourcelessTransactionManager());
}
/**
* Create a new instance with the provided transaction manager.
*
* @param transactionManager
*/
public MapJobRepositoryFactoryBean(PlatformTransactionManager transactionManager) {
setTransactionManager(transactionManager);
}
public JobExecutionDao getJobExecutionDao() {
return jobExecutionDao;
}
public JobInstanceDao getJobInstanceDao() {
return jobInstanceDao;
}
public StepExecutionDao getStepExecutionDao() {
return stepExecutionDao;
}
public ExecutionContextDao getExecutionContextDao() {
return executionContextDao;
}
/**
* Convenience method to clear all the map daos globally, removing all
* entities.
*/
public static void clear() {
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
MapExecutionContextDao.clear();
public void clear() {
jobInstanceDao.clear();
jobExecutionDao.clear();
stepExecutionDao.clear();
executionContextDao.clear();
}
@Override
protected JobExecutionDao createJobExecutionDao() throws Exception {
return new MapJobExecutionDao();
jobExecutionDao = new MapJobExecutionDao();
return jobExecutionDao;
}
@Override
protected JobInstanceDao createJobInstanceDao() throws Exception {
return new MapJobInstanceDao();
jobInstanceDao = new MapJobInstanceDao();
return jobInstanceDao;
}
@Override
protected StepExecutionDao createStepExecutionDao() throws Exception {
return new MapStepExecutionDao();
stepExecutionDao = new MapStepExecutionDao();
return stepExecutionDao;
}
@Override
protected ExecutionContextDao createExecutionContextDao() throws Exception {
return new MapExecutionContextDao();
executionContextDao = new MapExecutionContextDao();
return executionContextDao;
}
}

View File

@@ -42,13 +42,16 @@ public abstract class AbstractJobParserTests {
@Autowired
private JobRepository jobRepository;
@Autowired
private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean;
@Autowired
protected ArrayList<String> stepNamesList = new ArrayList<String>();
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
mapJobRepositoryFactoryBean.clear();
stepNamesList.clear();
}

View File

@@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
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.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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -51,11 +49,6 @@ public class BranchStepJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testBranchStep() throws Exception {
assertNotNull(job);
@@ -70,4 +63,5 @@ public class BranchStepJobParserTests {
assertTrue(names.contains("job.s3"));
assertFalse(names.contains("job.s2"));
}
}

View File

@@ -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;
@@ -29,7 +28,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.test.context.ContextConfiguration;
@@ -50,11 +48,6 @@ public class DecisionJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testDecisionState() throws Exception {
assertNotNull(job);

View File

@@ -16,18 +16,16 @@
package org.springframework.batch.core.configuration.xml;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.ClassUtils;
/**
* @author Dan Garrette
* @author Dave Syer
* @since 2.0
*/
@RunWith(JUnit4ClassRunner.class)
public class DuplicateTransitionJobParserTests extends AbstractJobParserTests {
public class DuplicateTransitionJobParserTests {
@Test(expected = BeanDefinitionStoreException.class)
public void testNextAttributeWithNestedElement() throws Exception {

View File

@@ -63,10 +63,13 @@ public class FlowJobParserTests {
@Autowired
private JobRepository jobRepository;
@Autowired
private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
mapJobRepositoryFactoryBean.clear();
}
@Test

View File

@@ -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;
@@ -48,11 +46,6 @@ public class OneStepJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testOneStep() throws Exception {
assertNotNull(job);

View File

@@ -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;
@@ -48,11 +46,6 @@ public class RepositoryJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testTaskletStepWithBadListener() throws Exception {
assertNotNull(job);

View File

@@ -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;
@@ -48,11 +46,6 @@ public class SplitJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testSplitJob() throws Exception {
assertNotNull(job);

View File

@@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
@@ -28,7 +27,6 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
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.item.ItemStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -68,11 +66,6 @@ public class StepWithBasicProcessTaskJobParserTests {
@Autowired
private StepParserStepFactoryBean factory;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testStepWithTask() throws Exception {
assertNotNull(job);

View File

@@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
@@ -28,7 +27,6 @@ import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
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.item.ItemStream;
import org.springframework.batch.retry.RetryListener;
import org.springframework.beans.factory.annotation.Autowired;
@@ -74,11 +72,6 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
@Autowired
private StepParserStepFactoryBean factory;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testStepWithTask() throws Exception {
assertNotNull(job);

View File

@@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
@@ -29,7 +28,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.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -54,11 +52,6 @@ public class StepWithSimpleTaskJobParserTests {
@Qualifier("listener")
private TestListener listener;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testJob() throws Exception {
assertNotNull(job);

View File

@@ -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;
@@ -46,11 +44,6 @@ public class TwoStepJobParserTests {
@Autowired
private JobRepository jobRepository;
@Before
public void setUp() {
MapJobRepositoryFactoryBean.clear();
}
@Test
public void testTwoStep() throws Exception {
assertNotNull(job);

View File

@@ -1,25 +1,35 @@
package org.springframework.batch.core.exlore.support;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
/**
* Tests for {@link MapJobExplorerFactoryBean}.
*/
public class MapJobExplorerFactoryBeanTests {
private MapJobExplorerFactoryBean tested = new MapJobExplorerFactoryBean();
/**
* Use the factory to create repository and check the repository remembers
* Use the factory to create repository and check the explorer remembers
* created executions.
*/
@Test
public void testCreateRepository() throws Exception {
public void testCreateExplorer() throws Exception {
MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean();
((JobRepository)repositoryFactory.getObject()).createJobExecution("foo", new JobParameters());
MapJobExplorerFactoryBean tested = new MapJobExplorerFactoryBean(repositoryFactory);
tested.afterPropertiesSet();
JobExplorer explorer = (JobExplorer) tested.getObject();
explorer.findRunningJobExecutions("foo");
assertEquals(1, explorer.findRunningJobExecutions("foo").size());
}

View File

@@ -33,7 +33,6 @@ 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.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
/**
@@ -47,12 +46,8 @@ public class MapJobExplorerIntegrationTests {
@Test
public void testRunningJobExecution() throws Exception {
MapJobRepositoryFactoryBean.clear();
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean();
ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
repositoryFactory.setTransactionManager(transactionManager);
repositoryFactory.afterPropertiesSet();
JobRepository jobRepository = (JobRepository) repositoryFactory.getObject();
jobLauncher.setJobRepository(jobRepository);
@@ -69,7 +64,7 @@ public class MapJobExplorerIntegrationTests {
return RepeatStatus.FINISHED;
}
});
step.setTransactionManager(transactionManager);
step.setTransactionManager(repositoryFactory.getTransactionManager());
step.setJobRepository(jobRepository);
step.afterPropertiesSet();
job.addStep(step);
@@ -79,7 +74,7 @@ public class MapJobExplorerIntegrationTests {
jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters());
Thread.sleep(500L);
JobExplorer explorer = (JobExplorer) new MapJobExplorerFactoryBean().getObject();
JobExplorer explorer = (JobExplorer) new MapJobExplorerFactoryBean(repositoryFactory).getObject();
Set<JobExecution> executions = explorer.findRunningJobExecutions("job");
assertEquals(1, executions.size());
assertEquals(1, executions.iterator().next().getStepExecutions().size());

View File

@@ -38,7 +38,6 @@ 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.StepSupport;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* @author Dave Syer
@@ -51,9 +50,7 @@ public class ExtendedAbstractJobTests {
@Before
public void setUp() throws Exception {
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
jobRepository = (JobRepository) factory.getObject();
job = new StubJob("job", jobRepository);
}
@@ -166,9 +163,7 @@ public class ExtendedAbstractJobTests {
}
}
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
factory.afterPropertiesSet();
JobRepository repository = (JobRepository) factory.getObject();
job.setJobRepository(repository);

View File

@@ -99,10 +99,6 @@ public class SimpleJobTests {
@Before
public void setUp() throws Exception {
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
MapExecutionContextDao.clear();
jobInstanceDao = new MapJobInstanceDao();
jobExecutionDao = new MapJobExecutionDao();
stepExecutionDao = new MapStepExecutionDao();

View File

@@ -42,14 +42,8 @@ import org.springframework.batch.core.job.flow.support.state.SplitState;
import org.springframework.batch.core.job.flow.support.state.StepState;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.dao.JobExecutionDao;
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.MapJobRepositoryFactoryBean;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* @author Dave Syer
@@ -69,13 +63,9 @@ public class FlowJobTests {
@Before
public void setUp() throws Exception {
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
factory.afterPropertiesSet();
jobExecutionDao = new MapJobExecutionDao();
jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), jobExecutionDao, new MapStepExecutionDao(),
new MapExecutionContextDao());
jobExecutionDao = factory.getJobExecutionDao();
jobRepository = (JobRepository) factory.getObject();
job.setJobRepository(jobRepository);
jobExecution = jobRepository.createJobExecution("job", new JobParameters());

View File

@@ -34,7 +34,6 @@ 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.step.StepSupport;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* @author Dave Syer
@@ -50,9 +49,7 @@ public class PartitionStepTests {
@Before
public void setUp() throws Exception {
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
jobRepository = (JobRepository) factory.getObject();
step.setJobRepository(jobRepository);
}

View File

@@ -17,7 +17,6 @@ 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.item.ExecutionContext;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
public class SimpleStepExecutionSplitterTests {
@@ -31,14 +30,13 @@ public class SimpleStepExecutionSplitterTests {
public void setUp() throws Exception {
step = new TaskletStep("step");
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
jobRepository = (JobRepository) factory.getObject();
}
@Test
public void testSimpleStepExecutionProviderJobRepositoryStep() throws Exception {
SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step);
Set<StepExecution> execs = provider.split(stepExecution, 2);
SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, step);
Set<StepExecution> execs = splitter.split(stepExecution, 2);
assertEquals(2, execs.size());
for (StepExecution execution : execs) {
@@ -49,12 +47,12 @@ public class SimpleStepExecutionSplitterTests {
@Test
public void testSimpleStepExecutionProviderJobRepositoryStepPartitioner() throws Exception {
final Map<String, ExecutionContext> map = Collections.singletonMap("foo", new ExecutionContext());
SimpleStepExecutionSplitter provider = new SimpleStepExecutionSplitter(jobRepository, step, new Partitioner() {
SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(jobRepository, step, new Partitioner() {
public Map<String, ExecutionContext> partition(int gridSize) {
return map;
}
});
assertEquals(1, provider.split(stepExecution, 2).size());
assertEquals(1, splitter.split(stepExecution, 2).size());
}
@Test

View File

@@ -17,19 +17,16 @@ public class MapExecutionContextDaoTests extends AbstractExecutionContextDaoTest
@Override
protected JobInstanceDao getJobInstanceDao() {
MapJobInstanceDao.clear();
return new MapJobInstanceDao();
}
@Override
protected JobExecutionDao getJobExecutionDao() {
MapJobExecutionDao.clear();
return new MapJobExecutionDao();
}
@Override
protected StepExecutionDao getStepExecutionDao() {
MapStepExecutionDao.clear();
return new MapStepExecutionDao();
}

View File

@@ -16,8 +16,6 @@ public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
@Override
protected JobExecutionDao getJobExecutionDao() {
MapJobExecutionDao.clear();
MapJobInstanceDao.clear();
return new MapJobExecutionDao();
}

View File

@@ -7,7 +7,6 @@ import org.junit.internal.runners.JUnit4ClassRunner;
public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
protected JobInstanceDao getJobInstanceDao() {
MapJobInstanceDao.clear();
return new MapJobInstanceDao();
}

View File

@@ -20,9 +20,6 @@ public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
}
protected JobRepository getJobRepository() {
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
return new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(), new MapStepExecutionDao(),
new MapExecutionContextDao());
}

View File

@@ -8,7 +8,6 @@ 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 org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* Tests for {@link MapJobRepositoryFactoryBean}.
@@ -23,7 +22,6 @@ public class MapJobRepositoryFactoryBeanTests {
*/
@Test
public void testCreateRepository() throws Exception {
tested.setTransactionManager(new ResourcelessTransactionManager());
tested.afterPropertiesSet();
JobRepository repository = (JobRepository) tested.getObject();
Job job = new JobSupport("jobName");

View File

@@ -94,10 +94,6 @@ public class FaultTolerantStepFactoryBeanRetryTests {
@Before
public void setUp() throws Exception {
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
factory = new FaultTolerantStepFactoryBean<String, String>();
factory.setBeanName("step");

View File

@@ -77,9 +77,7 @@ public class FaultTolerantStepFactoryBeanRollbackTests {
factory.setSkippableExceptionClasses(getExceptionMap(Exception.class));
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean();
repositoryFactory.setTransactionManager(new ResourcelessTransactionManager());
repositoryFactory.afterPropertiesSet();
repository = (JobRepository) repositoryFactory.getObject();
factory.setJobRepository(repository);

View File

@@ -103,9 +103,7 @@ public class FaultTolerantStepFactoryBeanTests {
factory
.setSkippableExceptionClasses(getExceptionMap(SkippableException.class, SkippableRuntimeException.class));
MapJobRepositoryFactoryBean.clear();
MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean();
repositoryFactory.setTransactionManager(new ResourcelessTransactionManager());
repositoryFactory.afterPropertiesSet();
repository = (JobRepository) repositoryFactory.getObject();
factory.setJobRepository(repository);

View File

@@ -81,9 +81,6 @@ public class SimpleStepFactoryBeanTests {
public void setUp() throws Exception {
job.setJobRepository(repository);
job.setBeanName("simpleJob");
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
}
@Test(expected = IllegalArgumentException.class)

View File

@@ -32,7 +32,6 @@ 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.item.ExecutionContext;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* @author Dave Syer
@@ -48,10 +47,8 @@ public class JobStepTests {
@Before
public void setUp() throws Exception {
MapJobRepositoryFactoryBean.clear();
step.setName("step");
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
factory.setTransactionManager(new ResourcelessTransactionManager());
jobRepository = (JobRepository) factory.getObject();
step.setJobRepository(jobRepository);
JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters());

View File

@@ -56,9 +56,6 @@ public class StepExecutorInterruptionTests extends TestCase {
private Field semaphore;
public void setUp() throws Exception {
MapJobInstanceDao.clear();
MapJobExecutionDao.clear();
MapStepExecutionDao.clear();
jobRepository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
new MapStepExecutionDao(), new MapExecutionContextDao());

View File

@@ -113,9 +113,6 @@ public class TaskletStepTests {
@Before
public void setUp() throws Exception {
MapJobInstanceDao.clear();
MapStepExecutionDao.clear();
MapJobExecutionDao.clear();
transactionManager = new ResourcelessTransactionManager();