RESOLVED - issue BATCH-1426: RetryTemplate calls BackOffPolicy even when retry will not occur.

This commit is contained in:
dsyer
2009-11-06 08:45:02 +00:00
parent f952924479
commit 05b5ac14cb
3 changed files with 14 additions and 15 deletions

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>

View File

@@ -245,15 +245,17 @@ public class RetryTemplate implements RetryOperations {
registerThrowable(retryPolicy, state, context, e);
try {
backOffPolicy.backOff(backOffContext);
}
catch (BackOffInterruptedException ex) {
lastException = e;
// back off was prevented by another thread - fail the
// retry
logger.debug("Abort retry because interrupted: count=" + context.getRetryCount());
throw ex;
if (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) {
try {
backOffPolicy.backOff(backOffContext);
}
catch (BackOffInterruptedException ex) {
lastException = e;
// back off was prevented by another thread - fail
// the retry
logger.debug("Abort retry because interrupted: count=" + context.getRetryCount());
throw ex;
}
}
logger.debug("Checking for rethrow: count=" + context.getRetryCount());

View File

@@ -18,7 +18,6 @@ package org.springframework.batch.retry.support;
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
@@ -273,7 +272,7 @@ public class RetryTemplateTests {
* re-thrown.
*/
@Test
public void testBackOffForRethrownException() throws Exception {
public void testNoBackOffForRethrownException() throws Exception {
RetryTemplate tested = new RetryTemplate();
tested.setRetryPolicy(new SimpleRetryPolicy(1, Collections.<Class<? extends Throwable>, Boolean> singletonMap(
@@ -285,8 +284,6 @@ public class RetryTemplateTests {
tested.setBackOffPolicy(bop);
expect(bop.start(isA(RetryContext.class))).andReturn(backOffContext);
bop.backOff(backOffContext);
expectLastCall().once();
replay(bop);
try {