Search in sources :

Example 1 with LeaveGroupRequestData

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

the class AbstractCoordinatorTest method setupLeaveGroup.

private RequestFuture<Void> setupLeaveGroup(LeaveGroupResponse leaveGroupResponse) {
    setupCoordinator(RETRY_BACKOFF_MS, Integer.MAX_VALUE, Optional.empty());
    mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
    mockClient.prepareResponse(joinGroupFollowerResponse(1, memberId, leaderId, Errors.NONE));
    mockClient.prepareResponse(syncGroupResponse(Errors.NONE));
    mockClient.prepareResponse(body -> {
        if (!(body instanceof LeaveGroupRequest)) {
            return false;
        }
        LeaveGroupRequestData leaveGroupRequest = ((LeaveGroupRequest) body).data();
        return leaveGroupRequest.members().get(0).memberId().equals(memberId) && leaveGroupRequest.members().get(0).reason().equals("test maybe leave group");
    }, leaveGroupResponse);
    coordinator.ensureActiveGroup();
    return coordinator.maybeLeaveGroup("test maybe leave group");
}
Also used : LeaveGroupRequestData(org.apache.kafka.common.message.LeaveGroupRequestData) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest)

Example 2 with LeaveGroupRequestData

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

the class KafkaAdminClientTest method testRemoveMembersFromGroup.

private void testRemoveMembersFromGroup(String reason, String expectedReason) throws Exception {
    final Cluster cluster = mockCluster(3, 0);
    final Time time = new MockTime();
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, cluster)) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(body -> {
            if (!(body instanceof LeaveGroupRequest)) {
                return false;
            }
            LeaveGroupRequestData leaveGroupRequest = ((LeaveGroupRequest) body).data();
            return leaveGroupRequest.members().stream().allMatch(member -> member.reason().equals(expectedReason));
        }, new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(Arrays.asList(new MemberResponse().setGroupInstanceId("instance-1"), new MemberResponse().setGroupInstanceId("instance-2")))));
        Collection<MemberToRemove> membersToRemove = Arrays.asList(new MemberToRemove("instance-1"), new MemberToRemove("instance-2"));
        RemoveMembersFromConsumerGroupOptions options = new RemoveMembersFromConsumerGroupOptions(membersToRemove);
        options.reason(reason);
        final RemoveMembersFromConsumerGroupResult result = env.adminClient().removeMembersFromConsumerGroup(GROUP_ID, options);
        assertNull(result.all().get());
    }
}
Also used : MemberResponse(org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse) LeaveGroupRequestData(org.apache.kafka.common.message.LeaveGroupRequestData) LeaveGroupResponse(org.apache.kafka.common.requests.LeaveGroupResponse) Cluster(org.apache.kafka.common.Cluster) Time(org.apache.kafka.common.utils.Time) MockTime(org.apache.kafka.common.utils.MockTime) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) LeaveGroupRequest(org.apache.kafka.common.requests.LeaveGroupRequest) MockTime(org.apache.kafka.common.utils.MockTime)

Example 3 with LeaveGroupRequestData

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

the class LeaveGroupRequestTest method testMultiLeaveConstructor.

@Test
public void testMultiLeaveConstructor() {
    final LeaveGroupRequestData expectedData = new LeaveGroupRequestData().setGroupId(groupId).setMembers(members);
    for (short version : ApiKeys.LEAVE_GROUP.allVersions()) {
        try {
            LeaveGroupRequest request = builder.build(version);
            if (version <= 2) {
                fail("Older version " + version + " request data should not be created due to non-single members");
            }
            assertEquals(expectedData, request.data());
            assertEquals(members, request.members());
            LeaveGroupResponse expectedResponse = new LeaveGroupResponse(Collections.emptyList(), Errors.COORDINATOR_LOAD_IN_PROGRESS, throttleTimeMs, version);
            assertEquals(expectedResponse, request.getErrorResponse(throttleTimeMs, Errors.COORDINATOR_LOAD_IN_PROGRESS.exception()));
        } catch (UnsupportedVersionException e) {
            assertTrue(e.getMessage().contains("leave group request only supports single member instance"));
        }
    }
}
Also used : LeaveGroupRequestData(org.apache.kafka.common.message.LeaveGroupRequestData) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Test(org.junit.jupiter.api.Test)

Example 4 with LeaveGroupRequestData

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

the class LeaveGroupRequestTest method testSingleLeaveConstructor.

@Test
public void testSingleLeaveConstructor() {
    final LeaveGroupRequestData expectedData = new LeaveGroupRequestData().setGroupId(groupId).setMemberId(memberIdOne);
    List<MemberIdentity> singleMember = Collections.singletonList(new MemberIdentity().setMemberId(memberIdOne));
    builder = new LeaveGroupRequest.Builder(groupId, singleMember);
    for (short version = 0; version <= 2; version++) {
        LeaveGroupRequest request = builder.build(version);
        assertEquals(expectedData, request.data());
        assertEquals(singleMember, request.members());
        int expectedThrottleTime = version >= 1 ? throttleTimeMs : AbstractResponse.DEFAULT_THROTTLE_TIME;
        LeaveGroupResponse expectedResponse = new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NOT_CONTROLLER.code()).setThrottleTimeMs(expectedThrottleTime));
        assertEquals(expectedResponse, request.getErrorResponse(throttleTimeMs, Errors.NOT_CONTROLLER.exception()));
    }
}
Also used : LeaveGroupRequestData(org.apache.kafka.common.message.LeaveGroupRequestData) MemberIdentity(org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity) LeaveGroupResponseData(org.apache.kafka.common.message.LeaveGroupResponseData) Test(org.junit.jupiter.api.Test)

Aggregations

LeaveGroupRequestData (org.apache.kafka.common.message.LeaveGroupRequestData)4 LeaveGroupResponseData (org.apache.kafka.common.message.LeaveGroupResponseData)2 LeaveGroupRequest (org.apache.kafka.common.requests.LeaveGroupRequest)2 Test (org.junit.jupiter.api.Test)2 Cluster (org.apache.kafka.common.Cluster)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 MemberIdentity (org.apache.kafka.common.message.LeaveGroupRequestData.MemberIdentity)1 MemberResponse (org.apache.kafka.common.message.LeaveGroupResponseData.MemberResponse)1 LeaveGroupResponse (org.apache.kafka.common.requests.LeaveGroupResponse)1 MockTime (org.apache.kafka.common.utils.MockTime)1 Time (org.apache.kafka.common.utils.Time)1