BATCH-1298 & BATCH-1318: Added additional tests for exception classes

This commit is contained in:
dhgarrette
2009-07-06 06:32:38 +00:00
parent 9e65f9819a
commit 3e0b8a72c8
6 changed files with 109 additions and 5 deletions

View File

@@ -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");

View File

@@ -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();

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}