Skip to content

Commit

Permalink
GH-2532: Ignore Kotlin Continuation Parameter
Browse files Browse the repository at this point in the history
Resolves #2532

The presence of the parameter caused the inferred type to be set to
`null` due to ambiguous parameters present.

It must be considered an ineligible type when inferring conversion types.

**cherry-pick to 3.0.x (#2533), 2.4.x (#2534)**

(cherry picked from commit f6d46f6)
  • Loading branch information
garyrussell authored and artembilan committed Oct 3, 2023
1 parent 3980b32 commit fceb0ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Expand Up @@ -425,7 +425,8 @@ private boolean isEligibleParameter(MethodParameter methodParameter) {
Type parameterType = methodParameter.getGenericParameterType();
if (parameterType.equals(Channel.class)
|| parameterType.equals(MessageProperties.class)
|| parameterType.equals(org.springframework.amqp.core.Message.class)) {
|| parameterType.equals(org.springframework.amqp.core.Message.class)
|| parameterType.getTypeName().startsWith("kotlin.coroutines.Continuation")) {
return false;
}
if (parameterType instanceof ParameterizedType) {
Expand Down
Expand Up @@ -21,12 +21,15 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isTrue
import org.junit.jupiter.api.Test
import org.springframework.amqp.core.AcknowledgeMode
import org.springframework.amqp.core.MessageListener
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
import org.springframework.amqp.rabbit.core.RabbitTemplate
import org.springframework.amqp.rabbit.junit.RabbitAvailable
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry
import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler
import org.springframework.amqp.utils.test.TestUtils
import org.springframework.aop.framework.ProxyFactory
import org.springframework.beans.BeansException
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -57,17 +60,20 @@ class EnableRabbitKotlinTests {
private lateinit var config: Config

@Test
fun `send and wait for consume`() {
fun `send and wait for consume`(@Autowired registry: RabbitListenerEndpointRegistry) {
val template = RabbitTemplate(this.config.cf())
template.convertAndSend("kotlinQueue", "test")
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue()
val listener = registry.getListenerContainer("single").messageListener
assertThat(TestUtils.getPropertyValue(listener, "messagingMessageConverter.inferredArgumentType").toString())
.isEqualTo("class java.lang.String")
}

@Test
fun `send and wait for consume with EH`() {
val template = RabbitTemplate(this.config.cf())
template.convertAndSend("kotlinQueue1", "test")
assertThat(this.config.ehLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(this.config.ehLatch.await(10, TimeUnit.SECONDS)).isTrue()
val reply = template.receiveAndConvert("kotlinReplyQueue", 10_000)
assertThat(reply).isEqualTo("error processed");
}
Expand All @@ -78,7 +84,7 @@ class EnableRabbitKotlinTests {

val latch = CountDownLatch(1)

@RabbitListener(queues = ["kotlinQueue"])
@RabbitListener(id = "single", queues = ["kotlinQueue"])
suspend fun handle(@Suppress("UNUSED_PARAMETER") data: String) {
this.latch.countDown()
}
Expand Down Expand Up @@ -121,7 +127,7 @@ class EnableRabbitKotlinTests {

}

@RabbitListener(queues = ["kotlinQueue1"], errorHandler = "#{eh}")
@RabbitListener(id = "multi", queues = ["kotlinQueue1"], errorHandler = "#{eh}")
@SendTo("kotlinReplyQueue")
open class Multi {

Expand Down

0 comments on commit fceb0ec

Please sign in to comment.