This commit is contained in:
Dave Syer
2019-03-20 17:11:13 +00:00
parent 84e906fbe6
commit 01d850ef28
10 changed files with 110 additions and 91 deletions

View File

@@ -36,11 +36,11 @@ public class BinaryExceptionClassifier extends SubclassClassifier<Throwable, Boo
private boolean traverseCauses;
public static BinaryExceptionClassifierBuilder newBuilder() {
public static BinaryExceptionClassifierBuilder builder() {
return new BinaryExceptionClassifierBuilder();
}
public static BinaryExceptionClassifier newDefaultClassifier() {
public static BinaryExceptionClassifier defaultClassifier() {
// create new instance for each call due to mutability
return new BinaryExceptionClassifier(Collections
.<Class<? extends Throwable>, Boolean>singletonMap(Exception.class, true),

View File

@@ -19,6 +19,7 @@ package org.springframework.retry;
* Callback for stateful retry after all tries are exhausted.
*
* @author Dave Syer
* @param <T> the type that is returned from the recovery
* @since 1.1
*/
public interface RecoveryCallback<T> {

View File

@@ -30,27 +30,26 @@ public interface RetryOperations {
/**
* Execute the supplied {@link RetryCallback} with the configured retry semantics. See
* implementations for configuration details.
* @param <T> the return value
* @param retryCallback the {@link RetryCallback}
* @param <E> 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 <T> the return value
* @param retryCallback the {@link RetryCallback}
* @param <E> the exception to throw
*/
<T, E extends Throwable> T execute(RetryCallback<T, E> 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 <T> the type to return
* @param <E> the type of the exception
* @param recoveryCallback the {@link RecoveryCallback}
* @param retryCallback the {@link RetryCallback} {@link RecoveryCallback} upon
* unsuccessful retry.
* @param <T> the type to return
* @param <E> 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, E extends Throwable> T execute(RetryCallback<T, E> retryCallback,
RecoveryCallback<T> 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 <T> the type of the return value
* @param <E> 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 <T> the type of the return value
* @param <E> the type of the exception to return
*/
<T, E extends Throwable> T execute(RetryCallback<T, E> 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 <T> the return value type
* @param <E> 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

View File

@@ -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).
* <p>
* For daily usage see {@link RetryTemplate#newBuilder()}
* For daily usage see {@link RetryTemplate#builder()}
* <p>
* 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

View File

@@ -43,8 +43,7 @@ import org.springframework.util.ClassUtils;
* .maxAttempts(3)
* .retryOn(Exception.class)
* .build();
* }</pre> or by
* {@link org.springframework.retry.support.RetryTemplate#newDefaultInstance()}
* }</pre> 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
+ "]";
}
}

View File

@@ -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;
}

View File

@@ -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.
* <p>
* A new instance can be fluently configured via {@link #newBuilder}, e.g: <pre> {@code
* RetryTemplate.newBuilder()
* A new instance can be fluently configured via {@link #builder}, e.g: <pre> {@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> T handleRetryExhausted(RecoveryCallback<T> recoveryCallback,
RetryContext context, RetryState state) throws Throwable {

View File

@@ -26,19 +26,19 @@ import org.springframework.util.Assert;
*
* <p>
* Examples: <pre>{@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 {
* <p>
* 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: <pre>{@code
* RetryTemplate.newBuilder()
* RetryTemplate.builder()
* .retryOn(IOException.class)
* .build()
* }</pre> but this will retry: <pre>{@code
* RetryTemplate.newBuilder()
* RetryTemplate.builder()
* .retryOn(IOException.class)
* .traversingCauses()
* .build()
* }</pre>
*
* @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<RetryListener> listenersList() {
if (listeners == null) {
listeners = new ArrayList<RetryListener>();
if (this.listeners == null) {
this.listeners = new ArrayList<RetryListener>();
}
return listeners;
return this.listeners;
}
}

View File

@@ -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);
}

View File

@@ -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 -------------- */