Search in sources :

Example 1 with OffsetCommitRequestPartition

use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition in project kafka by apache.

the class MessageTest method testOffsetCommitRequestVersions.

@Test
public void testOffsetCommitRequestVersions() throws Exception {
    String groupId = "groupId";
    String topicName = "topic";
    String metadata = "metadata";
    int partition = 2;
    int offset = 100;
    testAllMessageRoundTrips(new OffsetCommitRequestData().setGroupId(groupId).setTopics(Collections.singletonList(new OffsetCommitRequestTopic().setName(topicName).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partition).setCommittedMetadata(metadata).setCommittedOffset(offset))))));
    Supplier<OffsetCommitRequestData> request = () -> new OffsetCommitRequestData().setGroupId(groupId).setMemberId("memberId").setGroupInstanceId("instanceId").setTopics(Collections.singletonList(new OffsetCommitRequestTopic().setName(topicName).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partition).setCommittedLeaderEpoch(10).setCommittedMetadata(metadata).setCommittedOffset(offset).setCommitTimestamp(20))))).setRetentionTimeMs(20);
    for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
        OffsetCommitRequestData requestData = request.get();
        if (version < 1) {
            requestData.setMemberId("");
            requestData.setGenerationId(-1);
        }
        if (version != 1) {
            requestData.topics().get(0).partitions().get(0).setCommitTimestamp(-1);
        }
        if (version < 2 || version > 4) {
            requestData.setRetentionTimeMs(-1);
        }
        if (version < 6) {
            requestData.topics().get(0).partitions().get(0).setCommittedLeaderEpoch(-1);
        }
        if (version < 7) {
            requestData.setGroupInstanceId(null);
        }
        if (version == 1) {
            testEquivalentMessageRoundTrip(version, requestData);
        } else if (version >= 2 && version <= 4) {
            testAllMessageRoundTripsBetweenVersions(version, (short) 5, requestData, requestData);
        } else {
            testAllMessageRoundTripsFromVersion(version, requestData);
        }
    }
}
Also used : OffsetCommitRequestTopic(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic) TxnOffsetCommitRequestTopic(org.apache.kafka.common.message.TxnOffsetCommitRequestData.TxnOffsetCommitRequestTopic) TxnOffsetCommitRequestPartition(org.apache.kafka.common.message.TxnOffsetCommitRequestData.TxnOffsetCommitRequestPartition) OffsetCommitRequestPartition(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition) Test(org.junit.jupiter.api.Test)

Example 2 with OffsetCommitRequestPartition

use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition in project kafka by apache.

the class OffsetCommitRequestTest method setUp.

@BeforeEach
public void setUp() {
    topics = Arrays.asList(new OffsetCommitRequestTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpoch).setCommittedMetadata(metadata))), new OffsetCommitRequestTopic().setName(topicTwo).setPartitions(Collections.singletonList(new OffsetCommitRequestPartition().setPartitionIndex(partitionTwo).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpoch).setCommittedMetadata(metadata))));
    data = new OffsetCommitRequestData().setGroupId(groupId).setTopics(topics);
}
Also used : OffsetCommitRequestTopic(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic) OffsetCommitRequestData(org.apache.kafka.common.message.OffsetCommitRequestData) OffsetCommitRequestPartition(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with OffsetCommitRequestPartition

use of org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition in project kafka by apache.

the class AlterConsumerGroupOffsetsHandler method buildRequest.

@Override
public OffsetCommitRequest.Builder buildRequest(int coordinatorId, Set<CoordinatorKey> groupIds) {
    validateKeys(groupIds);
    Map<String, OffsetCommitRequestTopic> offsetData = new HashMap<>();
    offsets.forEach((topicPartition, offsetAndMetadata) -> {
        OffsetCommitRequestTopic topic = offsetData.computeIfAbsent(topicPartition.topic(), key -> new OffsetCommitRequestTopic().setName(topicPartition.topic()));
        topic.partitions().add(new OffsetCommitRequestPartition().setCommittedOffset(offsetAndMetadata.offset()).setCommittedLeaderEpoch(offsetAndMetadata.leaderEpoch().orElse(-1)).setCommittedMetadata(offsetAndMetadata.metadata()).setPartitionIndex(topicPartition.partition()));
    });
    OffsetCommitRequestData data = new OffsetCommitRequestData().setGroupId(groupId.idValue).setTopics(new ArrayList<>(offsetData.values()));
    return new OffsetCommitRequest.Builder(data);
}
Also used : OffsetCommitRequestTopic(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic) HashMap(java.util.HashMap) OffsetCommitRequestData(org.apache.kafka.common.message.OffsetCommitRequestData) OffsetCommitRequestPartition(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition)

Aggregations

OffsetCommitRequestPartition (org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestPartition)3 OffsetCommitRequestTopic (org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic)3 OffsetCommitRequestData (org.apache.kafka.common.message.OffsetCommitRequestData)2 HashMap (java.util.HashMap)1 TxnOffsetCommitRequestPartition (org.apache.kafka.common.message.TxnOffsetCommitRequestData.TxnOffsetCommitRequestPartition)1 TxnOffsetCommitRequestTopic (org.apache.kafka.common.message.TxnOffsetCommitRequestData.TxnOffsetCommitRequestTopic)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1