Skip to content

add test to check metadata #17747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ydb/core/kafka_proxy/ut/kafka_test_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,25 @@ TMessagePtr<TInitProducerIdResponseData> TKafkaTestClient::InitProducerId(const
return WriteAndRead<TInitProducerIdResponseData>(header, request);
}

TMessagePtr<TOffsetCommitResponseData> TKafkaTestClient::OffsetCommit(TString groupId, std::unordered_map<TString, std::vector<std::pair<ui64,ui64>>> topicsToPartions) {


TMessagePtr<TOffsetCommitResponseData> TKafkaTestClient::OffsetCommit(TString groupId, std::unordered_map<TString, std::vector<TConsumerOffset>> topicsToConsumerOffsets) {
Cerr << ">>>>> TOffsetCommitRequestData\n";

TRequestHeaderData header = Header(NKafka::EApiKey::OFFSET_COMMIT, 1);

TOffsetCommitRequestData request;
request.GroupId = groupId;

for (const auto& topicToPartitions : topicsToPartions) {
for (const auto& topicToConsumerOffsets : topicsToConsumerOffsets) {
NKafka::TOffsetCommitRequestData::TOffsetCommitRequestTopic topic;
topic.Name = topicToPartitions.first;
topic.Name = topicToConsumerOffsets.first;

for (auto partitionAndOffset : topicToPartitions.second) {
for (auto consumerOffset : topicToConsumerOffsets.second) {
NKafka::TOffsetCommitRequestData::TOffsetCommitRequestTopic::TOffsetCommitRequestPartition partition;
partition.PartitionIndex = partitionAndOffset.first;
partition.CommittedOffset = partitionAndOffset.second;
partition.PartitionIndex = consumerOffset.PartitionIndex;
partition.CommittedOffset = consumerOffset.Offset;
partition.CommittedMetadata = consumerOffset.Metadata;
topic.Partitions.push_back(partition);
}
request.Topics.push_back(topic);
Expand Down Expand Up @@ -663,4 +666,4 @@ void TKafkaTestClient::FillTopicsFromJoinGroupMetadata(TKafkaBytes& metadata, TH
topics.emplace(topic.value());
}
}
}
}
11 changes: 9 additions & 2 deletions ydb/core/kafka_proxy/ut/kafka_test_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ struct TReadInfo {
i32 GenerationId;
};

struct TConsumerOffset {
ui64 PartitionIndex;
ui64 Offset;
TString Metadata;
};


class TKafkaTestClient {
public:
TKafkaTestClient(ui16 port, const TString clientName = "TestClient");
Expand All @@ -61,7 +68,7 @@ class TKafkaTestClient {

TMessagePtr<TInitProducerIdResponseData> InitProducerId(const TString& transactionalId = "");

TMessagePtr<TOffsetCommitResponseData> OffsetCommit(TString groupId, std::unordered_map<TString, std::vector<std::pair<ui64,ui64>>> topicsToPartions);
TMessagePtr<TOffsetCommitResponseData> OffsetCommit(TString groupId, std::unordered_map<TString, std::vector<TConsumerOffset>> topicsToConsumerOffsets);

TMessagePtr<TProduceResponseData> Produce(const TString& topicName, ui32 partition, const TKafkaRecordBatch& batch);

Expand Down Expand Up @@ -128,4 +135,4 @@ class TKafkaTestClient {

ui32 Correlation;
TString ClientName;
};
};
30 changes: 21 additions & 9 deletions ydb/core/kafka_proxy/ut/ut_protocol.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


#include <library/cpp/testing/unittest/registar.h>

#include "kafka_test_client.h"
Expand Down Expand Up @@ -279,6 +281,8 @@ void CreateTopic(NYdb::NTopic::TTopicClient& pqClient, TString& topicName, ui32

}



Y_UNIT_TEST_SUITE(KafkaProtocol) {
// this test imitates kafka producer behaviour:
// 1. get api version,
Expand Down Expand Up @@ -996,6 +1000,8 @@ Y_UNIT_TEST_SUITE(KafkaProtocol) {
TString headerKey = "header-key";
TString headerValue = "header-value";

TString commitedMetaData = "additional-info";

NYdb::NTopic::TTopicClient pqClient(*testServer.Driver);
CreateTopic(pqClient, firstTopicName, minActivePartitions, {firstConsumerName, secondConsumerName});
CreateTopic(pqClient, secondTopicName, minActivePartitions, {firstConsumerName, secondConsumerName});
Expand Down Expand Up @@ -1043,10 +1049,10 @@ Y_UNIT_TEST_SUITE(KafkaProtocol) {

{
// Check commit
std::unordered_map<TString, std::vector<std::pair<ui64,ui64>>> offsets;
std::vector<std::pair<ui64, ui64>> partitionsAndOffsets;
std::unordered_map<TString, std::vector<TConsumerOffset>> offsets;
std::vector<TConsumerOffset> partitionsAndOffsets;
for (ui64 i = 0; i < minActivePartitions; ++i) {
partitionsAndOffsets.emplace_back(std::make_pair(i, recordsCount));
partitionsAndOffsets.emplace_back(TConsumerOffset{i, static_cast<ui64>(recordsCount), commitedMetaData});
}
offsets[firstTopicName] = partitionsAndOffsets;
offsets[shortTopicName] = partitionsAndOffsets;
Expand Down Expand Up @@ -1074,12 +1080,18 @@ Y_UNIT_TEST_SUITE(KafkaProtocol) {
topicsToPartions[firstTopicName] = std::vector<i32>{0, 1, 2 , 3 };
auto msg = client.OffsetFetch(firstConsumerName, topicsToPartions);
UNIT_ASSERT_VALUES_EQUAL(msg->Groups.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(msg->Groups.size(), 1);
UNIT_ASSERT_VALUES_EQUAL(msg->Groups[0].Topics.size(), 1);
const auto& partitions = msg->Groups[0].Topics[0].Partitions;
UNIT_ASSERT_VALUES_EQUAL(partitions.size(), 4);
auto partition0 = std::find_if(partitions.begin(), partitions.end(), [](const auto& partition) { return partition.PartitionIndex == 0; });
UNIT_ASSERT_VALUES_UNEQUAL(partition0, partitions.end());
UNIT_ASSERT_VALUES_EQUAL(partition0->CommittedOffset, 5);
// ToDo: return here to change ASSERT to check that metadata is transfered correctly
// after realization of metadata saving is completed.
for (auto p = partitions.begin(); p != partitions.end(); p++) {
UNIT_ASSERT_VALUES_EQUAL(p->Metadata, "");
}
}

{
Expand All @@ -1097,10 +1109,10 @@ Y_UNIT_TEST_SUITE(KafkaProtocol) {

{
// Check commit with nonexistent topic
std::unordered_map<TString, std::vector<std::pair<ui64,ui64>>> offsets;
std::vector<std::pair<ui64, ui64>> partitionsAndOffsets;
std::unordered_map<TString, std::vector<TConsumerOffset>> offsets;
std::vector<TConsumerOffset> partitionsAndOffsets;
for (ui64 i = 0; i < minActivePartitions; ++i) {
partitionsAndOffsets.emplace_back(std::make_pair(i, recordsCount));
partitionsAndOffsets.emplace_back(TConsumerOffset{i, static_cast<ui64>(recordsCount), commitedMetaData});
}
offsets[firstTopicName] = partitionsAndOffsets;
offsets[notExistsTopicName] = partitionsAndOffsets;
Expand Down Expand Up @@ -1130,10 +1142,10 @@ Y_UNIT_TEST_SUITE(KafkaProtocol) {

{
// Check commit with nonexistent consumer
std::unordered_map<TString, std::vector<std::pair<ui64,ui64>>> offsets;
std::vector<std::pair<ui64, ui64>> partitionsAndOffsets;
std::unordered_map<TString, std::vector<TConsumerOffset>> offsets;
std::vector<TConsumerOffset> partitionsAndOffsets;
for (ui64 i = 0; i < minActivePartitions; ++i) {
partitionsAndOffsets.emplace_back(std::make_pair(i, recordsCount));
partitionsAndOffsets.emplace_back(TConsumerOffset{i, static_cast<ui64>(recordsCount), commitedMetaData});
}
offsets[firstTopicName] = partitionsAndOffsets;

Expand Down