OPEN - issue BATCH-833: TransactionAttributes swallows Exceptions
http://jira.springframework.org/browse/BATCH-833 Moved TransactionAttributes check into chunk, in order to be consistent with chunk size.
This commit is contained in:
@@ -286,37 +286,9 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
|
||||
// Attempt to flush before the step execution and stream
|
||||
// state are updated
|
||||
try {
|
||||
itemHandler.flush();
|
||||
}
|
||||
catch (Error e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
nonRollbackException = e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
nonRollbackException = e;
|
||||
}
|
||||
itemHandler.flush();
|
||||
|
||||
try {
|
||||
stream.update(stepExecution.getExecutionContext());
|
||||
}
|
||||
catch (Error e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
nonRollbackException = e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
nonRollbackException = e;
|
||||
}
|
||||
stream.update(stepExecution.getExecutionContext());
|
||||
|
||||
try {
|
||||
getJobRepository().saveOrUpdateExecutionContext(stepExecution);
|
||||
@@ -408,7 +380,22 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
}
|
||||
// check for interruption before each item as well
|
||||
interruptionPolicy.checkInterrupted(execution);
|
||||
ExitStatus exitStatus = itemHandler.handle(contribution);
|
||||
ExitStatus exitStatus = ExitStatus.FINISHED;
|
||||
|
||||
try{
|
||||
exitStatus = itemHandler.handle(contribution);
|
||||
}
|
||||
catch (Error e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (transactionAttribute.rollbackOn(e)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// check for interruption after each item as well
|
||||
interruptionPolicy.checkInterrupted(execution);
|
||||
return exitStatus;
|
||||
|
||||
@@ -841,35 +841,6 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testNoRollbackOnHandlerException() throws Exception{
|
||||
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
ItemReader itemReader = new AbstractItemReader() {
|
||||
public Object read() throws Exception {
|
||||
// Trigger a rollback
|
||||
throw exception;
|
||||
}
|
||||
};
|
||||
itemOrientedStep.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
|
||||
itemOrientedStep.setTransactionAttribute(new NeverRollbackTransactionAttribute());
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
// step.setLastExecution(stepExecution);
|
||||
|
||||
try {
|
||||
itemOrientedStep.execute(stepExecution);
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// The original rollback was caused by this one:
|
||||
assertSame(exception, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoRollbackOnFlushException() throws Exception{
|
||||
|
||||
final RuntimeException exception = new RuntimeException();
|
||||
|
||||
Reference in New Issue
Block a user