11/*
2- * Copyright 2016-2024 the original author or authors.
2+ * Copyright 2016-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.apache.kafka.clients.producer.ProducerConfig
2020import org.apache.kafka.common.serialization.StringDeserializer
2121import org.apache.kafka.common.serialization.StringSerializer
2222import org.assertj.core.api.Assertions.assertThat
23+ import org.awaitility.Awaitility.await
2324import org.junit.jupiter.api.Test
2425import org.springframework.beans.factory.annotation.Autowired
2526import org.springframework.beans.factory.annotation.Value
@@ -29,10 +30,16 @@ import org.springframework.kafka.annotation.EnableKafka
2930import org.springframework.kafka.annotation.KafkaHandler
3031import org.springframework.kafka.annotation.KafkaListener
3132import 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
3338import org.springframework.kafka.listener.KafkaListenerErrorHandler
39+ import org.springframework.kafka.support.Acknowledgment
3440import org.springframework.kafka.test.EmbeddedKafkaBroker
3541import org.springframework.kafka.test.context.EmbeddedKafka
42+ import org.springframework.kafka.test.utils.KafkaTestUtils
3643import org.springframework.messaging.handler.annotation.SendTo
3744import org.springframework.test.annotation.DirtiesContext
3845import org.springframework.test.context.junit.jupiter.SpringJUnitConfig
@@ -45,6 +52,7 @@ import java.util.concurrent.TimeUnit
4552 * Kotlin Annotated async return listener tests.
4653 *
4754 * @author Wang ZhiYang
55+ * @author Artem Bilan
4856 *
4957 * @since 3.1
5058 */
@@ -65,6 +73,11 @@ class EnableKafkaKotlinCoroutinesTests {
6573 this .template.send(" kotlinAsyncTestTopic1" , " foo" )
6674 assertThat(this .config.latch1.await(10 , TimeUnit .SECONDS )).isTrue()
6775 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+ }
6881 }
6982
7083 @Test
@@ -114,6 +127,8 @@ class EnableKafkaKotlinCoroutinesTests {
114127 @Volatile
115128 lateinit var received: String
116129
130+ lateinit var acknowledgment: Acknowledgment
131+
117132 @Volatile
118133 lateinit var batchReceived: String
119134
@@ -204,8 +219,9 @@ class EnableKafkaKotlinCoroutinesTests {
204219
205220 @KafkaListener(id = " kotlin" , topics = [" kotlinAsyncTestTopic1" ],
206221 containerFactory = " kafkaListenerContainerFactory" )
207- suspend fun listen (value : String ) {
222+ suspend fun listen (value : String , acknowledgment : Acknowledgment ) {
208223 this .received = value
224+ this .acknowledgment = acknowledgment
209225 this .latch1.countDown()
210226 }
211227
0 commit comments