|
26 | 26 | import org.junit.jupiter.params.provider.ValueSource;
|
27 | 27 | import reactor.core.publisher.Flux;
|
28 | 28 | import reactor.core.publisher.Mono;
|
| 29 | +import reactor.test.StepVerifier; |
29 | 30 |
|
30 | 31 | import org.springframework.cache.Cache;
|
31 | 32 | import org.springframework.cache.CacheManager;
|
@@ -145,6 +146,23 @@ void cacheErrorHandlerWithLoggingCacheErrorHandler() {
|
145 | 146 | assertThat(r1).as("cacheFlux blockFirst").isEqualTo(2L);
|
146 | 147 | }
|
147 | 148 |
|
| 149 | + @Test |
| 150 | + void cacheErrorHandlerWithLoggingCacheErrorHandlerAndMethodError() { |
| 151 | + AnnotationConfigApplicationContext ctx = |
| 152 | + new AnnotationConfigApplicationContext(ExceptionCacheManager.class, ReactiveFailureCacheableService.class, ErrorHandlerCachingConfiguration.class); |
| 153 | + ReactiveCacheableService service = ctx.getBean(ReactiveCacheableService.class); |
| 154 | + |
| 155 | + Object key = new Object(); |
| 156 | + StepVerifier.create(service.cacheMono(key)) |
| 157 | + .expectErrorMessage("mono service error") |
| 158 | + .verify(); |
| 159 | + |
| 160 | + key = new Object(); |
| 161 | + StepVerifier.create(service.cacheFlux(key)) |
| 162 | + .expectErrorMessage("flux service error") |
| 163 | + .verify(); |
| 164 | + } |
| 165 | + |
148 | 166 | @Test
|
149 | 167 | void cacheErrorHandlerWithSimpleCacheErrorHandler() {
|
150 | 168 | AnnotationConfigApplicationContext ctx =
|
@@ -214,6 +232,20 @@ Flux<Long> cacheFlux(Object arg) {
|
214 | 232 | }
|
215 | 233 | }
|
216 | 234 |
|
| 235 | + @CacheConfig(cacheNames = "first") |
| 236 | + static class ReactiveFailureCacheableService extends ReactiveCacheableService { |
| 237 | + |
| 238 | + @Cacheable |
| 239 | + Mono<Long> cacheMono(Object arg) { |
| 240 | + return Mono.error(new IllegalStateException("mono service error")); |
| 241 | + } |
| 242 | + |
| 243 | + @Cacheable |
| 244 | + Flux<Long> cacheFlux(Object arg) { |
| 245 | + return Flux.error(new IllegalStateException("flux service error")); |
| 246 | + } |
| 247 | + } |
| 248 | + |
217 | 249 |
|
218 | 250 | @Configuration(proxyBeanMethods = false)
|
219 | 251 | @EnableCaching
|
|
0 commit comments