Perform retryable proceed() call on invocableClone()

Closes gh-35353
This commit is contained in:
Juergen Hoeller
2025-08-21 17:38:07 +02:00
parent 57fa52262e
commit 8f4107953d
2 changed files with 37 additions and 3 deletions
@@ -17,18 +17,21 @@
package org.springframework.resilience;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.AccessDeniedException;
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import org.aopalliance.intercept.MethodInterceptor;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.framework.ProxyConfig;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -59,7 +62,30 @@ class RetryInterceptorTests {
pf.setTarget(target);
pf.addAdvice(new SimpleRetryInterceptor(
new MethodRetrySpec((m, t) -> true, 5, Duration.ofMillis(10))));
NonAnnotatedBean proxy = (NonAnnotatedBean) pf.getProxy();
pf.addAdvice(new SimpleTraceInterceptor());
PlainInterface proxy = (PlainInterface) pf.getProxy();
assertThatIOException().isThrownBy(proxy::retryOperation).withMessage("6");
assertThat(target.counter).isEqualTo(6);
}
@Test
void withSimpleInterceptorAndNoTarget() {
NonAnnotatedBean target = new NonAnnotatedBean();
ProxyFactory pf = new ProxyFactory();
pf.addAdvice(new SimpleRetryInterceptor(
new MethodRetrySpec((m, t) -> true, 5, Duration.ofMillis(10))));
pf.addAdvice(new SimpleTraceInterceptor());
pf.addAdvice((MethodInterceptor) invocation -> {
try {
return invocation.getMethod().invoke(target, invocation.getArguments());
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
});
pf.addInterface(PlainInterface.class);
PlainInterface proxy = (PlainInterface) pf.getProxy();
assertThatIOException().isThrownBy(proxy::retryOperation).withMessage("6");
assertThat(target.counter).isEqualTo(6);
@@ -237,7 +263,7 @@ class RetryInterceptorTests {
}
static class NonAnnotatedBean {
static class NonAnnotatedBean implements PlainInterface {
int counter = 0;
@@ -248,6 +274,12 @@ class RetryInterceptorTests {
}
public interface PlainInterface {
void retryOperation() throws IOException;
}
static class AnnotatedMethodBean {
int counter = 0;