use of org.apache.kafka.common.requests.DescribeGroupsResponse in project kafka by apache.
the class DescribeConsumerGroupsHandlerTest method handleWithError.
private AdminApiHandler.ApiResult<CoordinatorKey, ConsumerGroupDescription> handleWithError(Errors error, String protocolType) {
DescribeConsumerGroupsHandler handler = new DescribeConsumerGroupsHandler(true, logContext);
DescribeGroupsResponse response = buildResponse(error, protocolType);
return handler.handleResponse(coordinator, singleton(CoordinatorKey.byGroupId(groupId1)), response);
}
use of org.apache.kafka.common.requests.DescribeGroupsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeNonConsumerGroups.
@Test
public void testDescribeNonConsumerGroups() throws Exception {
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
DescribeGroupsResponseData data = new DescribeGroupsResponseData();
data.groups().add(DescribeGroupsResponse.groupMetadata(GROUP_ID, Errors.NONE, "", "non-consumer", "", asList(), Collections.emptySet()));
env.kafkaClient().prepareResponse(new DescribeGroupsResponse(data));
final DescribeConsumerGroupsResult result = env.adminClient().describeConsumerGroups(singletonList(GROUP_ID));
TestUtils.assertFutureError(result.describedGroups().get(GROUP_ID), IllegalArgumentException.class);
}
}
use of org.apache.kafka.common.requests.DescribeGroupsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeMultipleConsumerGroups.
@Test
public void testDescribeMultipleConsumerGroups() {
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
TopicPartition myTopicPartition0 = new TopicPartition("my_topic", 0);
TopicPartition myTopicPartition1 = new TopicPartition("my_topic", 1);
TopicPartition myTopicPartition2 = new TopicPartition("my_topic", 2);
final List<TopicPartition> topicPartitions = new ArrayList<>();
topicPartitions.add(0, myTopicPartition0);
topicPartitions.add(1, myTopicPartition1);
topicPartitions.add(2, myTopicPartition2);
final ByteBuffer memberAssignment = ConsumerProtocol.serializeAssignment(new ConsumerPartitionAssignor.Assignment(topicPartitions));
byte[] memberAssignmentBytes = new byte[memberAssignment.remaining()];
memberAssignment.get(memberAssignmentBytes);
DescribeGroupsResponseData group0Data = new DescribeGroupsResponseData();
group0Data.groups().add(DescribeGroupsResponse.groupMetadata(GROUP_ID, Errors.NONE, "", ConsumerProtocol.PROTOCOL_TYPE, "", asList(DescribeGroupsResponse.groupMember("0", null, "clientId0", "clientHost", memberAssignmentBytes, null), DescribeGroupsResponse.groupMember("1", null, "clientId1", "clientHost", memberAssignmentBytes, null)), Collections.emptySet()));
DescribeGroupsResponseData groupConnectData = new DescribeGroupsResponseData();
group0Data.groups().add(DescribeGroupsResponse.groupMetadata("group-connect-0", Errors.NONE, "", "connect", "", asList(DescribeGroupsResponse.groupMember("0", null, "clientId0", "clientHost", memberAssignmentBytes, null), DescribeGroupsResponse.groupMember("1", null, "clientId1", "clientHost", memberAssignmentBytes, null)), Collections.emptySet()));
env.kafkaClient().prepareResponse(new DescribeGroupsResponse(group0Data));
env.kafkaClient().prepareResponse(new DescribeGroupsResponse(groupConnectData));
Collection<String> groups = new HashSet<>();
groups.add(GROUP_ID);
groups.add("group-connect-0");
final DescribeConsumerGroupsResult result = env.adminClient().describeConsumerGroups(groups);
assertEquals(2, result.describedGroups().size());
assertEquals(groups, result.describedGroups().keySet());
}
}
use of org.apache.kafka.common.requests.DescribeGroupsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeConsumerGroupRetryBackoff.
@Test
public void testDescribeConsumerGroupRetryBackoff() throws Exception {
MockTime time = new MockTime();
int retryBackoff = 100;
try (final AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, mockCluster(3, 0), newStrMap(AdminClientConfig.RETRY_BACKOFF_MS_CONFIG, "" + retryBackoff))) {
MockClient mockClient = env.kafkaClient();
mockClient.setNodeApiVersions(NodeApiVersions.create());
AtomicLong firstAttemptTime = new AtomicLong(0);
AtomicLong secondAttemptTime = new AtomicLong(0);
mockClient.prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
DescribeGroupsResponseData data = new DescribeGroupsResponseData();
data.groups().add(DescribeGroupsResponse.groupMetadata(GROUP_ID, Errors.NOT_COORDINATOR, "", "", "", Collections.emptyList(), Collections.emptySet()));
mockClient.prepareResponse(body -> {
firstAttemptTime.set(time.milliseconds());
return true;
}, new DescribeGroupsResponse(data));
mockClient.prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
data = new DescribeGroupsResponseData();
data.groups().add(DescribeGroupsResponse.groupMetadata(GROUP_ID, Errors.NONE, "", ConsumerProtocol.PROTOCOL_TYPE, "", Collections.emptyList(), Collections.emptySet()));
mockClient.prepareResponse(body -> {
secondAttemptTime.set(time.milliseconds());
return true;
}, new DescribeGroupsResponse(data));
final KafkaFuture<Map<String, ConsumerGroupDescription>> future = env.adminClient().describeConsumerGroups(singletonList(GROUP_ID)).all();
TestUtils.waitForCondition(() -> mockClient.numAwaitingResponses() == 1, "Failed awaiting DescribeConsumerGroup first request failure");
TestUtils.waitForCondition(() -> ((KafkaAdminClient) env.adminClient()).numPendingCalls() == 1, "Failed to add retry DescribeConsumerGroup call on first failure");
time.sleep(retryBackoff);
future.get();
long actualRetryBackoff = secondAttemptTime.get() - firstAttemptTime.get();
assertEquals(retryBackoff, actualRetryBackoff, "DescribeConsumerGroup retry did not await expected backoff!");
}
}
use of org.apache.kafka.common.requests.DescribeGroupsResponse in project kafka by apache.
the class KafkaAdminClientTest method testDescribeConsumerGroupNumRetries.
@Test
public void testDescribeConsumerGroupNumRetries() 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()));
DescribeGroupsResponseData data = new DescribeGroupsResponseData();
data.groups().add(DescribeGroupsResponse.groupMetadata(GROUP_ID, Errors.NOT_COORDINATOR, "", "", "", Collections.emptyList(), Collections.emptySet()));
env.kafkaClient().prepareResponse(new DescribeGroupsResponse(data));
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
final DescribeConsumerGroupsResult result = env.adminClient().describeConsumerGroups(singletonList(GROUP_ID));
TestUtils.assertFutureError(result.all(), TimeoutException.class);
}
}
Aggregations