use of org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData in project kafka by apache.
the class OffsetFetchResponseTest method testConstructorWithMultipleGroups.
@Test
public void testConstructorWithMultipleGroups() {
Map<String, Map<TopicPartition, PartitionData>> responseData = new HashMap<>();
Map<String, Errors> errorMap = new HashMap<>();
Map<TopicPartition, PartitionData> pd1 = new HashMap<>();
Map<TopicPartition, PartitionData> pd2 = new HashMap<>();
Map<TopicPartition, PartitionData> pd3 = new HashMap<>();
pd1.put(new TopicPartition(topicOne, partitionOne), new PartitionData(offset, leaderEpochOne, metadata, Errors.TOPIC_AUTHORIZATION_FAILED));
pd2.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(offset, leaderEpochTwo, metadata, Errors.UNKNOWN_TOPIC_OR_PARTITION));
pd3.put(new TopicPartition(topicThree, partitionThree), new PartitionData(offset, leaderEpochThree, metadata, Errors.NONE));
responseData.put(groupOne, pd1);
responseData.put(groupTwo, pd2);
responseData.put(groupThree, pd3);
errorMap.put(groupOne, Errors.NOT_COORDINATOR);
errorMap.put(groupTwo, Errors.COORDINATOR_LOAD_IN_PROGRESS);
errorMap.put(groupThree, Errors.NONE);
for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
if (version >= 8) {
OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, errorMap, responseData);
assertEquals(Errors.NOT_COORDINATOR, response.groupLevelError(groupOne));
assertEquals(Errors.COORDINATOR_LOAD_IN_PROGRESS, response.groupLevelError(groupTwo));
assertEquals(Errors.NONE, response.groupLevelError(groupThree));
assertTrue(response.groupHasError(groupOne));
assertTrue(response.groupHasError(groupTwo));
assertFalse(response.groupHasError(groupThree));
assertEquals(5, response.errorCounts().size());
assertEquals(Utils.mkMap(Utils.mkEntry(Errors.NOT_COORDINATOR, 1), Utils.mkEntry(Errors.TOPIC_AUTHORIZATION_FAILED, 1), Utils.mkEntry(Errors.UNKNOWN_TOPIC_OR_PARTITION, 1), Utils.mkEntry(Errors.COORDINATOR_LOAD_IN_PROGRESS, 1), Utils.mkEntry(Errors.NONE, 2)), response.errorCounts());
assertEquals(throttleTimeMs, response.throttleTimeMs());
Map<TopicPartition, PartitionData> responseData1 = response.partitionDataMap(groupOne);
assertEquals(pd1, responseData1);
responseData1.forEach((tp, data) -> assertTrue(data.hasError()));
Map<TopicPartition, PartitionData> responseData2 = response.partitionDataMap(groupTwo);
assertEquals(pd2, responseData2);
responseData2.forEach((tp, data) -> assertTrue(data.hasError()));
Map<TopicPartition, PartitionData> responseData3 = response.partitionDataMap(groupThree);
assertEquals(pd3, responseData3);
responseData3.forEach((tp, data) -> assertFalse(data.hasError()));
}
}
}
use of org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData 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.requests.OffsetFetchResponse.PartitionData 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.requests.OffsetFetchResponse.PartitionData in project kafka by apache.
the class OffsetFetchResponseTest method setUp.
@BeforeEach
public void setUp() {
partitionDataMap = new HashMap<>();
partitionDataMap.put(new TopicPartition(topicOne, partitionOne), new PartitionData(offset, leaderEpochOne, metadata, Errors.TOPIC_AUTHORIZATION_FAILED));
partitionDataMap.put(new TopicPartition(topicTwo, partitionTwo), new PartitionData(offset, leaderEpochTwo, metadata, Errors.UNKNOWN_TOPIC_OR_PARTITION));
}
use of org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData in project kafka by apache.
the class OffsetFetchResponseTest method testNullableMetadataV0ToV7.
@Test
public void testNullableMetadataV0ToV7() {
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, Errors.GROUP_AUTHORIZATION_FAILED, partitionDataMap);
OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code()).setThrottleTimeMs(throttleTimeMs).setTopics(Collections.singletonList(new OffsetFetchResponseTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartition().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpochOne.orElse(-1)).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(null)))));
assertEquals(expectedData, response.data());
}
Aggregations