use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic in project kafka by apache.
the class MetadataTest method buildTopicCollection.
private MetadataResponseTopicCollection buildTopicCollection(String topic, MetadataResponsePartition partitionMetadata) {
MetadataResponseTopic topicMetadata = new MetadataResponseTopic().setErrorCode(Errors.NONE.code()).setName(topic).setIsInternal(false);
topicMetadata.setPartitions(Collections.singletonList(partitionMetadata));
MetadataResponseTopicCollection topics = new MetadataResponseTopicCollection();
topics.add(topicMetadata);
return topics;
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic in project kafka by apache.
the class KafkaAdminClientTest method expectMetadataRequest.
private void expectMetadataRequest(AdminClientUnitTestEnv env, TopicPartition topicPartition, Node leader) {
MetadataResponseData.MetadataResponseTopicCollection responseTopics = new MetadataResponseData.MetadataResponseTopicCollection();
MetadataResponseTopic responseTopic = new MetadataResponseTopic().setName(topicPartition.topic()).setErrorCode(Errors.NONE.code());
responseTopics.add(responseTopic);
MetadataResponsePartition responsePartition = new MetadataResponsePartition().setErrorCode(Errors.NONE.code()).setPartitionIndex(topicPartition.partition()).setLeaderId(leader.id()).setReplicaNodes(singletonList(leader.id())).setIsrNodes(singletonList(leader.id()));
responseTopic.partitions().add(responsePartition);
env.kafkaClient().prepareResponse(request -> {
if (!(request instanceof MetadataRequest)) {
return false;
}
MetadataRequest metadataRequest = (MetadataRequest) request;
return metadataRequest.topics().equals(singletonList(topicPartition.topic()));
}, new MetadataResponse(new MetadataResponseData().setTopics(responseTopics), MetadataResponseData.HIGHEST_SUPPORTED_VERSION));
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic in project kafka by apache.
the class PartitionLeaderStrategyTest method responseWithPartitionData.
private MetadataResponse responseWithPartitionData(Map<TopicPartition, MetadataResponsePartition> responsePartitions) {
MetadataResponseData responseData = new MetadataResponseData();
for (Map.Entry<TopicPartition, MetadataResponsePartition> entry : responsePartitions.entrySet()) {
TopicPartition topicPartition = entry.getKey();
MetadataResponseTopic responseTopic = responseData.topics().find(topicPartition.topic());
if (responseTopic == null) {
responseTopic = new MetadataResponseTopic().setName(topicPartition.topic()).setErrorCode(Errors.NONE.code());
responseData.topics().add(responseTopic);
}
responseTopic.partitions().add(entry.getValue());
}
return new MetadataResponse(responseData, ApiKeys.METADATA.latestVersion());
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic in project kafka by apache.
the class TopicAdminTest method prepareMetadataResponse.
private MetadataResponse prepareMetadataResponse(Cluster cluster, Errors error) {
List<MetadataResponseTopic> metadata = new ArrayList<>();
for (String topic : cluster.topics()) {
List<MetadataResponseData.MetadataResponsePartition> pms = new ArrayList<>();
for (PartitionInfo pInfo : cluster.availablePartitionsForTopic(topic)) {
MetadataResponseData.MetadataResponsePartition pm = new MetadataResponseData.MetadataResponsePartition().setErrorCode(error.code()).setPartitionIndex(pInfo.partition()).setLeaderId(pInfo.leader().id()).setLeaderEpoch(234).setReplicaNodes(Arrays.stream(pInfo.replicas()).map(Node::id).collect(Collectors.toList())).setIsrNodes(Arrays.stream(pInfo.inSyncReplicas()).map(Node::id).collect(Collectors.toList())).setOfflineReplicas(Arrays.stream(pInfo.offlineReplicas()).map(Node::id).collect(Collectors.toList()));
pms.add(pm);
}
MetadataResponseTopic tm = new MetadataResponseTopic().setErrorCode(error.code()).setName(topic).setIsInternal(false).setPartitions(pms);
metadata.add(tm);
}
return MetadataResponse.prepareResponse(true, 0, cluster.nodes(), cluster.clusterResource().clusterId(), cluster.controller().id(), metadata, MetadataResponse.AUTHORIZED_OPERATIONS_OMITTED);
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic in project kafka by apache.
the class GetListOffsetsCallsBenchmark method setup.
@Setup(Level.Trial)
public void setup() {
MetadataResponseData data = new MetadataResponseData();
List<MetadataResponseTopic> mrTopicList = new ArrayList<>();
Set<String> topics = new HashSet<>();
for (int topicIndex = 0; topicIndex < topicCount; topicIndex++) {
Uuid topicId = Uuid.randomUuid();
String topicName = "topic-" + topicIndex;
MetadataResponseTopic mrTopic = new MetadataResponseTopic().setTopicId(topicId).setName(topicName).setErrorCode((short) 0).setIsInternal(false);
List<MetadataResponsePartition> mrPartitionList = new ArrayList<>();
for (int partition = 0; partition < partitionCount; partition++) {
TopicPartition tp = new TopicPartition(topicName, partition);
topics.add(tp.topic());
futures.put(tp, new KafkaFutureImpl<>());
topicPartitionOffsets.put(tp, OffsetSpec.latest());
MetadataResponsePartition mrPartition = new MetadataResponsePartition().setLeaderId(partition % numNodes).setPartitionIndex(partition).setIsrNodes(Arrays.asList(0, 1, 2)).setReplicaNodes(Arrays.asList(0, 1, 2)).setOfflineReplicas(Collections.emptyList()).setErrorCode((short) 0);
mrPartitionList.add(mrPartition);
}
mrTopic.setPartitions(mrPartitionList);
mrTopicList.add(mrTopic);
}
data.setTopics(new MetadataResponseData.MetadataResponseTopicCollection(mrTopicList.listIterator()));
long deadline = 0L;
short version = 0;
context = new MetadataOperationContext<>(topics, new ListOffsetsOptions(), deadline, futures);
context.setResponse(Optional.of(new MetadataResponse(data, version)));
AdminClientUnitTestEnv adminEnv = new AdminClientUnitTestEnv(mockCluster());
admin = (KafkaAdminClient) adminEnv.adminClient();
}
Aggregations