/** * Check to make sure that ItemStreamException can be skipped. (see * BATCH-915) */ @Test public void testReadSkipItemStreamException() throws Exception { reader.setFailures("2"); reader.setExceptionType(ItemStreamException.class); Map<Class<? extends Throwable>, Boolean> map = new HashMap<>(); map.put(ItemStreamException.class, true); factory.setSkippableExceptionClasses(map); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(1, stepExecution.getSkipCount()); assertEquals(1, stepExecution.getReadSkipCount()); assertEquals(4, stepExecution.getReadCount()); assertEquals(0, stepExecution.getWriteSkipCount()); assertEquals(0, stepExecution.getRollbackCount()); // writer did not skip "2" as it never made it to writer, only "4" did assertTrue(reader.getRead().contains("4")); assertFalse(reader.getRead().contains("2")); List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,3,4,5")); assertEquals(expectedOutput, writer.getWritten()); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step .getName())); }
/** * Scenario: Exception in reader that should not cause rollback */ @Test public void testReaderDefaultNoRollbackOnCheckedException() throws Exception { reader.setItems("1", "2", "3", "4"); reader.setFailures("2", "3"); reader.setExceptionType(SkippableException.class); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(2, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getRollbackCount()); }
/** * Scenario: Exception in reader that should not cause rollback */ @SuppressWarnings("unchecked") @Test public void testReaderAttributesOverrideSkippableNoRollback() throws Exception { reader.setFailures("2", "3"); reader.setItems("1", "2", "3", "4"); reader.setExceptionType(SkippableException.class); // No skips by default factory.setSkippableExceptionClasses(getExceptionMap(RuntimeException.class)); // But this one is explicit in the tx-attrs so it should be skipped factory.setNoRollbackExceptionClasses(getExceptionList(SkippableException.class)); Step step = factory.getObject(); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals(0, stepExecution.getSkipCount()); assertEquals(0, stepExecution.getRollbackCount()); }