Polishing

This commit is contained in:
Sam Brannen
2025-12-08 17:11:38 +01:00
parent a9da900b5b
commit 68f8139206
3 changed files with 30 additions and 27 deletions
@@ -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 {
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;
}
@@ -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 {
@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 {
@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 {
}
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;
@@ -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();