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