Skip to content

Commit

Permalink
try to fix kafka test not waiting for created topic
Browse files Browse the repository at this point in the history
  • Loading branch information
mslabek committed Nov 26, 2024
1 parent 41870ee commit 2fd52cd
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import org.apache.kafka.clients.admin.{NewTopic, TopicDescription}
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.{Callback, KafkaProducer, ProducerRecord, RecordMetadata}
import org.apache.kafka.common.header.Headers
import retry.When

import java.time.Duration
import java.util
import java.util.{Collections, UUID}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Future, Promise}
import scala.concurrent.{Await, Future, Promise}
import scala.jdk.CollectionConverters._
import scala.util.{Failure, Success, Try}
import scala.concurrent.duration._
Expand All @@ -33,12 +32,15 @@ class KafkaClient(kafkaAddress: String, id: String) extends LazyLogging {
def createTopic(name: String, partitions: Int = 5): Unit = {
adminClient.createTopics(Collections.singletonList(new NewTopic(name, partitions, 1: Short))).all().get()
// When kraft enabled, topics doesn't appear instantly after createTopic
retry.Pause(10, 1.second)(Timer.default)(
Future {
topic(name)
}
val maxTime = 10.seconds
Await.result(
retry.Pause(10, 1.second)(Timer.default)(
Future {
topic(name)
}
),
maxTime
)

}

def deleteTopic(name: String): Unit =
Expand Down

0 comments on commit 2fd52cd

Please sign in to comment.