Search in sources :

Example 1 with OffsetFetchResponse

use of org.apache.kafka.common.requests.OffsetFetchResponse in project kafka by apache.

the class KafkaAdminClientTest method testListConsumerGroupOffsetsRetriableErrors.

@Test
public void testListConsumerGroupOffsetsRetriableErrors() throws Exception {
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new OffsetFetchResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Collections.emptyMap()));
        /*
             * We need to return two responses here, one for NOT_COORDINATOR call when calling list consumer offsets
             * api using coordinator that has moved. This will retry whole operation. So we need to again respond with a
             * FindCoordinatorResponse.
             *
             * And the same reason for the following COORDINATOR_NOT_AVAILABLE error response
             */
        env.kafkaClient().prepareResponse(new OffsetFetchResponse(Errors.NOT_COORDINATOR, Collections.emptyMap()));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new OffsetFetchResponse(Errors.COORDINATOR_NOT_AVAILABLE, Collections.emptyMap()));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new OffsetFetchResponse(Errors.NONE, Collections.emptyMap()));
        final ListConsumerGroupOffsetsResult errorResult1 = env.adminClient().listConsumerGroupOffsets(GROUP_ID);
        assertEquals(Collections.emptyMap(), errorResult1.partitionsToOffsetAndMetadata().get());
    }
}
Also used : OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with OffsetFetchResponse

use of org.apache.kafka.common.requests.OffsetFetchResponse in project kafka by apache.

the class KafkaAdminClientTest method testListConsumerGroupOffsetsNumRetries.

@Test
public void testListConsumerGroupOffsetsNumRetries() throws Exception {
    final Cluster cluster = mockCluster(3, 0);
    final Time time = new MockTime();
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster, AdminClientConfig.RETRIES_CONFIG, "0")) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new OffsetFetchResponse(Errors.NOT_COORDINATOR, Collections.emptyMap()));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        final ListConsumerGroupOffsetsResult result = env.adminClient().listConsumerGroupOffsets(GROUP_ID);
        TestUtils.assertFutureError(result.partitionsToOffsetAndMetadata(), TimeoutException.class);
    }
}
Also used : OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) Cluster(org.apache.kafka.common.Cluster) Time(org.apache.kafka.common.utils.Time) MockTime(org.apache.kafka.common.utils.MockTime) MockTime(org.apache.kafka.common.utils.MockTime) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with OffsetFetchResponse

use of org.apache.kafka.common.requests.OffsetFetchResponse in project kafka by apache.

the class ListConsumerGroupOffsetsHandlerTest method buildResponse.

private OffsetFetchResponse buildResponse(Errors error) {
    Map<TopicPartition, PartitionData> responseData = new HashMap<>();
    OffsetFetchResponse response = new OffsetFetchResponse(error, responseData);
    return response;
}
Also used : OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 4 with OffsetFetchResponse

use of org.apache.kafka.common.requests.OffsetFetchResponse in project kafka by apache.

the class ListConsumerGroupOffsetsHandlerTest method handleWithPartitionError.

private AdminApiHandler.ApiResult<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> handleWithPartitionError(Errors error) {
    ListConsumerGroupOffsetsHandler handler = new ListConsumerGroupOffsetsHandler(groupId, tps, logContext);
    OffsetFetchResponse response = buildResponseWithPartitionError(error);
    return handler.handleResponse(new Node(1, "host", 1234), singleton(CoordinatorKey.byGroupId(groupId)), response);
}
Also used : OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) Node(org.apache.kafka.common.Node)

Example 5 with OffsetFetchResponse

use of org.apache.kafka.common.requests.OffsetFetchResponse in project kafka by apache.

the class ListConsumerGroupOffsetsHandlerTest method handleWithError.

private AdminApiHandler.ApiResult<CoordinatorKey, Map<TopicPartition, OffsetAndMetadata>> handleWithError(Errors error) {
    ListConsumerGroupOffsetsHandler handler = new ListConsumerGroupOffsetsHandler(groupId, tps, logContext);
    OffsetFetchResponse response = buildResponse(error);
    return handler.handleResponse(new Node(1, "host", 1234), singleton(CoordinatorKey.byGroupId(groupId)), response);
}
Also used : OffsetFetchResponse(org.apache.kafka.common.requests.OffsetFetchResponse) Node(org.apache.kafka.common.Node)

Aggregations

OffsetFetchResponse (org.apache.kafka.common.requests.OffsetFetchResponse)13 Test (org.junit.jupiter.api.Test)7 TopicPartition (org.apache.kafka.common.TopicPartition)6 HashMap (java.util.HashMap)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Node (org.apache.kafka.common.Node)2 Errors (org.apache.kafka.common.protocol.Errors)2 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)2 MockTime (org.apache.kafka.common.utils.MockTime)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MockClient (org.apache.kafka.clients.MockClient)1 Cluster (org.apache.kafka.common.Cluster)1 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 LogContext (org.apache.kafka.common.utils.LogContext)1 Time (org.apache.kafka.common.utils.Time)1