use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition in project kafka by apache.
the class OffsetCommitRequest method getErrorResponseTopics.
public static List<OffsetCommitResponseTopic> getErrorResponseTopics(List<OffsetCommitRequestTopic> requestTopics, Errors e) {
List<OffsetCommitResponseTopic> responseTopicData = new ArrayList<>();
for (OffsetCommitRequestTopic entry : requestTopics) {
List<OffsetCommitResponsePartition> responsePartitions = new ArrayList<>();
for (OffsetCommitRequestData.OffsetCommitRequestPartition requestPartition : entry.partitions()) {
responsePartitions.add(new OffsetCommitResponsePartition().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(e.code()));
}
responseTopicData.add(new OffsetCommitResponseTopic().setName(entry.name()).setPartitions(responsePartitions));
}
return responseTopicData;
}
use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition 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.OffsetCommitResponsePartition in project kafka by apache.
the class AlterConsumerGroupOffsetsHandler method handleResponse.
@Override
public ApiResult<CoordinatorKey, Map<TopicPartition, Errors>> handleResponse(Node coordinator, Set<CoordinatorKey> groupIds, AbstractResponse abstractResponse) {
validateKeys(groupIds);
final OffsetCommitResponse response = (OffsetCommitResponse) abstractResponse;
final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
final Set<CoordinatorKey> groupsToRetry = new HashSet<>();
final Map<TopicPartition, Errors> partitionResults = new HashMap<>();
for (OffsetCommitResponseTopic topic : response.data().topics()) {
for (OffsetCommitResponsePartition partition : topic.partitions()) {
TopicPartition topicPartition = new TopicPartition(topic.name(), partition.partitionIndex());
Errors error = Errors.forCode(partition.errorCode());
if (error != Errors.NONE) {
handleError(groupId, topicPartition, error, partitionResults, groupsToUnmap, groupsToRetry);
} else {
partitionResults.put(topicPartition, error);
}
}
}
if (groupsToUnmap.isEmpty() && groupsToRetry.isEmpty()) {
return ApiResult.completed(groupId, partitionResults);
} else {
return ApiResult.unmapped(new ArrayList<>(groupsToUnmap));
}
}
use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition in project kafka by apache.
the class MessageTest method testOffsetCommitResponseVersions.
@Test
public void testOffsetCommitResponseVersions() throws Exception {
Supplier<OffsetCommitResponseData> response = () -> new OffsetCommitResponseData().setTopics(singletonList(new OffsetCommitResponseTopic().setName("topic").setPartitions(singletonList(new OffsetCommitResponsePartition().setPartitionIndex(1).setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()))))).setThrottleTimeMs(20);
for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
OffsetCommitResponseData responseData = response.get();
if (version < 3) {
responseData.setThrottleTimeMs(0);
}
testAllMessageRoundTripsFromVersion(version, responseData);
}
}
use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition in project kafka by apache.
the class OffsetCommitRequestTest method testGetErrorResponseTopics.
@Test
public void testGetErrorResponseTopics() {
List<OffsetCommitResponseTopic> expectedTopics = Arrays.asList(new OffsetCommitResponseTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()).setPartitionIndex(partitionOne))), new OffsetCommitResponseTopic().setName(topicTwo).setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()).setPartitionIndex(partitionTwo))));
assertEquals(expectedTopics, getErrorResponseTopics(topics, Errors.UNKNOWN_MEMBER_ID));
}
Aggregations