summaryrefslogtreecommitdiff
path: root/test/test_easy_fs.cpp
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-26 18:02:29 +0800
committerchenzizhan <[email protected]>2024-07-26 18:02:29 +0800
commit240bbbb0e0409a6bca409eb319a0a00960cbc6fb (patch)
treeb15ddd24d6b851ccf797a5919df52d7994e4dbc9 /test/test_easy_fs.cpp
parent3f46275f81d2d5af416f27fb24ab2c5ac21ec418 (diff)
parent97e8724310c1a0d51600d723c6d3dcb6c4495d5f (diff)
Merge branch 'refactor-heavykeeper-newkey' into develop-version4
Diffstat (limited to 'test/test_easy_fs.cpp')
-rw-r--r--test/test_easy_fs.cpp75
1 files changed, 23 insertions, 52 deletions
diff --git a/test/test_easy_fs.cpp b/test/test_easy_fs.cpp
index d3f45b7..a0e507d 100644
--- a/test/test_easy_fs.cpp
+++ b/test/test_easy_fs.cpp
@@ -13,54 +13,25 @@
TEST(test_easy_fieldstat, new_and_free)
{
- struct fieldstat_easy *fse = fieldstat_easy_new(10, "instance name1231231231", &TEST_TAG_STRING, 1);
+ struct fieldstat_easy *fse = fieldstat_easy_new(10, "instance name1231231231", &TEST_FIELD_STRING, 1);
fieldstat_easy_free(fse);
}
TEST(test_easy_fieldstat, output_to_buff)
{
- struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, &TEST_TAG_STRING, 1);
+ struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, &TEST_FIELD_STRING, 1);
fieldstat_easy_register_counter(fse, "metric counter");
- fieldstat_easy_counter_incrby(fse, 0, 0, &TEST_TAG_INT, 1, 1);
+ fieldstat_easy_counter_incrby(fse, 0, 0, &TEST_FIELD_INT, 1, 1);
// read file, should be empty
char *buff = NULL;
size_t buff_len = 0;
fieldstat_easy_output(fse, &buff, &buff_len);
cJSON *root = cJSON_Parse(buff);
cJSON *cell = cJSON_GetArrayItem(root, 0);
- cJSON *metric = cJSON_GetObjectItem(cell, "fields");
- long long value = cJSON_GetObjectItem(metric, "metric counter")->valueint;
+ long long value = cJSON_GetObjectItem(cell, "metric counter")->valueint;
EXPECT_EQ(value, 1);
- cJSON *tags = cJSON_GetObjectItem(cell, "tags");
- EXPECT_EQ(cJSON_GetObjectItem(tags, TEST_TAG_INT.key)->valueint, TEST_TAG_INT.value_longlong);
- EXPECT_STREQ(cJSON_GetObjectItem(tags, TEST_TAG_STRING.key)->valuestring, TEST_TAG_STRING.value_str);
-
- cJSON_Delete(root);
- free(buff);
- fieldstat_easy_free(fse);
-}
-
-TEST(test_easy_fieldstat, output_to_buff_with_delta)
-{
- struct fieldstat_easy *fse = fieldstat_easy_new(1, NULL, NULL, 0);
- fieldstat_easy_enable_delta_in_active_output(fse);
- fieldstat_easy_register_counter(fse, "metric counter");
- fieldstat_easy_counter_incrby(fse, 0, 0, NULL, 0, 1);
- char *buff = NULL;
- size_t buff_len = 0;
- fieldstat_easy_output(fse, &buff, &buff_len);
- free(buff);
- fieldstat_easy_counter_incrby(fse, 0, 0, NULL, 0, 1);
- fieldstat_easy_output(fse, &buff, &buff_len);
-
- cJSON *root = cJSON_Parse(buff);
- cJSON *cell = cJSON_GetArrayItem(root, 0);
- cJSON *metric = cJSON_GetObjectItem(cell, "fields");
- long long value = cJSON_GetObjectItem(metric, "metric counter")->valueint;
- EXPECT_EQ(value, 2);
- cJSON *metric_delta = cJSON_GetObjectItem(cell, "fields_delta");
- long long value_delta = cJSON_GetObjectItem(metric_delta, "metric counter")->valueint;
- EXPECT_EQ(value_delta, 1);
+ EXPECT_EQ(cJSON_GetObjectItem(cell, TEST_FIELD_INT.key)->valueint, TEST_FIELD_INT.value_longlong);
+ EXPECT_STREQ(cJSON_GetObjectItem(cell, TEST_FIELD_STRING.key)->valuestring, TEST_FIELD_STRING.value_str);
cJSON_Delete(root);
free(buff);
@@ -92,9 +63,9 @@ TEST(test_easy_fieldstat, output_to_file)
EXPECT_EQ(cJSON_GetArraySize(root), 0); // is empty and valid
cJSON_Delete(root);
- fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_TAG_INT, 1, 1);
- fieldstat_easy_counter_incrby(fse, 1, counter_id, &TEST_TAG_INT, 1, 10);
- fieldstat_easy_counter_incrby(fse, 2, counter_id, &TEST_TAG_INT, 1, 100);
+ fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_FIELD_INT, 1, 1);
+ fieldstat_easy_counter_incrby(fse, 1, counter_id, &TEST_FIELD_INT, 1, 10);
+ fieldstat_easy_counter_incrby(fse, 2, counter_id, &TEST_FIELD_INT, 1, 100);
sleep(2);
// 2nd interval: merge 3 thread's data, and output
@@ -123,7 +94,7 @@ TEST(test_easy_fieldstat, output_to_file)
cJSON_Delete(root);
// 4th interval: new data, output again
- fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_TAG_DOUBLE, 1, 10086);
+ fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_FIELD_DOUBLE, 1, 10086);
sleep(2);
printf("4th interval\n");
root = read_file();
@@ -182,9 +153,9 @@ TEST(test_easy_fieldstat, output_interval_ok)
struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, NULL, 0);
fieldstat_easy_register_histogram(fse, "metric histogram", 1, 10000, 3); // a pretty time consuming metric
- fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_INT, 1, 1);
- fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_DOUBLE, 1, 10);
- fieldstat_easy_histogram_record(fse, 0, 0, &TEST_TAG_STRING, 1, 110);
+ fieldstat_easy_histogram_record(fse, 0, 0, &TEST_FIELD_INT, 1, 1);
+ fieldstat_easy_histogram_record(fse, 0, 0, &TEST_FIELD_DOUBLE, 1, 10);
+ fieldstat_easy_histogram_record(fse, 0, 0, &TEST_FIELD_STRING, 1, 110);
fieldstat_easy_enable_auto_output(fse, FILENAME, 1);
@@ -197,10 +168,10 @@ TEST(test_easy_fieldstat, output_interval_ok)
TEST(test_easy_fieldstat, ensure_data_racing_of_two_output_and_of_incyby)
{
const int N_THREADS = 3;
- struct fieldstat_tag global_tags[1];
- struct fieldstat_tag tmptag;
+ struct field global_tags[1];
+ struct field tmptag;
tmptag.key = "app id";
- tmptag.type = TAG_INTEGER;
+ tmptag.type = FIELD_VALUE_INTEGER;
tmptag.value_longlong = 1;
global_tags[0] = tmptag;
@@ -213,8 +184,8 @@ TEST(test_easy_fieldstat, ensure_data_racing_of_two_output_and_of_incyby)
for (int thread_id = 0; thread_id < N_THREADS; thread_id++) {
threads[thread_id] = std::thread([fse, counter_id, hdr_id, thread_id]() {
for (int i = 0; i < 1000000; i++) { // loop million times to ensure no core dump
- fieldstat_easy_counter_incrby(fse, thread_id, counter_id, &TEST_TAG_INT, 1, 1);
- fieldstat_easy_histogram_record(fse, thread_id, hdr_id, &TEST_TAG_INT, 1, rand() % 10000);
+ fieldstat_easy_counter_incrby(fse, thread_id, counter_id, &TEST_FIELD_INT, 1, 1);
+ fieldstat_easy_histogram_record(fse, thread_id, hdr_id, &TEST_FIELD_INT, 1, rand() % 10000);
usleep(1); // 1us * 1000000 = 1s, just long enough to output
}
});
@@ -231,8 +202,8 @@ TEST(test_easy_fieldstat, reset)
{
struct fieldstat_easy *fse = fieldstat_easy_new(3, NULL, NULL, 0);
int counter_id = fieldstat_easy_register_counter(fse, "metric counter");
- fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_TAG_INT, 1, 1);
- fieldstat_easy_counter_incrby(fse, 1, counter_id, &TEST_TAG_INT, 1, 1);
+ fieldstat_easy_counter_incrby(fse, 0, counter_id, &TEST_FIELD_INT, 1, 1);
+ fieldstat_easy_counter_incrby(fse, 1, counter_id, &TEST_FIELD_INT, 1, 1);
char **objects = NULL;
size_t n_objects = 0;
@@ -250,8 +221,7 @@ TEST(test_easy_fieldstat, reset)
long long get_value(const char *input, const char *key) {
cJSON *root = cJSON_Parse(input);
- cJSON *metric = cJSON_GetObjectItem(root, "fields");
- long long value = cJSON_GetObjectItem(metric, key)->valueint;
+ long long value = cJSON_GetObjectItem(root, key)->valueint;
cJSON_Delete(root);
return value;
}
@@ -268,7 +238,7 @@ TEST(test_easy_fieldstat, accuracy_in_multithread)
for (int thread_id = 0; thread_id < N_THREADS; thread_id++) {
threads[thread_id] = std::thread([fse, counter_id, thread_id]() {
for (size_t i = 0; i < 2000000ULL; i++) { // 1 million times
- fieldstat_easy_counter_incrby(fse, thread_id, counter_id, &TEST_TAG_INT, 1, 1);
+ fieldstat_easy_counter_incrby(fse, thread_id, counter_id, &TEST_FIELD_INT, 1, 1);
}
});
}
@@ -305,5 +275,6 @@ TEST(test_easy_fieldstat, accuracy_in_multithread)
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
+ // testing::GTEST_FLAG(filter) = "test_easy_fieldstat.accuracy_in_multithread";
return RUN_ALL_TESTS();
} \ No newline at end of file