use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponsePartition 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.MetadataResponsePartition in project kafka by apache.
the class PartitionLeaderStrategyTest method testRetryIfLeaderUnknown.
@Test
public void testRetryIfLeaderUnknown() {
TopicPartition topicPartition = new TopicPartition("foo", 0);
Map<TopicPartition, MetadataResponsePartition> responsePartitions = singletonMap(topicPartition, partitionResponseDataWithLeader(topicPartition, -1, Arrays.asList(5, 6, 7)));
LookupResult<TopicPartition> result = handleLookupResponse(mkSet(topicPartition), responseWithPartitionData(responsePartitions));
assertEquals(emptyMap(), result.failedKeys);
assertEquals(emptyMap(), result.mappedKeys);
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponsePartition 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.MetadataResponsePartition in project kafka by apache.
the class PartitionLeaderStrategyTest method testPartitionSuccessfullyMapped.
@Test
public void testPartitionSuccessfullyMapped() {
TopicPartition topicPartition1 = new TopicPartition("foo", 0);
TopicPartition topicPartition2 = new TopicPartition("bar", 1);
Map<TopicPartition, MetadataResponsePartition> responsePartitions = new HashMap<>(2);
responsePartitions.put(topicPartition1, partitionResponseDataWithLeader(topicPartition1, 5, Arrays.asList(5, 6, 7)));
responsePartitions.put(topicPartition2, partitionResponseDataWithLeader(topicPartition2, 1, Arrays.asList(2, 1, 3)));
LookupResult<TopicPartition> result = handleLookupResponse(mkSet(topicPartition1, topicPartition2), responseWithPartitionData(responsePartitions));
assertEquals(emptyMap(), result.failedKeys);
assertEquals(mkSet(topicPartition1, topicPartition2), result.mappedKeys.keySet());
assertEquals(5, result.mappedKeys.get(topicPartition1));
assertEquals(1, result.mappedKeys.get(topicPartition2));
}
use of org.apache.kafka.common.message.MetadataResponseData.MetadataResponsePartition in project kafka by apache.
the class PartitionLeaderStrategyTest method testIgnoreUnrequestedPartitions.
@Test
public void testIgnoreUnrequestedPartitions() {
TopicPartition requestedTopicPartition = new TopicPartition("foo", 0);
TopicPartition unrequestedTopicPartition = new TopicPartition("foo", 1);
Map<TopicPartition, MetadataResponsePartition> responsePartitions = new HashMap<>(2);
responsePartitions.put(requestedTopicPartition, partitionResponseDataWithLeader(requestedTopicPartition, 5, Arrays.asList(5, 6, 7)));
responsePartitions.put(unrequestedTopicPartition, partitionResponseDataWithError(unrequestedTopicPartition, Errors.UNKNOWN_SERVER_ERROR));
LookupResult<TopicPartition> result = handleLookupResponse(mkSet(requestedTopicPartition), responseWithPartitionData(responsePartitions));
assertEquals(emptyMap(), result.failedKeys);
assertEquals(mkSet(requestedTopicPartition), result.mappedKeys.keySet());
assertEquals(5, result.mappedKeys.get(requestedTopicPartition));
}
Aggregations