BATCH-1745: Added test to verify restart behavior
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
<<<<<<< HEAD
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
=======
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -8,15 +25,51 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
//@Ignore
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class TaskletStepAllowStartIfCompleteTest {
|
||||
|
||||
<<<<<<< HEAD
|
||||
@Autowired
|
||||
Job job;
|
||||
|
||||
@Autowired
|
||||
JobRepository jobRepository;
|
||||
|
||||
@Resource
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
//retrieve the step from the context and see that it's allow is set
|
||||
AbstractStep abstractStep = (AbstractStep) context.getBean("simpleJob.step1");
|
||||
assertTrue(abstractStep.isAllowStartIfComplete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
JobParametersBuilder paramBuilder = new JobParametersBuilder();
|
||||
paramBuilder.addDate("value", new Date());
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), paramBuilder.toJobParameters());
|
||||
|
||||
job.execute(jobExecution);
|
||||
|
||||
jobExecution = jobRepository.createJobExecution(job.getName(), paramBuilder.toJobParameters());
|
||||
job.execute(jobExecution);
|
||||
|
||||
int count = jobRepository.getStepExecutionCount(jobExecution.getJobInstance(), "simpleJob.step1");
|
||||
assertEquals(2, count);
|
||||
}
|
||||
=======
|
||||
@Resource
|
||||
private ApplicationContext context;
|
||||
|
||||
@@ -27,4 +80,5 @@ public class TaskletStepAllowStartIfCompleteTest {
|
||||
assertTrue(abstractStep.isAllowStartIfComplete());
|
||||
}
|
||||
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@
|
||||
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"/>
|
||||
|
||||
<batch:job id="simpleJob">
|
||||
<<<<<<< HEAD
|
||||
<batch:step id="simpleJob.step1" allow-start-if-complete="true" next="simpleJob.step2">
|
||||
=======
|
||||
<batch:step id="simpleJob.step1" allow-start-if-complete="true">
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
<batch:tasklet>
|
||||
<bean class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
|
||||
<property name="targetObject">
|
||||
@@ -20,6 +24,21 @@
|
||||
</bean>
|
||||
</batch:tasklet>
|
||||
</batch:step>
|
||||
<<<<<<< HEAD
|
||||
<batch:step id="simpleJob.step2">
|
||||
<batch:tasklet>
|
||||
<bean class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter">
|
||||
<property name="targetObject">
|
||||
<bean class="java.lang.String" scope="step">
|
||||
<constructor-arg value="#{jobParameters['value']}"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="targetMethod" value="length"/>
|
||||
</bean>
|
||||
</batch:tasklet>
|
||||
</batch:step>
|
||||
=======
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
</batch:job>
|
||||
|
||||
<bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
|
||||
@@ -27,7 +46,11 @@
|
||||
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
|
||||
<property name="jobRegistry" ref="jobRegistry"/>
|
||||
</bean>
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
|
||||
>>>>>>> a9edfc18765552d54ac46f721d128260ceaf1e72
|
||||
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user