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 08de29a2c..481199cc1 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 @@ -29,8 +29,6 @@ import org.springframework.util.Assert; */ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean, InitializingBean { - - private PlatformTransactionManager transactionManager; private ProxyFactory proxyFactory; @@ -103,6 +101,7 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean, I 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(); @@ -113,23 +112,23 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean, I proxyFactory.addInterface(JobRepository.class); proxyFactory.setTarget(getTarget()); } - + public void afterPropertiesSet() throws Exception { Assert.notNull(transactionManager, "TransactionManager must not be null."); - - initializeProxy(); + + initializeProxy(); } private Object getTarget() throws Exception { return new SimpleJobRepository(createJobInstanceDao(), createJobExecutionDao(), createStepExecutionDao(), createExecutionContextDao()); } - + public Object getObject() throws Exception { - if (proxyFactory==null) { + if (proxyFactory == null) { afterPropertiesSet(); - } - return proxyFactory.getProxy(); + } + return proxyFactory.getProxy(); } } diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java index 53fbdee47..c901b12fb 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/launch/RemoteLauncherTests.java @@ -83,6 +83,31 @@ public class RemoteLauncherTests { assertTrue(launcher.getJobNames().contains("loopJob")); } + @Test + public void testPauseJob() throws Exception { + final int SLEEP_INTERVAL = 500; + assertTrue(isConnected()); + assertTrue(launcher.getJobNames().contains("loopJob")); + long executionId = launcher.start("loopJob", ""); + + // sleep long enough to avoid race conditions (serializable tx isolation + // doesn't work with HSQL) + Thread.sleep(SLEEP_INTERVAL); + launcher.pause(executionId); + + Thread.sleep(SLEEP_INTERVAL); + long resumedId = launcher.resume(executionId); + assertEquals("Picked up the same execution after pause and resume", executionId, resumedId); + +// launcher.pause(executionId); +// Thread.sleep(SLEEP_INTERVAL); +// long resumeId2 = launcher.resume(executionId); +// assertEquals("Picked up the same execution after pause and resume", executionId, resumeId2); + + launcher.stop(executionId); + + } + /* * (non-Javadoc) *