Browse Source

Polishing

pull/35990/head
Sam Brannen 1 week ago
parent
commit
68f8139206
  1. 21
      spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java
  2. 28
      spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java
  3. 8
      spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java

21
spring-context/src/test/java/org/springframework/resilience/ReactiveRetryInterceptorTests.java

@ -70,12 +70,7 @@ class ReactiveRetryInterceptorTests { @@ -70,12 +70,7 @@ class ReactiveRetryInterceptorTests {
@Test
void withPostProcessorForMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBean.class));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
AnnotatedMethodBean proxy = bf.getBean(AnnotatedMethodBean.class);
AnnotatedMethodBean proxy = getProxiedAnnotatedMethodBean();
AnnotatedMethodBean target = (AnnotatedMethodBean) AopProxyUtils.getSingletonTarget(proxy);
assertThatIllegalStateException()
@ -329,13 +324,23 @@ class ReactiveRetryInterceptorTests { @@ -329,13 +324,23 @@ class ReactiveRetryInterceptorTests {
return ex -> assertThat(ex).matches(Exceptions::isRetryExhausted, "is RetryExhaustedException");
}
private static AnnotatedMethodBean getProxiedAnnotatedMethodBean() {
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBean.class);
return bf.getBean(AnnotatedMethodBean.class);
}
private static AnnotatedClassBean getProxiedAnnotatedClassBean() {
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedClassBean.class);
return bf.getBean(AnnotatedClassBean.class);
}
private static DefaultListableBeanFactory createBeanFactoryFor(Class<?> beanClass) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedClassBean.class));
bf.registerBeanDefinition("bean", new RootBeanDefinition(beanClass));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
return bf.getBean(AnnotatedClassBean.class);
return bf;
}

28
spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java

@ -99,11 +99,7 @@ class RetryInterceptorTests { @@ -99,11 +99,7 @@ class RetryInterceptorTests {
@Test
void withPostProcessorForMethod() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBean.class));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBean.class);
AnnotatedMethodBean proxy = bf.getBean(AnnotatedMethodBean.class);
AnnotatedMethodBean target = (AnnotatedMethodBean) AopProxyUtils.getSingletonTarget(proxy);
@ -113,11 +109,7 @@ class RetryInterceptorTests { @@ -113,11 +109,7 @@ class RetryInterceptorTests {
@Test
void withPostProcessorForMethodWithInterface() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBeanWithInterface.class));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBeanWithInterface.class);
AnnotatedInterface proxy = bf.getBean(AnnotatedInterface.class);
AnnotatedMethodBeanWithInterface target = (AnnotatedMethodBeanWithInterface) AopProxyUtils.getSingletonTarget(proxy);
@ -179,11 +171,7 @@ class RetryInterceptorTests { @@ -179,11 +171,7 @@ class RetryInterceptorTests {
@Test
void withPostProcessorForClass() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedClassBean.class));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedClassBean.class);
AnnotatedClassBean proxy = bf.getBean(AnnotatedClassBean.class);
AnnotatedClassBean target = (AnnotatedClassBean) AopProxyUtils.getSingletonTarget(proxy);
@ -324,6 +312,16 @@ class RetryInterceptorTests { @@ -324,6 +312,16 @@ class RetryInterceptorTests {
}
private static DefaultListableBeanFactory createBeanFactoryFor(Class<?> beanClass) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("bean", new RootBeanDefinition(beanClass));
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
return bf;
}
static class NonAnnotatedBean implements PlainInterface {
int counter = 0;

8
spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java

@ -155,13 +155,13 @@ public class RetryTemplate implements RetryOperations { @@ -155,13 +155,13 @@ public class RetryTemplate implements RetryOperations {
Throwable lastException = initialException;
while (this.retryPolicy.shouldRetry(lastException)) {
try {
long duration = backOffExecution.nextBackOff();
if (duration == BackOffExecution.STOP) {
long sleepTime = backOffExecution.nextBackOff();
if (sleepTime == BackOffExecution.STOP) {
break;
}
logger.debug(() -> "Backing off for %dms after retryable operation '%s'"
.formatted(duration, retryableName));
Thread.sleep(duration);
.formatted(sleepTime, retryableName));
Thread.sleep(sleepTime);
}
catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();

Loading…
Cancel
Save