Search in sources :

Example 11 with MetadataResponseData

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);
    });
}
Also used : MetadataResponseData(org.apache.kafka.common.message.MetadataResponseData) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) Test(org.junit.jupiter.api.Test)

Example 12 with MetadataResponseData

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());
}
Also used : MetadataResponseTopic(org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic) MetadataResponseData(org.apache.kafka.common.message.MetadataResponseData) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse)

Example 13 with MetadataResponseData

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) MetadataRequestTopic(org.apache.kafka.common.message.MetadataRequestData.MetadataRequestTopic) MetadataResponseData(org.apache.kafka.common.message.MetadataResponseData)

Aggregations

MetadataResponseData (org.apache.kafka.common.message.MetadataResponseData)13 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)11 Test (org.junit.jupiter.api.Test)7 MetadataResponsePartition (org.apache.kafka.common.message.MetadataResponseData.MetadataResponsePartition)6 MetadataResponseTopic (org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopic)6 TopicPartition (org.apache.kafka.common.TopicPartition)5 HashSet (java.util.HashSet)2 Node (org.apache.kafka.common.Node)2 MetadataResponseBrokerCollection (org.apache.kafka.common.message.MetadataResponseData.MetadataResponseBrokerCollection)2 MetadataResponseTopicCollection (org.apache.kafka.common.message.MetadataResponseData.MetadataResponseTopicCollection)2 MetadataRequest (org.apache.kafka.common.requests.MetadataRequest)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AdminClientUnitTestEnv (org.apache.kafka.clients.admin.AdminClientUnitTestEnv)1 ListOffsetsOptions (org.apache.kafka.clients.admin.ListOffsetsOptions)1 Uuid (org.apache.kafka.common.Uuid)1