BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy); batchRetryTemplate.setRetryPolicy(retryPolicyWrapper); batchRetryTemplate.setRetryContextCache(retryContextCache); batchRetryTemplate.setListeners(retryListeners.toArray(new RetryListener[0]));
@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)); }
batchRetryTemplate.execute(retryCallback, batchRecoveryCallback, BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier)); batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs, rollbackClassifier)); if (!batchRetryTemplate.canRetry(context)) {
batchRetryTemplate.execute(retryCallback, recoveryCallback);
@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); }
@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()); }
batchRetryTemplate.execute(retryCallback, batchRecoveryCallback, BatchRetryTemplate.createState( getInputKeys(inputs), rollbackClassifier)); batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs, rollbackClassifier));
@Test // BATCH-2663 public void testFilterCountOnSkipInWriteWithRetry() throws Exception { SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(3); batchRetryTemplate.setRetryPolicy(retryPolicy); processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy()); processor.setItemProcessor(new ItemProcessor<String, String>() { @Override public String process(String item) throws Exception { if (item.equals("1")) { return null; } return item; } }); Chunk<String> inputs = new Chunk<>(Arrays.asList("fail", "1", "2")); processAndExpectPlannedRuntimeException(inputs); // (first attempt) Process fail, 1, 2 // item 1 is filtered out so it is removed from the chunk => now inputs = [fail, 2] processAndExpectPlannedRuntimeException(inputs); // (first retry) Process fail, 2 processAndExpectPlannedRuntimeException(inputs); // (second retry) Process fail, 2 // retry exhausted (maxAttempts = 3) => now scanning processAndExpectPlannedRuntimeException(inputs); // (scanning) Process fail processor.process(contribution, inputs); // (scanning) Process 2 assertEquals(1, list.size()); assertEquals("[2]", list.toString()); assertEquals(1, contribution.getWriteSkipCount()); assertEquals(3, contribution.getFilterCount()); }
return batchRetryTemplate.execute(retryCallback, recoveryCallback);
@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)); }
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(2); batchRetryTemplate.setRetryPolicy(retryPolicy); processor.setWriteSkipPolicy(new LimitCheckingItemSkipPolicy(1, Collections.<Class<? extends Throwable>, Boolean> singletonMap(
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy); batchRetryTemplate.setRetryPolicy(retryPolicyWrapper); batchRetryTemplate.setRetryContextCache(new MapRetryContextCache(cacheCapacity)); batchRetryTemplate.setRetryContextCache(retryContextCache); batchRetryTemplate.setListeners(retryListeners);
@Test public void testExhaustedRetryAfterShuffle() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true))); template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); fail("Expected RecoverableException"); template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); fail("Expected ExhaustedRetryException"); String[] result = template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); assertEquals("[d, c]", Arrays.toString(result)); template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); fail("Expected ExhaustedRetryException"); result = template.execute(retryCallback, BatchRetryTemplate.createState(outputs)); assertEquals("[e, f]", Arrays.toString(result));
batchRetryTemplate.execute(retryCallback, batchRecoveryCallback, BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier)); batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs, rollbackClassifier)); if (!batchRetryTemplate.canRetry(context)) {
return batchRetryTemplate.execute(retryCallback, recoveryCallback);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(2); batchRetryTemplate.setRetryPolicy(retryPolicy); processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy()); processor.setItemWriter(new ItemWriter<String>() {
BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate(); if (backOffPolicy != null) { batchRetryTemplate.setBackOffPolicy(backOffPolicy); batchRetryTemplate.setRetryPolicy(retryPolicyWrapper); batchRetryTemplate.setRetryContextCache(retryContextCache); batchRetryTemplate.setListeners(retryListeners.toArray(new RetryListener[0]));
@Test public void testExhaustedRetryWithRecovery() throws Exception { BatchRetryTemplate template = new BatchRetryTemplate(); template.setRetryPolicy(new SimpleRetryPolicy(1, Collections .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true))); template.execute(retryCallback, recoveryCallback, BatchRetryTemplate.createState(outputs)); fail("Expected RecoverableException"); String[] result = template.execute(retryCallback, recoveryCallback, BatchRetryTemplate.createState(outputs)); assertEquals("[r:b, r:c]", Arrays.toString(result));
batchRetryTemplate.execute(retryCallback, batchRecoveryCallback, BatchRetryTemplate.createState(getInputKeys(inputs), rollbackClassifier)); batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState(inputs, rollbackClassifier)); if (!batchRetryTemplate.canRetry(context)) {
O output = batchRetryTemplate.execute(retryCallback, recoveryCallback, new DefaultRetryState( getInputKey(item), rollbackClassifier)); if (output != null) {