Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,29 @@ public static void createTopic(String topicName, int numOfPartitions, String boo
}

// validates topic is created
await().atMost(3, TimeUnit.SECONDS).until(() -> checkTopicExistence(topicName, bootstrapServers));
await().atMost(10, TimeUnit.SECONDS).until(() -> checkTopicExistence(topicName, bootstrapServers));
}

public static boolean checkTopicExistence(String topicName, String bootstrapServers) {
return getAdminClient(bootstrapServers, (client -> {
Map<String, KafkaFuture<TopicDescription>> topics = client.describeTopics(List.of(topicName)).values();
Map<String, KafkaFuture<TopicDescription>> topics = client.describeTopics(List.of(topicName)).topicNameValues();

try {
return topics.containsKey(topicName) && topics.get(topicName).get().name().equals(topicName);
} catch (InterruptedException e) {
LOGGER.error("error on checkTopicExistence", e);
return false;
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("error on checkTopicExistence", e);
return false;
}
}));
}

private static <Rep> Rep getAdminClient(String bootstrapServer, Function<AdminClient, Rep> function) {
AdminClient adminClient = KafkaAdminClient.create(
Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer, AdminClientConfig.CLIENT_ID_CONFIG, "test")
);
try {
try (
AdminClient adminClient = KafkaAdminClient.create(
Map.of(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer, AdminClientConfig.CLIENT_ID_CONFIG, "test")
)
) {
return function.apply(adminClient);
} finally {
adminClient.close();
}
}
}
Loading