OPEN - issue BATCH-486: Users must choose between skip and retry
This commit is contained in:
@@ -16,21 +16,11 @@
|
||||
|
||||
package org.springframework.batch.retry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemKeyGenerator;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
|
||||
public class ListItemReaderRecoverer extends ListItemReader implements ItemRecoverer, ItemKeyGenerator {
|
||||
public class StubItemKeyGeneratorRecoverer implements ItemRecoverer, ItemKeyGenerator {
|
||||
|
||||
/**
|
||||
* Delegate to super class constructor.
|
||||
* @param list
|
||||
*/
|
||||
public ListItemReaderRecoverer(List list) {
|
||||
super(list);
|
||||
}
|
||||
/**
|
||||
* Do nothing. Subclassses should override to implement recovery behaviour.
|
||||
*
|
||||
@@ -17,13 +17,12 @@
|
||||
package org.springframework.batch.retry.callback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.AbstractItemWriter;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.StubItemKeyGeneratorRecoverer;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryException;
|
||||
import org.springframework.batch.retry.TerminatedRetryException;
|
||||
@@ -39,7 +38,7 @@ public class ItemWriterRetryCallbackTests extends TestCase {
|
||||
|
||||
RetryTemplate template;
|
||||
|
||||
ListItemReaderRecoverer provider;
|
||||
StubItemKeyGeneratorRecoverer recoverer;
|
||||
|
||||
ItemWriterRetryCallback callback;
|
||||
|
||||
@@ -48,7 +47,7 @@ public class ItemWriterRetryCallbackTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
template = new RetryTemplate();
|
||||
provider = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo" })) {
|
||||
recoverer = new StubItemKeyGeneratorRecoverer() {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
calls.add(data);
|
||||
@@ -144,12 +143,12 @@ public class ItemWriterRetryCallbackTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testGetKey() throws Exception {
|
||||
callback.setKeyGenerator(provider);
|
||||
callback.setKeyGenerator(recoverer);
|
||||
assertEquals("key0", callback.getKeyGenerator().getKey("foo"));
|
||||
}
|
||||
|
||||
public void testRecoverWithoutSession() throws Exception {
|
||||
provider.recover("foo", null);
|
||||
recoverer.recover("foo", null);
|
||||
assertEquals(1, count);
|
||||
assertEquals(1, calls.size());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.batch.retry.policy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,9 +29,9 @@ import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.StubItemKeyGeneratorRecoverer;
|
||||
import org.springframework.batch.retry.callback.ItemWriterRetryCallback;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
@@ -41,7 +40,7 @@ public class ItemWriterRetryPolicyTests extends TestCase {
|
||||
|
||||
private ItemWriterRetryPolicy policy = new ItemWriterRetryPolicy();
|
||||
|
||||
private ListItemReaderRecoverer reader;
|
||||
private StubItemKeyGeneratorRecoverer recoverer;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -57,7 +56,7 @@ public class ItemWriterRetryPolicyTests extends TestCase {
|
||||
super.setUp();
|
||||
// The list simulates a failed delivery, redelivery of the same message,
|
||||
// then a new message...
|
||||
reader = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
recoverer = new StubItemKeyGeneratorRecoverer() {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -168,7 +167,7 @@ public class ItemWriterRetryPolicyTests extends TestCase {
|
||||
public void write(Object data) {
|
||||
}
|
||||
});
|
||||
callback.setRecoverer(reader);
|
||||
callback.setRecoverer(recoverer);
|
||||
RetryContext context = policy.open(callback, null);
|
||||
assertNotNull(context);
|
||||
assertTrue(policy.canRetry(context));
|
||||
@@ -210,7 +209,7 @@ public class ItemWriterRetryPolicyTests extends TestCase {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
});
|
||||
callback.setRecoverer(reader);
|
||||
callback.setRecoverer(recoverer);
|
||||
RetryTemplate template = new RetryTemplate();
|
||||
template.setRetryPolicy(policy);
|
||||
Object result = null;
|
||||
|
||||
Reference in New Issue
Block a user