Skip to content
Closed
Show file tree
Hide file tree
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 @@ -27,6 +27,7 @@
import org.apache.kafka.clients.admin.CreatePartitionsResult;
import org.apache.kafka.clients.admin.NewPartitions;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.admin.OffsetSpec;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
Expand Down Expand Up @@ -134,6 +135,15 @@ public void createTopicWithPartitions(String topicName, int numPartitions)
admin.createTopics(
List.of(new NewTopic(topicName, numPartitions, (short) 1))
).all().get();

// createTopics() may complete before the partition leaders are ready to
// handle requests. Verify every partition through its leader before
// allowing callers to start a supervisor or publish records.
final Map<TopicPartition, OffsetSpec> partitionOffsets = new HashMap<>();
for (int partition = 0; partition < numPartitions; partition++) {
partitionOffsets.put(new TopicPartition(topicName, partition), OffsetSpec.latest());
}
admin.listOffsets(partitionOffsets).all().get();
Comment thread
FrankChen021 marked this conversation as resolved.
}
catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -60,6 +61,16 @@ public void testKafka()
final String topicName = "test-topic";
resource.createTopicWithPartitions(topicName, 3);
assertEquals(Set.of(topicName), resource.listTopics());

// Verify that callers can publish immediately after topic creation.
resource.publishRecordsToTopicWithoutTransaction(
topicName,
Collections.nCopies(1_000, new byte[]{1})
);
final Map<String, Long> partitionOffsets = resource.getPartitionOffsets(topicName);
assertEquals(3, partitionOffsets.size());
assertEquals(1_000, partitionOffsets.values().stream().mapToLong(Long::longValue).sum());
Comment thread
FrankChen021 marked this conversation as resolved.

resource.deleteTopic(topicName);

resource.stop();
Expand Down
Loading