slbotbm commented on code in PR #3102:
URL: https://github.com/apache/iggy/pull/3102#discussion_r3161792611


##########
foreign/cpp/tests/client/low_level_e2e.cpp:
##########
@@ -149,3 +153,671 @@ TEST(LowLevelE2E_Client, DeleteNullConnectionIsNoop) {
     iggy::ffi::Client *client = nullptr;
     ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
 }
+
+TEST(LowLevelE2E_Client, GetStatsBeforeLoginThrows) {
+    RecordProperty("description", "Rejects get_stats before connect, and after 
connect but before login.");
+    iggy::ffi::Client *client = nullptr;
+    ASSERT_NO_THROW({ client = iggy::ffi::new_connection(""); });
+    ASSERT_NE(client, nullptr);
+
+    ASSERT_THROW(client->get_stats(), std::exception);
+    ASSERT_NO_THROW(client->connect());
+    ASSERT_THROW(client->get_stats(), std::exception);
+
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
+    client = nullptr;
+}
+
+// TODO(slbotbm-this PR): add a test to create some streams, topics, 
partitions, and segments, send messages, and create
+// consumer groups and verify it.
+TEST(LowLevelE2E_Client, GetStatsReturnsServerStats) {
+    RecordProperty("description",
+                   "Returns empty resource counts first, then reflects 
aggregated streams, topics, partitions, "
+                   "consumer groups, and clients.");
+    const std::string first_stream_name                 = 
"cpp-get-stats-stream-1";
+    const std::string second_stream_name                = 
"cpp-get-stats-stream-2";
+    const std::string first_topic_name                  = 
"cpp-get-stats-topic-1";
+    const std::string second_topic_name                 = 
"cpp-get-stats-topic-2";
+    const std::string third_topic_name                  = 
"cpp-get-stats-topic-3";
+    const std::string first_group_name                  = 
"cpp-get-stats-group-1";
+    const std::string second_group_name                 = 
"cpp-get-stats-group-2";
+    const std::string third_group_name                  = 
"cpp-get-stats-group-3";
+    constexpr std::uint32_t additional_partitions_count = 2;
+    iggy::ffi::Client *client                           = login_to_server();
+    ASSERT_NE(client, nullptr);
+
+    iggy::ffi::Client *second_client = nullptr;
+    iggy::ffi::Client *third_client  = nullptr;
+
+    iggy::ffi::Stats empty_stats{};
+    ASSERT_NO_THROW({
+        empty_stats = client->get_stats();
+        EXPECT_NE(empty_stats.process_id, 0u);
+        EXPECT_GT(empty_stats.threads_count, 0u);
+        EXPECT_GT(empty_stats.total_memory, 0u);
+        EXPECT_GE(empty_stats.available_memory, 0u);
+        EXPECT_GE(empty_stats.total_disk_space, empty_stats.free_disk_space);
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.hostname).empty());
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.os_name).empty());
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.os_version).empty());
+        
EXPECT_FALSE(static_cast<std::string>(empty_stats.kernel_version).empty());
+        
EXPECT_FALSE(static_cast<std::string>(empty_stats.iggy_server_version).empty());
+        EXPECT_TRUE(empty_stats.iggy_server_semver == 
std::numeric_limits<std::uint32_t>::max() ||
+                    empty_stats.iggy_server_semver > 0u);
+        EXPECT_GE(empty_stats.cache_metrics.size(), 0u);

Review Comment:
   done



##########
foreign/cpp/tests/client/low_level_e2e.cpp:
##########
@@ -149,3 +153,671 @@ TEST(LowLevelE2E_Client, DeleteNullConnectionIsNoop) {
     iggy::ffi::Client *client = nullptr;
     ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
 }
