use of org.apache.kafka.common.requests.MetadataResponse 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.requests.MetadataResponse 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.requests.MetadataResponse in project kafka by apache.
the class PartitionLeaderStrategyTest method assertRetriablePartitionError.
private void assertRetriablePartitionError(TopicPartition topicPartition, Errors error) {
MetadataResponse response = responseWithPartitionData(singletonMap(topicPartition, partitionResponseDataWithError(topicPartition, error)));
assertRetriableError(topicPartition, response);
}
use of org.apache.kafka.common.requests.MetadataResponse in project kafka by apache.
the class AllBrokersStrategyTest method testHandleResponseWithNoBrokers.
@Test
public void testHandleResponseWithNoBrokers() {
AllBrokersStrategy strategy = new AllBrokersStrategy(logContext);
MetadataResponseData response = new MetadataResponseData();
AdminApiLookupStrategy.LookupResult<AllBrokersStrategy.BrokerKey> lookupResult = strategy.handleResponse(AllBrokersStrategy.LOOKUP_KEYS, new MetadataResponse(response, ApiKeys.METADATA.latestVersion()));
assertEquals(Collections.emptyMap(), lookupResult.failedKeys);
assertEquals(Collections.emptyMap(), lookupResult.mappedKeys);
}
use of org.apache.kafka.common.requests.MetadataResponse in project kafka by apache.
the class AllBrokersStrategyTest method testHandleResponseWithInvalidLookupKeys.
@Test
public void testHandleResponseWithInvalidLookupKeys() {
AllBrokersStrategy strategy = new AllBrokersStrategy(logContext);
AllBrokersStrategy.BrokerKey key1 = new AllBrokersStrategy.BrokerKey(OptionalInt.empty());
AllBrokersStrategy.BrokerKey key2 = new AllBrokersStrategy.BrokerKey(OptionalInt.of(1));
MetadataResponse response = new MetadataResponse(new MetadataResponseData(), ApiKeys.METADATA.latestVersion());
assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(mkSet(key1), response));
assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(mkSet(key2), response));
assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(mkSet(key1, key2), response));
Set<AllBrokersStrategy.BrokerKey> keys = new HashSet<>(AllBrokersStrategy.LOOKUP_KEYS);
keys.add(key2);
assertThrows(IllegalArgumentException.class, () -> strategy.handleResponse(keys, response));
}
Aggregations