From f107a77cda0102c6521f2785f473af9538ca2ea7 Mon Sep 17 00:00:00 2001 From: Kim In Hoi <31230862+hotire@users.noreply.github.com> Date: Wed, 19 Jan 2022 01:09:43 +0900 Subject: [PATCH] GH-254: Add RetryTemplBuilder.(not)RetryOn(List) Fixes https://github.com/spring-projects/spring-retry/issues/254 Add method with list parameter by overloading existed method --- .../retry/support/RetryTemplateBuilder.java | 49 ++++++++++++++++++- .../support/RetryTemplateBuilderTest.java | 12 ++++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java index dd5bdba..62ee2e4 100644 --- a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java +++ b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java @@ -82,6 +82,7 @@ import org.springframework.util.Assert; * * @author Aleksandr Shamukov * @author Artem Bilan + * @author Kim In Hoi * @since 1.3 */ public class RetryTemplateBuilder { @@ -276,7 +277,7 @@ public class RetryTemplateBuilder { *
* You should select the way you want to configure exception classifier: white list or * black list. If you choose white list - use this method, if black - use - * {@link #notRetryOn(Class)} + * {@link #notRetryOn(Class)} or {@link #notRetryOn(List)} * @param throwable to be retryable (with it's subclasses) * @return this * @see BinaryExceptionClassifierBuilder#retryOn @@ -295,7 +296,7 @@ public class RetryTemplateBuilder { *
* You should select the way you want to configure exception classifier: white list or * black list. If you choose black list - use this method, if white - use - * {@link #retryOn(Class)} + * {@link #retryOn(Class)} or {@link #retryOn(List)} * @param throwable to be not retryable (with it's subclasses) * @return this * @see BinaryExceptionClassifierBuilder#notRetryOn @@ -306,6 +307,50 @@ public class RetryTemplateBuilder { return this; } + /** + * Add all throwables to the while list of retryable exceptions. + *
+ * Warn: touching this method drops default {@code retryOn(Exception.class)} and you + * should configure whole classifier from scratch. + *
+ * You should select the way you want to configure exception classifier: white list or
+ * black list. If you choose white list - use this method, if black - use
+ * {@link #notRetryOn(Class)} or {@link #notRetryOn(List)}
+ * @param throwables to be retryable (with it's subclasses)
+ * @return this
+ * @since 1.3.2
+ * @see BinaryExceptionClassifierBuilder#retryOn
+ * @see BinaryExceptionClassifier
+ */
+ public RetryTemplateBuilder retryOn(List
+ * Warn: touching this method drops default {@code retryOn(Exception.class)} and you
+ * should configure whole classifier from scratch.
+ *
+ * You should select the way you want to configure exception classifier: white list or
+ * black list. If you choose black list - use this method, if white - use
+ * {@link #retryOn(Class)} or {@link #retryOn(List)}
+ * @param throwables to be not retryable (with it's subclasses)
+ * @return this
+ * @since 1.3.2
+ * @see BinaryExceptionClassifierBuilder#notRetryOn
+ * @see BinaryExceptionClassifier
+ */
+ public RetryTemplateBuilder notRetryOn(List{@code
diff --git a/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java b/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java
index f158f03..7033432 100644
--- a/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java
+++ b/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java
@@ -50,6 +50,7 @@ import static org.springframework.retry.util.test.TestUtils.getPropertyValue;
* follow project's style.
*
* @author Aleksandr Shamukov
+ * @author Kim In Hoi
*/
public class RetryTemplateBuilderTest {
@@ -77,13 +78,15 @@ public class RetryTemplateBuilderTest {
RetryListener listener2 = mock(RetryListener.class);
RetryTemplate template = RetryTemplate.builder().maxAttempts(10).exponentialBackoff(99, 1.5, 1717)
- .retryOn(IOException.class).traversingCauses().withListener(listener1)
+ .retryOn(IOException.class).retryOn(Collections.