+
+TEST(LowLevelE2E_Client, GetStatsBeforeLoginThrows) {
+    RecordProperty("description", "Rejects get_stats before connect, and after 
connect but before login.");
+    iggy::ffi::Client *client = nullptr;
+    ASSERT_NO_THROW({ client = iggy::ffi::new_connection(""); });
+    ASSERT_NE(client, nullptr);
+
+    ASSERT_THROW(client->get_stats(), std::exception);
+    ASSERT_NO_THROW(client->connect());
+    ASSERT_THROW(client->get_stats(), std::exception);
+
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
+    client = nullptr;
+}
+
+// TODO(slbotbm-this PR): add a test to create some streams, topics, 
partitions, and segments, send messages, and create
+// consumer groups and verify it.
+TEST(LowLevelE2E_Client, GetStatsReturnsServerStats) {
+    RecordProperty("description",
+                   "Returns empty resource counts first, then reflects 
aggregated streams, topics, partitions, "
+                   "consumer groups, and clients.");
+    const std::string first_stream_name                 = 
"cpp-get-stats-stream-1";
+    const std::string second_stream_name                = 
"cpp-get-stats-stream-2";
+    const std::string first_topic_name                  = 
"cpp-get-stats-topic-1";
+    const std::string second_topic_name                 = 
"cpp-get-stats-topic-2";
+    const std::string third_topic_name                  = 
"cpp-get-stats-topic-3";
+    const std::string first_group_name                  = 
"cpp-get-stats-group-1";
+    const std::string second_group_name                 = 
"cpp-get-stats-group-2";
+    const std::string third_group_name                  = 
"cpp-get-stats-group-3";
+    constexpr std::uint32_t additional_partitions_count = 2;
+    iggy::ffi::Client *client                           = login_to_server();
+    ASSERT_NE(client, nullptr);
+
+    iggy::ffi::Client *second_client = nullptr;
+    iggy::ffi::Client *third_client  = nullptr;
+
+    iggy::ffi::Stats empty_stats{};
+    ASSERT_NO_THROW({
+        empty_stats = client->get_stats();
+        EXPECT_NE(empty_stats.process_id, 0u);
+        EXPECT_GT(empty_stats.threads_count, 0u);
+        EXPECT_GT(empty_stats.total_memory, 0u);
+        EXPECT_GE(empty_stats.available_memory, 0u);
+        EXPECT_GE(empty_stats.total_disk_space, empty_stats.free_disk_space);
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.hostname).empty());
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.os_name).empty());
+        EXPECT_FALSE(static_cast<std::string>(empty_stats.os_version).empty());
+        
EXPECT_FALSE(static_cast<std::string>(empty_stats.kernel_version).empty());
+        
EXPECT_FALSE(static_cast<std::string>(empty_stats.iggy_server_version).empty());
+        EXPECT_TRUE(empty_stats.iggy_server_semver == 
std::numeric_limits<std::uint32_t>::max() ||
+                    empty_stats.iggy_server_semver > 0u);
+        EXPECT_GE(empty_stats.cache_metrics.size(), 0u);
+        EXPECT_EQ(empty_stats.streams_count, 0u);
+        EXPECT_EQ(empty_stats.topics_count, 0u);
+        EXPECT_EQ(empty_stats.partitions_count, 0u);
+        EXPECT_EQ(empty_stats.consumer_groups_count, 0u);
+    });
+
+    ASSERT_NO_THROW(client->create_stream(first_stream_name));
+    ASSERT_NO_THROW(client->create_stream(second_stream_name));
+    
ASSERT_NO_THROW(client->create_topic(make_string_identifier(first_stream_name), 
first_topic_name, 1, "none", 0,
+                                         "server_default", 0, 
"server_default"));
+    
ASSERT_NO_THROW(client->create_topic(make_string_identifier(first_stream_name), 
second_topic_name, 2, "none", 0,
+                                         "server_default", 0, 
"server_default"));
+    
ASSERT_NO_THROW(client->create_topic(make_string_identifier(second_stream_name),
 third_topic_name, 3, "none", 0,
+                                         "server_default", 0, 
"server_default"));
+    
ASSERT_NO_THROW(client->create_partitions(make_string_identifier(first_stream_name),
+                                              
make_string_identifier(first_topic_name), additional_partitions_count));
+    const auto first_group  = 
client->create_consumer_group(make_string_identifier(first_stream_name),
+                                                            
make_string_identifier(first_topic_name), first_group_name);
+    const auto second_group = client->create_consumer_group(
+        make_string_identifier(first_stream_name), 
make_string_identifier(second_topic_name), second_group_name);
+    const auto third_group = 
client->create_consumer_group(make_string_identifier(second_stream_name),
+                                                           
make_string_identifier(third_topic_name), third_group_name);
+
+    ASSERT_NO_THROW({ second_client = login_to_server(); });
+    ASSERT_NE(second_client, nullptr);
+    ASSERT_NO_THROW({ third_client = login_to_server(); });
+    ASSERT_NE(third_client, nullptr);
+
+    const auto first_stream_details           = 
client->get_stream(make_string_identifier(first_stream_name));
+    const auto second_stream_details          = 
client->get_stream(make_string_identifier(second_stream_name));
+    const std::uint32_t expected_topics_count = 
first_stream_details.topics_count + second_stream_details.topics_count;
+    std::uint32_t first_topic_partitions      = 0;
+    std::uint32_t second_topic_partitions     = 0;
+    std::uint32_t third_topic_partitions      = 0;
+    for (const auto &topic : first_stream_details.topics) {
+        if (topic.name == first_topic_name) {
+            first_topic_partitions = topic.partitions_count;
+        }
+        if (topic.name == second_topic_name) {
+            second_topic_partitions = topic.partitions_count;
+        }
+    }
+    for (const auto &topic : second_stream_details.topics) {
+        if (topic.name == third_topic_name) {
+            third_topic_partitions = topic.partitions_count;
+        }
+    }
+    const std::uint32_t expected_partitions_count =
+        first_topic_partitions + second_topic_partitions + 
third_topic_partitions;
+
+    ASSERT_NO_THROW({
+        const auto stats = client->get_stats();
+        EXPECT_EQ(stats.streams_count, 2u);
+        EXPECT_EQ(stats.topics_count, expected_topics_count);
+        EXPECT_EQ(stats.partitions_count, expected_partitions_count);
+        EXPECT_EQ(stats.segments_count, expected_partitions_count);
+        EXPECT_EQ(stats.consumer_groups_count, 3u);
+        EXPECT_EQ(stats.clients_count, empty_stats.clients_count + 2u);
+        EXPECT_EQ(first_group.partitions_count, first_topic_partitions);
+        EXPECT_EQ(second_group.partitions_count, second_topic_partitions);
+        EXPECT_EQ(third_group.partitions_count, third_topic_partitions);
+    });
+
+    
ASSERT_NO_THROW(client->delete_stream(make_string_identifier(second_stream_name)));
+    
ASSERT_NO_THROW(client->delete_stream(make_string_identifier(first_stream_name)));
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(third_client));
+    third_client = nullptr;
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(second_client));
+    second_client = nullptr;
+
+    ASSERT_NO_THROW({
+        const auto stats = client->get_stats();
+        EXPECT_EQ(stats.streams_count, 0u);
+        EXPECT_EQ(stats.topics_count, 0u);
+        EXPECT_EQ(stats.partitions_count, 0u);
+        EXPECT_EQ(stats.segments_count, 0u);
+        EXPECT_EQ(stats.consumer_groups_count, 0u);
+    });
+
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
+    client = nullptr;
+}
+
+TEST(LowLevelE2E_Client, GetStatsIsStableAcrossBackToBackCalls) {
+    RecordProperty(
+        "description",
+        "Returns sane invariant fields across back-to-back get_stats calls on 
an idle authenticated client.");
+    iggy::ffi::Client *client = login_to_server();
+    ASSERT_NE(client, nullptr);
+
+    iggy::ffi::Stats first_stats{};
+    iggy::ffi::Stats second_stats{};
+    ASSERT_NO_THROW({
+        first_stats  = client->get_stats();
+        second_stats = client->get_stats();
+    });
+
+    EXPECT_NE(first_stats.process_id, 0u);
+    EXPECT_NE(second_stats.process_id, 0u);
+    EXPECT_EQ(second_stats.process_id, first_stats.process_id);
+    EXPECT_GT(first_stats.threads_count, 0u);
+    EXPECT_GT(second_stats.threads_count, 0u);
+    EXPECT_GT(first_stats.total_memory, 0u);
+    EXPECT_GT(second_stats.total_memory, 0u);
+    EXPECT_FALSE(static_cast<std::string>(first_stats.hostname).empty());
+    EXPECT_FALSE(static_cast<std::string>(second_stats.hostname).empty());
+    EXPECT_FALSE(static_cast<std::string>(first_stats.os_name).empty());
+    EXPECT_FALSE(static_cast<std::string>(second_stats.os_name).empty());
+    EXPECT_FALSE(static_cast<std::string>(first_stats.os_version).empty());
+    EXPECT_FALSE(static_cast<std::string>(second_stats.os_version).empty());
+    EXPECT_FALSE(static_cast<std::string>(first_stats.kernel_version).empty());
+    
EXPECT_FALSE(static_cast<std::string>(second_stats.kernel_version).empty());
+    
EXPECT_FALSE(static_cast<std::string>(first_stats.iggy_server_version).empty());
+    
EXPECT_FALSE(static_cast<std::string>(second_stats.iggy_server_version).empty());
+    EXPECT_EQ(static_cast<std::string>(second_stats.hostname), 
static_cast<std::string>(first_stats.hostname));
+    EXPECT_EQ(static_cast<std::string>(second_stats.os_name), 
static_cast<std::string>(first_stats.os_name));
+    EXPECT_EQ(static_cast<std::string>(second_stats.os_version), 
static_cast<std::string>(first_stats.os_version));
+    EXPECT_EQ(static_cast<std::string>(second_stats.kernel_version),
+              static_cast<std::string>(first_stats.kernel_version));
+    EXPECT_EQ(static_cast<std::string>(second_stats.iggy_server_version),
+              static_cast<std::string>(first_stats.iggy_server_version));
+    EXPECT_EQ(second_stats.iggy_server_semver, first_stats.iggy_server_semver);
+    EXPECT_EQ(second_stats.clients_count, first_stats.clients_count);
+    EXPECT_EQ(second_stats.streams_count, first_stats.streams_count);
+    EXPECT_EQ(second_stats.topics_count, first_stats.topics_count);
+    EXPECT_EQ(second_stats.partitions_count, first_stats.partitions_count);
+    EXPECT_EQ(second_stats.consumer_groups_count, 
first_stats.consumer_groups_count);
+
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
+    client = nullptr;
+}
+
+TEST(LowLevelE2E_Client, GetMeBeforeLoginThrows) {
+    RecordProperty("description", "Rejects get_me before connect, and after 
connect but before login.");
+    iggy::ffi::Client *client = nullptr;
+    ASSERT_NO_THROW({ client = iggy::ffi::new_connection(""); });
+    ASSERT_NE(client, nullptr);
+
+    ASSERT_THROW(client->get_me(), std::exception);
+    ASSERT_NO_THROW(client->connect());
+    ASSERT_THROW(client->get_me(), std::exception);
+
+    ASSERT_NO_THROW(iggy::ffi::delete_connection(client));
+    client = nullptr;
+}
+
+// TODO(slbotbm-this PR): add additional validation for get_me after merging 
join_consumer_group PR.

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to