[PATCH]delete useless code
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "maat_rule.h"
|
||||
#include "maat_utils.h"
|
||||
#include "log/log.h"
|
||||
#include "../test_utils.h"
|
||||
#include "maat_config_monitor.h"
|
||||
#include "maat_redis_monitor.h"
|
||||
|
||||
@@ -33,133 +34,6 @@ protected:
|
||||
|
||||
struct log_handle *IPPortPluginTable::logger;
|
||||
|
||||
int count_line_num_cb(const char *table_name, const char *line, void *u_para)
|
||||
{
|
||||
(*((unsigned int *)u_para))++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int line_idx = 0;
|
||||
long long absolute_expire_time=0;
|
||||
int make_serial_rule(const char *table_name, const char *line, void *u_para)
|
||||
{
|
||||
struct serial_rule *s_rule=(struct serial_rule *)u_para;
|
||||
redisContext *ctx = s_rule->ref_ctx;
|
||||
char *buff = ALLOC(char, strlen(line) + 1);
|
||||
|
||||
memcpy(buff, line, strlen(line) + 1);
|
||||
while(buff[strlen(line) - 1] == '\n' || buff[strlen(line) - 1] == '\t') {
|
||||
buff[strlen(line) - 1] = '\0';
|
||||
}
|
||||
|
||||
const char *redis_rule_key = "TEST_RULE_KEY";
|
||||
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;
|
||||
} else {
|
||||
s_rule->rule_id = maat_read_redis_integer(reply);
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
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++;
|
||||
|
||||
FREE(buff);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_config_to_redis(char *redis_ip, int redis_port, int redis_db,
|
||||
struct log_handle *logger)
|
||||
{
|
||||
redisContext *c =
|
||||
maat_connect_redis(redis_ip, redis_port, redis_db, logger);
|
||||
if (NULL == c) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
redisReply *reply = maat_wrap_redis_command(c, logger, "flushdb");
|
||||
if (NULL == reply) {
|
||||
return -1;
|
||||
} else {
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
reply = maat_wrap_redis_command(c, logger, "SET MAAT_VERSION 1");
|
||||
if (NULL == reply) {
|
||||
return -1;
|
||||
} else {
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
reply = maat_wrap_redis_command(c, logger, "SET MAAT_PRE_VER 1");
|
||||
if (NULL == reply) {
|
||||
return -1;
|
||||
} else {
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
reply = maat_wrap_redis_command(c, logger, "SET SEQUENCE_REGION 1");
|
||||
if (NULL == reply) {
|
||||
return -1;
|
||||
} else {
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
reply = maat_wrap_redis_command(c, logger, "SET SEQUENCE_GROUP 1");
|
||||
if (NULL == reply) {
|
||||
return -1;
|
||||
} else {
|
||||
freeReplyObject(reply);
|
||||
reply = NULL;
|
||||
}
|
||||
|
||||
size_t total_line_cnt = 0;
|
||||
char iris_idx_path[PATH_MAX] = {0};
|
||||
snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index");
|
||||
config_monitor_traverse(0, iris_idx_path, NULL, count_line_num_cb, NULL,
|
||||
&total_line_cnt, NULL, logger);
|
||||
|
||||
struct serial_rule *s_rule = ALLOC(struct serial_rule, total_line_cnt);
|
||||
s_rule->ref_ctx = c;
|
||||
long long server_time = maat_redis_server_time_s(c);
|
||||
if (server_time < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
absolute_expire_time = server_time + 300;
|
||||
config_monitor_traverse(0, iris_idx_path, NULL, make_serial_rule, NULL,
|
||||
s_rule, NULL, logger);
|
||||
s_rule->ref_ctx = NULL;
|
||||
line_idx = 0;
|
||||
absolute_expire_time = 0;
|
||||
|
||||
int success_cnt = 0;
|
||||
do {
|
||||
success_cnt = maat_cmd_write_rule(c, s_rule, total_line_cnt,
|
||||
server_time, logger);
|
||||
} while (success_cnt < 0);
|
||||
|
||||
EXPECT_EQ(success_cnt, (int)total_line_cnt);
|
||||
|
||||
for (size_t i = 0; i < total_line_cnt; i++) {
|
||||
maat_clear_rule_cache(s_rule + i);
|
||||
}
|
||||
FREE(s_rule);
|
||||
redisFree(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ipport_plugin_ud {
|
||||
long long rule_id;
|
||||
char *buffer;
|
||||
@@ -365,9 +239,13 @@ TEST_F(IPPortPluginTable, WITHOUT_SAME_IP) {
|
||||
char redis_ip[32] = "127.0.0.1";
|
||||
int redis_port = 6379;
|
||||
int redis_db = 0;
|
||||
char iris_idx_path[PATH_MAX] = {0};
|
||||
struct log_handle *logger = IPPortPluginTable::logger;
|
||||
|
||||
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
|
||||
snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index");
|
||||
|
||||
int ret = write_iris_to_redis(iris_idx_path, redis_ip, redis_port,
|
||||
redis_db, logger);
|
||||
assert(ret == 0);
|
||||
|
||||
struct maat_options *opts = maat_options_new();
|
||||
@@ -434,9 +312,13 @@ TEST_F(IPPortPluginTable, WITH_256SAME_IP) {
|
||||
char redis_ip[32] = "127.0.0.1";
|
||||
int redis_port = 6379;
|
||||
int redis_db = 0;
|
||||
char iris_idx_path[PATH_MAX] = {0};
|
||||
struct log_handle *logger = IPPortPluginTable::logger;
|
||||
|
||||
int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger);
|
||||
snprintf(iris_idx_path, sizeof(iris_idx_path), "test_data/index");
|
||||
|
||||
int ret = write_iris_to_redis(iris_idx_path, redis_ip, redis_port,
|
||||
redis_db, logger);
|
||||
assert(ret == 0);
|
||||
|
||||
struct maat_options *opts = maat_options_new();
|
||||
|
||||
Reference in New Issue
Block a user