Skip to content

Commit 854f6ff

Browse files
committed
Merge branch '6.1.x'
2 parents d79258a + e32a2f3 commit 854f6ff

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,8 @@ public Object findInCaches(CacheOperationContext context, Cache cache, Object ke
11551155
.onErrorResume(RuntimeException.class, ex -> {
11561156
try {
11571157
getErrorHandler().handleCacheGetError((RuntimeException) ex, cache, key);
1158-
return evaluate(null, invoker, method, contexts);
1158+
Object e = evaluate(null, invoker, method, contexts);
1159+
return (e != null ? e : Flux.error((RuntimeException) ex));
11591160
}
11601161
catch (RuntimeException exception) {
11611162
return Flux.error(exception);
@@ -1169,7 +1170,8 @@ public Object findInCaches(CacheOperationContext context, Cache cache, Object ke
11691170
.onErrorResume(RuntimeException.class, ex -> {
11701171
try {
11711172
getErrorHandler().handleCacheGetError((RuntimeException) ex, cache, key);
1172-
return evaluate(null, invoker, method, contexts);
1173+
Object e = evaluate(null, invoker, method, contexts);
1174+
return (e != null ? e : Mono.error((RuntimeException) ex));
11731175
}
11741176
catch (RuntimeException exception) {
11751177
return Mono.error(exception);

spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.jupiter.params.provider.ValueSource;
2727
import reactor.core.publisher.Flux;
2828
import reactor.core.publisher.Mono;
29+
import reactor.test.StepVerifier;
2930

3031
import org.springframework.cache.Cache;
3132
import org.springframework.cache.CacheManager;
@@ -145,6 +146,23 @@ void cacheErrorHandlerWithLoggingCacheErrorHandler() {
145146
assertThat(r1).as("cacheFlux blockFirst").isEqualTo(2L);
146147
}
147148

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+
148166
@Test
149167
void cacheErrorHandlerWithSimpleCacheErrorHandler() {
150168
AnnotationConfigApplicationContext ctx =
@@ -214,6 +232,20 @@ Flux<Long> cacheFlux(Object arg) {
214232
}
215233
}
216234

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+
217249

218250
@Configuration(proxyBeanMethods = false)
219251
@EnableCaching

0 commit comments

Comments
 (0)