|
1 | 1 | /*
|
2 |
| - * Copyright 2006-2023 the original author or authors. |
| 2 | + * Copyright 2006-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
29 | 29 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
30 | 30 | import org.springframework.context.annotation.Bean;
|
31 | 31 | import org.springframework.context.annotation.Configuration;
|
| 32 | +import org.springframework.retry.ExhaustedRetryException; |
32 | 33 | import org.springframework.retry.RetryContext;
|
33 | 34 | import org.springframework.retry.policy.CircuitBreakerRetryPolicy;
|
34 | 35 | import org.springframework.retry.support.RetrySynchronizationManager;
|
@@ -106,15 +107,21 @@ void runtimeExpressions() throws Exception {
|
106 | 107 | assertThat(maxAttempts.get()).isEqualTo(10);
|
107 | 108 | CircuitBreakerRetryPolicy policy = TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy",
|
108 | 109 | CircuitBreakerRetryPolicy.class);
|
109 |
| - Supplier openTO = TestUtils.getPropertyValue(policy, "openTimeoutSupplier", Supplier.class); |
| 110 | + Supplier<?> openTO = TestUtils.getPropertyValue(policy, "openTimeoutSupplier", Supplier.class); |
110 | 111 | assertThat(openTO).isNotNull();
|
111 | 112 | assertThat(openTO.get()).isEqualTo(10000L);
|
112 |
| - Supplier resetTO = TestUtils.getPropertyValue(policy, "resetTimeoutSupplier", Supplier.class); |
| 113 | + Supplier<?> resetTO = TestUtils.getPropertyValue(policy, "resetTimeoutSupplier", Supplier.class); |
113 | 114 | assertThat(resetTO).isNotNull();
|
114 | 115 | assertThat(resetTO.get()).isEqualTo(20000L);
|
115 | 116 | RetryContext ctx = service.getContext();
|
116 | 117 | assertThat(TestUtils.getPropertyValue(ctx, "openWindow")).isEqualTo(10000L);
|
117 | 118 | assertThat(TestUtils.getPropertyValue(ctx, "timeout")).isEqualTo(20000L);
|
| 119 | + |
| 120 | + assertThatExceptionOfType(ExhaustedRetryException.class).isThrownBy(service::exhaustedRetryService); |
| 121 | + |
| 122 | + assertThatExceptionOfType(RuntimeException.class).isThrownBy(service::noWrapExhaustedRetryService) |
| 123 | + .withMessage("Planned"); |
| 124 | + |
118 | 125 | context.close();
|
119 | 126 | }
|
120 | 127 |
|
@@ -154,6 +161,10 @@ interface Service {
|
154 | 161 |
|
155 | 162 | void expressionService3();
|
156 | 163 |
|
| 164 | + void exhaustedRetryService(); |
| 165 | + |
| 166 | + void noWrapExhaustedRetryService(); |
| 167 | + |
157 | 168 | int getCount();
|
158 | 169 |
|
159 | 170 | RetryContext getContext();
|
@@ -197,6 +208,18 @@ public void expressionService3() {
|
197 | 208 | this.count++;
|
198 | 209 | }
|
199 | 210 |
|
| 211 | + @Override |
| 212 | + @CircuitBreaker |
| 213 | + public void exhaustedRetryService() { |
| 214 | + throw new RuntimeException("Planned"); |
| 215 | + } |
| 216 | + |
| 217 | + @Override |
| 218 | + @CircuitBreaker(throwLastExceptionOnExhausted = true) |
| 219 | + public void noWrapExhaustedRetryService() { |
| 220 | + throw new RuntimeException("Planned"); |
| 221 | + } |
| 222 | + |
200 | 223 | @Override
|
201 | 224 | public RetryContext getContext() {
|
202 | 225 | return this.context;
|
|
0 commit comments