IN PROGRESS - BATCH-518: removed ExecutionContext-related methods from StepExecutionDao
This commit is contained in:
@@ -3,7 +3,6 @@ package org.springframework.batch.core.repository.dao;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
public interface StepExecutionDao {
|
||||
|
||||
@@ -27,22 +26,6 @@ public interface StepExecutionDao {
|
||||
*/
|
||||
void updateStepExecution(StepExecution stepExecution);
|
||||
|
||||
/**
|
||||
* Find all {@link ExecutionContext} for the given {@link StepExecution}.
|
||||
*
|
||||
* @throws IllegalArgumentException if the id is null.
|
||||
*/
|
||||
ExecutionContext findExecutionContext(StepExecution stepExecution);
|
||||
|
||||
/**
|
||||
* Save the {@link ExecutionContext} of the given {@link StepExecution}.
|
||||
*
|
||||
* @param stepExecution the {@link StepExecution} containing the
|
||||
* {@link ExecutionContext} to be saved.
|
||||
* @throws IllegalArgumentException if the attributes are null.
|
||||
*/
|
||||
void persistExecutionContext(StepExecution stepExecution);
|
||||
|
||||
StepExecution getStepExecution(JobExecution jobExecution, Step step);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
public abstract class AbstractExecutionContextDaoTests {
|
||||
@@ -13,7 +14,11 @@ public abstract class AbstractExecutionContextDaoTests {
|
||||
|
||||
private JobExecutionDao jobDao;
|
||||
|
||||
private StepExecutionDao stepDao;
|
||||
|
||||
private JobExecution execution;
|
||||
|
||||
private StepExecution stepExecution;
|
||||
|
||||
public void testSaveAndFindContext() {
|
||||
jobDao.saveJobExecution(execution);
|
||||
@@ -56,4 +61,57 @@ public abstract class AbstractExecutionContextDaoTests {
|
||||
assertEquals(ctx, retrieved);
|
||||
assertEquals(7, retrieved.getLong("longKey"));
|
||||
}
|
||||
|
||||
public void testSaveAndFindStepContext() {
|
||||
stepDao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext(new HashMap<String, Object>() {
|
||||
{
|
||||
put("key", "value");
|
||||
}
|
||||
});
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.getExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
}
|
||||
|
||||
public void testSaveAndFindEmptyStepContext() {
|
||||
stepDao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext();
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.getExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
}
|
||||
|
||||
public void testUpdateStepContext() {
|
||||
stepDao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext(new HashMap<String, Object>() {
|
||||
{
|
||||
put("key", "value");
|
||||
}
|
||||
});
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ctx.putLong("longKey", 7);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.getExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
assertEquals(7, retrieved.getLong("longKey"));
|
||||
}
|
||||
|
||||
public void testStoreInteger(){
|
||||
stepDao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ec = new ExecutionContext();
|
||||
ec.put("intValue", new Integer(343232));
|
||||
stepExecution.setExecutionContext(ec);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext restoredEc = dao.getExecutionContext(stepExecution);
|
||||
assertEquals(ec, restoredEc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
protected StepExecutionDao stepExecutionDao;
|
||||
|
||||
protected JobExecutionDao jobExecutionDao;
|
||||
|
||||
protected ExecutionContextDao ecDao;
|
||||
|
||||
protected JobInstance jobInstance;
|
||||
|
||||
@@ -74,6 +76,10 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
public void setJobExecutionDao(JobExecutionDao jobExecutionDao) {
|
||||
this.jobExecutionDao = jobExecutionDao;
|
||||
}
|
||||
|
||||
public void setExecutionContextDao(ExecutionContextDao ecDao) {
|
||||
this.ecDao = ecDao;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -117,8 +123,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
|
||||
public void testUpdateStepWithExecutionContext() {
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
stepExecutionDao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext tempAttributes = stepExecutionDao.findExecutionContext(stepExecution);
|
||||
ecDao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext tempAttributes = ecDao.getExecutionContext(stepExecution);
|
||||
assertEquals(executionContext, tempAttributes);
|
||||
}
|
||||
|
||||
@@ -141,7 +147,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
execution.setExecutionContext(executionContext);
|
||||
execution.setExitStatus(ExitStatus.FAILED.addExitDescription("java.lang.Exception"));
|
||||
stepExecutionDao.saveStepExecution(execution);
|
||||
stepExecutionDao.persistExecutionContext(execution);
|
||||
ecDao.persistExecutionContext(execution);
|
||||
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
|
||||
assertNotNull(retrievedExecution);
|
||||
assertEquals(execution, retrievedExecution);
|
||||
@@ -202,15 +208,15 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
public void testSaveExecutionContext(){
|
||||
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
stepExecutionDao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext attributes = stepExecutionDao.findExecutionContext(stepExecution);
|
||||
ecDao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext attributes = ecDao.getExecutionContext(stepExecution);
|
||||
assertEquals(executionContext, attributes);
|
||||
executionContext.putString("newString", "newString");
|
||||
executionContext.putLong("newLong", 1);
|
||||
executionContext.putDouble("newDouble", 2.5);
|
||||
executionContext.put("newSerializable", "serializableValue");
|
||||
stepExecutionDao.persistExecutionContext(stepExecution);
|
||||
attributes = stepExecutionDao.findExecutionContext(stepExecution);
|
||||
ecDao.persistExecutionContext(stepExecution);
|
||||
attributes = ecDao.getExecutionContext(stepExecution);
|
||||
assertEquals(executionContext, attributes);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
@@ -27,7 +25,6 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.StepSupport;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
@@ -148,48 +145,6 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
assertEquals(BatchStatus.STOPPED, retrieved.getStatus());
|
||||
}
|
||||
|
||||
public void testSaveAndFindContext() {
|
||||
dao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext(new HashMap<String, Object>() {
|
||||
{
|
||||
put("key", "value");
|
||||
}
|
||||
});
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.findExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
}
|
||||
|
||||
public void testSaveAndFindEmptyContext() {
|
||||
dao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext();
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.findExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
}
|
||||
|
||||
public void testUpdateContext() {
|
||||
dao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ctx = new ExecutionContext(new HashMap<String, Object>() {
|
||||
{
|
||||
put("key", "value");
|
||||
}
|
||||
});
|
||||
stepExecution.setExecutionContext(ctx);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ctx.putLong("longKey", 7);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
|
||||
ExecutionContext retrieved = dao.findExecutionContext(stepExecution);
|
||||
assertEquals(ctx, retrieved);
|
||||
assertEquals(7, retrieved.getLong("longKey"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception should be raised when the version of update argument doesn't
|
||||
* match the version of persisted entity.
|
||||
@@ -219,15 +174,5 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testStoreInteger(){
|
||||
dao.saveStepExecution(stepExecution);
|
||||
ExecutionContext ec = new ExecutionContext();
|
||||
ec.put("intValue", new Integer(343232));
|
||||
stepExecution.setExecutionContext(ec);
|
||||
dao.persistExecutionContext(stepExecution);
|
||||
ExecutionContext restoredEc = dao.findExecutionContext(stepExecution);
|
||||
assertEquals(ec, restoredEc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user