@Test public void testNotRethrownWithThreshold() throws Throwable { handler.setThresholds(Collections.<Class<? extends Throwable>, Integer> singletonMap(Exception.class, 1)); // No exception... handler.handleException(context, new RuntimeException("Foo")); AtomicInteger counter = (AtomicInteger) context.getAttribute(context.attributeNames()[0]); assertNotNull(counter); assertEquals(1, counter.get()); }
/** * Test method for * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} . */ public void testNoRethrowWhenRetryNotExhausted() throws Throwable { RetryPolicy retryPolicy = new AlwaysRetryPolicy(); RuntimeException ex = new RuntimeException("foo"); SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections .<Class<? extends Throwable>> singleton(Error.class)); // Then pretend to handle the exception in the parent context... handler.handleException(context.getParent(), ex); assertEquals(0, context.attributeNames().length); assertEquals(0, context.getParent().attributeNames().length); }
/** * Test method for * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} . */ public void testRethrowWhenFatal() throws Throwable { RetryPolicy retryPolicy = new AlwaysRetryPolicy(); RuntimeException ex = new RuntimeException("foo"); SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections .<Class<? extends Throwable>> singleton(RuntimeException.class)); // Then pretend to handle the exception in the parent context... try { handler.handleException(context.getParent(), ex); fail("Expected RuntimeException"); } catch (RuntimeException e) { assertEquals(ex, e); } assertEquals(0, context.attributeNames().length); // One for the counter in the delegate exception handler assertEquals(1, context.getParent().attributeNames().length); }
/** * Test method for * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} . */ public void testRethrowWhenRetryExhausted() throws Throwable { RetryPolicy retryPolicy = new NeverRetryPolicy(); RuntimeException ex = new RuntimeException("foo"); SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections .<Class<? extends Throwable>> singleton(Error.class)); // Then pretend to handle the exception in the parent context... try { handler.handleException(context.getParent(), ex); fail("Expected RuntimeException"); } catch (RuntimeException e) { assertEquals(ex, e); } assertEquals(0, context.attributeNames().length); // One for the retry exhausted flag and one for the counter in the // delegate exception handler assertEquals(2, context.getParent().attributeNames().length); }