diff --git a/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java b/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java index 54ca49f..2e16608 100644 --- a/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java +++ b/src/main/java/org/springframework/classify/BinaryExceptionClassifier.java @@ -36,11 +36,11 @@ public class BinaryExceptionClassifier extends SubclassClassifier, Boolean>singletonMap(Exception.class, true), diff --git a/src/main/java/org/springframework/retry/RecoveryCallback.java b/src/main/java/org/springframework/retry/RecoveryCallback.java index b55e798..8dccd98 100644 --- a/src/main/java/org/springframework/retry/RecoveryCallback.java +++ b/src/main/java/org/springframework/retry/RecoveryCallback.java @@ -19,6 +19,7 @@ package org.springframework.retry; * Callback for stateful retry after all tries are exhausted. * * @author Dave Syer + * @param the type that is returned from the recovery * @since 1.1 */ public interface RecoveryCallback { diff --git a/src/main/java/org/springframework/retry/RetryOperations.java b/src/main/java/org/springframework/retry/RetryOperations.java index a620081..f0daba1 100644 --- a/src/main/java/org/springframework/retry/RetryOperations.java +++ b/src/main/java/org/springframework/retry/RetryOperations.java @@ -30,27 +30,26 @@ public interface RetryOperations { /** * Execute the supplied {@link RetryCallback} with the configured retry semantics. See * implementations for configuration details. + * @param the return value + * @param retryCallback the {@link RetryCallback} + * @param the exception to throw * @return the value returned by the {@link RetryCallback} upon successful invocation. * @throws E any {@link Exception} raised by the {@link RetryCallback} upon * unsuccessful retry. * @throws E the exception thrown - * @param the return value - * @param retryCallback the {@link RetryCallback} - * @param the exception to throw */ T execute(RetryCallback retryCallback) throws E; /** * Execute the supplied {@link RetryCallback} with a fallback on exhausted retry to * the {@link RecoveryCallback}. See implementations for configuration details. - * @return the value returned by the {@link RetryCallback} upon successful invocation, - * and that returned by the {@link RecoveryCallback} otherwise. - * @throws E any {@link Exception} raised by the - * @param the type to return - * @param the type of the exception * @param recoveryCallback the {@link RecoveryCallback} * @param retryCallback the {@link RetryCallback} {@link RecoveryCallback} upon - * unsuccessful retry. + * @param the type to return + * @param the type of the exception + * @return the value returned by the {@link RetryCallback} upon successful invocation, + * and that returned by the {@link RecoveryCallback} otherwise. + * @throws E any {@link Exception} raised by the unsuccessful retry. */ T execute(RetryCallback retryCallback, RecoveryCallback recoveryCallback) throws E; @@ -66,13 +65,13 @@ public interface RetryOperations { * See implementations for configuration details. * @param retryCallback the {@link RetryCallback} * @param retryState the {@link RetryState} + * @param the type of the return value + * @param the type of the exception to return * @return the value returned by the {@link RetryCallback} upon successful invocation, * and that returned by the {@link RecoveryCallback} otherwise. * @throws E any {@link Exception} raised by the {@link RecoveryCallback}. * @throws ExhaustedRetryException if the last attempt for this state has already been * reached - * @param the type of the return value - * @param the type of the exception to return */ T execute(RetryCallback retryCallback, RetryState retryState) throws E, ExhaustedRetryException; @@ -84,9 +83,9 @@ public interface RetryOperations { * @param recoveryCallback the {@link RecoveryCallback} * @param retryState the {@link RetryState} * @param retryCallback the {@link RetryCallback} - * @see #execute(RetryCallback, RetryState) * @param the return value type * @param the exception type + * @see #execute(RetryCallback, RetryState) * @return the value returned by the {@link RetryCallback} upon successful invocation, * and that returned by the {@link RecoveryCallback} otherwise. * @throws E any {@link Exception} raised by the {@link RecoveryCallback} upon diff --git a/src/main/java/org/springframework/retry/policy/MaxAttemptsRetryPolicy.java b/src/main/java/org/springframework/retry/policy/MaxAttemptsRetryPolicy.java index 8a6f85d..5a7c6a4 100644 --- a/src/main/java/org/springframework/retry/policy/MaxAttemptsRetryPolicy.java +++ b/src/main/java/org/springframework/retry/policy/MaxAttemptsRetryPolicy.java @@ -28,7 +28,7 @@ import org.springframework.retry.support.RetryTemplate; * It is not recommended to use it directly, because usually exception classification is * strongly recommended (to not retry on OutOfMemoryError, for example). *

- * For daily usage see {@link RetryTemplate#newBuilder()} + * For daily usage see {@link RetryTemplate#builder()} *

* Volatility of maxAttempts allows concurrent modification and does not require safe * publication of new instance after construction. @@ -44,8 +44,8 @@ public class MaxAttemptsRetryPolicy implements RetryPolicy { private volatile int maxAttempts; /** - * Create a {@link MaxAttemptsRetryPolicy} with the default number of retry attempts, - * retrying all throwables. + * Create a {@link MaxAttemptsRetryPolicy} with the default number of retry attempts + * (3), retrying all throwables. */ public MaxAttemptsRetryPolicy() { this.maxAttempts = DEFAULT_MAX_ATTEMPTS; @@ -54,6 +54,7 @@ public class MaxAttemptsRetryPolicy implements RetryPolicy { /** * Create a {@link MaxAttemptsRetryPolicy} with the specified number of retry * attempts, retrying all throwables. + * @param maxAttempts the maximum number of attempts */ public MaxAttemptsRetryPolicy(int maxAttempts) { this.maxAttempts = maxAttempts; @@ -86,7 +87,7 @@ public class MaxAttemptsRetryPolicy implements RetryPolicy { */ @Override public boolean canRetry(RetryContext context) { - return context.getRetryCount() < maxAttempts; + return context.getRetryCount() < this.maxAttempts; } @Override diff --git a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java index 32631c6..b8e6943 100644 --- a/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java +++ b/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java @@ -43,8 +43,7 @@ import org.springframework.util.ClassUtils; * .maxAttempts(3) * .retryOn(Exception.class) * .build(); - * } or by - * {@link org.springframework.retry.support.RetryTemplate#newDefaultInstance()} + * } or by {@link org.springframework.retry.support.RetryTemplate#defaultInstance()} * * @author Dave Syer * @author Rob Harrop @@ -69,15 +68,16 @@ public class SimpleRetryPolicy implements RetryPolicy { * retrying all exceptions. */ public SimpleRetryPolicy() { - this(DEFAULT_MAX_ATTEMPTS, BinaryExceptionClassifier.newDefaultClassifier()); + this(DEFAULT_MAX_ATTEMPTS, BinaryExceptionClassifier.defaultClassifier()); } /** * Create a {@link SimpleRetryPolicy} with the specified number of retry attempts, * retrying all exceptions. + * @param maxAttempts the maximum number of attempts */ public SimpleRetryPolicy(int maxAttempts) { - this(maxAttempts, BinaryExceptionClassifier.newDefaultClassifier()); + this(maxAttempts, BinaryExceptionClassifier.defaultClassifier()); } /** @@ -167,7 +167,7 @@ public class SimpleRetryPolicy implements RetryPolicy { public boolean canRetry(RetryContext context) { Throwable t = context.getLastThrowable(); return (t == null || retryForException(t)) - && context.getRetryCount() < maxAttempts; + && context.getRetryCount() < this.maxAttempts; } /** @@ -213,12 +213,13 @@ public class SimpleRetryPolicy implements RetryPolicy { * @return true if this exception or its ancestors have been registered as retryable. */ private boolean retryForException(Throwable ex) { - return retryableClassifier.classify(ex); + return this.retryableClassifier.classify(ex); } @Override public String toString() { - return ClassUtils.getShortName(getClass()) + "[maxAttempts=" + maxAttempts + "]"; + return ClassUtils.getShortName(getClass()) + "[maxAttempts=" + this.maxAttempts + + "]"; } } diff --git a/src/main/java/org/springframework/retry/support/RetrySynchronizationManager.java b/src/main/java/org/springframework/retry/support/RetrySynchronizationManager.java index bc80d1a..5abc319 100644 --- a/src/main/java/org/springframework/retry/support/RetrySynchronizationManager.java +++ b/src/main/java/org/springframework/retry/support/RetrySynchronizationManager.java @@ -44,7 +44,7 @@ public final class RetrySynchronizationManager { * @return the current retry context, or null if there isn't one */ public static RetryContext getContext() { - RetryContext result = (RetryContext) context.get(); + RetryContext result = context.get(); return result; } diff --git a/src/main/java/org/springframework/retry/support/RetryTemplate.java b/src/main/java/org/springframework/retry/support/RetryTemplate.java index feeaafb..55bfe56 100644 --- a/src/main/java/org/springframework/retry/support/RetryTemplate.java +++ b/src/main/java/org/springframework/retry/support/RetryTemplate.java @@ -57,8 +57,8 @@ import org.springframework.retry.policy.SimpleRetryPolicy; * properties. The {@link org.springframework.retry.backoff.BackOffPolicy} controls how * long the pause is between each individual retry attempt. *

- * A new instance can be fluently configured via {@link #newBuilder}, e.g:

 {@code
- * RetryTemplate.newBuilder()
+ * A new instance can be fluently configured via {@link #builder}, e.g: 
 {@code
+ * RetryTemplate.builder()
  *                 .maxAttempts(10)
  *                 .fixedBackoff(1000)
  *                 .build();
@@ -103,7 +103,7 @@ public class RetryTemplate implements RetryOperations {
 	 * can be overwritten during manual configuration
 	 * @since 1.3
 	 */
-	public static RetryTemplateBuilder newBuilder() {
+	public static RetryTemplateBuilder builder() {
 		return new RetryTemplateBuilder();
 	}
 
@@ -113,7 +113,7 @@ public class RetryTemplate implements RetryOperations {
 	 * @return a new instance of RetryTemplate with default behaviour
 	 * @since 1.3
 	 */
-	public static RetryTemplate newDefaultInstance() {
+	public static RetryTemplate defaultInstance() {
 		return new RetryTemplateBuilder().build();
 	}
 
@@ -519,6 +519,7 @@ public class RetryTemplate implements RetryOperations {
 	 * @throws ExhaustedRetryException if the state is not null and there is no recovery
 	 * callback
 	 * @return T the payload to return
+	 * @throws Throwable if there is an error
 	 */
 	protected  T handleRetryExhausted(RecoveryCallback recoveryCallback,
 			RetryContext context, RetryState state) throws Throwable {
diff --git a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java
index 467f538..98d0072 100644
--- a/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java
+++ b/src/main/java/org/springframework/retry/support/RetryTemplateBuilder.java
@@ -26,19 +26,19 @@ import org.springframework.util.Assert;
  *
  * 

* Examples:

{@code
- * RetryTemplate.newBuilder()
+ * RetryTemplate.builder()
  *      .maxAttempts(10)
  *      .exponentialBackoff(100, 2, 10000)
  *      .retryOn(IOException.class)
  *      .traversingCauses()
  *      .build();
  *
- * RetryTemplate.newBuilder()
+ * RetryTemplate.builder()
  *      .fixedBackoff(10)
  *      .withinMillis(3000)
  *      .build();
  *
- * RetryTemplate.newBuilder()
+ * RetryTemplate.builder()
  *      .infiniteRetry()
  *      .retryOn(IOException.class)
  *      .uniformRandomBackoff(1000, 3000)
@@ -87,12 +87,14 @@ public class RetryTemplateBuilder {
 	 * that is "retry only on {@link Exception} and it's subclasses".
 	 * @param maxAttempts includes initial attempt and all retries. E.g: maxAttempts = 3
 	 * means one initial attempt and two retries.
+	 * @return this
 	 * @see MaxAttemptsRetryPolicy
 	 */
 	public RetryTemplateBuilder maxAttempts(int maxAttempts) {
 		Assert.isTrue(maxAttempts > 0, "Number of attempts should be positive");
-		Assert.isNull(baseRetryPolicy, "You have already selected another retry policy");
-		baseRetryPolicy = new MaxAttemptsRetryPolicy(maxAttempts);
+		Assert.isNull(this.baseRetryPolicy,
+				"You have already selected another retry policy");
+		this.baseRetryPolicy = new MaxAttemptsRetryPolicy(maxAttempts);
 		return this;
 	}
 
@@ -102,11 +104,13 @@ public class RetryTemplateBuilder {
 	 * Invocation of this method does not discard default exception classification rule,
 	 * that is "retry only on {@link Exception} and it's subclasses".
 	 * @param timeout whole execution timeout in milliseconds
+	 * @return this
 	 * @see TimeoutRetryPolicy
 	 */
 	public RetryTemplateBuilder withinMillis(long timeout) {
 		Assert.isTrue(timeout > 0, "Timeout should be positive");
-		Assert.isNull(baseRetryPolicy, "You have already selected another retry policy");
+		Assert.isNull(this.baseRetryPolicy,
+				"You have already selected another retry policy");
 		TimeoutRetryPolicy timeoutRetryPolicy = new TimeoutRetryPolicy();
 		timeoutRetryPolicy.setTimeout(timeout);
 		this.baseRetryPolicy = timeoutRetryPolicy;
@@ -118,12 +122,13 @@ public class RetryTemplateBuilder {
 	 * 

* Invocation of this method does not discard default exception classification rule, * that is "retry only on {@link Exception} and it's subclasses". - * + * @return this * @see TimeoutRetryPolicy */ public RetryTemplateBuilder infiniteRetry() { - Assert.isNull(baseRetryPolicy, "You have already selected another retry policy"); - baseRetryPolicy = new AlwaysRetryPolicy(); + Assert.isNull(this.baseRetryPolicy, + "You have already selected another retry policy"); + this.baseRetryPolicy = new AlwaysRetryPolicy(); return this; } @@ -134,11 +139,13 @@ public class RetryTemplateBuilder { * Invocation of this method does not discard default exception classification rule, * that is "retry only on {@link Exception} and it's subclasses". * @param policy will be directly set to resulting {@link RetryTemplate} + * @return this */ public RetryTemplateBuilder customPolicy(RetryPolicy policy) { Assert.notNull(policy, "Policy should not be null"); - Assert.isNull(baseRetryPolicy, "You have already selected another retry policy"); - baseRetryPolicy = policy; + Assert.isNull(this.baseRetryPolicy, + "You have already selected another retry policy"); + this.baseRetryPolicy = policy; return this; } @@ -153,6 +160,7 @@ public class RetryTemplateBuilder { * @param initialInterval in milliseconds * @param multiplier see the formula above * @param maxInterval in milliseconds + * @return this * @see ExponentialBackOffPolicy */ public RetryTemplateBuilder exponentialBackoff(long initialInterval, @@ -171,12 +179,13 @@ public class RetryTemplateBuilder { * @param maxInterval in milliseconds * @param withRandom adds some randomness to backoff intervals. For details, see * {@link ExponentialRandomBackOffPolicy} + * @return this * @see ExponentialBackOffPolicy * @see ExponentialRandomBackOffPolicy */ public RetryTemplateBuilder exponentialBackoff(long initialInterval, double multiplier, long maxInterval, boolean withRandom) { - Assert.isNull(backOffPolicy, "You have already selected backoff policy"); + Assert.isNull(this.backOffPolicy, "You have already selected backoff policy"); Assert.isTrue(initialInterval >= 1, "Initial interval should be >= 1"); Assert.isTrue(multiplier > 1, "Multiplier should be > 1"); Assert.isTrue(maxInterval > initialInterval, @@ -186,21 +195,22 @@ public class RetryTemplateBuilder { policy.setInitialInterval(initialInterval); policy.setMultiplier(multiplier); policy.setMaxInterval(maxInterval); - backOffPolicy = policy; + this.backOffPolicy = policy; return this; } /** * Perform each retry after fixed amount of time. * @param interval fixed interval in milliseconds + * @return this * @see FixedBackOffPolicy */ public RetryTemplateBuilder fixedBackoff(long interval) { - Assert.isNull(backOffPolicy, "You have already selected backoff policy"); + Assert.isNull(this.backOffPolicy, "You have already selected backoff policy"); Assert.isTrue(interval >= 1, "Interval should be >= 1"); FixedBackOffPolicy policy = new FixedBackOffPolicy(); policy.setBackOffPeriod(interval); - backOffPolicy = policy; + this.backOffPolicy = policy; return this; } @@ -208,10 +218,11 @@ public class RetryTemplateBuilder { * Use {@link UniformRandomBackOffPolicy}, see it's doc for details. * @param minInterval in milliseconds * @param maxInterval in milliseconds + * @return this * @see UniformRandomBackOffPolicy */ public RetryTemplateBuilder uniformRandomBackoff(long minInterval, long maxInterval) { - Assert.isNull(backOffPolicy, "You have already selected backoff policy"); + Assert.isNull(this.backOffPolicy, "You have already selected backoff policy"); Assert.isTrue(minInterval >= 1, "Min interval should be >= 1"); Assert.isTrue(maxInterval >= 1, "Max interval should be >= 1"); Assert.isTrue(maxInterval > minInterval, @@ -219,24 +230,25 @@ public class RetryTemplateBuilder { UniformRandomBackOffPolicy policy = new UniformRandomBackOffPolicy(); policy.setMinBackOffPeriod(minInterval); policy.setMaxBackOffPeriod(maxInterval); - backOffPolicy = policy; + this.backOffPolicy = policy; return this; } /** * Do not pause between attempts, retry immediately. - * + * @return this * @see NoBackOffPolicy */ public RetryTemplateBuilder noBackoff() { - Assert.isNull(backOffPolicy, "You have already selected backoff policy"); - backOffPolicy = new NoBackOffPolicy(); + Assert.isNull(this.backOffPolicy, "You have already selected backoff policy"); + this.backOffPolicy = new NoBackOffPolicy(); return this; } /** * You can provide your own {@link BackOffPolicy} via this method. * @param backOffPolicy will be directly set to resulting {@link RetryTemplate} + * @return this */ public RetryTemplateBuilder customBackoff(BackOffPolicy backOffPolicy) { Assert.isNull(this.backOffPolicy, "You have already selected backoff policy"); @@ -257,6 +269,7 @@ public class RetryTemplateBuilder { * black list. If you choose white list - use this method, if black - use * {@link #notRetryOn(Class)} * @param throwable to be retryable (with it's subclasses) + * @return this * @see BinaryExceptionClassifierBuilder#retryOn * @see BinaryExceptionClassifier */ @@ -275,6 +288,7 @@ public class RetryTemplateBuilder { * black list. If you choose black list - use this method, if white - use * {@link #retryOn(Class)} * @param throwable to be not retryable (with it's subclasses) + * @return this * @see BinaryExceptionClassifierBuilder#notRetryOn * @see BinaryExceptionClassifier */ @@ -286,16 +300,16 @@ public class RetryTemplateBuilder { /** * Suppose throwing a {@code new MyLogicException(new IOException())}. This template * will not retry on it:

{@code
-	 * RetryTemplate.newBuilder()
+	 * RetryTemplate.builder()
 	 *          .retryOn(IOException.class)
 	 *          .build()
 	 * }
but this will retry:
{@code
-	 * RetryTemplate.newBuilder()
+	 * RetryTemplate.builder()
 	 *          .retryOn(IOException.class)
 	 *          .traversingCauses()
 	 *          .build()
 	 * }
- * + * @return this * @see BinaryExceptionClassifier */ public RetryTemplateBuilder traversingCauses() { @@ -308,6 +322,7 @@ public class RetryTemplateBuilder { /** * Appends provided {@code listener} to {@link RetryTemplate}'s listener list. * @param listener to be appended + * @return this * @see RetryTemplate * @see RetryListener */ @@ -320,6 +335,7 @@ public class RetryTemplateBuilder { /** * Appends all provided {@code listeners} to {@link RetryTemplate}'s listener list. * @param listeners to be appended + * @return this * @see RetryTemplate * @see RetryListener */ @@ -348,32 +364,32 @@ public class RetryTemplateBuilder { // Exception classifier - BinaryExceptionClassifier exceptionClassifier = classifierBuilder != null - ? classifierBuilder.build() - : BinaryExceptionClassifier.newDefaultClassifier(); + BinaryExceptionClassifier exceptionClassifier = this.classifierBuilder != null + ? this.classifierBuilder.build() + : BinaryExceptionClassifier.defaultClassifier(); // Retry policy - if (baseRetryPolicy == null) { - baseRetryPolicy = new MaxAttemptsRetryPolicy(); + if (this.baseRetryPolicy == null) { + this.baseRetryPolicy = new MaxAttemptsRetryPolicy(); } CompositeRetryPolicy finalPolicy = new CompositeRetryPolicy(); - finalPolicy.setPolicies(new RetryPolicy[] { baseRetryPolicy, + finalPolicy.setPolicies(new RetryPolicy[] { this.baseRetryPolicy, new BinaryExceptionClassifierRetryPolicy(exceptionClassifier) }); retryTemplate.setRetryPolicy(finalPolicy); // Backoff policy - if (backOffPolicy == null) { - backOffPolicy = new NoBackOffPolicy(); + if (this.backOffPolicy == null) { + this.backOffPolicy = new NoBackOffPolicy(); } - retryTemplate.setBackOffPolicy(backOffPolicy); + retryTemplate.setBackOffPolicy(this.backOffPolicy); // Listeners - if (listeners != null) { - retryTemplate.setListeners(listeners.toArray(new RetryListener[0])); + if (this.listeners != null) { + retryTemplate.setListeners(this.listeners.toArray(new RetryListener[0])); } return retryTemplate; @@ -382,17 +398,17 @@ public class RetryTemplateBuilder { /* ---------------- Private utils -------------- */ private BinaryExceptionClassifierBuilder classifierBuilder() { - if (classifierBuilder == null) { - classifierBuilder = new BinaryExceptionClassifierBuilder(); + if (this.classifierBuilder == null) { + this.classifierBuilder = new BinaryExceptionClassifierBuilder(); } - return classifierBuilder; + return this.classifierBuilder; } private List listenersList() { - if (listeners == null) { - listeners = new ArrayList(); + if (this.listeners == null) { + this.listeners = new ArrayList(); } - return listeners; + return this.listeners; } } diff --git a/src/test/java/org/springframework/classify/BinaryExceptionClassifierBuilderTest.java b/src/test/java/org/springframework/classify/BinaryExceptionClassifierBuilderTest.java index b3276b4..6b2d5f3 100644 --- a/src/test/java/org/springframework/classify/BinaryExceptionClassifierBuilderTest.java +++ b/src/test/java/org/springframework/classify/BinaryExceptionClassifierBuilderTest.java @@ -32,10 +32,10 @@ public class BinaryExceptionClassifierBuilderTest { @Test public void testWhiteList() { - RetryTemplate.newBuilder().infiniteRetry().retryOn(IOException.class) + RetryTemplate.builder().infiniteRetry().retryOn(IOException.class) .uniformRandomBackoff(1000, 3000).build(); - BinaryExceptionClassifier classifier = BinaryExceptionClassifier.newBuilder() + BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder() .retryOn(IOException.class).retryOn(TimeoutException.class).build(); Assert.assertTrue(classifier.classify(new IOException())); @@ -47,7 +47,7 @@ public class BinaryExceptionClassifierBuilderTest { @Test public void testWhiteListWithTraverseCauses() { - BinaryExceptionClassifier classifier = BinaryExceptionClassifier.newBuilder() + BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder() .retryOn(IOException.class).retryOn(TimeoutException.class) .traversingCauses().build(); @@ -62,7 +62,7 @@ public class BinaryExceptionClassifierBuilderTest { @Test public void testBlackList() { - BinaryExceptionClassifier classifier = BinaryExceptionClassifier.newBuilder() + BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder() .notRetryOn(Error.class).notRetryOn(InterruptedException.class) .traversingCauses().build(); @@ -77,7 +77,7 @@ public class BinaryExceptionClassifierBuilderTest { @Test(expected = IllegalArgumentException.class) public void testFailOnNotationMix() { - BinaryExceptionClassifier.newBuilder().retryOn(IOException.class) + BinaryExceptionClassifier.builder().retryOn(IOException.class) .notRetryOn(OutOfMemoryError.class); } diff --git a/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java b/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java index c480bb0..65b0a49 100644 --- a/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java +++ b/src/test/java/org/springframework/retry/support/RetryTemplateBuilderTest.java @@ -58,7 +58,7 @@ public class RetryTemplateBuilderTest { @Test public void testDefaultBehavior() { - RetryTemplate template = RetryTemplate.newBuilder().build(); + RetryTemplate template = RetryTemplate.builder().build(); PolicyTuple policyTuple = PolicyTuple.extractWithAsserts(template); assertDefaultClassifier(policyTuple); @@ -82,7 +82,7 @@ public class RetryTemplateBuilderTest { RetryListener listener1 = mock(RetryListener.class); RetryListener listener2 = mock(RetryListener.class); - RetryTemplate template = RetryTemplate.newBuilder().maxAttempts(10) + RetryTemplate template = RetryTemplate.builder().maxAttempts(10) .exponentialBackoff(99, 1.5, 1717).retryOn(IOException.class) .traversingCauses().withListener(listener1) .withListeners(Collections.singletonList(listener2)).build(); @@ -113,12 +113,12 @@ public class RetryTemplateBuilderTest { @Test(expected = IllegalArgumentException.class) public void testFailOnRetryPoliciesConflict() { - RetryTemplate.newBuilder().maxAttempts(3).withinMillis(1000).build(); + RetryTemplate.builder().maxAttempts(3).withinMillis(1000).build(); } @Test public void testTimeoutPolicy() { - RetryTemplate template = RetryTemplate.newBuilder().withinMillis(10000).build(); + RetryTemplate template = RetryTemplate.builder().withinMillis(10000).build(); PolicyTuple policyTuple = PolicyTuple.extractWithAsserts(template); assertDefaultClassifier(policyTuple); @@ -130,7 +130,7 @@ public class RetryTemplateBuilderTest { @Test public void testInfiniteRetry() { - RetryTemplate template = RetryTemplate.newBuilder().infiniteRetry().build(); + RetryTemplate template = RetryTemplate.builder().infiniteRetry().build(); PolicyTuple policyTuple = PolicyTuple.extractWithAsserts(template); assertDefaultClassifier(policyTuple); @@ -142,7 +142,7 @@ public class RetryTemplateBuilderTest { public void testCustomPolicy() { RetryPolicy customPolicy = mock(RetryPolicy.class); - RetryTemplate template = RetryTemplate.newBuilder().customPolicy(customPolicy) + RetryTemplate template = RetryTemplate.builder().customPolicy(customPolicy) .build(); PolicyTuple policyTuple = PolicyTuple.extractWithAsserts(template); @@ -164,12 +164,12 @@ public class RetryTemplateBuilderTest { @Test(expected = IllegalArgumentException.class) public void testFailOnEmptyExceptionClassifierRules() { - RetryTemplate.newBuilder().traversingCauses().build(); + RetryTemplate.builder().traversingCauses().build(); } @Test(expected = IllegalArgumentException.class) public void testFailOnNotationMix() { - RetryTemplate.newBuilder().retryOn(IOException.class) + RetryTemplate.builder().retryOn(IOException.class) .notRetryOn(OutOfMemoryError.class); } @@ -177,17 +177,17 @@ public class RetryTemplateBuilderTest { @Test(expected = IllegalArgumentException.class) public void testFailOnBackOffPolicyNull() { - RetryTemplate.newBuilder().customBackoff(null).build(); + RetryTemplate.builder().customBackoff(null).build(); } @Test(expected = IllegalArgumentException.class) public void testFailOnBackOffPolicyConflict() { - RetryTemplate.newBuilder().noBackoff().fixedBackoff(1000).build(); + RetryTemplate.builder().noBackoff().fixedBackoff(1000).build(); } @Test public void testUniformRandomBackOff() { - RetryTemplate template = RetryTemplate.newBuilder().uniformRandomBackoff(10, 100) + RetryTemplate template = RetryTemplate.builder().uniformRandomBackoff(10, 100) .build(); Assert.assertTrue(getPropertyValue(template, "backOffPolicy") instanceof UniformRandomBackOffPolicy); @@ -195,14 +195,14 @@ public class RetryTemplateBuilderTest { @Test public void testNoBackOff() { - RetryTemplate template = RetryTemplate.newBuilder().noBackoff().build(); + RetryTemplate template = RetryTemplate.builder().noBackoff().build(); Assert.assertTrue( getPropertyValue(template, "backOffPolicy") instanceof NoBackOffPolicy); } @Test public void testExpBackOffWithRandom() { - RetryTemplate template = RetryTemplate.newBuilder() + RetryTemplate template = RetryTemplate.builder() .exponentialBackoff(10, 2, 500, true).build(); Assert.assertTrue(getPropertyValue(template, "backOffPolicy") instanceof ExponentialRandomBackOffPolicy); @@ -210,17 +210,17 @@ public class RetryTemplateBuilderTest { @Test(expected = IllegalArgumentException.class) public void testValidateInitAndMax() { - RetryTemplate.newBuilder().exponentialBackoff(100, 2, 100).build(); + RetryTemplate.builder().exponentialBackoff(100, 2, 100).build(); } @Test(expected = IllegalArgumentException.class) public void testValidateMeaninglessMultipier() { - RetryTemplate.newBuilder().exponentialBackoff(100, 1, 200).build(); + RetryTemplate.builder().exponentialBackoff(100, 1, 200).build(); } @Test(expected = IllegalArgumentException.class) public void testValidateZeroInitInterval() { - RetryTemplate.newBuilder().exponentialBackoff(0, 2, 200).build(); + RetryTemplate.builder().exponentialBackoff(0, 2, 200).build(); } /* ---------------- Utils -------------- */