summaryrefslogtreecommitdiff
path: root/test/test_metric_counter.cpp
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-07-11 16:03:19 +0800
committerchenzizhan <[email protected]>2023-07-11 16:03:19 +0800
commit1acd976fc0894bb111ee93d1f0c9f8bcec5e5dc3 (patch)
tree32ad8f245f9e9da83f09313a3a434a9c64cd0522 /test/test_metric_counter.cpp
parentd2f2e1c98100d38df067ec6e89fbd65d0e135d99 (diff)
merge(without test)
Diffstat (limited to 'test/test_metric_counter.cpp')
-rw-r--r--test/test_metric_counter.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/test_metric_counter.cpp b/test/test_metric_counter.cpp
new file mode 100644
index 0000000..846256e
--- /dev/null
+++ b/test/test_metric_counter.cpp
@@ -0,0 +1,53 @@
+
+#include <gtest/gtest.h>
+#include "fieldstat.h"
+#include "utils.hpp"
+
+TEST(metric_test_counter, simple_register_and_query)
+{
+ struct fieldstat *instance = fieldstat_new();
+ int cube_id = fieldstat_register_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_COMPREHENSIVE, 10);
+ EXPECT_EQ(cube_id, 0);
+
+ int metric_id = fieldstat_register_counter(instance, cube_id, "czz_test counter metric", false);
+ EXPECT_EQ(metric_id, 0);
+
+ int cell_id = fieldstat_cube_add(instance, cube_id, &TEST_TAG_STRING, 1, 1);
+ EXPECT_NE(cell_id, -1);
+
+ fieldstat_counter_incrby(instance, metric_id, cube_id, cell_id, 10086);
+
+ // query
+ int ret_cell_id = fieldstat_get_max_cube_id(instance);
+ EXPECT_EQ(ret_cell_id, 0);
+ int ret_metric_id = fieldstat_get_max_metric_id(instance, ret_cell_id);
+ EXPECT_EQ(ret_metric_id, 0);
+ long long measure = fieldstat_counter_get(instance, cube_id, metric_id, cell_id);
+ printf("fieldstat_counter_get done, measure: %lld\n", measure);
+ EXPECT_EQ(measure, 10086);
+ const char *name = fieldstat_get_metric_name(instance, cube_id, metric_id);
+ EXPECT_STREQ(name, "czz_test counter metric");
+
+ printf("going to get cells\n");
+
+ int *ret_cell_ids = NULL;
+ struct fieldstat_tag_list *tag_list = NULL;
+ size_t n_cell = 0;
+ fieldstat_get_cells(instance, cube_id, metric_id, &ret_cell_ids, &tag_list, &n_cell);
+ EXPECT_EQ(n_cell, 1);
+ EXPECT_EQ(ret_cell_ids[0], cell_id);
+ EXPECT_EQ(tag_list->n_tag, 1);
+ EXPECT_STREQ(tag_list->tag[0].key, TEST_TAG_STRING.key);
+
+ fieldstat_free(instance);
+ free(ret_cell_ids);
+ fieldstat_tag_list_arr_free(tag_list, n_cell);
+}
+
+// TODO: cell 超过
+
+int main(int argc, char *argv[])
+{
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+} \ No newline at end of file