Search in sources :

Example 1 with ListGroupsRequest

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

the class KafkaAdminClientTest method testListConsumerGroupsWithStatesOlderBrokerVersion.

@Test
public void testListConsumerGroupsWithStatesOlderBrokerVersion() throws Exception {
    ApiVersion listGroupV3 = new ApiVersion().setApiKey(ApiKeys.LIST_GROUPS.id).setMinVersion((short) 0).setMaxVersion((short) 3);
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create(Collections.singletonList(listGroupV3)));
        env.kafkaClient().prepareResponse(prepareMetadataResponse(env.cluster(), Errors.NONE));
        // Check we can list groups with older broker if we don't specify states
        env.kafkaClient().prepareResponseFrom(new ListGroupsResponse(new ListGroupsResponseData().setErrorCode(Errors.NONE.code()).setGroups(Collections.singletonList(new ListGroupsResponseData.ListedGroup().setGroupId("group-1").setProtocolType(ConsumerProtocol.PROTOCOL_TYPE)))), env.cluster().nodeById(0));
        ListConsumerGroupsOptions options = new ListConsumerGroupsOptions();
        ListConsumerGroupsResult result = env.adminClient().listConsumerGroups(options);
        Collection<ConsumerGroupListing> listing = result.all().get();
        assertEquals(1, listing.size());
        List<ConsumerGroupListing> expected = Collections.singletonList(new ConsumerGroupListing("group-1", false, Optional.empty()));
        assertEquals(expected, listing);
        // But we cannot set a state filter with older broker
        env.kafkaClient().prepareResponse(prepareMetadataResponse(env.cluster(), Errors.NONE));
        env.kafkaClient().prepareUnsupportedVersionResponse(body -> body instanceof ListGroupsRequest);
        options = new ListConsumerGroupsOptions().inStates(singleton(ConsumerGroupState.STABLE));
        result = env.adminClient().listConsumerGroups(options);
        TestUtils.assertFutureThrows(result.all(), UnsupportedVersionException.class);
    }
}
Also used : ListGroupsRequest(org.apache.kafka.common.requests.ListGroupsRequest) ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion) ListGroupsResponse(org.apache.kafka.common.requests.ListGroupsResponse) ListGroupsResponseData(org.apache.kafka.common.message.ListGroupsResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ApiVersion (org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion)1 ListGroupsResponseData (org.apache.kafka.common.message.ListGroupsResponseData)1 ListGroupsRequest (org.apache.kafka.common.requests.ListGroupsRequest)1 ListGroupsResponse (org.apache.kafka.common.requests.ListGroupsResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1