use of org.apache.kafka.common.message.MetadataResponseData in project kafka by apache.
the class AllBrokersStrategyTest method testHandleResponse.
@Test
public void testHandleResponse() {
AllBrokersStrategy strategy = new AllBrokersStrategy(logContext);
MetadataResponseData response = new MetadataResponseData();
response.brokers().add(new MetadataResponseData.MetadataResponseBroker().setNodeId(1).setHost("host1").setPort(9092));
response.brokers().add(new MetadataResponseData.MetadataResponseBroker().setNodeId(2).setHost("host2").setPort(9092));
AdminApiLookupStrategy.LookupResult<AllBrokersStrategy.BrokerKey> lookupResult = strategy.handleResponse(AllBrokersStrategy.LOOKUP_KEYS, new MetadataResponse(response, ApiKeys.METADATA.latestVersion()));
assertEquals(Collections.emptyMap(), lookupResult.failedKeys);
Set<AllBrokersStrategy.BrokerKey> expectedMappedKeys = mkSet(new AllBrokersStrategy.BrokerKey(OptionalInt.of(1)), new AllBrokersStrategy.BrokerKey(OptionalInt.of(2)));
assertEquals(expectedMappedKeys, lookupResult.mappedKeys.keySet());
lookupResult.mappedKeys.forEach((brokerKey, brokerId) -> {
assertEquals(OptionalInt.of(brokerId), brokerKey.brokerId);
});
}
use of org.apache.kafka.common.message.MetadataResponseData in project kafka by apache.
the class PartitionLeaderStrategyTest method responseWithTopicError.
private MetadataResponse responseWithTopicError(String topic, Errors error) {
MetadataResponseTopic responseTopic = new MetadataResponseTopic().setName(topic).setErrorCode(error.code());
MetadataResponseData responseData = new MetadataResponseData();
responseData.topics().add(responseTopic);
return new MetadataResponse(responseData, ApiKeys.METADATA.latestVersion());
}
use of org.apache.kafka.common.message.MetadataResponseData in project kafka by apache.
the class MetadataRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
MetadataResponseData responseData = new MetadataResponseData();
if (data.topics() != null) {
for (MetadataRequestTopic topic : data.topics()) {
// the response does not allow null, so convert to empty string if necessary
String topicName = topic.name() == null ? "" : topic.name();
responseData.topics().add(new MetadataResponseData.MetadataResponseTopic().setName(topicName).setTopicId(topic.topicId()).setErrorCode(error.code()).setIsInternal(false).setPartitions(Collections.emptyList()));
}
}
responseData.setThrottleTimeMs(throttleTimeMs);
return new MetadataResponse(responseData, true);
}
Aggregations