1
1
/*
2
- * Copyright 2016-2024 the original author or authors.
2
+ * Copyright 2016-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.apache.kafka.clients.producer.ProducerConfig
20
20
import org.apache.kafka.common.serialization.StringDeserializer
21
21
import org.apache.kafka.common.serialization.StringSerializer
22
22
import org.assertj.core.api.Assertions.assertThat
23
+ import org.awaitility.Awaitility.await
23
24
import org.junit.jupiter.api.Test
24
25
import org.springframework.beans.factory.annotation.Autowired
25
26
import org.springframework.beans.factory.annotation.Value
@@ -29,10 +30,16 @@ import org.springframework.kafka.annotation.EnableKafka
29
30
import org.springframework.kafka.annotation.KafkaHandler
30
31
import org.springframework.kafka.annotation.KafkaListener
31
32
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
32
- import org.springframework.kafka.core.*
33
+ import org.springframework.kafka.core.ConsumerFactory
34
+ import org.springframework.kafka.core.DefaultKafkaConsumerFactory
35
+ import org.springframework.kafka.core.DefaultKafkaProducerFactory
36
+ import org.springframework.kafka.core.KafkaTemplate
37
+ import org.springframework.kafka.core.ProducerFactory
33
38
import org.springframework.kafka.listener.KafkaListenerErrorHandler
39
+ import org.springframework.kafka.support.Acknowledgment
34
40
import org.springframework.kafka.test.EmbeddedKafkaBroker
35
41
import org.springframework.kafka.test.context.EmbeddedKafka
42
+ import org.springframework.kafka.test.utils.KafkaTestUtils
36
43
import org.springframework.messaging.handler.annotation.SendTo
37
44
import org.springframework.test.annotation.DirtiesContext
38
45
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig
@@ -45,6 +52,7 @@ import java.util.concurrent.TimeUnit
45
52
* Kotlin Annotated async return listener tests.
46
53
*
47
54
* @author Wang ZhiYang
55
+ * @author Artem Bilan
48
56
*
49
57
* @since 3.1
50
58
*/
@@ -65,6 +73,11 @@ class EnableKafkaKotlinCoroutinesTests {
65
73
this .template.send(" kotlinAsyncTestTopic1" , " foo" )
66
74
assertThat(this .config.latch1.await(10 , TimeUnit .SECONDS )).isTrue()
67
75
assertThat(this .config.received).isEqualTo(" foo" )
76
+ await()
77
+ .untilAsserted {
78
+ assertThat(KafkaTestUtils .getPropertyValue(this .config.acknowledgment, " acked" ))
79
+ .isEqualTo(java.lang.Boolean .TRUE )
80
+ }
68
81
}
69
82
70
83
@Test
@@ -114,6 +127,8 @@ class EnableKafkaKotlinCoroutinesTests {
114
127
@Volatile
115
128
lateinit var received: String
116
129
130
+ lateinit var acknowledgment: Acknowledgment
131
+
117
132
@Volatile
118
133
lateinit var batchReceived: String
119
134
@@ -204,8 +219,9 @@ class EnableKafkaKotlinCoroutinesTests {
204
219
205
220
@KafkaListener(id = " kotlin" , topics = [" kotlinAsyncTestTopic1" ],
206
221
containerFactory = " kafkaListenerContainerFactory" )
207
- suspend fun listen (value : String ) {
222
+ suspend fun listen (value : String , acknowledgment : Acknowledgment ) {
208
223
this .received = value
224
+ this .acknowledgment = acknowledgment
209
225
this .latch1.countDown()
210
226
}
211
227
0 commit comments