OPEN - BATCH-990: Implement and test synchronizeStatus() in MapJobExecutionDao
use upgradeStatus(..) instead of setStatus(..) in synchronizeStatus()
This commit is contained in:
@@ -269,28 +269,59 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Successful synchronization from STARTED to STOPPING status.
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSynchronizeStatus() {
|
||||
public void testSynchronizeStatusUpgrade() {
|
||||
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
exec1.setStatus(BatchStatus.STARTED);
|
||||
exec1.setStatus(BatchStatus.STOPPING);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
Assert.state(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
|
||||
exec2.setStatus(BatchStatus.STARTED);
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* UNKNOWN status won't be changed by synchronizeStatus, because it is the
|
||||
* 'largest' BatchStatus (will not downgrade).
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSynchronizeStatusDowngrade() {
|
||||
|
||||
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.setStatus(BatchStatus.UNKNOWN);
|
||||
exec2.setVersion(7);
|
||||
Assert.state(exec1.getVersion() != exec2.getVersion());
|
||||
Assert.state(exec1.getStatus().isLessThan(exec2.getStatus()));
|
||||
|
||||
dao.synchronizeStatus(exec2);
|
||||
|
||||
assertEquals(exec1.getVersion(), exec2.getVersion());
|
||||
assertEquals(BatchStatus.UNKNOWN, 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
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "sql-dao-test.xml" })
|
||||
@@ -38,14 +34,4 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
return stepExecutionDao;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testUpdateExecutionStatus(){
|
||||
|
||||
dao.saveJobExecution(execution);
|
||||
execution.setStatus(BatchStatus.COMPLETED);
|
||||
execution.incrementVersion();
|
||||
dao.synchronizeStatus(execution);
|
||||
assertEquals(BatchStatus.STARTING, execution.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user