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());
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations