use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.
the class OffsetFetchResponse method errorCounts.
@Override
public Map<Errors, Integer> errorCounts() {
Map<Errors, Integer> counts = new HashMap<>();
if (!groupLevelErrors.isEmpty()) {
// built response with v8 or above
for (Map.Entry<String, Errors> entry : groupLevelErrors.entrySet()) {
updateErrorCounts(counts, entry.getValue());
}
for (OffsetFetchResponseGroup group : data.groups()) {
group.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
}
} else {
// built response with v0-v7
updateErrorCounts(counts, error);
data.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
}
return counts;
}
use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.
the class OffsetFetchResponse method buildResponseData.
private Map<TopicPartition, PartitionData> buildResponseData(String groupId) {
Map<TopicPartition, PartitionData> responseData = new HashMap<>();
OffsetFetchResponseGroup group = data.groups().stream().filter(g -> g.groupId().equals(groupId)).collect(Collectors.toList()).get(0);
for (OffsetFetchResponseTopics topic : group.topics()) {
for (OffsetFetchResponsePartitions partition : topic.partitions()) {
responseData.put(new TopicPartition(topic.name(), partition.partitionIndex()), new PartitionData(partition.committedOffset(), RequestUtils.getLeaderEpoch(partition.committedLeaderEpoch()), partition.metadata(), Errors.forCode(partition.errorCode())));
}
}
return responseData;
}
use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.
the class OffsetFetchResponseTest method testUseDefaultLeaderEpochV8.
@Test
public void testUseDefaultLeaderEpochV8() {
final Optional<Integer> emptyLeaderEpoch = Optional.empty();
partitionDataMap.clear();
partitionDataMap.put(new TopicPartition(topicOne, partitionOne), new PartitionData(offset, emptyLeaderEpoch, metadata, Errors.UNKNOWN_TOPIC_OR_PARTITION));
OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.NOT_COORDINATOR), Collections.singletonMap(groupOne, partitionDataMap));
OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(metadata))))).setErrorCode(Errors.NOT_COORDINATOR.code()))).setThrottleTimeMs(throttleTimeMs);
assertEquals(expectedData, response.data());
}
use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.
the class OffsetFetchResponseTest method testNullableMetadataV8AndAbove.
@Test
public void testNullableMetadataV8AndAbove() {
PartitionData pd = new PartitionData(offset, leaderEpochOne, null, Errors.UNKNOWN_TOPIC_OR_PARTITION);
// test PartitionData.equals with null metadata
assertEquals(pd, pd);
partitionDataMap.clear();
partitionDataMap.put(new TopicPartition(topicOne, partitionOne), pd);
OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.GROUP_AUTHORIZATION_FAILED), Collections.singletonMap(groupOne, partitionDataMap));
OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpochOne.orElse(-1)).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(null))))).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code()))).setThrottleTimeMs(throttleTimeMs);
assertEquals(expectedData, response.data());
}
use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.
the class MessageTest method testOffsetFetchV8AndAbove.
@Test
public void testOffsetFetchV8AndAbove() throws Exception {
String groupOne = "group1";
String groupTwo = "group2";
String groupThree = "group3";
String groupFour = "group4";
String groupFive = "group5";
String topic1 = "topic1";
String topic2 = "topic2";
String topic3 = "topic3";
OffsetFetchRequestTopics topicOne = new OffsetFetchRequestTopics().setName(topic1).setPartitionIndexes(Collections.singletonList(5));
OffsetFetchRequestTopics topicTwo = new OffsetFetchRequestTopics().setName(topic2).setPartitionIndexes(Collections.singletonList(10));
OffsetFetchRequestTopics topicThree = new OffsetFetchRequestTopics().setName(topic3).setPartitionIndexes(Collections.singletonList(15));
List<OffsetFetchRequestTopics> groupOneTopics = singletonList(topicOne);
OffsetFetchRequestGroup group1 = new OffsetFetchRequestGroup().setGroupId(groupOne).setTopics(groupOneTopics);
List<OffsetFetchRequestTopics> groupTwoTopics = Arrays.asList(topicOne, topicTwo);
OffsetFetchRequestGroup group2 = new OffsetFetchRequestGroup().setGroupId(groupTwo).setTopics(groupTwoTopics);
List<OffsetFetchRequestTopics> groupThreeTopics = Arrays.asList(topicOne, topicTwo, topicThree);
OffsetFetchRequestGroup group3 = new OffsetFetchRequestGroup().setGroupId(groupThree).setTopics(groupThreeTopics);
OffsetFetchRequestGroup group4 = new OffsetFetchRequestGroup().setGroupId(groupFour).setTopics(null);
OffsetFetchRequestGroup group5 = new OffsetFetchRequestGroup().setGroupId(groupFive).setTopics(null);
OffsetFetchRequestData requestData = new OffsetFetchRequestData().setGroups(Arrays.asList(group1, group2, group3, group4, group5)).setRequireStable(true);
testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData);
testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData.setRequireStable(false));
for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
if (version >= 8) {
testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, requestData);
}
}
OffsetFetchResponseTopics responseTopic1 = new OffsetFetchResponseTopics().setName(topic1).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(5).setMetadata(null).setCommittedOffset(100).setCommittedLeaderEpoch(3).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code())));
OffsetFetchResponseTopics responseTopic2 = new OffsetFetchResponseTopics().setName(topic2).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(10).setMetadata("foo").setCommittedOffset(200).setCommittedLeaderEpoch(2).setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code())));
OffsetFetchResponseTopics responseTopic3 = new OffsetFetchResponseTopics().setName(topic3).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(15).setMetadata("bar").setCommittedOffset(300).setCommittedLeaderEpoch(1).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code())));
OffsetFetchResponseGroup responseGroup1 = new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(responseTopic1)).setErrorCode(Errors.NOT_COORDINATOR.code());
OffsetFetchResponseGroup responseGroup2 = new OffsetFetchResponseGroup().setGroupId(groupTwo).setTopics(Arrays.asList(responseTopic1, responseTopic2)).setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code());
OffsetFetchResponseGroup responseGroup3 = new OffsetFetchResponseGroup().setGroupId(groupThree).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
OffsetFetchResponseGroup responseGroup4 = new OffsetFetchResponseGroup().setGroupId(groupFour).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
OffsetFetchResponseGroup responseGroup5 = new OffsetFetchResponseGroup().setGroupId(groupFive).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
Supplier<OffsetFetchResponseData> response = () -> new OffsetFetchResponseData().setGroups(Arrays.asList(responseGroup1, responseGroup2, responseGroup3, responseGroup4, responseGroup5)).setThrottleTimeMs(10);
for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
if (version >= 8) {
OffsetFetchResponseData responseData = response.get();
testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, responseData);
}
}
}
Aggregations