Search in sources :

Example 1 with PartitionData

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()));
        }
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with PartitionData

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());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 3 with PartitionData

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());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 4 with PartitionData

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));
}
Also used : PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with PartitionData

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());
}
Also used : OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) Test(org.junit.jupiter.api.Test)

Aggregations

TopicPartition (org.apache.kafka.common.TopicPartition)10 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)10 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)5 OffsetFetchResponseData (org.apache.kafka.common.message.OffsetFetchResponseData)5 Map (java.util.Map)2 OffsetFetchResponseGroup (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup)2 OffsetFetchResponsePartition (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition)2 OffsetFetchResponsePartitions (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)2 OffsetFetchResponseTopic (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic)2 OffsetFetchResponseTopics (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics)2 OffsetFetchResponse (org.apache.kafka.common.requests.OffsetFetchResponse)2 List (java.util.List)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 Errors (org.apache.kafka.common.protocol.Errors)1 Builder (org.apache.kafka.common.requests.OffsetFetchRequest.Builder)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1