cmccabe commented on a change in pull request #11410: URL: https://github.com/apache/kafka/pull/11410#discussion_r732090271
########## File path: core/src/test/scala/unit/kafka/utils/TestUtils.scala ########## @@ -346,6 +367,97 @@ object TestUtils extends Logging { config.setProperty(KafkaConfig.LogMessageFormatVersionProp, version.version) } + def createAdminClient[B <: KafkaBroker]( + brokers: Seq[B], + adminConfig: Properties): Admin = { + val adminClientProperties = if (adminConfig.isEmpty) { + val newConfig = new Properties() + newConfig.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, getBrokerListStrFromServers(brokers)) + newConfig + } else { + adminConfig + } + Admin.create(adminClientProperties) + } + + def createTopicWithAdmin[B <: KafkaBroker]( + topic: String, + numPartitions: Int = 1, + replicationFactor: Int = 1, + brokers: Seq[B], + topicConfig: Properties = new Properties, + adminConfig: Properties = new Properties): scala.collection.immutable.Map[Int, Int] = { + val adminClient = createAdminClient(brokers, adminConfig) + try { + val configsMap = new java.util.HashMap[String, String]() + topicConfig.forEach((k, v) => configsMap.put(k.toString, v.toString)) + try { + adminClient.createTopics(Collections.singletonList(new NewTopic( + topic, numPartitions, replicationFactor.toShort).configs(configsMap))).all().get() + } catch { + case e: ExecutionException => if (e.getCause != null && + e.getCause.isInstanceOf[TopicExistsException] && + topicHasSameNumPartitionsAndReplicationFactor(adminClient, topic, numPartitions, replicationFactor)) { + } else { Review comment: ok -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org