| 1 | /* Copyright (c) 2015, 2026, Oracle and/or its affiliates. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License, version 2.0, |
| 5 | as published by the Free Software Foundation. |
| 6 | |
| 7 | This program is designed to work with certain software (including |
| 8 | but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | as designated in a particular file or component or in included license |
| 10 | documentation. The authors of MySQL hereby grant you an additional |
| 11 | permission to link the program and your derivative works with the |
| 12 | separately licensed software that they have either included with |
| 13 | the program or referenced in the documentation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License, version 2.0, for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | |
| 24 | #include <ctime> |
| 25 | |
| 26 | #include "gcs_base_test.h" |
| 27 | |
| 28 | #include "gcs_xcom_statistics_interface.h" |
| 29 | |
| 30 | namespace gcs_xcom_statistics_unittest { |
| 31 | |
| 32 | class XcomStatisticsTest : public GcsBaseTest { |
| 33 | protected: |
| 34 | XcomStatisticsTest() = default; |
| 35 | |
| 36 | void SetUp() override { xcom_stats_if = new Gcs_xcom_statistics(); } |
| 37 | |
| 38 | void TearDown() override { delete xcom_stats_if; } |
| 39 | |
| 40 | Gcs_xcom_statistics *xcom_stats_if; |
| 41 | }; |
| 42 | |
| 43 | TEST_F(XcomStatisticsTest, UpdateMessageSentTest) { |
| 44 | long message_length = 1000; |
| 45 | |
| 46 | xcom_stats_if->update_message_sent(message_length); |
| 47 | |
| 48 | ASSERT_EQ(message_length, xcom_stats_if->get_total_bytes_sent()); |
| 49 | ASSERT_EQ(1, xcom_stats_if->get_total_messages_sent()); |
| 50 | } |
| 51 | |
| 52 | TEST_F(XcomStatisticsTest, UpdateMessagesSentTest) { |
| 53 | long message_length = 1000; |
| 54 | |
| 55 | xcom_stats_if->update_message_sent(message_length); |
| 56 | xcom_stats_if->update_message_sent(message_length); |
| 57 | |
| 58 | EXPECT_EQ(message_length * 2, xcom_stats_if->get_total_bytes_sent()); |
| 59 | EXPECT_EQ(2, xcom_stats_if->get_total_messages_sent()); |
| 60 | } |
| 61 | |
| 62 | TEST_F(XcomStatisticsTest, UpdateMessageReceivedTest) { |
| 63 | long message_length = 1000; |
| 64 | |
| 65 | xcom_stats_if->update_message_received(message_length); |
| 66 | |
| 67 | EXPECT_EQ(message_length, xcom_stats_if->get_total_bytes_received()); |
| 68 | EXPECT_EQ(1, xcom_stats_if->get_total_messages_received()); |
| 69 | EXPECT_GE(time(nullptr), xcom_stats_if->get_last_message_timestamp()); |
| 70 | EXPECT_EQ(message_length, xcom_stats_if->get_max_message_length()); |
| 71 | EXPECT_EQ(message_length, xcom_stats_if->get_min_message_length()); |
| 72 | } |
| 73 | |
| 74 | TEST_F(XcomStatisticsTest, UpdateMessagesReceivedTest) { |
| 75 | long message_length_big = 1000; |
| 76 | long message_length_small = 1000; |
| 77 | |
| 78 | xcom_stats_if->update_message_received(message_length_big); |
| 79 | xcom_stats_if->update_message_received(message_length_small); |
| 80 | |
| 81 | EXPECT_EQ(message_length_big + message_length_small, |
| 82 | xcom_stats_if->get_total_bytes_received()); |
| 83 | |
| 84 | EXPECT_EQ(2, xcom_stats_if->get_total_messages_received()); |
| 85 | EXPECT_GE(time(nullptr), xcom_stats_if->get_last_message_timestamp()); |
| 86 | EXPECT_EQ(message_length_big, xcom_stats_if->get_max_message_length()); |
| 87 | EXPECT_EQ(message_length_small, xcom_stats_if->get_min_message_length()); |
| 88 | } |
| 89 | |
| 90 | } // namespace gcs_xcom_statistics_unittest |