BATCH-604:JdbcStepExecutionDao will now deserialize object correctly.

This commit is contained in:
lucasward
2008-04-25 20:13:31 +00:00
parent 0113be7585
commit 66e91b0dbe
4 changed files with 54 additions and 7 deletions

View File

@@ -107,7 +107,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
executionContext.putDouble(key, rs.getDouble("DOUBLE_VAL"));
}
else if (type == AttributeType.OBJECT) {
executionContext.put(key, rs.getObject("OBJECT_VAL"));
executionContext.put(key, SerializationUtils.deserialize(rs.getBinaryStream("OBJECT_VAL")));
}
else {
throw new UnexpectedJobExecutionException("Invalid type found: [" + typeCd

View File

@@ -201,5 +201,15 @@ 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.saveOrUpdateExecutionContext(stepExecution);
ExecutionContext restoredEc = dao.findExecutionContext(stepExecution);
assertEquals(ec, restoredEc);
}
}

View File

@@ -17,5 +17,5 @@ public class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
protected String[] getConfigLocations() {
return new String[] { "sql-dao-test.xml" };
}
}

View File

@@ -134,14 +134,14 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
public void testSkipAndRetry() throws Exception {
factory.setSkippableExceptionClasses(new Class[] {Exception.class});
factory.setSkipLimit(1);
factory.setSkipLimit(2);
List items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(new String[] { "a", "b", "c" }));
items.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e", "f" }));
ItemReader provider = new ListItemReader(items) {
public Object read() {
Object item = super.read();
count++;
if ("b".equals(item)) {
if ("b".equals(item) || "d".equals(item)) {
throw new RuntimeException("Read error - planned but skippable.");
}
return item;
@@ -154,8 +154,45 @@ public class StatefulRetryStepFactoryBeanTests extends TestCase {
StepExecution stepExecution = new StepExecution(step, jobExecution);
step.execute(stepExecution);
assertEquals(1, stepExecution.getSkipCount());
assertEquals(2, stepExecution.getSkipCount());
// b is processed once and skipped, plus 1, plus c, plus the null at end
assertEquals(4, count);
assertEquals(7, count);
}
//The following test fails due to current expected behavior of retry
//that will be addressed in 1.1
// public void testSkipAndRetryWithWriteFailure() throws Exception {
//
// factory.setSkippableExceptionClasses(new Class[] {RetryException.class});
// factory.setSkipLimit(2);
// List items = TransactionAwareProxyFactory.createTransactionalList();
// items.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e", "f" }));
// ItemReader provider = new ListItemReader(items) {
// public Object read() {
// Object item = super.read();
// System.out.print("Read Called! Item: [" + item + "]");
// count++;
// return item;
// }
// };
//
// ItemWriter itemWriter = new AbstractItemWriter(){
// public void write(Object item) throws Exception {
// System.out.print("Write Called! Item: [" + item + "]");
// if ("b".equals(item) || "d".equals(item)) {
// throw new RuntimeException("Read error - planned but skippable.");
// }
// }};
// factory.setItemReader(provider);
// factory.setItemWriter(itemWriter);
// factory.setRetryLimit(5);
// factory.setRetryableExceptionClasses(new Class[]{RuntimeException.class});
// AbstractStep step = (AbstractStep) factory.getObject();
// step.setName("mytest");
// StepExecution stepExecution = new StepExecution(step, jobExecution);
// step.execute(stepExecution);
//
// assertEquals(2, stepExecution.getSkipCount());
// assertEquals(9, count);
// }
}