OPEN - issue BATCH-1129: Problems with exception classifications
http://jira.springframework.org/browse/BATCH-1129
This commit is contained in:
@@ -5,6 +5,7 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -18,6 +19,8 @@ import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.PassThroughItemProcessor;
|
||||
import org.springframework.batch.retry.policy.NeverRetryPolicy;
|
||||
import org.springframework.batch.support.BinaryExceptionClassifier;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
|
||||
public class FaultTolerantChunkProcessorTests {
|
||||
|
||||
@@ -65,6 +68,21 @@ public class FaultTolerantChunkProcessorTests {
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformWithExceptionAndNoRollback() throws Exception {
|
||||
processor.setItemProcessor(new ItemProcessor<String, String>() {
|
||||
public String process(String item) throws Exception {
|
||||
if (item.equals("1")) throw new DataIntegrityViolationException("Planned");
|
||||
return item;
|
||||
}
|
||||
});
|
||||
processor.setProcessSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setRollbackClassifier(new BinaryExceptionClassifier(Collections.<Class<? extends Throwable>> singleton(DataIntegrityViolationException.class), false));
|
||||
Chunk<String> inputs = new Chunk<String>(Arrays.asList("1", "2"));
|
||||
processor.process(contribution, inputs);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterWrite() throws Exception {
|
||||
Chunk<String> chunk = new Chunk<String>(Arrays.asList("foo", "fail", "bar"));
|
||||
@@ -78,13 +96,15 @@ public class FaultTolerantChunkProcessorTests {
|
||||
try {
|
||||
processor.process(contribution, chunk);
|
||||
fail();
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("Planned failure!", e.getMessage());
|
||||
}
|
||||
try {
|
||||
processor.process(contribution, chunk);
|
||||
fail();
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("Planned failure!", e.getMessage());
|
||||
}
|
||||
assertEquals(2, chunk.getItems().size());
|
||||
@@ -120,7 +140,8 @@ public class FaultTolerantChunkProcessorTests {
|
||||
try {
|
||||
processor.process(contribution, chunk);
|
||||
fail();
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("Planned failure!", e.getMessage());
|
||||
}
|
||||
processor.process(contribution, chunk);
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.batch.core.step.tasklet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -298,7 +301,7 @@ public class TaskletStepTests {
|
||||
step.execute(stepExecution);
|
||||
|
||||
// context saved before looping and updated once for every processing
|
||||
// loop (once in this case)
|
||||
// loop (once in this case)
|
||||
assertEquals(3, list.size());
|
||||
}
|
||||
|
||||
@@ -543,8 +546,8 @@ public class TaskletStepTests {
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.STOPPED, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertTrue("Message does not contain 'JobInterruptedException': " + msg, contains(msg,
|
||||
"JobInterruptedException"));
|
||||
assertTrue("Message does not contain 'JobInterruptedException': " + msg, msg
|
||||
.contains("JobInterruptedException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -619,7 +622,7 @@ public class TaskletStepTests {
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.UNKNOWN, stepExecution.getStatus());
|
||||
String msg = stepExecution.getExitStatus().getExitDescription();
|
||||
assertTrue("Message does not contain ResetFailedException: " + msg, contains(msg, "ResetFailedException"));
|
||||
assertTrue("Message does not contain ResetFailedException: " + msg, msg.contains("ResetFailedException"));
|
||||
// The original rollback was caused by this one:
|
||||
assertEquals("Bar", stepExecution.getFailureExceptions().get(0).getCause().getMessage());
|
||||
}
|
||||
@@ -767,28 +770,6 @@ public class TaskletStepTests {
|
||||
|
||||
}
|
||||
|
||||
// This doesn't make sense for concurrent tasklet execution scenario.
|
||||
// @Test
|
||||
// public void testModifyingExecutionContextMidProcessCausesException() throws Exception {
|
||||
// StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
// final ExecutionContext ec = stepExecution.getExecutionContext();
|
||||
// step.setTasklet(new Tasklet() {
|
||||
// public RepeatStatus execute(StepContribution contribution, AttributeAccessor attributes) throws Exception {
|
||||
// ec.putString("test", "test");
|
||||
// return RepeatStatus.FINISHED;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// step.execute(stepExecution);
|
||||
// assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// assertEquals(1, stepExecution.getFailureExceptions().size());
|
||||
// assertTrue(stepExecution.getFailureExceptions().get(0) instanceof IllegalStateException);
|
||||
// }
|
||||
|
||||
private boolean contains(String str, String searchStr) {
|
||||
return str.indexOf(searchStr) != -1;
|
||||
}
|
||||
|
||||
private static class JobRepositoryStub extends JobRepositorySupport {
|
||||
|
||||
private int updateCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user