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");
}
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());
}
}
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"));
}
}
}
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()));
}
}
Aggregations