Upgrade to spring javaformat 0.0.39
Closes gh-346
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -219,7 +219,7 @@
|
||||
<plugin>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
<version>0.0.31</version>
|
||||
<version>0.0.39</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ public class ClassifierAdapter<C, T> implements Classifier<C, T> {
|
||||
public final void setDelegate(Object delegate) {
|
||||
this.classifier = null;
|
||||
this.invoker = MethodInvokerUtils
|
||||
.getMethodInvokerByAnnotation(org.springframework.classify.annotation.Classifier.class, delegate);
|
||||
.getMethodInvokerByAnnotation(org.springframework.classify.annotation.Classifier.class, delegate);
|
||||
if (this.invoker == null) {
|
||||
this.invoker = MethodInvokerUtils.<C, T>getMethodInvokerForSingleArgument(delegate);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -228,8 +228,11 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn
|
||||
RetryTemplate template = createTemplate(retryable.listeners());
|
||||
template.setRetryPolicy(getRetryPolicy(retryable, true));
|
||||
template.setBackOffPolicy(getBackoffPolicy(retryable.backoff(), true));
|
||||
return RetryInterceptorBuilder.stateless().retryOperations(template).label(retryable.label())
|
||||
.recoverer(getRecoverer(target, method)).build();
|
||||
return RetryInterceptorBuilder.stateless()
|
||||
.retryOperations(template)
|
||||
.label(retryable.label())
|
||||
.recoverer(getRecoverer(target, method))
|
||||
.build();
|
||||
}
|
||||
|
||||
private MethodInterceptor getStatefulInterceptor(Object target, Method method, Retryable retryable) {
|
||||
@@ -251,16 +254,24 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn
|
||||
if (!StringUtils.hasText(label)) {
|
||||
label = method.toGenericString();
|
||||
}
|
||||
return RetryInterceptorBuilder.circuitBreaker().keyGenerator(new FixedKeyGenerator("circuit"))
|
||||
.retryOperations(template).recoverer(getRecoverer(target, method)).label(label).build();
|
||||
return RetryInterceptorBuilder.circuitBreaker()
|
||||
.keyGenerator(new FixedKeyGenerator("circuit"))
|
||||
.retryOperations(template)
|
||||
.recoverer(getRecoverer(target, method))
|
||||
.label(label)
|
||||
.build();
|
||||
}
|
||||
RetryPolicy policy = getRetryPolicy(retryable, false);
|
||||
template.setRetryPolicy(policy);
|
||||
template.setBackOffPolicy(getBackoffPolicy(retryable.backoff(), false));
|
||||
String label = retryable.label();
|
||||
return RetryInterceptorBuilder.stateful().keyGenerator(this.methodArgumentsKeyGenerator)
|
||||
.newMethodArgumentsIdentifier(this.newMethodArgumentsIdentifier).retryOperations(template).label(label)
|
||||
.recoverer(getRecoverer(target, method)).build();
|
||||
return RetryInterceptorBuilder.stateful()
|
||||
.keyGenerator(this.methodArgumentsKeyGenerator)
|
||||
.newMethodArgumentsIdentifier(this.newMethodArgumentsIdentifier)
|
||||
.retryOperations(template)
|
||||
.label(label)
|
||||
.recoverer(getRecoverer(target, method))
|
||||
.build();
|
||||
}
|
||||
|
||||
private void openTimeout(CircuitBreakerRetryPolicy breaker, CircuitBreaker circuit) {
|
||||
@@ -383,7 +394,8 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn
|
||||
if (simple == null) {
|
||||
if (hasExpression) {
|
||||
simple = new ExpressionRetryPolicy(maxAttempts, policyMap, true, resolve(exceptionExpression),
|
||||
retryNotExcluded).withBeanFactory(this.beanFactory);
|
||||
retryNotExcluded)
|
||||
.withBeanFactory(this.beanFactory);
|
||||
}
|
||||
else {
|
||||
simple = new SimpleRetryPolicy(maxAttempts, policyMap, true, retryNotExcluded);
|
||||
|
||||
@@ -99,7 +99,7 @@ public class RetryConfiguration extends AbstractPointcutAdvisor
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableRetry = AnnotationAttributes
|
||||
.fromMap(importMetadata.getAnnotationAttributes(EnableRetry.class.getName()));
|
||||
.fromMap(importMetadata.getAnnotationAttributes(EnableRetry.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,8 +37,10 @@ public class BinaryExceptionClassifierBuilderTests {
|
||||
public void testWhiteList() {
|
||||
RetryTemplate.builder().infiniteRetry().retryOn(IOException.class).uniformRandomBackoff(1000, 3000).build();
|
||||
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder().retryOn(IOException.class)
|
||||
.retryOn(TimeoutException.class).build();
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder()
|
||||
.retryOn(IOException.class)
|
||||
.retryOn(TimeoutException.class)
|
||||
.build();
|
||||
|
||||
assertThat(classifier.classify(new IOException())).isTrue();
|
||||
// should not retry due to traverseCauses=fasle
|
||||
@@ -49,8 +51,11 @@ public class BinaryExceptionClassifierBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testWhiteListWithTraverseCauses() {
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder().retryOn(IOException.class)
|
||||
.retryOn(TimeoutException.class).traversingCauses().build();
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder()
|
||||
.retryOn(IOException.class)
|
||||
.retryOn(TimeoutException.class)
|
||||
.traversingCauses()
|
||||
.build();
|
||||
|
||||
assertThat(classifier.classify(new IOException())).isTrue();
|
||||
// should retry due to traverseCauses=true
|
||||
@@ -63,8 +68,11 @@ public class BinaryExceptionClassifierBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testBlackList() {
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder().notRetryOn(Error.class)
|
||||
.notRetryOn(InterruptedException.class).traversingCauses().build();
|
||||
BinaryExceptionClassifier classifier = BinaryExceptionClassifier.builder()
|
||||
.notRetryOn(Error.class)
|
||||
.notRetryOn(InterruptedException.class)
|
||||
.traversingCauses()
|
||||
.build();
|
||||
|
||||
// should not retry due to OutOfMemoryError is a subclass of Error
|
||||
assertThat(classifier.classify(new OutOfMemoryError())).isFalse();
|
||||
@@ -77,7 +85,8 @@ public class BinaryExceptionClassifierBuilderTests {
|
||||
@Test
|
||||
public void testFailOnNotationMix() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> BinaryExceptionClassifier.builder()
|
||||
.retryOn(IOException.class).notRetryOn(OutOfMemoryError.class));
|
||||
.retryOn(IOException.class)
|
||||
.notRetryOn(OutOfMemoryError.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,14 +55,14 @@ public class BinaryExceptionClassifierTests {
|
||||
@Test
|
||||
public void testClassifyExactMatch() {
|
||||
Collection<Class<? extends Throwable>> set = Collections
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
assertThat(new BinaryExceptionClassifier(set).classify(new IllegalStateException("Foo"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassifyExactMatchInCause() {
|
||||
Collection<Class<? extends Throwable>> set = Collections
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(set);
|
||||
binaryExceptionClassifier.setTraverseCauses(true);
|
||||
assertThat(binaryExceptionClassifier.classify(new RuntimeException(new IllegalStateException("Foo")))).isTrue();
|
||||
@@ -71,7 +71,7 @@ public class BinaryExceptionClassifierTests {
|
||||
@Test
|
||||
public void testClassifySubclassMatchInCause() {
|
||||
Collection<Class<? extends Throwable>> set = Collections
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
.<Class<? extends Throwable>>singleton(IllegalStateException.class);
|
||||
BinaryExceptionClassifier binaryExceptionClassifier = new BinaryExceptionClassifier(set);
|
||||
binaryExceptionClassifier.setTraverseCauses(true);
|
||||
assertThat(binaryExceptionClassifier.classify(new RuntimeException(new FooException("Foo")))).isTrue();
|
||||
@@ -86,9 +86,9 @@ public class BinaryExceptionClassifierTests {
|
||||
binaryExceptionClassifier.setTraverseCauses(true);
|
||||
assertThat(
|
||||
binaryExceptionClassifier.classify(new RuntimeException(new FooException("Foo", new BarException()))))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
assertThat(((Map<?, ?>) new DirectFieldAccessor(binaryExceptionClassifier).getPropertyValue("classified"))
|
||||
.containsKey(FooException.class)).isTrue();
|
||||
.containsKey(FooException.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +111,7 @@ public class BinaryExceptionClassifierTests {
|
||||
Collections.<Class<? extends Throwable>>singleton(IllegalStateException.class), false);
|
||||
classifier.setTraverseCauses(true);
|
||||
assertThat(classifier.classify(new RuntimeException(new RuntimeException(new IllegalStateException("Foo")))))
|
||||
.isFalse();
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,8 +61,8 @@ public class SubclassExceptionClassifierTests {
|
||||
|
||||
@Test
|
||||
public void testClassifySubclassMatch() {
|
||||
this.classifier.setTypeMap(
|
||||
Collections.<Class<? extends Throwable>, String>singletonMap(RuntimeException.class, "foo"));
|
||||
this.classifier
|
||||
.setTypeMap(Collections.<Class<? extends Throwable>, String>singletonMap(RuntimeException.class, "foo"));
|
||||
assertThat(this.classifier.classify(new IllegalStateException("Foo"))).isEqualTo("foo");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,13 +30,13 @@ public class AnyThrowTests {
|
||||
@Test
|
||||
public void testRuntimeException() {
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> AnyThrow.throwAny(new RuntimeException("planned")));
|
||||
.isThrownBy(() -> AnyThrow.throwAny(new RuntimeException("planned")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncheckedRuntimeException() {
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> AnyThrow.throwUnchecked(new RuntimeException("planned")));
|
||||
.isThrownBy(() -> AnyThrow.throwUnchecked(new RuntimeException("planned")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,13 +69,13 @@ public class CircuitBreakerTests {
|
||||
assertThat(delegates).hasSize(1);
|
||||
Map<?, ?> methodMap = (Map<?, ?>) delegates.values().iterator().next();
|
||||
MethodInterceptor interceptor = (MethodInterceptor) methodMap
|
||||
.get(Service.class.getDeclaredMethod("expressionService"));
|
||||
.get(Service.class.getDeclaredMethod("expressionService"));
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(interceptor);
|
||||
assertThat(accessor.getPropertyValue("retryOperations.retryPolicy.delegate.maxAttempts")).isEqualTo(8);
|
||||
assertThat(accessor.getPropertyValue("retryOperations.retryPolicy.openTimeout")).isEqualTo(19000L);
|
||||
assertThat(accessor.getPropertyValue("retryOperations.retryPolicy.resetTimeout")).isEqualTo(20000L);
|
||||
assertThat(accessor.getPropertyValue("retryOperations.retryPolicy.delegate.expression.expression"))
|
||||
.isEqualTo("#root instanceof RuntimeExpression");
|
||||
.isEqualTo("#root instanceof RuntimeExpression");
|
||||
|
||||
interceptor = (MethodInterceptor) methodMap.get(Service.class.getDeclaredMethod("expressionService2"));
|
||||
accessor = new DirectFieldAccessor(interceptor);
|
||||
@@ -98,7 +98,7 @@ public class CircuitBreakerTests {
|
||||
assertThat(delegates).hasSize(1);
|
||||
Map<?, ?> methodMap = (Map<?, ?>) delegates.values().iterator().next();
|
||||
MethodInterceptor interceptor = (MethodInterceptor) methodMap
|
||||
.get(Service.class.getDeclaredMethod("expressionService3"));
|
||||
.get(Service.class.getDeclaredMethod("expressionService3"));
|
||||
Supplier<?> maxAttempts = TestUtils.getPropertyValue(interceptor,
|
||||
"retryOperations.retryPolicy.delegate.maxAttemptsSupplier", Supplier.class);
|
||||
assertThat(maxAttempts).isNotNull();
|
||||
|
||||
@@ -240,17 +240,19 @@ public class EnableRetryTests {
|
||||
assertThat(service.getCount()).isEqualTo(9);
|
||||
RetryConfiguration config = context.getBean(RetryConfiguration.class);
|
||||
AnnotationAwareRetryOperationsInterceptor advice = (AnnotationAwareRetryOperationsInterceptor) new DirectFieldAccessor(
|
||||
config).getPropertyValue("advice");
|
||||
config)
|
||||
.getPropertyValue("advice");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Map<Method, MethodInterceptor>> delegates = (Map<Object, Map<Method, MethodInterceptor>>) new DirectFieldAccessor(
|
||||
advice).getPropertyValue("delegates");
|
||||
advice)
|
||||
.getPropertyValue("delegates");
|
||||
MethodInterceptor interceptor = delegates.get(target(service))
|
||||
.get(ExpressionService.class.getDeclaredMethod("service3"));
|
||||
.get(ExpressionService.class.getDeclaredMethod("service3"));
|
||||
RetryTemplate template = (RetryTemplate) new DirectFieldAccessor(interceptor)
|
||||
.getPropertyValue("retryOperations");
|
||||
.getPropertyValue("retryOperations");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
ExponentialBackOffPolicy backOff = (ExponentialBackOffPolicy) templateAccessor
|
||||
.getPropertyValue("backOffPolicy");
|
||||
.getPropertyValue("backOffPolicy");
|
||||
assertThat(backOff.getInitialInterval()).isEqualTo(1);
|
||||
assertThat(backOff.getMaxInterval()).isEqualTo(5);
|
||||
assertThat(backOff.getMultiplier()).isEqualTo(1.1);
|
||||
@@ -281,17 +283,19 @@ public class EnableRetryTests {
|
||||
|
||||
RetryConfiguration config = context.getBean(RetryConfiguration.class);
|
||||
AnnotationAwareRetryOperationsInterceptor advice = (AnnotationAwareRetryOperationsInterceptor) new DirectFieldAccessor(
|
||||
config).getPropertyValue("advice");
|
||||
config)
|
||||
.getPropertyValue("advice");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Object, Map<Method, MethodInterceptor>> delegates = (Map<Object, Map<Method, MethodInterceptor>>) new DirectFieldAccessor(
|
||||
advice).getPropertyValue("delegates");
|
||||
advice)
|
||||
.getPropertyValue("delegates");
|
||||
MethodInterceptor interceptor = delegates.get(target(service))
|
||||
.get(ExpressionService.class.getDeclaredMethod("service6"));
|
||||
.get(ExpressionService.class.getDeclaredMethod("service6"));
|
||||
RetryTemplate template = (RetryTemplate) new DirectFieldAccessor(interceptor)
|
||||
.getPropertyValue("retryOperations");
|
||||
.getPropertyValue("retryOperations");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
ExponentialBackOffPolicy backOff = (ExponentialBackOffPolicy) templateAccessor
|
||||
.getPropertyValue("backOffPolicy");
|
||||
.getPropertyValue("backOffPolicy");
|
||||
assertThat(backOff.getInitialInterval()).isEqualTo(1000);
|
||||
assertThat(backOff.getMaxInterval()).isEqualTo(2000);
|
||||
assertThat(backOff.getMultiplier()).isEqualTo(1.2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ public class EnableRetryWithBackoffTests {
|
||||
assertThat(context.getBean(PeriodSleeper.class).getPeriods().toString()).isNotEqualTo("[1000, 1100]");
|
||||
assertThat(periods.get(0) > 1000).describedAs("Wrong periods: %s" + periods.toString()).isTrue();
|
||||
assertThat(periods.get(1) > 1100 && periods.get(1) < 1210).describedAs("Wrong periods: %s" + periods.toString())
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EnableRetryWithBackoffTests {
|
||||
assertThat(context.getBean(PeriodSleeper.class).getPeriods().toString()).isNotEqualTo("[1000, 1100]");
|
||||
assertThat(periods.get(0) > 1000).describedAs("Wrong periods: %s" + periods.toString()).isTrue();
|
||||
assertThat(periods.get(1) > 1100 && periods.get(1) < 1210).describedAs("Wrong periods: %s" + periods.toString())
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2023 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,13 +57,17 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
isParameterizedTypeAssignable.setAccessible(true);
|
||||
|
||||
assertThat(isParameterizedTypeAssignable.invoke(null, getGenericReturnTypeByName("m1"),
|
||||
getGenericReturnTypeByName("m2"))).isEqualTo(Boolean.TRUE);
|
||||
getGenericReturnTypeByName("m2")))
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
assertThat(isParameterizedTypeAssignable.invoke(null, getGenericReturnTypeByName("m2"),
|
||||
getGenericReturnTypeByName("m2_1"))).isEqualTo(Boolean.FALSE);
|
||||
getGenericReturnTypeByName("m2_1")))
|
||||
.isEqualTo(Boolean.FALSE);
|
||||
assertThat(isParameterizedTypeAssignable.invoke(null, getGenericReturnTypeByName("m3"),
|
||||
getGenericReturnTypeByName("m4"))).isEqualTo(Boolean.FALSE);
|
||||
getGenericReturnTypeByName("m4")))
|
||||
.isEqualTo(Boolean.FALSE);
|
||||
assertThat(isParameterizedTypeAssignable.invoke(null, getGenericReturnTypeByName("m5"),
|
||||
getGenericReturnTypeByName("m6"))).isEqualTo(Boolean.TRUE);
|
||||
getGenericReturnTypeByName("m6")))
|
||||
.isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private static ParameterizedType getGenericReturnTypeByName(String name) {
|
||||
@@ -98,7 +102,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
new SpecificException(), ReflectionUtils.findMethod(SpecificException.class, "foo", String.class));
|
||||
assertThatExceptionOfType(ExhaustedRetryException.class)
|
||||
.isThrownBy(() -> handler.recover(new Object[] { "Dave" }, new Error("Planned")));
|
||||
.isThrownBy(() -> handler.recover(new Object[] { "Dave" }, new Error("Planned")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +177,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, GenericReturnTypeRecover.One> recoverResponseMap = (Map<String, GenericReturnTypeRecover.One>) handler
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
assertThat(CollectionUtils.isEmpty(recoverResponseMap)).isFalse();
|
||||
assertThat(recoverResponseMap.get("bar")).isNotNull();
|
||||
assertThat(recoverResponseMap.get("bar").name).isEqualTo("barRecoverValue");
|
||||
@@ -216,11 +220,11 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
ReflectionUtils.findMethod(NestedGenericInheritanceReturnTypeRecover.class, "foo", String.class));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Map<String, Map<Integer, String>>> recoverResponseMapRe = (Map<String, Map<String, Map<Integer, String>>>) fooHandler
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
assertThat(recoverResponseMapRe.get("foo").get("foo").get(0)).isEqualTo("fooRecoverReValue");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Map<String, Map<Integer, String>>> recoverResponseMapIe = (Map<String, Map<String, Map<Integer, String>>>) fooHandler
|
||||
.recover(new Object[] { "Aldo" }, new IllegalStateException("Planned"));
|
||||
.recover(new Object[] { "Aldo" }, new IllegalStateException("Planned"));
|
||||
assertThat(recoverResponseMapIe.get("foo").get("foo").get(0)).isEqualTo("fooRecoverIeValue");
|
||||
}
|
||||
|
||||
@@ -231,7 +235,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
ReflectionUtils.findMethod(NestedGenericInheritanceReturnTypeRecover.class, "bar", String.class));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Map<String, Map<Number, String>>> recoverResponseMapRe = (Map<String, Map<String, Map<Number, String>>>) barHandler
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
.recover(new Object[] { "Aldo" }, new RuntimeException("Planned"));
|
||||
assertThat(recoverResponseMapRe.get("bar").get("bar").get(0.0)).isEqualTo("barRecoverNumberValue");
|
||||
|
||||
}
|
||||
@@ -279,7 +283,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
new MultipleQualifyingRecoversExtendsThrowable(), foo);
|
||||
assertThat(handler.recover(new Object[] { "Kevin" }, new IllegalArgumentException("Planned"))).isEqualTo(2);
|
||||
assertThat(handler.recover(new Object[] { "Kevin" }, new UnsupportedOperationException("Planned")))
|
||||
.isEqualTo(3);
|
||||
.isEqualTo(3);
|
||||
|
||||
}
|
||||
|
||||
@@ -289,7 +293,7 @@ public class RecoverAnnotationRecoveryHandlerTests {
|
||||
RecoverAnnotationRecoveryHandler<?> handler = new RecoverAnnotationRecoveryHandler<Integer>(
|
||||
new InheritanceOnArgumentClass(), foo);
|
||||
assertThat(handler.recover(new Object[] { new ArrayList<String>() }, new IllegalArgumentException("Planned")))
|
||||
.isEqualTo(1);
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,8 +61,11 @@ public class BackOffPolicyBuilderTests {
|
||||
@Test
|
||||
public void shouldCreateUniformRandomBackOffPolicy() {
|
||||
Sleeper mockSleeper = mock(Sleeper.class);
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder().delay(1).maxDelay(5000).sleeper(mockSleeper)
|
||||
.build();
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder()
|
||||
.delay(1)
|
||||
.maxDelay(5000)
|
||||
.sleeper(mockSleeper)
|
||||
.build();
|
||||
assertThat(UniformRandomBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
|
||||
UniformRandomBackOffPolicy policy = (UniformRandomBackOffPolicy) backOffPolicy;
|
||||
assertThat(policy.getMinBackOffPeriod()).isEqualTo(1);
|
||||
@@ -73,8 +76,13 @@ public class BackOffPolicyBuilderTests {
|
||||
@Test
|
||||
public void shouldCreateExponentialBackOff() {
|
||||
Sleeper mockSleeper = mock(Sleeper.class);
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder().delay(100).maxDelay(1000).multiplier(2)
|
||||
.random(false).sleeper(mockSleeper).build();
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder()
|
||||
.delay(100)
|
||||
.maxDelay(1000)
|
||||
.multiplier(2)
|
||||
.random(false)
|
||||
.sleeper(mockSleeper)
|
||||
.build();
|
||||
assertThat(ExponentialBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
|
||||
ExponentialBackOffPolicy policy = (ExponentialBackOffPolicy) backOffPolicy;
|
||||
assertThat(policy.getInitialInterval()).isEqualTo(100);
|
||||
@@ -86,8 +94,13 @@ public class BackOffPolicyBuilderTests {
|
||||
@Test
|
||||
public void shouldCreateExponentialRandomBackOff() {
|
||||
Sleeper mockSleeper = mock(Sleeper.class);
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder().delay(10000).maxDelay(100000).multiplier(10)
|
||||
.random(true).sleeper(mockSleeper).build();
|
||||
BackOffPolicy backOffPolicy = BackOffPolicyBuilder.newBuilder()
|
||||
.delay(10000)
|
||||
.maxDelay(100000)
|
||||
.multiplier(10)
|
||||
.random(true)
|
||||
.sleeper(mockSleeper)
|
||||
.build();
|
||||
assertThat(ExponentialRandomBackOffPolicy.class.isAssignableFrom(backOffPolicy.getClass())).isTrue();
|
||||
ExponentialRandomBackOffPolicy policy = (ExponentialRandomBackOffPolicy) backOffPolicy;
|
||||
assertThat(policy.getInitialInterval()).isEqualTo(10000);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,9 +66,9 @@ public class ExponentialRandomBackOffPolicyTests {
|
||||
long expectedMaxValue = 2 * (long) (initialInterval
|
||||
+ initialInterval * Math.max(1, Math.pow(backOffPolicy.getMultiplier(), i)));
|
||||
assertThat(sleeps.get(i))
|
||||
.describedAs("Found a sleep [%d] which exceeds our max expected value of %d at interval %d",
|
||||
sleeps.get(i), expectedMaxValue, i)
|
||||
.isLessThan(expectedMaxValue);
|
||||
.describedAs("Found a sleep [%d] which exceeds our max expected value of %d at interval %d",
|
||||
sleeps.get(i), expectedMaxValue, i)
|
||||
.isLessThan(expectedMaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ public class ExponentialRandomBackOffPolicyTests {
|
||||
long expectedMaxValue = 2 * (long) (initialInterval
|
||||
+ initialInterval * Math.max(1, Math.pow(backOffPolicy.getMultiplier(), i)));
|
||||
assertThat(sleeps.get(i))
|
||||
.describedAs("Found a sleep [%d] which exceeds our max expected value of %d at interval %d",
|
||||
sleeps.get(i), expectedMaxValue, i)
|
||||
.isLessThanOrEqualTo(expectedMaxValue);
|
||||
.describedAs("Found a sleep [%d] which exceeds our max expected value of %d at interval %d",
|
||||
sleeps.get(i), expectedMaxValue, i)
|
||||
.isLessThanOrEqualTo(expectedMaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,7 +41,7 @@ public class ThreadWaitSleeperTests {
|
||||
long lower = desired - variance;
|
||||
long upper = desired + 2 * variance;
|
||||
assertThat(lower).describedAs("Expected value to be between '%d' and '%d' but was '%d'", lower, upper, actual)
|
||||
.isLessThanOrEqualTo(actual);
|
||||
.isLessThanOrEqualTo(actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,8 @@ public class RetryInterceptorBuilderTests {
|
||||
public void testWithCustomRetryTemplate() {
|
||||
RetryOperations retryOperations = new RetryTemplate();
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
|
||||
.retryOperations(retryOperations).build();
|
||||
.retryOperations(retryOperations)
|
||||
.build();
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(3);
|
||||
assertSame(retryOperations, TestUtils.getPropertyValue(interceptor, "retryOperations"));
|
||||
}
|
||||
@@ -67,40 +68,49 @@ public class RetryInterceptorBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testWithCustomizedBackOffMoreAttempts() {
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().maxAttempts(5)
|
||||
.backOffOptions(1, 2, 10).build();
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
|
||||
.maxAttempts(5)
|
||||
.backOffOptions(1, 2, 10)
|
||||
.build();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(5);
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.initialInterval"))
|
||||
.isEqualTo(1L);
|
||||
.isEqualTo(1L);
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.multiplier")).isEqualTo(2.0);
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.maxInterval")).isEqualTo(10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithCustomBackOffPolicy() {
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().maxAttempts(5)
|
||||
.backOffPolicy(new FixedBackOffPolicy()).build();
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
|
||||
.maxAttempts(5)
|
||||
.backOffPolicy(new FixedBackOffPolicy())
|
||||
.build();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(5);
|
||||
assertThat(TestUtils
|
||||
.getPropertyValue(interceptor, "retryOperations.backOffPolicy.backOffPeriod", Supplier.class).get())
|
||||
.isEqualTo(1000L);
|
||||
assertThat(
|
||||
TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.backOffPeriod", Supplier.class)
|
||||
.get())
|
||||
.isEqualTo(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithCustomNewMessageIdentifier() throws Exception {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().maxAttempts(5)
|
||||
.newMethodArgumentsIdentifier(args -> {
|
||||
latch.countDown();
|
||||
return false;
|
||||
}).backOffPolicy(new FixedBackOffPolicy()).build();
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
|
||||
.maxAttempts(5)
|
||||
.newMethodArgumentsIdentifier(args -> {
|
||||
latch.countDown();
|
||||
return false;
|
||||
})
|
||||
.backOffPolicy(new FixedBackOffPolicy())
|
||||
.build();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(5);
|
||||
assertThat(TestUtils
|
||||
.getPropertyValue(interceptor, "retryOperations.backOffPolicy.backOffPeriod", Supplier.class).get())
|
||||
.isEqualTo(1000L);
|
||||
assertThat(
|
||||
TestUtils.getPropertyValue(interceptor, "retryOperations.backOffPolicy.backOffPeriod", Supplier.class)
|
||||
.get())
|
||||
.isEqualTo(1000L);
|
||||
final AtomicInteger count = new AtomicInteger();
|
||||
Foo delegate = createDelegate(interceptor, count);
|
||||
Object message = "";
|
||||
@@ -117,9 +127,9 @@ public class RetryInterceptorBuilderTests {
|
||||
@Test
|
||||
public void testWitCustomRetryPolicyTraverseCause() {
|
||||
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful()
|
||||
.retryPolicy(new SimpleRetryPolicy(15,
|
||||
Collections.<Class<? extends Throwable>, Boolean>singletonMap(Exception.class, true), true))
|
||||
.build();
|
||||
.retryPolicy(new SimpleRetryPolicy(15,
|
||||
Collections.<Class<? extends Throwable>, Boolean>singletonMap(Exception.class, true), true))
|
||||
.build();
|
||||
assertThat(TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts")).isEqualTo(15);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -163,7 +163,7 @@ public class RetryOperationsInterceptorTests {
|
||||
assertThat(monitoringTags.entrySet()).hasSize(3);
|
||||
assertThat(monitoringTags.get(labelTagName)).isEqualTo(label);
|
||||
assertThat(monitoringTags.get(classTagName))
|
||||
.isEqualTo(RetryOperationsInterceptorTests.Service.class.getSimpleName());
|
||||
.isEqualTo(RetryOperationsInterceptorTests.Service.class.getSimpleName());
|
||||
assertThat(monitoringTags.get(methodTagName)).isEqualTo("service");
|
||||
assertThat(argumentsAsExpected.get()).isTrue();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -88,7 +88,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
public void testDefaultInterceptorSunnyDay() {
|
||||
((Advised) service).addAdvice(interceptor);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +96,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setLabel("FOO");
|
||||
((Advised) service).addAdvice(interceptor);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
assertThat(context.getAttribute(RetryContext.NAME)).isEqualTo("FOO");
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
public void testDefaultTransformerInterceptorSunnyDay() {
|
||||
((Advised) transformer).addAdvice(interceptor);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> transformer.transform("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
((Advised) service).addAdvice(interceptor);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2));
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
service.service("foo");
|
||||
assertThat(count).isEqualTo(2);
|
||||
@@ -143,7 +143,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2));
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> transformer.transform("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
Collection<String> result = transformer.transform("foo");
|
||||
assertThat(count).isEqualTo(2);
|
||||
@@ -156,10 +156,10 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
assertThatExceptionOfType(ExhaustedRetryException.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Retry exhausted");
|
||||
.withMessageStartingWith("Retry exhausted");
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> service.service("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
interceptor.setRecoverer((data, cause) -> {
|
||||
count++;
|
||||
@@ -216,7 +216,7 @@ public class StatefulRetryOperationsInterceptorTests {
|
||||
interceptor.setRetryOperations(retryTemplate);
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> transformer.transform("foo"))
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
.withMessageStartingWith("Not enough calls");
|
||||
assertThat(count).isEqualTo(1);
|
||||
interceptor.setRecoverer((data, cause) -> {
|
||||
count++;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,12 +75,12 @@ public class CircuitBreakerRetryTemplateTests {
|
||||
this.retryTemplate.setRetryPolicy(new CircuitBreakerRetryPolicy(new NeverRetryPolicy()));
|
||||
this.retryTemplate.setThrowLastExceptionOnExhausted(true);
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.state))
|
||||
.isEqualTo(this.callback.exceptionToThrow);
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.state))
|
||||
.isEqualTo(this.callback.exceptionToThrow);
|
||||
assertThat(this.callback.getAttempts()).isEqualTo(1);
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.state))
|
||||
.isEqualTo(this.callback.exceptionToThrow);
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.state))
|
||||
.isEqualTo(this.callback.exceptionToThrow);
|
||||
assertThat(this.callback.getAttempts()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ public class FatalExceptionRetryPolicyTests {
|
||||
|
||||
Object result = null;
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState("foo")));
|
||||
.isThrownBy(() -> retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState("foo")));
|
||||
result = retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState("foo"));
|
||||
// Callback is called once: the recovery path should also be called
|
||||
assertThat(callback.attempts).isEqualTo(1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public class MapRetryContextCacheTests {
|
||||
cache.setCapacity(1);
|
||||
cache.put("foo", context);
|
||||
assertThatExceptionOfType(RetryCacheCapacityExceededException.class)
|
||||
.isThrownBy(() -> cache.put("foo", context));
|
||||
.isThrownBy(() -> cache.put("foo", context));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -81,7 +81,7 @@ public class RetryContextSerializationTests {
|
||||
assertThat(context.getRetryCount()).isEqualTo(1);
|
||||
assertThat(
|
||||
((RetryContext) SerializationUtils.deserialize(SerializationUtils.serialize(context))).getRetryCount())
|
||||
.isEqualTo(1);
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -89,7 +89,7 @@ public class RetryContextSerializationTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testSerializationCycleForPolicy(RetryPolicy policy) {
|
||||
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize(policy)) instanceof RetryPolicy)
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public class SoftReferenceMapRetryContextCacheTests {
|
||||
cache.setCapacity(1);
|
||||
cache.put("foo", context);
|
||||
assertThatExceptionOfType(RetryCacheCapacityExceededException.class)
|
||||
.isThrownBy(() -> cache.put("foo", context));
|
||||
.isThrownBy(() -> cache.put("foo", context));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,12 +51,12 @@ public class StatefulRetryIntegrationTests {
|
||||
assertThat(cache.containsKey("foo")).isFalse();
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> retryTemplate.execute(callback, retryState))
|
||||
.withMessage(null);
|
||||
.withMessage(null);
|
||||
|
||||
assertThat(cache.containsKey("foo")).isTrue();
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> retryTemplate.execute(callback, retryState))
|
||||
.withMessageContaining("exhausted");
|
||||
.withMessageContaining("exhausted");
|
||||
|
||||
assertThat(cache.containsKey("foo")).isFalse();
|
||||
|
||||
@@ -80,7 +80,7 @@ public class StatefulRetryIntegrationTests {
|
||||
|
||||
Object result = "start_foo";
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> retryTemplate.execute(callback, retryState))
|
||||
.withMessage(null);
|
||||
.withMessage(null);
|
||||
|
||||
assertThat(cache.containsKey("foo")).isTrue();
|
||||
|
||||
@@ -108,7 +108,7 @@ public class StatefulRetryIntegrationTests {
|
||||
|
||||
Object result = "start_foo";
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> retryTemplate.execute(callback, retryState))
|
||||
.withMessage(null);
|
||||
.withMessage(null);
|
||||
|
||||
assertThat(cache.containsKey("foo")).isTrue();
|
||||
|
||||
@@ -158,7 +158,7 @@ public class StatefulRetryIntegrationTests {
|
||||
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1));
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> retryTemplate.execute(callback, retryState))
|
||||
.withMessage(null);
|
||||
.withMessage(null);
|
||||
|
||||
retryTemplate.execute(callback, retryState);
|
||||
// The second attempt is successful by design...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,7 +74,7 @@ public class CircuitBreakerInterceptorStatisticsTests {
|
||||
assertThat(result).isEqualTo(RECOVERED);
|
||||
assertThat(stats.getRecoveryCount()).describedAs("There should be two recoveries").isEqualTo(2);
|
||||
assertThat(stats.getErrorCount()).describedAs("There should only be one error because the circuit is now open")
|
||||
.isEqualTo(1);
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -85,7 +85,8 @@ public class CircuitBreakerStatisticsTests {
|
||||
assertThat(result).isEqualTo(RECOVERED);
|
||||
assertThat(stats.getRecoveryCount()).describedAs("There should be two recoveries", null).isEqualTo(2);
|
||||
assertThat(stats.getErrorCount())
|
||||
.describedAs("There should only be one error because the circuit is now open", null).isEqualTo(1);
|
||||
.describedAs("There should only be one error because the circuit is now open", null)
|
||||
.isEqualTo(1);
|
||||
assertThat(stats.getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_OPEN)).isEqualTo(Boolean.TRUE);
|
||||
// Both recoveries are through a short circuit because we used NeverRetryPolicy
|
||||
assertThat(stats.getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_SHORT_COUNT)).isEqualTo(2);
|
||||
@@ -99,7 +100,7 @@ public class CircuitBreakerStatisticsTests {
|
||||
throw new ExhaustedRetryException("Planned exhausted");
|
||||
};
|
||||
assertThatExceptionOfType(ExhaustedRetryException.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.recovery, this.state));
|
||||
.isThrownBy(() -> this.retryTemplate.execute(this.callback, this.recovery, this.state));
|
||||
MutableRetryStatistics stats = (MutableRetryStatistics) repository.findOne("test");
|
||||
assertThat(stats.getStartedCount()).isEqualTo(1);
|
||||
assertThat(stats.getAbortCount()).isEqualTo(1);
|
||||
@@ -123,7 +124,8 @@ public class CircuitBreakerStatisticsTests {
|
||||
MutableRetryStatistics stats = (MutableRetryStatistics) repository.findOne("test");
|
||||
assertThat(stats.getAbortCount()).describedAs("There should be two aborts").isEqualTo(2);
|
||||
assertThat(stats.getErrorCount())
|
||||
.describedAs("There should only be one error because the circuit is now open", null).isEqualTo(1);
|
||||
.describedAs("There should only be one error because the circuit is now open", null)
|
||||
.isEqualTo(1);
|
||||
assertThat(stats.getAttribute(CircuitBreakerRetryPolicy.CIRCUIT_OPEN)).isEqualTo(true);
|
||||
resetAndAssert(this.cache, stats);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,9 +44,9 @@ public class RetrySimulationTests {
|
||||
System.out.println("Percentiles: " + simulation.getPercentiles());
|
||||
|
||||
assertThat(simulation.getLongestTotalSleepSequence().getSleeps())
|
||||
.isEqualTo(Arrays.asList(400l, 400l, 400l, 400l));
|
||||
.isEqualTo(Arrays.asList(400l, 400l, 400l, 400l));
|
||||
assertThat(simulation.getPercentiles())
|
||||
.isEqualTo(Arrays.asList(400d, 400d, 400d, 400d, 400d, 400d, 400d, 400d, 400d));
|
||||
.isEqualTo(Arrays.asList(400d, 400d, 400d, 400d, 400d, 400d, 400d, 400d, 400d));
|
||||
assertThat(simulation.getPercentile(0.5)).isEqualTo(400d);
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ public class RetrySimulationTests {
|
||||
System.out.println("Percentiles: " + simulation.getPercentiles());
|
||||
|
||||
assertThat(simulation.getLongestTotalSleepSequence().getSleeps())
|
||||
.isEqualTo(Arrays.asList(100l, 200l, 400l, 800l));
|
||||
.isEqualTo(Arrays.asList(100l, 200l, 400l, 800l));
|
||||
assertThat(simulation.getPercentiles())
|
||||
.isEqualTo(Arrays.asList(100d, 100d, 200d, 200d, 300d, 400d, 400d, 800d, 800d));
|
||||
.isEqualTo(Arrays.asList(100d, 100d, 200d, 200d, 300d, 400d, 400d, 800d, 800d));
|
||||
assertThat(simulation.getPercentile(0.5f)).isEqualTo(300d);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,10 +79,15 @@ public class RetryTemplateBuilderTests {
|
||||
RetryListener listener1 = mock(RetryListener.class);
|
||||
RetryListener listener2 = mock(RetryListener.class);
|
||||
|
||||
RetryTemplate template = RetryTemplate.builder().maxAttempts(10).exponentialBackoff(99, 1.5, 1717)
|
||||
.retryOn(IOException.class)
|
||||
.retryOn(Collections.<Class<? extends Throwable>>singletonList(IllegalArgumentException.class))
|
||||
.traversingCauses().withListener(listener1).withListeners(Collections.singletonList(listener2)).build();
|
||||
RetryTemplate template = RetryTemplate.builder()
|
||||
.maxAttempts(10)
|
||||
.exponentialBackoff(99, 1.5, 1717)
|
||||
.retryOn(IOException.class)
|
||||
.retryOn(Collections.<Class<? extends Throwable>>singletonList(IllegalArgumentException.class))
|
||||
.traversingCauses()
|
||||
.withListener(listener1)
|
||||
.withListeners(Collections.singletonList(listener2))
|
||||
.build();
|
||||
|
||||
PolicyTuple policyTuple = PolicyTuple.extractWithAsserts(template);
|
||||
|
||||
@@ -108,7 +113,7 @@ public class RetryTemplateBuilderTests {
|
||||
@Test
|
||||
public void testFailOnRetryPoliciesConflict() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().maxAttempts(3).withinMillis(1000).build());
|
||||
.isThrownBy(() -> RetryTemplate.builder().maxAttempts(3).withinMillis(1000).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,15 +166,15 @@ public class RetryTemplateBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testFailOnNotationMix() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> RetryTemplate.builder().retryOn(IOException.class).notRetryOn(OutOfMemoryError.class));
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().retryOn(IOException.class).notRetryOn(OutOfMemoryError.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailOnNotationsMix() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> RetryTemplate.builder()
|
||||
.retryOn(Collections.<Class<? extends Throwable>>singletonList(IOException.class))
|
||||
.notRetryOn(Collections.<Class<? extends Throwable>>singletonList(OutOfMemoryError.class)));
|
||||
.retryOn(Collections.<Class<? extends Throwable>>singletonList(IOException.class))
|
||||
.notRetryOn(Collections.<Class<? extends Throwable>>singletonList(OutOfMemoryError.class)));
|
||||
}
|
||||
|
||||
/* ---------------- BackOff -------------- */
|
||||
@@ -182,7 +187,7 @@ public class RetryTemplateBuilderTests {
|
||||
@Test
|
||||
public void testFailOnBackOffPolicyConflict() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().noBackoff().fixedBackoff(1000).build());
|
||||
.isThrownBy(() -> RetryTemplate.builder().noBackoff().fixedBackoff(1000).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,19 +211,19 @@ public class RetryTemplateBuilderTests {
|
||||
@Test
|
||||
public void testValidateInitAndMax() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(100, 2, 100).build());
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(100, 2, 100).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateMeaninglessMultipier() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(100, 1, 200).build());
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(100, 1, 200).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateZeroInitInterval() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(0, 2, 200).build());
|
||||
.isThrownBy(() -> RetryTemplate.builder().exponentialBackoff(0, 2, 200).build());
|
||||
}
|
||||
|
||||
/* ---------------- Utils -------------- */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -225,11 +225,11 @@ public class RetryTemplateTests {
|
||||
assertThat(RetryTemplateTests.this.context).isNotSameAs(status1);
|
||||
assertThat(status1.getParent()).isSameAs(RetryTemplateTests.this.context);
|
||||
assertThat(RetrySynchronizationManager.getContext()).describedAs("The context should be the child")
|
||||
.isSameAs(status1);
|
||||
.isSameAs(status1);
|
||||
return null;
|
||||
});
|
||||
assertThat(RetrySynchronizationManager.getContext()).describedAs("The context should be restored")
|
||||
.isSameAs(status);
|
||||
.isSameAs(status);
|
||||
return result;
|
||||
});
|
||||
assertThat(this.count).isEqualTo(2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -93,7 +93,7 @@ public class StatefulRecoveryRetryTests {
|
||||
};
|
||||
Object result = null;
|
||||
assertThatExceptionOfType(Exception.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, recoveryCallback, state));
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, recoveryCallback, state));
|
||||
// On the second retry, the recovery path is taken...
|
||||
result = this.retryTemplate.execute(callback, recoveryCallback, state);
|
||||
assertThat(result).isEqualTo(input); // default result is the item
|
||||
@@ -139,9 +139,9 @@ public class StatefulRecoveryRetryTests {
|
||||
};
|
||||
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> this.retryTemplate.execute(callback, state))
|
||||
.withMessage("Barf!");
|
||||
.withMessage("Barf!");
|
||||
assertThatExceptionOfType(ExhaustedRetryException.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, state));
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, state));
|
||||
|
||||
RetryContext context = this.retryTemplate.open(retryPolicy, state);
|
||||
// True after exhausted - the history is reset...
|
||||
@@ -165,12 +165,12 @@ public class StatefulRecoveryRetryTests {
|
||||
};
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> this.retryTemplate.execute(callback, state))
|
||||
.withMessage("Barf!");
|
||||
.withMessage("Barf!");
|
||||
// Only fails second attempt because the algorithm to detect
|
||||
// inconsistent has codes relies on the cache having been used for this
|
||||
// item already...
|
||||
assertThatExceptionOfType(RetryException.class).isThrownBy(() -> this.retryTemplate.execute(callback, state))
|
||||
.withStackTraceContaining("inconsistent");
|
||||
.withStackTraceContaining("inconsistent");
|
||||
|
||||
RetryContext context = this.retryTemplate.open(retryPolicy, state);
|
||||
// True after exhausted - the history is reset...
|
||||
@@ -190,12 +190,12 @@ public class StatefulRecoveryRetryTests {
|
||||
};
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, new DefaultRetryState("foo")))
|
||||
.withMessage("Barf!");
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, new DefaultRetryState("foo")))
|
||||
.withMessage("Barf!");
|
||||
|
||||
assertThatExceptionOfType(RetryException.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, new DefaultRetryState("bar")))
|
||||
.withStackTraceContaining("capacity");
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, new DefaultRetryState("bar")))
|
||||
.withStackTraceContaining("capacity");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,7 +214,8 @@ public class StatefulRecoveryRetryTests {
|
||||
RecoveryCallback<Object> recoveryCallback = context -> null;
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, recoveryCallback, state)).withMessage("Barf!");
|
||||
.isThrownBy(() -> this.retryTemplate.execute(callback, recoveryCallback, state))
|
||||
.withMessage("Barf!");
|
||||
this.retryTemplate.execute(callback, recoveryCallback, state);
|
||||
|
||||
RetryContext context = this.retryTemplate.open(retryPolicy, state);
|
||||
|
||||
Reference in New Issue
Block a user