Search in sources :

Example 1 with MemberResponse

use of org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse in project kafka by apache.

the class MessageTest method testLeaveGroupResponseVersions.

@Test
public void testLeaveGroupResponseVersions() throws Exception {
    Supplier<LeaveGroupResponseData> newResponse = () -> new LeaveGroupResponseData().setErrorCode(Errors.NOT_COORDINATOR.code());
    testAllMessageRoundTrips(newResponse.get());
    testAllMessageRoundTripsFromVersion((short) 1, newResponse.get().setThrottleTimeMs(1000));
    testAllMessageRoundTripsFromVersion((short) 3, newResponse.get().setMembers(Collections.singletonList(new MemberResponse().setMemberId(memberId).setGroupInstanceId(instanceId))));
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MemberResponse

use of org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse in project kafka by apache.

the class KafkaAdminClientTest method testRemoveMembersFromGroupRetryBackoff.

@Test
public void testRemoveMembersFromGroupRetryBackoff() 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()));
        env.kafkaClient().prepareResponse(body -> {
            firstAttemptTime.set(time.milliseconds());
            return true;
        }, new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NOT_COORDINATOR.code())));
        mockClient.prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        MemberResponse responseOne = new MemberResponse().setGroupInstanceId("instance-1").setErrorCode(Errors.NONE.code());
        env.kafkaClient().prepareResponse(body -> {
            secondAttemptTime.set(time.milliseconds());
            return true;
        }, new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Collections.singletonList(responseOne))));
        Collection<MemberToRemove> membersToRemove = singletonList(new MemberToRemove("instance-1"));
        final KafkaFuture<Void> future = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove)).all();
        TestUtils.waitForCondition(() -> mockClient.numAwaitingResponses() == 1, "Failed awaiting RemoveMembersFromGroup first request failure");
        TestUtils.waitForCondition(() -> ((KafkaAdminClient) env.adminClient()).numPendingCalls() == 1, "Failed to add retry RemoveMembersFromGroup call on first failure");
        time.sleep(retryBackoff);
        future.get();
        long actualRetryBackoff = secondAttemptTime.get() - firstAttemptTime.get();
        assertEquals(retryBackoff, actualRetryBackoff, "RemoveMembersFromGroup retry did not await expected backoff!");
    }
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) AtomicLong(java.util.concurrent.atomic.AtomicLong) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) 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 3 with MemberResponse

use of org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse in project kafka by apache.

the class KafkaAdminClientTest method testRemoveMembersFromGroupRetriableErrors.

@Test
public void testRemoveMembersFromGroupRetriableErrors() 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 LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code())));
        /*
             * We need to return two responses here, one for NOT_COORDINATOR call when calling remove member
             * 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 LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NOT_COORDINATOR.code())));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.COORDINATOR_NOT_AVAILABLE.code())));
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        MemberResponse memberResponse = new MemberResponse().setGroupInstanceId("instance-1").setErrorCode(Errors.NONE.code());
        env.kafkaClient().prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Collections.singletonList(memberResponse))));
        MemberToRemove memberToRemove = new MemberToRemove("instance-1");
        Collection<MemberToRemove> membersToRemove = singletonList(memberToRemove);
        final RemoveMembersFromConsumerGroupResult result = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, new RemoveMembersFromConsumerGroupOptions(membersToRemove));
        assertNull(result.all().get());
        assertNull(result.memberResult(memberToRemove).get());
    }
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with MemberResponse

use of org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse in project kafka by apache.

the class AbstractCoordinatorTest method testHandleMultipleMembersLeaveGroupResponse.

@Test
public void testHandleMultipleMembersLeaveGroupResponse() {
    MemberResponse memberResponse = new MemberResponse().setMemberId(memberId).setErrorCode(Errors.NONE.code());
    LeaveGroupResponse response = leaveGroupResponse(Arrays.asList(memberResponse, memberResponse));
    RequestFuture<Void> leaveGroupFuture = setupLeaveGroup(response);
    assertNotNull(leaveGroupFuture);
    assertTrue(leaveGroupFuture.exception() instanceof IllegalStateException);
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) Test(org.junit.jupiter.api.Test)

Example 5 with MemberResponse

use of org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse in project kafka by apache.

the class AbstractCoordinatorTest method testHandleNormalLeaveGroupResponse.

@Test
public void testHandleNormalLeaveGroupResponse() {
    MemberResponse memberResponse = new MemberResponse().setMemberId(memberId).setErrorCode(Errors.NONE.code());
    LeaveGroupResponse response = leaveGroupResponse(Collections.singletonList(memberResponse));
    RequestFuture<Void> leaveGroupFuture = setupLeaveGroup(response);
    assertNotNull(leaveGroupFuture);
    assertTrue(leaveGroupFuture.succeeded());
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MemberResponse (org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse)9 LeaveGroupResponse (org.apache.kafka.common.requests.LeaveGroupResponse)8 Test (org.junit.jupiter.api.Test)7 LeaveGroupResponseData (org.apache.kafka.common.message.LeaveGroupResponseData)4 MockTime (org.apache.kafka.common.utils.MockTime)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Cluster (org.apache.kafka.common.Cluster)2 UnknownMemberIdException (org.apache.kafka.common.errors.UnknownMemberIdException)2 LeaveGroupRequestData (org.apache.kafka.common.message.LeaveGroupRequestData)2 MemberIdentity (org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity)2 Errors (org.apache.kafka.common.protocol.Errors)2 LeaveGroupRequest (org.apache.kafka.common.requests.LeaveGroupRequest)2 Time (org.apache.kafka.common.utils.Time)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1