IN PROGRESS - issue BATCH-569: Add RetryOperationsInterceptor with stateful retry
Tidy up some TODOs
This commit is contained in:
@@ -106,8 +106,6 @@ public class FlatFileItemReaderAdvancedTests extends TestCase {
|
||||
// we should now process all records after first commit point
|
||||
assertEquals("[testLine3]", reader.read().toString());
|
||||
|
||||
// TODO update and assert ExecutionContext
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatException;
|
||||
import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
@@ -62,8 +63,12 @@ public class RepeatOperationsInterceptorTests extends TestCase {
|
||||
final List calls = new ArrayList();
|
||||
interceptor.setRepeatOperations(new RepeatOperations() {
|
||||
public ExitStatus iterate(RepeatCallback callback) {
|
||||
Object result = "1";
|
||||
try {
|
||||
Object result = callback.doInIteration(null);
|
||||
calls.add(result);
|
||||
} catch (Exception e) {
|
||||
throw new RepeatException("Encountered exception in repeat.", e);
|
||||
}
|
||||
return ExitStatus.CONTINUABLE;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -67,6 +67,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
TaskExecutorRepeatTemplate jobTemplate = new TaskExecutorRepeatTemplate();
|
||||
final RepeatTemplate stepTemplate = new RepeatTemplate();
|
||||
SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
|
||||
taskExecutor.setConcurrencyLimit(2);
|
||||
jobTemplate.setTaskExecutor(taskExecutor);
|
||||
|
||||
final String threadName = Thread.currentThread().getName();
|
||||
@@ -92,9 +93,9 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
// Thread.sleep(500);
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
// Because of the throttling and queueing internally to a TaskExecutor,
|
||||
// more than one thread will be used - the number used is (as of writing)
|
||||
// one less than the throttle limit of the template.
|
||||
// TODO: see if we can get it to use only one thread?
|
||||
// more than one thread will be used - the number used is the
|
||||
// concurrency limit in the task executor, plus 1.
|
||||
// System.err.println(threadNames);
|
||||
assertTrue(threadNames.size() >= 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,9 +262,6 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
// TODO parameter is rewritten and then compared to value it has
|
||||
// just been assigned
|
||||
context = RepeatSynchronizationManager.getContext();
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
return super.doInIteration(context);
|
||||
}
|
||||
@@ -307,9 +304,6 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
count++;
|
||||
// TODO parameter is rewritten and then compared to value it has
|
||||
// just been assigned
|
||||
context = RepeatSynchronizationManager.getContext();
|
||||
assertSame(context, RepeatSynchronizationManager.getContext());
|
||||
super.doInIteration(context);
|
||||
return ExitStatus.CONTINUABLE;
|
||||
|
||||
@@ -80,9 +80,6 @@ public class CompositeRetryPolicyTests extends TestCase {
|
||||
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() {
|
||||
public void close(RetryContext context) {
|
||||
list.add("1");
|
||||
// TODO: test that all close methods are called if this
|
||||
// happens...
|
||||
// throw new RuntimeException("Pah!");
|
||||
}
|
||||
}, new MockRetryPolicySupport() {
|
||||
public void close(RetryContext context) {
|
||||
@@ -95,6 +92,30 @@ public class CompositeRetryPolicyTests extends TestCase {
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
public void testExceptionOnPoliciesClose() throws Exception {
|
||||
final List list = new ArrayList();
|
||||
CompositeRetryPolicy policy = new CompositeRetryPolicy();
|
||||
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport() {
|
||||
public void close(RetryContext context) {
|
||||
list.add("1");
|
||||
throw new RuntimeException("Pah!");
|
||||
}
|
||||
}, new MockRetryPolicySupport() {
|
||||
public void close(RetryContext context) {
|
||||
list.add("2");
|
||||
}
|
||||
} });
|
||||
RetryContext context = policy.open(null, null);
|
||||
assertNotNull(context);
|
||||
try {
|
||||
policy.close(context);
|
||||
fail("Expected RuntimeException");
|
||||
} catch (RuntimeException e) {
|
||||
assertEquals("Pah!", e.getMessage());
|
||||
}
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
public void testRetryCount() throws Exception {
|
||||
CompositeRetryPolicy policy = new CompositeRetryPolicy();
|
||||
policy.setPolicies(new RetryPolicy[] { new MockRetryPolicySupport(), new MockRetryPolicySupport() });
|
||||
|
||||
Reference in New Issue
Block a user