From 05b5ac14cbd2f0bb7381eb7836587e84835d62d4 Mon Sep 17 00:00:00 2001 From: dsyer Date: Fri, 6 Nov 2009 08:45:02 +0000 Subject: [PATCH] RESOLVED - issue BATCH-1426: RetryTemplate calls BackOffPolicy even when retry will not occur. --- spring-batch-infrastructure-tests/.classpath | 4 ++-- .../batch/retry/support/RetryTemplate.java | 20 ++++++++++--------- .../retry/support/RetryTemplateTests.java | 5 +---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/spring-batch-infrastructure-tests/.classpath b/spring-batch-infrastructure-tests/.classpath index 96489ff1c..2daddec39 100644 --- a/spring-batch-infrastructure-tests/.classpath +++ b/spring-batch-infrastructure-tests/.classpath @@ -1,9 +1,9 @@ - + - + diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java index 8704ab760..2d5fc1714 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/support/RetryTemplate.java @@ -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()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java index 74b4ae1d3..d04105fdd 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/support/RetryTemplateTests.java @@ -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., 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 {