BATCH-1298 & BATCH-1318: Added additional tests for exception classes
This commit is contained in:
@@ -50,6 +50,10 @@ public class ExceptionThrowingTaskletStub implements Tasklet {
|
||||
return committed;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
committed.clear();
|
||||
}
|
||||
|
||||
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
|
||||
committed.add(1);
|
||||
throw exception.newInstance("Expected exception");
|
||||
|
||||
@@ -189,6 +189,76 @@ public class FaultTolerantExceptionClassesTests {
|
||||
assertEquals("[]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackDefaultRollbackException() throws Exception {
|
||||
writer.setExceptionType(RuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackDefault");
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3]", writer.getWritten().toString());
|
||||
// TODO BATCH-1318: assertEquals("[]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackDefaultNoRollbackException() throws Exception {
|
||||
writer.setExceptionType(SkippableRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackDefault");
|
||||
// TODO BATCH-1318: assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3]", writer.getWritten().toString());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackSkippableRollbackException() throws Exception {
|
||||
writer.setExceptionType(SkippableRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackSkippable");
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
assertEquals("[1, 2, 3, 1, 2, 3, 4]", writer.getWritten().toString());
|
||||
assertEquals("[1, 2, 4]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackSkippableNoRollbackException() throws Exception {
|
||||
writer.setExceptionType(FatalRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackSkippable");
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
assertEquals("[1, 2, 3, 1, 2, 3, 4]", writer.getWritten().toString());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3, 1, 2, 3, 4]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackFatalRollbackException() throws Exception {
|
||||
writer.setExceptionType(SkippableRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackFatal");
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
assertEquals("[1, 2, 3]", writer.getWritten().toString());
|
||||
assertEquals("[]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackFatalNoRollbackException() throws Exception {
|
||||
writer.setExceptionType(FatalRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackFatal");
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3]", writer.getWritten().toString());
|
||||
// TODO BATCH-1318: assertEquals("[1, 2, 3]", writer.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackTaskletRollbackException() throws Exception {
|
||||
tasklet.setExceptionType(FatalRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackTasklet");
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
assertEquals("[]", tasklet.getCommitted().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRollbackTaskletNoRollbackException() throws Exception {
|
||||
tasklet.setExceptionType(SkippableRuntimeException.class);
|
||||
StepExecution stepExecution = launchStep("noRollbackTasklet");
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
// TODO BATCH-1298: assertEquals("[1]", tasklet.getCommitted().toString());
|
||||
}
|
||||
|
||||
private StepExecution launchStep(String stepName) throws JobExecutionAlreadyRunningException, JobRestartException,
|
||||
JobInstanceAlreadyCompleteException {
|
||||
SimpleJob job = new SimpleJob();
|
||||
|
||||
@@ -57,6 +57,7 @@ public class SkipProcessorStub<T> extends AbstractExceptionThrowingItemHandlerSt
|
||||
|
||||
public T process(T item) throws Exception {
|
||||
processed.add(item);
|
||||
committed.add(item);
|
||||
try {
|
||||
checkFailure(item);
|
||||
}
|
||||
@@ -68,7 +69,6 @@ public class SkipProcessorStub<T> extends AbstractExceptionThrowingItemHandlerSt
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
committed.add(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,8 @@ public class SkipReaderStub<T> extends AbstractExceptionThrowingItemHandlerStub<
|
||||
return null;
|
||||
}
|
||||
T item = items[counter];
|
||||
checkFailure(item);
|
||||
read.add(item);
|
||||
checkFailure(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ public class SkipWriterStub<T> extends AbstractExceptionThrowingItemHandlerStub<
|
||||
logger.debug("Writing: " + items);
|
||||
for (T item : items) {
|
||||
written.add(item);
|
||||
checkFailure(item);
|
||||
committed.add(item);
|
||||
checkFailure(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,20 +44,50 @@
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
<step id="noRollback" xmlns="http://www.springframework.org/schema/batch">
|
||||
<step id="noRollbackDefault" xmlns="http://www.springframework.org/schema/batch">
|
||||
<tasklet>
|
||||
<chunk reader="reader" writer="writer" commit-interval="4" skip-limit="1">
|
||||
<skippable-exception-classes>
|
||||
org.springframework.batch.core.step.item.FatalRuntimeException
|
||||
</skippable-exception-classes>
|
||||
</chunk>
|
||||
<no-rollback-exception-classes>
|
||||
org.springframework.batch.core.step.item.SkippableRuntimeException
|
||||
</no-rollback-exception-classes>
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
<step id="noRollbackSkippable" xmlns="http://www.springframework.org/schema/batch">
|
||||
<tasklet>
|
||||
<chunk reader="reader" writer="writer" commit-interval="4" skip-limit="1">
|
||||
<skippable-exception-classes>
|
||||
org.springframework.batch.core.step.item.SkippableRuntimeException
|
||||
org.springframework.batch.core.step.item.SkippableException
|
||||
org.springframework.batch.core.step.item.FatalRuntimeException
|
||||
org.springframework.batch.core.step.item.FatalException
|
||||
</skippable-exception-classes>
|
||||
</chunk>
|
||||
<no-rollback-exception-classes>
|
||||
org.springframework.batch.core.step.item.FatalRuntimeException
|
||||
</no-rollback-exception-classes>
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
<step id="noRollbackFatal" xmlns="http://www.springframework.org/schema/batch">
|
||||
<tasklet>
|
||||
<chunk reader="reader" writer="writer" commit-interval="4" skip-limit="1">
|
||||
<skippable-exception-classes>
|
||||
java.lang.Exception
|
||||
</skippable-exception-classes>
|
||||
<fatal-exception-classes>
|
||||
org.springframework.batch.core.step.item.SkippableRuntimeException
|
||||
org.springframework.batch.core.step.item.SkippableException
|
||||
org.springframework.batch.core.step.item.FatalRuntimeException
|
||||
org.springframework.batch.core.step.item.FatalException
|
||||
</fatal-exception-classes>
|
||||
</chunk>
|
||||
<no-rollback-exception-classes>
|
||||
org.springframework.batch.core.step.item.SkippableRuntimeException
|
||||
org.springframework.batch.core.step.item.FatalRuntimeException
|
||||
</no-rollback-exception-classes>
|
||||
</tasklet>
|
||||
</step>
|
||||
|
||||
Reference in New Issue
Block a user