@@ -34,6 +34,7 @@ import org.apache.kafka.common.Metric
3434import org.apache.kafka.common.MetricName
3535import org.apache.kafka.common.PartitionInfo
3636import org.apache.kafka.common.TopicPartition
37+ import org.apache.kafka.common.Uuid
3738import org.apache.kafka.common.serialization.StringDeserializer
3839import org.apache.kafka.common.serialization.StringSerializer
3940import org.junit.jupiter.api.AfterAll
@@ -49,6 +50,8 @@ import java.util.concurrent.TimeUnit
4950import kotlin.test.assertEquals
5051import kotlin.time.Duration.Companion.seconds
5152
53+ private val testIterations: Int =
54+ System .getProperties().getProperty(" io.github.nomisrev.kafka.TEST_ITERATIONS" )?.toIntOrNull() ? : 1
5255
5356@TestInstance(TestInstance .Lifecycle .PER_CLASS )
5457abstract class KafkaSpec {
@@ -62,7 +65,7 @@ abstract class KafkaSpec {
6265 fun destroy () {
6366 kafka.stop()
6467 }
65-
68+
6669 @BeforeAll
6770 @JvmStatic
6871 fun setup () {
@@ -85,10 +88,10 @@ abstract class KafkaSpec {
8588 withEnv(" KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND" , " true" )
8689 withReuse(true )
8790 }
88-
91+
8992 fun KafkaReceiver (): KafkaReceiver <String , String > =
9093 KafkaReceiver (receiverSetting())
91-
94+
9295 fun receiverSetting (): ReceiverSettings <String , String > =
9396 ReceiverSettings (
9497 bootstrapServers = kafka.bootstrapServers,
@@ -168,15 +171,17 @@ abstract class KafkaSpec {
168171 partitions : Int = 4,
169172 replicationFactor : Short = 1,
170173 test : suspend TopicTestScope .(NewTopic ) -> Unit
171- ): Unit = runTest {
172- val topic = NewTopic (nextTopicName(), partitions, replicationFactor).configs(topicConfig)
173- admin {
174- createTopic(topic)
175- try {
176- TopicTestScope (topic, this @runTest).test(topic)
177- } finally {
178- topic.shouldBeEmpty()
179- deleteTopic(topic.name())
174+ ): Unit = repeat(testIterations) {
175+ runTest {
176+ val topic = NewTopic (nextTopicName(), partitions, replicationFactor).configs(topicConfig)
177+ admin {
178+ createTopic(topic)
179+ try {
180+ TopicTestScope (topic, this @runTest).test(topic)
181+ } finally {
182+ topic.shouldBeEmpty()
183+ deleteTopic(topic.name())
184+ }
180185 }
181186 }
182187 }
@@ -295,6 +300,9 @@ abstract class KafkaSpec {
295300 {
296301 val producer = KafkaProducer (it.properties(), it.keySerializer, it.valueSerializer)
297302 object : Producer <String , String > {
303+ override fun clientInstanceId (p0 : Duration ? ): Uuid =
304+ producer.clientInstanceId(p0)
305+
298306 override fun close () {}
299307
300308 override fun close (timeout : Duration ? ) {}
0 commit comments