RESOLVED - BATCH-954: Failure on job stop
check version before synchronizing JobExecution.status. If versions do not match synchronize both status and version.
This commit is contained in:
@@ -438,6 +438,7 @@ public class SimpleJobTests {
|
||||
|
||||
job.setSteps(Arrays.asList(new Step[] { step1, step2 }));
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
assertEquals(1, jobExecution.getAllFailureExceptions().size());
|
||||
Throwable expected = jobExecution.getAllFailureExceptions().get(0);
|
||||
assertTrue("Wrong exception " + expected, expected instanceof JobInterruptedException);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
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.partition.PartitionHandler;
|
||||
@@ -34,19 +35,21 @@ import org.springframework.batch.core.repository.support.MapJobRepositoryFactory
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PartitionStepTests {
|
||||
|
||||
|
||||
private PartitionStep step = new PartitionStep();
|
||||
|
||||
private Step remote = new StepSupport("remote");
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MapJobRepositoryFactoryBean.clear();
|
||||
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
|
||||
factory.setTransactionManager(new ResourcelessTransactionManager());
|
||||
jobRepository = (JobRepository) factory.getObject();
|
||||
@@ -68,7 +71,8 @@ public class PartitionStepTests {
|
||||
}
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
StepExecution stepExecution = new JobExecution(0L).createStepExecution("foo");
|
||||
JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters());
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// one master and two workers
|
||||
@@ -91,7 +95,8 @@ public class PartitionStepTests {
|
||||
}
|
||||
});
|
||||
step.afterPropertiesSet();
|
||||
StepExecution stepExecution = new JobExecution(0L).createStepExecution("foo");
|
||||
JobExecution jobExecution = jobRepository.createJobExecution("vanillaJob", new JobParameters());
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("foo");
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// one master and two workers
|
||||
|
||||
@@ -22,12 +22,13 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public abstract class AbstractJobExecutionDaoTests extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
|
||||
protected JobExecutionDao dao;
|
||||
|
||||
protected JobInstance jobInstance = new JobInstance((long) 1, new JobParameters(), "execTestJob");
|
||||
protected JobInstance jobInstance = new JobInstance(1L, new JobParameters(), "execTestJob");
|
||||
|
||||
protected JobExecution execution = new JobExecution(jobInstance);
|
||||
|
||||
@@ -248,7 +249,7 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.incrementVersion();
|
||||
@@ -266,7 +267,31 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
// expected
|
||||
}
|
||||
|
||||
} /*
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSynchronizeStatus() {
|
||||
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
exec1.setStatus(BatchStatus.STARTED);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
Assert.state(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.setVersion(7);
|
||||
Assert.state(exec1.getVersion() != exec2.getVersion());
|
||||
Assert.state(exec1.getStatus() != exec2.getStatus());
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
assertEquals(exec1.getVersion(), exec2.getVersion());
|
||||
assertEquals(exec1.getStatus(), exec2.getStatus());
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure the executions are equal. Normally, comparing the id's
|
||||
* is sufficient. However, for testing purposes, especially of a DAO, we
|
||||
* need to make sure all the fields are being stored/retrieved correctly.
|
||||
|
||||
@@ -44,6 +44,7 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
|
||||
dao.saveJobExecution(execution);
|
||||
execution.setStatus(BatchStatus.COMPLETED);
|
||||
execution.incrementVersion();
|
||||
dao.synchronizeStatus(execution);
|
||||
assertEquals(BatchStatus.STARTING, execution.getStatus());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user