use of org.apache.kafka.common.message.LeaveGroupResponseData in project kafka by apache.
the class LeaveGroupResponseTest method testParse.
@Test
public void testParse() {
Map<Errors, Integer> expectedErrorCounts = Collections.singletonMap(Errors.NOT_COORDINATOR, 1);
LeaveGroupResponseData data = new LeaveGroupResponseData().setErrorCode(Errors.NOT_COORDINATOR.code()).setThrottleTimeMs(throttleTimeMs);
for (short version : ApiKeys.LEAVE_GROUP.allVersions()) {
ByteBuffer buffer = MessageUtil.toByteBuffer(data, version);
LeaveGroupResponse leaveGroupResponse = LeaveGroupResponse.parse(buffer, version);
assertEquals(expectedErrorCounts, leaveGroupResponse.errorCounts());
if (version >= 1) {
assertEquals(throttleTimeMs, leaveGroupResponse.throttleTimeMs());
} else {
assertEquals(DEFAULT_THROTTLE_TIME, leaveGroupResponse.throttleTimeMs());
}
assertEquals(Errors.NOT_COORDINATOR, leaveGroupResponse.error());
}
}
use of org.apache.kafka.common.message.LeaveGroupResponseData 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()));
}
}
use of org.apache.kafka.common.message.LeaveGroupResponseData in project kafka by apache.
the class ConsumerCoordinatorTest method testCommitAfterLeaveGroup.
@Test
public void testCommitAfterLeaveGroup() {
// enable auto-assignment
subscriptions.subscribe(singleton(topic1), rebalanceListener);
joinAsFollowerAndReceiveAssignment(coordinator, singletonList(t1p));
// now switch to manual assignment
client.prepareResponse(new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code())));
subscriptions.unsubscribe();
coordinator.maybeLeaveGroup("test commit after leave");
subscriptions.assignFromUser(singleton(t1p));
// the client should not reuse generation/memberId from auto-subscribed generation
client.prepareResponse(body -> {
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
return commitRequest.data().memberId().equals(OffsetCommitRequest.DEFAULT_MEMBER_ID) && commitRequest.data().generationId() == OffsetCommitRequest.DEFAULT_GENERATION_ID;
}, offsetCommitResponse(singletonMap(t1p, Errors.NONE)));
AtomicBoolean success = new AtomicBoolean(false);
coordinator.commitOffsetsAsync(singletonMap(t1p, new OffsetAndMetadata(100L)), callback(success));
coordinator.invokeCompletedOffsetCommitCallbacks();
assertTrue(success.get());
}
use of org.apache.kafka.common.message.LeaveGroupResponseData in project kafka by apache.
the class ConsumerCoordinatorTest method gracefulCloseTest.
private void gracefulCloseTest(ConsumerCoordinator coordinator, boolean shouldLeaveGroup) {
final AtomicBoolean commitRequested = new AtomicBoolean();
final AtomicBoolean leaveGroupRequested = new AtomicBoolean();
client.prepareResponse(body -> {
commitRequested.set(true);
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
return commitRequest.data().groupId().equals(groupId);
}, new OffsetCommitResponse(new OffsetCommitResponseData()));
if (shouldLeaveGroup)
client.prepareResponse(body -> {
leaveGroupRequested.set(true);
LeaveGroupRequest leaveRequest = (LeaveGroupRequest) body;
return leaveRequest.data().groupId().equals(groupId);
}, new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code())));
client.prepareResponse(body -> {
commitRequested.set(true);
OffsetCommitRequest commitRequest = (OffsetCommitRequest) body;
return commitRequest.data().groupId().equals(groupId);
}, new OffsetCommitResponse(new OffsetCommitResponseData()));
coordinator.close();
assertTrue(commitRequested.get(), "Commit not requested");
assertEquals(shouldLeaveGroup, leaveGroupRequested.get(), "leaveGroupRequested should be " + shouldLeaveGroup);
if (shouldLeaveGroup) {
assertEquals(1, rebalanceListener.revokedCount);
assertEquals(singleton(t1p), rebalanceListener.revoked);
}
}
use of org.apache.kafka.common.message.LeaveGroupResponseData in project kafka by apache.
the class KafkaConsumerTest method testGracefulClose.
@Test
public void testGracefulClose() throws Exception {
Map<TopicPartition, Errors> response = new HashMap<>();
response.put(tp0, Errors.NONE);
OffsetCommitResponse commitResponse = offsetCommitResponse(response);
LeaveGroupResponse leaveGroupResponse = new LeaveGroupResponse(new LeaveGroupResponseData().setErrorCode(Errors.NONE.code()));
consumerCloseTest(5000, Arrays.asList(commitResponse, leaveGroupResponse), 0, false);
}
Aggregations