BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy);
@Test public void testSuccessfulAttempt() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); String result = template.execute(new RetryCallback<String, Exception>() { @Override public String doWithRetry(RetryContext context) throws Exception { assertTrue("Wrong context type: " + context.getClass().getSimpleName(), context.getClass() .getSimpleName().contains("Batch")); return "2"; } }, Arrays.<RetryState> asList(new DefaultRetryState("1"))); assertEquals("2", result); }
@Test(expected = ExhaustedRetryException.class) public void testExhaustedRetry() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true))); RetryCallback<String[], Exception> retryCallback = new RetryCallback<String[], Exception>() { @Override public String[] doWithRetry(RetryContext context) throws Exception { if (count++ < 2) { throw new RecoverableException("Recoverable"); } return outputs.toArray(new String[0]); } }; outputs = Arrays.asList("a", "b"); try { template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); fail("Expected RecoverableException"); } catch (RecoverableException e) { assertEquals("Recoverable", e.getMessage()); } outputs = Arrays.asList("a", "c"); template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); }
@Test public void testUnSuccessfulAttemptAndRetry() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); RetryCallback<String[], Exception> retryCallback = new RetryCallback<String[], Exception>() { @Override public String[] doWithRetry(RetryContext context) throws Exception { assertEquals(count, context.getRetryCount()); if (count++ == 0) { throw new RecoverableException("Recoverable"); } return new String[] { "a", "b" }; } }; List<RetryState> states = Arrays.<RetryState> asList(new DefaultRetryState("1"), new DefaultRetryState("2")); try { template.execute(retryCallback, states); fail("Expected RecoverableException"); } catch (RecoverableException e) { assertEquals("Recoverable", e.getMessage()); } String[] result = template.execute(retryCallback, states); assertEquals("[a, b]", Arrays.toString(result)); }
@Test public void testExhaustedRetryWithRecovery() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
@Before public void setUp() { batchRetryTemplate = new BatchRetryTemplate(); processor = new FaultTolerantChunkProcessor<>( new PassThroughItemProcessor<>(), new ItemWriter<String>() { @Override public void write(List<? extends String> items) throws Exception { if (items.contains("fail")) { throw new RuntimeException("Planned failure!"); } list.addAll(items); } }, batchRetryTemplate); batchRetryTemplate.setRetryPolicy(new NeverRetryPolicy()); }
@Test public void testExhaustedRetryAfterShuffle() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy);
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy);
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy);
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy);