Skip to content

Commit

Permalink
Merge branch '6.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Nov 5, 2024
2 parents c6126b2 + 0beb56a commit 7e1d6fe
Show file tree
Hide file tree
Showing 11 changed files with 533 additions and 533 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ import kotlin.annotation.AnnotationTarget.TYPE
@SpringJUnitConfig(InterceptorConfig::class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class AspectJAutoProxyInterceptorKotlinIntegrationTests(
@Autowired val echo: Echo,
@Autowired val firstAdvisor: TestPointcutAdvisor,
@Autowired val secondAdvisor: TestPointcutAdvisor,
@Autowired val countingAspect: CountingAspect,
@Autowired val reactiveTransactionManager: ReactiveCallCountingTransactionManager) {

@Test
fun `Multiple interceptors with regular function`() {
assertThat(firstAdvisor.interceptor.invocations).isEmpty()
assertThat(secondAdvisor.interceptor.invocations).isEmpty()
val value = "Hello!"
assertThat(echo.echo(value)).isEqualTo(value)
@Autowired val echo: Echo,
@Autowired val firstAdvisor: TestPointcutAdvisor,
@Autowired val secondAdvisor: TestPointcutAdvisor,
@Autowired val countingAspect: CountingAspect,
@Autowired val reactiveTransactionManager: ReactiveCallCountingTransactionManager) {

@Test
fun `Multiple interceptors with regular function`() {
assertThat(firstAdvisor.interceptor.invocations).isEmpty()
assertThat(secondAdvisor.interceptor.invocations).isEmpty()
val value = "Hello!"
assertThat(echo.echo(value)).isEqualTo(value)
assertThat(firstAdvisor.interceptor.invocations).singleElement().matches { String::class.java.isAssignableFrom(it) }
assertThat(secondAdvisor.interceptor.invocations).singleElement().matches { String::class.java.isAssignableFrom(it) }
}

@Test
fun `Multiple interceptors with suspending function`() {
assertThat(firstAdvisor.interceptor.invocations).isEmpty()
assertThat(secondAdvisor.interceptor.invocations).isEmpty()
val value = "Hello!"
runBlocking {
assertThat(echo.suspendingEcho(value)).isEqualTo(value)
}
}

@Test
fun `Multiple interceptors with suspending function`() {
assertThat(firstAdvisor.interceptor.invocations).isEmpty()
assertThat(secondAdvisor.interceptor.invocations).isEmpty()
val value = "Hello!"
runBlocking {
assertThat(echo.suspendingEcho(value)).isEqualTo(value)
}
assertThat(firstAdvisor.interceptor.invocations).singleElement().matches { Mono::class.java.isAssignableFrom(it) }
assertThat(secondAdvisor.interceptor.invocations).singleElement().matches { Mono::class.java.isAssignableFrom(it) }
}
}

@Test // gh-33095
fun `Aspect and reactive transactional with suspending function`() {
Expand Down Expand Up @@ -113,17 +113,17 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
assertThat(countingAspect.counter).`as`("aspect applied once per key").isEqualTo(2)
}

@Configuration
@EnableAspectJAutoProxy
@EnableTransactionManagement
@Configuration
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableCaching
open class InterceptorConfig {
open class InterceptorConfig {

@Bean
open fun firstAdvisor() = TestPointcutAdvisor().apply { order = 0 }
@Bean
open fun firstAdvisor() = TestPointcutAdvisor().apply { order = 0 }

@Bean
open fun secondAdvisor() = TestPointcutAdvisor().apply { order = 1 }
@Bean
open fun secondAdvisor() = TestPointcutAdvisor().apply { order = 1 }

@Bean
open fun countingAspect() = CountingAspect()
Expand All @@ -138,34 +138,34 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
return ConcurrentMapCacheManager()
}

@Bean
open fun echo(): Echo {
return Echo()
}
}
@Bean
open fun echo(): Echo {
return Echo()
}
}

class TestMethodInterceptor: MethodInterceptor {
class TestMethodInterceptor: MethodInterceptor {

var invocations: MutableList<Class<*>> = mutableListOf()
var invocations: MutableList<Class<*>> = mutableListOf()

@Suppress("RedundantNullableReturnType")
override fun invoke(invocation: MethodInvocation): Any? {
val result = invocation.proceed()
invocations.add(result!!.javaClass)
return result
}
@Suppress("RedundantNullableReturnType")
override fun invoke(invocation: MethodInvocation): Any? {
val result = invocation.proceed()
invocations.add(result!!.javaClass)
return result
}

}
}

class TestPointcutAdvisor : StaticMethodMatcherPointcutAdvisor(TestMethodInterceptor()) {
class TestPointcutAdvisor : StaticMethodMatcherPointcutAdvisor(TestMethodInterceptor()) {

val interceptor: TestMethodInterceptor
get() = advice as TestMethodInterceptor
val interceptor: TestMethodInterceptor
get() = advice as TestMethodInterceptor

override fun matches(method: Method, targetClass: Class<*>): Boolean {
return targetClass == Echo::class.java && method.name.lowercase().endsWith("echo")
}
}
override fun matches(method: Method, targetClass: Class<*>): Boolean {
return targetClass == Echo::class.java && method.name.lowercase().endsWith("echo")
}
}

@Target(CLASS, FUNCTION, ANNOTATION_CLASS, TYPE)
@Retention(AnnotationRetention.RUNTIME)
Expand All @@ -185,16 +185,16 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
}
}

open class Echo {
open class Echo {

open fun echo(value: String): String {
return value
}
open fun echo(value: String): String {
return value
}

open suspend fun suspendingEcho(value: String): String {
delay(1)
return value
}
open suspend fun suspendingEcho(value: String): String {
delay(1)
return value
}

@Transactional
@Counting
Expand All @@ -212,6 +212,6 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests(
return "$value ${cacheCounter++}"
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import kotlin.coroutines.Continuation
*/
class AopUtilsKotlinTests {

@Test
fun `Invoking suspending function should return Mono`() {
val value = "foo"
val method = ReflectionUtils.findMethod(WithoutInterface::class.java, "handle",
@Test
fun `Invoking suspending function should return Mono`() {
val value = "foo"
val method = ReflectionUtils.findMethod(WithoutInterface::class.java, "handle",
String::class. java, Continuation::class.java)!!
val continuation = Continuation<Any>(CoroutineName("test")) { }
val continuation = Continuation<Any>(CoroutineName("test")) { }
val result = AopUtils.invokeJoinpointUsingReflection(WithoutInterface(), method, arrayOf(value, continuation))
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
assertThat(it.block()).isEqualTo(value)
}
}
assertThat(result).isInstanceOfSatisfying(Mono::class.java) {
assertThat(it.block()).isEqualTo(value)
}
}

@Test
fun `Invoking suspending function on bridged method should return Mono`() {
Expand All @@ -54,11 +54,11 @@ class AopUtilsKotlinTests {
}
}

@Suppress("unused")
suspend fun suspendingFunction(value: String): String {
delay(1)
return value
}
@Suppress("unused")
suspend fun suspendingFunction(value: String): String {
delay(1)
return value
}

class WithoutInterface {
suspend fun handle(value: String): String {
Expand Down
Loading

0 comments on commit 7e1d6fe

Please sign in to comment.