Search in sources :

Example 1 with DescribeGroupsResponse

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

Example 2 with DescribeGroupsResponse

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

Example 3 with DescribeGroupsResponse

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());
    }
}
Also used : ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) TopicPartition(org.apache.kafka.common.TopicPartition) DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) ConsumerPartitionAssignor(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with DescribeGroupsResponse

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!");
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) Map(java.util.Map) HashMap(java.util.HashMap) MockTime(org.apache.kafka.common.utils.MockTime) MockClient(org.apache.kafka.clients.MockClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with DescribeGroupsResponse

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);
    }
}
Also used : DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) Cluster(org.apache.kafka.common.Cluster) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) 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)

Aggregations

DescribeGroupsResponse (org.apache.kafka.common.requests.DescribeGroupsResponse)9 DescribeGroupsResponseData (org.apache.kafka.common.message.DescribeGroupsResponseData)7 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ArrayList (java.util.ArrayList)4 TopicPartition (org.apache.kafka.common.TopicPartition)4 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ConsumerPartitionAssignor (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor)3 DescribedGroupMember (org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroupMember)3 MockTime (org.apache.kafka.common.utils.MockTime)3 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Cluster (org.apache.kafka.common.Cluster)2 AclOperation (org.apache.kafka.common.acl.AclOperation)2 Errors (org.apache.kafka.common.protocol.Errors)2 Time (org.apache.kafka.common.utils.Time)2 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1