Skip to content

Commit 68f8139

Browse files
committed
Polishing
1 parent a9da900 commit 68f8139

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ void withSimpleInterceptor() {
7070

7171
@Test
7272
void withPostProcessorForMethod() {
73-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
74-
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBean.class));
75-
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
76-
bpp.setBeanFactory(bf);
77-
bf.addBeanPostProcessor(bpp);
78-
AnnotatedMethodBean proxy = bf.getBean(AnnotatedMethodBean.class);
73+
AnnotatedMethodBean proxy = getProxiedAnnotatedMethodBean();
7974
AnnotatedMethodBean target = (AnnotatedMethodBean) AopProxyUtils.getSingletonTarget(proxy);
8075

8176
assertThatIllegalStateException()
@@ -329,13 +324,23 @@ private static ThrowingConsumer<? super Throwable> isRetryExhaustedException() {
329324
return ex -> assertThat(ex).matches(Exceptions::isRetryExhausted, "is RetryExhaustedException");
330325
}
331326

327+
private static AnnotatedMethodBean getProxiedAnnotatedMethodBean() {
328+
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBean.class);
329+
return bf.getBean(AnnotatedMethodBean.class);
330+
}
331+
332332
private static AnnotatedClassBean getProxiedAnnotatedClassBean() {
333+
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedClassBean.class);
334+
return bf.getBean(AnnotatedClassBean.class);
335+
}
336+
337+
private static DefaultListableBeanFactory createBeanFactoryFor(Class<?> beanClass) {
333338
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
334-
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedClassBean.class));
339+
bf.registerBeanDefinition("bean", new RootBeanDefinition(beanClass));
335340
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
336341
bpp.setBeanFactory(bf);
337342
bf.addBeanPostProcessor(bpp);
338-
return bf.getBean(AnnotatedClassBean.class);
343+
return bf;
339344
}
340345

341346

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ void withSimpleInterceptorAndNoTarget() {
9999

100100
@Test
101101
void withPostProcessorForMethod() {
102-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
103-
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBean.class));
104-
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
105-
bpp.setBeanFactory(bf);
106-
bf.addBeanPostProcessor(bpp);
102+
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBean.class);
107103
AnnotatedMethodBean proxy = bf.getBean(AnnotatedMethodBean.class);
108104
AnnotatedMethodBean target = (AnnotatedMethodBean) AopProxyUtils.getSingletonTarget(proxy);
109105

@@ -113,11 +109,7 @@ void withPostProcessorForMethod() {
113109

114110
@Test
115111
void withPostProcessorForMethodWithInterface() {
116-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
117-
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedMethodBeanWithInterface.class));
118-
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
119-
bpp.setBeanFactory(bf);
120-
bf.addBeanPostProcessor(bpp);
112+
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedMethodBeanWithInterface.class);
121113
AnnotatedInterface proxy = bf.getBean(AnnotatedInterface.class);
122114
AnnotatedMethodBeanWithInterface target = (AnnotatedMethodBeanWithInterface) AopProxyUtils.getSingletonTarget(proxy);
123115

@@ -179,11 +171,7 @@ void withPostProcessorForMethodWithInterfaceAndExposeInterfaces() {
179171

180172
@Test
181173
void withPostProcessorForClass() {
182-
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
183-
bf.registerBeanDefinition("bean", new RootBeanDefinition(AnnotatedClassBean.class));
184-
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
185-
bpp.setBeanFactory(bf);
186-
bf.addBeanPostProcessor(bpp);
174+
DefaultListableBeanFactory bf = createBeanFactoryFor(AnnotatedClassBean.class);
187175
AnnotatedClassBean proxy = bf.getBean(AnnotatedClassBean.class);
188176
AnnotatedClassBean target = (AnnotatedClassBean) AopProxyUtils.getSingletonTarget(proxy);
189177

@@ -324,6 +312,16 @@ void withAsyncAnnotation() {
324312
}
325313

326314

315+
private static DefaultListableBeanFactory createBeanFactoryFor(Class<?> beanClass) {
316+
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
317+
bf.registerBeanDefinition("bean", new RootBeanDefinition(beanClass));
318+
RetryAnnotationBeanPostProcessor bpp = new RetryAnnotationBeanPostProcessor();
319+
bpp.setBeanFactory(bf);
320+
bf.addBeanPostProcessor(bpp);
321+
return bf;
322+
}
323+
324+
327325
static class NonAnnotatedBean implements PlainInterface {
328326

329327
int counter = 0;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ public RetryListener getRetryListener() {
155155
Throwable lastException = initialException;
156156
while (this.retryPolicy.shouldRetry(lastException)) {
157157
try {
158-
long duration = backOffExecution.nextBackOff();
159-
if (duration == BackOffExecution.STOP) {
158+
long sleepTime = backOffExecution.nextBackOff();
159+
if (sleepTime == BackOffExecution.STOP) {
160160
break;
161161
}
162162
logger.debug(() -> "Backing off for %dms after retryable operation '%s'"
163-
.formatted(duration, retryableName));
164-
Thread.sleep(duration);
163+
.formatted(sleepTime, retryableName));
164+
Thread.sleep(sleepTime);
165165
}
166166
catch (InterruptedException interruptedException) {
167167
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)