[PATCH]add log handle for maat_wrap_redis_command
This commit is contained in:
@@ -17,17 +17,20 @@ struct log_handle *g_logger = NULL;
|
||||
TEST(json_mode, maat_scan_string) {
|
||||
char tmp_iris_path[PATH_MAX] = {0};
|
||||
char json_iris_path[PATH_MAX] = {0};
|
||||
snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
|
||||
snprintf(json_iris_path, sizeof(json_iris_path),
|
||||
"./%s_iris_tmp", json_filename);
|
||||
|
||||
if (access(json_iris_path, F_OK) < 0) {
|
||||
char *json_buff = NULL;
|
||||
size_t json_buff_sz = 0;
|
||||
|
||||
int ret = load_file_to_memory(json_filename, (unsigned char**)&json_buff, &json_buff_sz);
|
||||
int ret = load_file_to_memory(json_filename,
|
||||
(unsigned char**)&json_buff,
|
||||
&json_buff_sz);
|
||||
EXPECT_NE(ret, -1);
|
||||
|
||||
ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
|
||||
NULL, NULL, g_logger);
|
||||
ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
|
||||
sizeof(tmp_iris_path), NULL, NULL, g_logger);
|
||||
FREE(json_buff);
|
||||
EXPECT_NE(ret, -1);
|
||||
}
|
||||
@@ -43,7 +46,8 @@ TEST(json_mode, maat_scan_string) {
|
||||
|
||||
const char *table_name = "KEYWORDS_TABLE";
|
||||
int table_id = maat_get_table_id(maat_inst, table_name);
|
||||
char scan_data[128] = "string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
char scan_data[128] =
|
||||
"string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
long long results[5] = {0};
|
||||
size_t n_hit_result = 0;
|
||||
int thread_id = 0;
|
||||
@@ -63,25 +67,30 @@ TEST(json_mode, maat_scan_string) {
|
||||
TEST(iris_mode, maat_scan_string) {
|
||||
char tmp_iris_path[512] = {0};
|
||||
char json_iris_path[512] = {0};
|
||||
snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
|
||||
snprintf(json_iris_path, sizeof(json_iris_path),
|
||||
"./%s_iris_tmp", json_filename);
|
||||
|
||||
if (access(json_iris_path, F_OK) < 0) {
|
||||
char *json_buff = NULL;
|
||||
size_t json_buff_sz = 0;
|
||||
|
||||
int ret = load_file_to_memory(json_filename, (unsigned char**)&json_buff, &json_buff_sz);
|
||||
int ret = load_file_to_memory(json_filename,
|
||||
(unsigned char**)&json_buff,
|
||||
&json_buff_sz);
|
||||
EXPECT_NE(ret, -1);
|
||||
|
||||
ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path, sizeof(tmp_iris_path),
|
||||
NULL, NULL, g_logger);
|
||||
ret = json2iris(json_buff, json_filename, NULL, tmp_iris_path,
|
||||
sizeof(tmp_iris_path), NULL, NULL, g_logger);
|
||||
FREE(json_buff);
|
||||
EXPECT_NE(ret, -1);
|
||||
}
|
||||
|
||||
char tmp_iris_full_idx_path[PATH_MAX] = {0};
|
||||
char tmp_iris_inc_idx_path[PATH_MAX] = {0};
|
||||
snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path), "%s/index", json_iris_path);
|
||||
snprintf(tmp_iris_inc_idx_path, sizeof(tmp_iris_inc_idx_path), "%s/index", json_iris_path);
|
||||
snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path),
|
||||
"%s/index", json_iris_path);
|
||||
snprintf(tmp_iris_inc_idx_path, sizeof(tmp_iris_inc_idx_path),
|
||||
"%s/index", json_iris_path);
|
||||
|
||||
struct maat_options *opts = maat_options_new();
|
||||
maat_options_set_iris(opts, tmp_iris_full_idx_path, tmp_iris_inc_idx_path);
|
||||
@@ -92,7 +101,8 @@ TEST(iris_mode, maat_scan_string) {
|
||||
|
||||
const char *table_name = "KEYWORDS_TABLE";
|
||||
int table_id = maat_get_table_id(maat_inst, table_name);
|
||||
char scan_data[128] = "string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
char scan_data[128] =
|
||||
"string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
long long results[5] = {0};
|
||||
size_t n_hit_result = 0;
|
||||
int thread_id = 0;
|
||||
@@ -129,7 +139,8 @@ int make_serial_rule(const char *table_name, const char *line, void *u_para)
|
||||
}
|
||||
|
||||
const char *redis_rule_key = "TEST_RULE_KEY";
|
||||
redisReply *reply = maat_wrap_redis_command(ctx, "INCRBY %s %d", redis_rule_key, 1);
|
||||
redisReply *reply =
|
||||
maat_wrap_redis_command(ctx, NULL, "INCRBY %s %d", redis_rule_key, 1);
|
||||
if (reply->type == REDIS_REPLY_NIL) {
|
||||
printf("incrby redis_rule_key:%s failed.", redis_rule_key);
|
||||
return -1;
|
||||
@@ -139,8 +150,8 @@ int make_serial_rule(const char *table_name, const char *line, void *u_para)
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id, table_name,
|
||||
buff, absolute_expire_time);
|
||||
maat_set_serial_rule(s_rule + line_idx, MAAT_OP_ADD, s_rule->rule_id,
|
||||
table_name, buff, absolute_expire_time);
|
||||
(s_rule + line_idx)->ref_ctx = ctx;
|
||||
line_idx++;
|
||||
|
||||
@@ -155,12 +166,14 @@ TEST(redis_mode, maat_scan_string) {
|
||||
int redis_port = 6379;
|
||||
int redis_db = 0;
|
||||
|
||||
snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
|
||||
snprintf(json_iris_path, sizeof(json_iris_path),
|
||||
"./%s_iris_tmp", json_filename);
|
||||
|
||||
redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, g_logger);
|
||||
redisContext *c =
|
||||
maat_connect_redis(redis_ip, redis_port, redis_db, g_logger);
|
||||
EXPECT_TRUE(c != NULL);
|
||||
|
||||
redisReply *reply = maat_wrap_redis_command(c, "flushdb");
|
||||
redisReply *reply = maat_wrap_redis_command(c, NULL, "flushdb");
|
||||
EXPECT_TRUE(reply != NULL);
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
@@ -170,20 +183,23 @@ TEST(redis_mode, maat_scan_string) {
|
||||
char *json_buff = NULL;
|
||||
size_t json_buff_sz = 0;
|
||||
|
||||
int ret = load_file_to_memory(json_filename, (unsigned char **)&json_buff, &json_buff_sz);
|
||||
int ret = load_file_to_memory(json_filename,
|
||||
(unsigned char **)&json_buff,
|
||||
&json_buff_sz);
|
||||
EXPECT_NE(ret, -1);
|
||||
|
||||
ret = json2iris(json_buff, json_filename, c, tmp_iris_path, sizeof(tmp_iris_path),
|
||||
NULL, NULL, g_logger);
|
||||
ret = json2iris(json_buff, json_filename, c, tmp_iris_path,
|
||||
sizeof(tmp_iris_path), NULL, NULL, g_logger);
|
||||
FREE(json_buff);
|
||||
EXPECT_NE(ret, -1);
|
||||
}
|
||||
|
||||
size_t total_line_cnt = 0;
|
||||
char tmp_iris_full_idx_path[PATH_MAX] = {0};
|
||||
snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path), "%s/index", json_iris_path);
|
||||
config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, count_line_num_cb, NULL,
|
||||
&total_line_cnt, NULL, g_logger);
|
||||
snprintf(tmp_iris_full_idx_path, sizeof(tmp_iris_full_idx_path),
|
||||
"%s/index", json_iris_path);
|
||||
config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, count_line_num_cb,
|
||||
NULL, &total_line_cnt, NULL, g_logger);
|
||||
|
||||
struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
|
||||
s_rule->ref_ctx = c;
|
||||
@@ -191,12 +207,13 @@ TEST(redis_mode, maat_scan_string) {
|
||||
EXPECT_NE(server_time, -1);
|
||||
|
||||
absolute_expire_time = server_time + 300;
|
||||
config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, make_serial_rule, NULL,
|
||||
s_rule, NULL, g_logger);
|
||||
config_monitor_traverse(0, tmp_iris_full_idx_path, NULL, make_serial_rule,
|
||||
NULL, s_rule, NULL, g_logger);
|
||||
s_rule->ref_ctx = NULL;
|
||||
int success_cnt = 0;
|
||||
do {
|
||||
success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt, server_time, g_logger);
|
||||
success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
|
||||
server_time, g_logger);
|
||||
} while (success_cnt < 0);
|
||||
|
||||
EXPECT_EQ(success_cnt, (int)total_line_cnt);
|
||||
@@ -209,12 +226,14 @@ TEST(redis_mode, maat_scan_string) {
|
||||
|
||||
struct maat_options *opts = maat_options_new();
|
||||
maat_options_set_redis(opts, redis_ip, redis_port, redis_db);
|
||||
maat_options_set_logger(opts, "./maat_input_mode_gtest.log", LOG_LEVEL_INFO);
|
||||
maat_options_set_logger(opts, "./maat_input_mode_gtest.log",
|
||||
LOG_LEVEL_INFO);
|
||||
|
||||
struct maat *maat_inst = maat_new(opts, table_info_path);
|
||||
const char *table_name = "KEYWORDS_TABLE";
|
||||
int table_id = maat_get_table_id(maat_inst, table_name);
|
||||
char scan_data[128] = "string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
char scan_data[128] =
|
||||
"string1, string2, string3, string4, string5, string6, string7, string8";
|
||||
long long results[5] = {0};
|
||||
size_t n_hit_result = 0;
|
||||
int thread_id = 0;
|
||||
@@ -238,7 +257,8 @@ int main(int argc, char ** argv)
|
||||
g_logger = log_handle_create("./maat_input_mode_gtest.log", 0);
|
||||
|
||||
char json_iris_path[NAME_MAX] = {0};
|
||||
snprintf(json_iris_path, sizeof(json_iris_path), "./%s_iris_tmp", json_filename);
|
||||
snprintf(json_iris_path, sizeof(json_iris_path),
|
||||
"./%s_iris_tmp", json_filename);
|
||||
if ((access(json_iris_path, F_OK)) == 0) {
|
||||
system_cmd_rmdir(json_iris_path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user