|
18 | 18 | */ |
19 | 19 |
|
20 | 20 | #include <chrono> |
| 21 | +#include <limits> |
21 | 22 | #include <regex> |
22 | 23 | #include <string> |
23 | 24 |
|
|
27 | 28 | // Ordering Required - Serializer template specializations before JsonSerializer.h |
28 | 29 | #include "generated/serializer/ApiSerializer.h" |
29 | 30 | #include "generated/serializer/CatalogSerializer.h" |
| 31 | +#include "generated/serializer/ConsumerPropertiesSerializer.h" |
30 | 32 | #include "generated/serializer/LayerVersionsSerializer.h" |
31 | 33 | #include "generated/serializer/PartitionsSerializer.h" |
| 34 | +#include "generated/serializer/StreamOffsetsSerializer.h" |
32 | 35 | #include "generated/serializer/VersionResponseSerializer.h" |
33 | 36 | #include "generated/serializer/JsonSerializer.h" |
34 | 37 |
|
@@ -426,4 +429,68 @@ TEST(SerializerTest, VersionResponse) { |
426 | 429 | ASSERT_EQ(expectedOutput, json); |
427 | 430 | } |
428 | 431 |
|
| 432 | +TEST(SerializerTest, ConsumerProperties) { |
| 433 | + std::string expected_output = |
| 434 | + "{\ |
| 435 | + \"kafkaConsumerProperties\":{\ |
| 436 | + \"key_string\":\"value_string\",\ |
| 437 | + \"key_c-string\":\"value_c-string\",\ |
| 438 | + \"key_int32\":\"42\",\ |
| 439 | + \"key_bool\":\"1\"\ |
| 440 | + }\ |
| 441 | + }"; |
| 442 | + |
| 443 | + olp::dataservice::read::ConsumerOptions expected_options = { |
| 444 | + olp::dataservice::read::ConsumerOption("key_string", |
| 445 | + std::string("value_string")), |
| 446 | + olp::dataservice::read::ConsumerOption("key_c-string", "value_c-string"), |
| 447 | + olp::dataservice::read::ConsumerOption("key_int32", int32_t{42}), |
| 448 | + olp::dataservice::read::ConsumerOption("key_bool", true)}; |
| 449 | + |
| 450 | + olp::dataservice::read::ConsumerProperties props(expected_options); |
| 451 | + auto json = olp::serializer::serialize(props); |
| 452 | + |
| 453 | + RemoveWhitespaceAndNewlines(expected_output); |
| 454 | + RemoveWhitespaceAndNewlines(json); |
| 455 | + |
| 456 | + EXPECT_EQ(expected_output, json); |
| 457 | +} |
| 458 | + |
| 459 | +TEST(SerializerTest, StreamOffset) { |
| 460 | + constexpr auto kMinInt32 = std::numeric_limits<int32_t>::min(); |
| 461 | + constexpr auto kMaxInt64 = std::numeric_limits<int64_t>::max(); |
| 462 | + |
| 463 | + std::string expected_output = |
| 464 | + "{\"offsets\":[\ |
| 465 | + {\ |
| 466 | + \"partition\":7,\ |
| 467 | + \"offset\":38562\ |
| 468 | + },\ |
| 469 | + {\ |
| 470 | + \"partition\":-2147483648,\ |
| 471 | + \"offset\":9223372036854775807\ |
| 472 | + }\ |
| 473 | + ]}"; |
| 474 | + |
| 475 | + StreamOffset kOffset1; |
| 476 | + kOffset1.SetPartition(7); |
| 477 | + kOffset1.SetOffset(38562); |
| 478 | + |
| 479 | + StreamOffset kOffset2; |
| 480 | + kOffset2.SetPartition(kMinInt32); |
| 481 | + kOffset2.SetOffset(kMaxInt64); |
| 482 | + |
| 483 | + const std::vector<StreamOffset> expected_offsets = {kOffset1, kOffset2}; |
| 484 | + |
| 485 | + StreamOffsets offsets; |
| 486 | + offsets.SetOffsets(expected_offsets); |
| 487 | + |
| 488 | + auto json = olp::serializer::serialize(offsets); |
| 489 | + |
| 490 | + RemoveWhitespaceAndNewlines(expected_output); |
| 491 | + RemoveWhitespaceAndNewlines(json); |
| 492 | + |
| 493 | + EXPECT_EQ(expected_output, json); |
| 494 | +} |
| 495 | + |
429 | 496 | } // namespace |
0 commit comments