Search in sources :

Example 1 with DescribeGroupsResponseData

use of org.apache.kafka.common.message.DescribeGroupsResponseData in project kafka by apache.

the class RequestResponseTest method createDescribeGroupResponse.

private DescribeGroupsResponse createDescribeGroupResponse() {
    String clientId = "consumer-1";
    String clientHost = "localhost";
    DescribeGroupsResponseData describeGroupsResponseData = new DescribeGroupsResponseData();
    DescribeGroupsResponseData.DescribedGroupMember member = DescribeGroupsResponse.groupMember("memberId", null, clientId, clientHost, new byte[0], new byte[0]);
    DescribedGroup metadata = DescribeGroupsResponse.groupMetadata("test-group", Errors.NONE, "STABLE", "consumer", "roundrobin", singletonList(member), DescribeGroupsResponse.AUTHORIZED_OPERATIONS_OMITTED);
    describeGroupsResponseData.groups().add(metadata);
    return new DescribeGroupsResponse(describeGroupsResponseData);
}
Also used : DescribeGroupsResponseData(org.apache.kafka.common.message.DescribeGroupsResponseData) DescribedGroup(org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroup)

Example 2 with DescribeGroupsResponseData

use of org.apache.kafka.common.message.DescribeGroupsResponseData 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 DescribeGroupsResponseData

use of org.apache.kafka.common.message.DescribeGroupsResponseData 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 DescribeGroupsResponseData

use of org.apache.kafka.common.message.DescribeGroupsResponseData 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 DescribeGroupsResponseData

use of org.apache.kafka.common.message.DescribeGroupsResponseData 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

DescribeGroupsResponseData (org.apache.kafka.common.message.DescribeGroupsResponseData)10 DescribeGroupsResponse (org.apache.kafka.common.requests.DescribeGroupsResponse)8 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 ConsumerPartitionAssignor (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor)4 TopicPartition (org.apache.kafka.common.TopicPartition)4 MockTime (org.apache.kafka.common.utils.MockTime)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Cluster (org.apache.kafka.common.Cluster)3 DescribedGroupMember (org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroupMember)3 Time (org.apache.kafka.common.utils.Time)3 InetSocketAddress (java.net.InetSocketAddress)2 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 Collection (java.util.Collection)2