@@ -28,6 +28,10 @@ import org.junit.jupiter.api.Test
28
28
import org.springframework.aop.framework.autoproxy.AspectJAutoProxyInterceptorKotlinIntegrationTests.InterceptorConfig
29
29
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor
30
30
import org.springframework.beans.factory.annotation.Autowired
31
+ import org.springframework.cache.CacheManager
32
+ import org.springframework.cache.annotation.Cacheable
33
+ import org.springframework.cache.annotation.EnableCaching
34
+ import org.springframework.cache.concurrent.ConcurrentMapCacheManager
31
35
import org.springframework.context.annotation.Bean
32
36
import org.springframework.context.annotation.Configuration
33
37
import org.springframework.context.annotation.EnableAspectJAutoProxy
@@ -93,9 +97,26 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
93
97
assertThat(reactiveTransactionManager.commits).`as `(" transactional applied" ).isOne()
94
98
}
95
99
100
+ @Test // gh-33210
101
+ fun `Aspect and cacheable with suspending function` () {
102
+ assertThat(countingAspect.counter).isZero()
103
+ val value = " Hello!"
104
+ runBlocking {
105
+ assertThat(echo.suspendingCacheableEcho(value)).isEqualTo(" $value 0" )
106
+ assertThat(echo.suspendingCacheableEcho(value)).isEqualTo(" $value 0" )
107
+ assertThat(echo.suspendingCacheableEcho(value)).isEqualTo(" $value 0" )
108
+ assertThat(countingAspect.counter).`as `(" aspect applied once" ).isOne()
109
+
110
+ assertThat(echo.suspendingCacheableEcho(" $value bis" )).isEqualTo(" $value bis 1" )
111
+ assertThat(echo.suspendingCacheableEcho(" $value bis" )).isEqualTo(" $value bis 1" )
112
+ }
113
+ assertThat(countingAspect.counter).`as `(" aspect applied once per key" ).isEqualTo(2 )
114
+ }
115
+
96
116
@Configuration
97
117
@EnableAspectJAutoProxy
98
118
@EnableTransactionManagement
119
+ @EnableCaching
99
120
open class InterceptorConfig {
100
121
101
122
@Bean
@@ -112,6 +133,11 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
112
133
return ReactiveCallCountingTransactionManager ()
113
134
}
114
135
136
+ @Bean
137
+ open fun cacheManager (): CacheManager {
138
+ return ConcurrentMapCacheManager ()
139
+ }
140
+
115
141
@Bean
116
142
open fun echo (): Echo {
117
143
return Echo ()
@@ -155,7 +181,7 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
155
181
fun logging (joinPoint : ProceedingJoinPoint ): Any {
156
182
return (joinPoint.proceed(joinPoint.args) as Mono <* >).doOnTerminate {
157
183
counter++
158
- }
184
+ }.checkpoint( " CountingAspect " )
159
185
}
160
186
}
161
187
@@ -177,6 +203,15 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
177
203
return value
178
204
}
179
205
206
+ open var cacheCounter: Int = 0
207
+
208
+ @Counting
209
+ @Cacheable(" something" )
210
+ open suspend fun suspendingCacheableEcho (value : String ): String {
211
+ delay(1 )
212
+ return " $value ${cacheCounter++ } "
213
+ }
214
+
180
215
}
181
216
182
217
}
0 commit comments