use of org.apache.kafka.common.message.OffsetCommitResponseData in project kafka by apache.
the class OffsetCommitResponseTest method testParse.
@Test
public void testParse() {
OffsetCommitResponseData data = new OffsetCommitResponseData().setTopics(Arrays.asList(new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionOne).setErrorCode(errorOne.code()))), new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionTwo).setErrorCode(errorTwo.code()))))).setThrottleTimeMs(throttleTimeMs);
for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
ByteBuffer buffer = MessageUtil.toByteBuffer(data, version);
OffsetCommitResponse response = OffsetCommitResponse.parse(buffer, version);
assertEquals(expectedErrorCounts, response.errorCounts());
if (version >= 3) {
assertEquals(throttleTimeMs, response.throttleTimeMs());
} else {
assertEquals(DEFAULT_THROTTLE_TIME, response.throttleTimeMs());
}
assertEquals(version >= 4, response.shouldClientThrottle(version));
}
}
use of org.apache.kafka.common.message.OffsetCommitResponseData 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);
}
}
Aggregations