完成外键内容的单元测试。

This commit is contained in:
zhengchao
2018-09-25 17:56:09 +08:00
parent 4bb67bf7fa
commit ad24e175dc
9 changed files with 277 additions and 50 deletions

View File

@@ -156,6 +156,8 @@ int Maat_cmd_set_group(Maat_feather_t feather, int group_id, const struct Maat_r
//Return -1 for failed.
int Maat_cmd_set_line(Maat_feather_t feather,const struct Maat_line_t* line_rule, enum MAAT_OPERATION op);
int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_rule, int line_num ,enum MAAT_OPERATION op);
int Maat_cmd_set_file(Maat_feather_t feather,const char* key, const char* value, size_t size, enum MAAT_OPERATION op);
//Return the value of key after the increment.
//If the key does not exist, it is set to 0 before performing the operation.
long long Maat_cmd_incrby(Maat_feather_t feather,const char* key, int increment);

View File

@@ -6,7 +6,7 @@
* to reside in the heart) of the departed would reach the paradise of afterlife
* successfully.
* Author: zhengchao@iie.ac.cn,MESA
* Version 2018-09-21 rule tags
* Version 2018-09-25 foreign key and rule tags.
* NOTE: MUST compile with G++
* All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018
*********************************************************

View File

@@ -677,10 +677,11 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
}
break;
case MAAT_OPT_FOREIGN_CONT_DIR:
memset(_feather->foreign_cont_dir, 0, sizeof(_feather->foreign_cont_dir));
strncpy(_feather->foreign_cont_dir, (char*)value, sizeof(_feather->foreign_cont_dir));
if(_feather->foreign_cont_dir[size-1]=='/')
if(_feather->foreign_cont_dir[strlen(_feather->foreign_cont_dir)-1]=='/')
{
_feather->foreign_cont_dir[size-1]='\0';
_feather->foreign_cont_dir[strlen(_feather->foreign_cont_dir)-1]='\0';
}
break;
case MAAT_OPT_FOREIGN_CONT_LINGER:

View File

@@ -23,6 +23,8 @@ const char* rm_expire_lock="EXPIRE_OP_LOCK";
const long rm_expire_lock_timeout=300*1000;
const static int MAAT_REDIS_SYNC_TIME=30*60;
const char* rm_op_str[]={"DEL","ADD","RENEW_TIMEOUT"};
const char* foreign_source_prefix="redis://";
const char* foreign_key_prefix="__FILE_";
struct _Maat_cmd_inner_t
@@ -1386,17 +1388,18 @@ const char* find_Nth_column(const char* line, int Nth, int* column_len)
int start=0, end=0;
for(i=0;i<(int)strlen(line);i++)
{
if(line[i]==' '||line[i]=='\t')
if(line[i]!=' '&&line[i]!='\t')
{
j++;
continue;
}
j++;
if(j==Nth-1)
{
start=i+1;
}
if(j==Nth)
{
end=i+1;
end=i;
break;
}
}
@@ -1415,7 +1418,7 @@ char* get_foreign_cont_filename(const char* table_name, int rule_id, const char*
{
char* filename=NULL;
char buffer[512];
snprintf(buffer, sizeof(buffer),"%s/%s/%d%s",dir, table_name, rule_id, foreign_key);
snprintf(buffer, sizeof(buffer),"%s/%s-%d-%s",dir, table_name, rule_id, foreign_key);
filename=(char*)calloc(sizeof(char), strlen(buffer)+1);
memcpy(filename, buffer, strlen(buffer));
return filename;
@@ -1442,13 +1445,12 @@ void rewrite_table_line_with_foreign(struct serial_rule_t*p)
origin_column=find_Nth_column(p->table_line, p->f_keys[i].column, &origin_column_size);
strncat(pos_rewrite_line, pos_origin_line, origin_column-pos_origin_line);
pos_rewrite_line+=origin_column-pos_origin_line;
pos_origin_line+=origin_column_size;
pos_origin_line=origin_column+origin_column_size;
strncat(pos_rewrite_line, p->f_keys[i].filename, strlen(p->f_keys[i].filename));
pos_rewrite_line+=strlen(p->f_keys[i].filename);
}
strncat(pos_rewrite_line, pos_origin_line, strlen(p->table_line)-(pos_origin_line-p->table_line));
pos_rewrite_line+=strlen(p->f_keys[i].filename);
free(p->table_line);
p->table_line=rewrite_line;
@@ -1457,11 +1459,9 @@ void rewrite_table_line_with_foreign(struct serial_rule_t*p)
int get_foreign_keys(redisContext *ctx, struct serial_rule_t* rule_list, int rule_num, _Maat_feather_t* feather, const char* dir,void *logger)
{
int ret=0, table_id=0, i=0, j=0;
int foregin_key_size=0;
int foreign_key_size=0;
int rule_with_foreign_key=0;
const char* foreign_source_prefix="redis://";
const char* foreign_key_prefix="__FILE_";
const char* p_foregin=NULL;
const char* p_foreign=NULL;
struct _Maat_table_info_t* p_table=NULL;
struct stat file_info;
for(i=0; i<rule_num; i++)
@@ -1484,34 +1484,34 @@ int get_foreign_keys(redisContext *ctx, struct serial_rule_t* rule_list, int rul
rule_list[i].f_keys=(struct foreign_key*)calloc(sizeof(struct foreign_key), rule_list[i].n_foreign);
for(j=0;j<p_table->n_foreign;j++)
{
p_foregin=find_Nth_column(rule_list[i].table_line, p_table->foreign_columns[j], &foregin_key_size);
if(p_foregin==NULL)
p_foreign=find_Nth_column(rule_list[i].table_line, p_table->foreign_columns[j], &foreign_key_size);
if(p_foreign==NULL)
{
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_redis_monitor
, "Get %s,%d foreign keys failed: No %dth column."
, rule_list[i].table_name, rule_list[i].rule_id, p_table->foreign_columns[j]);
continue;
}
if(0!=strncasecmp(p_foregin, foreign_source_prefix, strlen(foreign_source_prefix)))
if(0!=strncmp(p_foreign, foreign_source_prefix, strlen(foreign_source_prefix)))
{
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_redis_monitor
,"Get %s,%d foreign key failed: Invalid source prefix %s."
, rule_list[i].table_name, rule_list[i].rule_id, p_foregin);
, rule_list[i].table_name, rule_list[i].rule_id, p_foreign);
continue;
}
rule_list[i].f_keys[j].column=p_table->foreign_columns[j];
foregin_key_size=foregin_key_size+1-strlen(foreign_source_prefix);
p_foregin+=strlen(foreign_source_prefix);
if(0!=strncasecmp(p_foregin, foreign_key_prefix, strlen(foreign_key_prefix)))
foreign_key_size=foreign_key_size-strlen(foreign_source_prefix);
p_foreign+=strlen(foreign_source_prefix);
if(0!=strncmp(p_foreign, foreign_key_prefix, strlen(foreign_key_prefix)))
{
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_redis_monitor
,"%s,%d foreign key prefix %s is discouraged."
, rule_list[i].table_name, rule_list[i].rule_id, p_foregin);
, rule_list[i].table_name, rule_list[i].rule_id, p_foreign);
}
rule_list[i].f_keys[j].key=(char*)calloc(sizeof(char),foregin_key_size);
memcpy(rule_list[i].f_keys[j].key, p_foregin, foregin_key_size);
rule_list[i].f_keys[j].key=(char*)calloc(sizeof(char),foreign_key_size+1);
memcpy(rule_list[i].f_keys[j].key, p_foreign, foreign_key_size);
rule_list[i].f_keys[j].filename=get_foreign_cont_filename(rule_list[i].table_name, rule_list[i].rule_id, p_foregin, dir);
rule_list[i].f_keys[j].filename=get_foreign_cont_filename(rule_list[i].table_name, rule_list[i].rule_id, rule_list[i].f_keys[j].key, dir);
ret=stat(rule_list[i].f_keys[j].filename, &file_info);
if(ret==0)
{
@@ -1867,11 +1867,14 @@ int Maat_cmd_set_group(Maat_feather_t feather,int group_id, const struct Maat_re
return 0;
}
int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_rule, int line_num ,enum MAAT_OPERATION op)
{
{
int i=0, j=0;
_Maat_feather_t* _feather=(_Maat_feather_t*)feather;
int ret=0, table_id=0,success_cnt=0;
struct serial_rule_t *s_rule=NULL;
struct _Maat_table_info_t* p_table=NULL;
long long server_time=0,absolute_expire_time=0;
const char* p_foreign=NULL;
int foreign_key_size=0;
if(_feather->redis_write_ctx==NULL)
{
@@ -1894,7 +1897,8 @@ int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_ru
, line_rule[i]->table_name);
ret=-1;
goto error_out;
}
}
p_table=_feather->p_table_info[table_id];
if(TABLE_TYPE_PLUGIN!=p_table->table_type)
{
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_command
@@ -1906,14 +1910,14 @@ int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_ru
}
if(op==MAAT_OP_ADD)
{
ret=get_valid_flag_offset(line_rule[i]->table_line
, _feather->p_table_info[table_id]->table_type
ret=get_valid_flag_offset(line_rule[i]->table_line
, p_table->table_type
, p_table->valid_flag_column);
if(ret<0||
(op==MAAT_OP_ADD&&line_rule[i]->table_line[ret]!='1'))
{
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_command
,"Command set line id %d failed: illegal valid flag."
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_command
,"Command set line %s %d failed: illegal valid flag."
, line_rule[i]->table_name, line_rule[i]->rule_id);
ret=-1;
goto error_out;
@@ -1926,6 +1930,31 @@ int Maat_cmd_set_lines(Maat_feather_t feather,const struct Maat_line_t** line_ru
if(line_rule[i]->expire_after>0)
{
absolute_expire_time=server_time+line_rule[i]->expire_after;
}
if(p_table->n_foreign>0)
{
for(j=0;j<p_table->n_foreign;j++)
{
p_foreign=find_Nth_column(line_rule[i]->table_line, p_table->foreign_columns[j], &foreign_key_size);
if(p_foreign==NULL)
{
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL, maat_command
, "Command set line %s %d failed: No %dth column."
, line_rule[i]->table_name, line_rule[i]->rule_id
, p_table->foreign_columns[j]);
ret=-1;
goto error_out;
}
if(0!=strncmp(p_foreign, foreign_source_prefix, strlen(foreign_source_prefix)))
{
MESA_handle_runtime_log(_feather->logger,RLOG_LV_FATAL,maat_redis_monitor
,"Command set line %s %d failed: Source prefix %s is mandatory."
, line_rule[i]->table_name, line_rule[i]->rule_id, foreign_source_prefix);
ret=-1;
goto error_out;
}
}
}
set_serial_rule(s_rule+i, op,line_rule[i]->rule_id,line_rule[i]->label_id,line_rule[i]->table_name,line_rule[i]->table_line, absolute_expire_time);
}
@@ -1948,6 +1977,49 @@ int Maat_cmd_set_line(Maat_feather_t feather,const struct Maat_line_t* line_rule
int ret=0;
ret=Maat_cmd_set_lines(feather,&line_rule, 1, op);
return ret;
}
int Maat_cmd_set_file(Maat_feather_t feather,const char* key, const char* value, size_t size, enum MAAT_OPERATION op)
{
struct _Maat_feather_t* _feather=(struct _Maat_feather_t*)feather;
redisContext* ctx=_feather->redis_write_ctx;
const char *arg_vec[3];
size_t len_vec[3];
arg_vec[0] = "SET";
len_vec[0] = strlen("SET");
arg_vec[1] = key;
len_vec[1] = strlen(key);
arg_vec[2] = value;
len_vec[2] = size;
redisReply *reply=NULL;
if(0!=strncmp(key, foreign_key_prefix, strlen(foreign_key_prefix)))
{
MESA_handle_runtime_log(_feather->logger, RLOG_LV_FATAL, maat_command, "Invalid File key, prefix %s is mandatory.", foreign_key_prefix);
return -1;
}
switch(op)
{
case MAAT_OP_ADD:
reply= (redisReply *)redisCommandArgv(ctx, sizeof(arg_vec) / sizeof(arg_vec[0]), arg_vec, len_vec);
break;
case MAAT_OP_DEL:
reply=_wrap_redisCommand(ctx,"EXPIRE %s %d", key, MAAT_REDIS_SYNC_TIME);
break;
default:
return -1;
break;
}
if(reply==NULL||reply->type==REDIS_REPLY_NIL||reply->type==REDIS_REPLY_ERROR)
{
MESA_handle_runtime_log(_feather->logger, RLOG_LV_FATAL, maat_command,"Set file failed, maybe Redis is busy.");
freeReplyObject(reply);
reply=NULL;
return -1;
}
freeReplyObject(reply);
return 0;
}
void Maat_add_region2cmd(struct Maat_cmd_t* cmd,int which_group,const struct Maat_region_t* region)
{

View File

@@ -32,7 +32,7 @@
#include "stream_fuzzy_hash.h"
#include "gram_index_engine.h"
int MAAT_FRAME_VERSION_2_2_20180921=1;
int MAAT_FRAME_VERSION_2_2_20180925=1;
const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin",
"unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""};
@@ -621,7 +621,7 @@ int read_plugin_table_info(const char* line, struct _Maat_table_info_t* p)
break;
}
}
if(i<2)
if(i<3)
{
goto error_out;
}
@@ -655,7 +655,7 @@ int read_plugin_table_info(const char* line, struct _Maat_table_info_t* p)
tmp=cJSON_GetObjectItem(json, "foreign");
if(tmp!=NULL)
{
_read_integer_arrary(tmp->string, p->foreign_columns, MAX_FOREIGN_CLMN_NUM);
p->n_foreign=_read_integer_arrary(tmp->valuestring, p->foreign_columns, MAX_FOREIGN_CLMN_NUM);
}
cJSON_Delete(json);

View File

@@ -13,4 +13,4 @@ file(COPY testdata DESTINATION ./)
file(COPY testdata_uni2ascii DESTINATION ./)
include(GoogleTest)
#gtest_discover_tests(test_maatframe)
gtest_discover_tests(test_maatframe)

View File

@@ -22,7 +22,7 @@ unsigned short test_maat_redis_port=6379;
const char* json_path="./maat_json.json";
const char* ful_cfg_dir="./rule/full/index/";
const char* inc_cfg_dir="./rule/inc/index/";
#define WAIT_FOR_EFFECTIVE_US 1000*1000
#define WAIT_FOR_EFFECTIVE_US 2*1000*1000
extern int my_scandir(const char *dir, struct dirent ***namelist,
int(*filter)(const struct dirent *),
int(*compar)(const void *, const void *));

View File

@@ -11,7 +11,7 @@
#id name type
#
#For plugin table. The first column's id is 1. 0 as not speicified.
#id name type valid_column tag_column
#id name type column_define
#
#For expr/expr_plus Table
#id name type src_charset dst_charset do_merge cross_cache quick_mode
@@ -28,4 +28,4 @@
9 SIM_URL similar --
10 IMAGE_FP expr UTF8 UTF8 yes 128 quickoff
11 TEST_EFFECTIVE_RANGE_TABLE plugin {"valid":4,"tag":5} --
12 TEST_EXETERN_LINK plugin {"valid":4,"foreign":"6,7","tag":3} --
12 TEST_FOREIGN_KEY plugin {"valid":4,"foreign":"6,8","tag":3} --

View File

@@ -17,6 +17,7 @@
#include <sys/stat.h>//fstat
#include <unistd.h>
#include <dirent.h>
#include <openssl/md5.h>
#include <gtest/gtest.h>
const char* test_maat_redis_ip="127.0.0.1";
@@ -24,14 +25,14 @@ unsigned short test_maat_redis_port=6379;
const char* json_path="./maat_json.json";
const char* ful_cfg_dir="./rule/full/index/";
const char* inc_cfg_dir="./rule/inc/index/";
#define WAIT_FOR_EFFECTIVE_US 1000*1000
#define WAIT_FOR_EFFECTIVE_US 1*1000*1000
extern int my_scandir(const char *dir, struct dirent ***namelist,
int(*filter)(const struct dirent *),
int(*compar)(const void *, const void *));
Maat_feather_t g_feather=NULL;
void *logger=NULL;
void *g_logger=NULL;
int g_iThreadNum=4;
const char* table_info_path="./table_info.conf";
int scan_interval_ms=1;
@@ -103,7 +104,7 @@ TEST(PluginTable, Callback)
Maat_read_entry_cb,
Maat_read_entry_finish_cb,
g_feather,
logger);
g_logger);
}
TEST(StringScan, Full)
@@ -527,7 +528,7 @@ TEST(RuleTags, Compile)
result,NULL, 4,
&mid, 0);
EXPECT_LE(ret, 0);
EXPECT_EQ(ret, -2);
ret=Maat_full_scan_string(g_feather, table_id,CHARSET_GBK, should_hit, strlen(should_hit),
result,NULL, 4,
@@ -660,8 +661,16 @@ protected:
Maat_set_feather_opt(_shared_feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms));
//Set a short intevral for testing.
Maat_set_feather_opt(_shared_feather, MAAT_OPT_EFFECT_INVERVAL_MS,&effective_interval_ms, sizeof(effective_interval_ms));
Maat_initiate_feather(_shared_feather);
const char* foregin_dir="./foreign_files/";
Maat_set_feather_opt(_shared_feather, MAAT_OPT_FOREIGN_CONT_DIR,foregin_dir, strlen(foregin_dir)+1);
int linger_timeout=4;
Maat_set_feather_opt(_shared_feather, MAAT_OPT_FOREIGN_CONT_LINGER,&linger_timeout, sizeof(linger_timeout));
Maat_cmd_flushDB(_shared_feather);
Maat_initiate_feather(_shared_feather);
}
static void TearDownTestCase()
{
@@ -734,7 +743,7 @@ int del_command(Maat_feather_t feather,int config_id)
return 0;
}
TEST_F(MaatCmdTest, Expr)
TEST_F(MaatCmdTest, SetExpr)
{
const char* scan_data="Hiredis is a minimalistic C client library for the Redis database.\r\n";
const char* table_name="HTTP_URL";
@@ -764,8 +773,11 @@ TEST_F(MaatCmdTest, Expr)
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_after, sizeof(version_after));
EXPECT_EQ(ret, 0);
EXPECT_GT(version_after, version_before);
table_id=Maat_table_register(feather,table_name);
ASSERT_GT(table_id, 0);
memset(&result, 0, sizeof(result));
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
&result,NULL, 1,
&mid, 0);
@@ -777,7 +789,7 @@ TEST_F(MaatCmdTest, Expr)
EXPECT_EQ(output_id_cnt, 1);
EXPECT_EQ(output_ids[0], config_id);
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
del_command(feather, config_id);
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
@@ -795,7 +807,7 @@ TEST_F(MaatCmdTest, Expr)
&mid, 0);
EXPECT_EQ(ret, 0);
}
TEST_F(MaatCmdTest, Lines)
TEST_F(MaatCmdTest, SetLines)
{
const int TEST_CMD_LINE_NUM=4;
const struct Maat_line_t *p_line[TEST_CMD_LINE_NUM];
@@ -830,7 +842,7 @@ TEST_F(MaatCmdTest, Lines)
return;
}
TEST_F(MaatCmdTest, IP)
TEST_F(MaatCmdTest, SetIP)
{
struct Maat_cmd_t* cmd=NULL;
struct Maat_rule_t rule;
@@ -961,6 +973,146 @@ TEST_F(MaatCmdTest, PauseUpdate)
}
void prepare_file_to_set(const char* filename, char** file_buff, size_t* file_size, char* file_key, size_t key_size)
{
int ret=0, i=0;
FILE* fp=NULL;
struct stat file_info;
unsigned char md5[MD5_DIGEST_LENGTH];
char md5string[MD5_DIGEST_LENGTH+1];
memset(md5, 0, sizeof(md5));
memset(md5string, 0, sizeof(md5string));
ret=stat(filename, &file_info);
ASSERT_TRUE(ret==0);
fp=fopen(filename,"r");
ASSERT_FALSE(fp==NULL);
*file_size=file_info.st_size;
*file_buff=(char*)malloc(*file_size);
ret=fread(*file_buff,1,*file_size,fp);
fclose(fp);
MD5((const unsigned char *)(*file_buff), (unsigned long)(*file_size), md5);
for(i = 0; i < MD5_DIGEST_LENGTH; ++i)
{
sprintf(&md5string[i*2], "%02x", (unsigned int)md5[i]);
}
snprintf(file_key, key_size, "__FILE_%s", md5string);
return;
}
char* md5_file(const char* filename, char* md5string)
{
FILE* fp=NULL;
int i=0;
unsigned char md5[MD5_DIGEST_LENGTH];
struct stat file_info;
stat(filename, &file_info);
size_t file_size=file_info.st_size;
fp=fopen(filename,"r");
if(fp==NULL)
{
return NULL;
}
char* file_buff=(char*)malloc(file_size);
fread(file_buff,1,file_size,fp);
fclose(fp);
MD5((const unsigned char *)(file_buff), (unsigned long)(file_size), md5);
for(i = 0; i < MD5_DIGEST_LENGTH; ++i)
{
sprintf(&md5string[i*2], "%02x", (unsigned int)md5[i]);
}
free(file_buff);
return md5string;
}
int is_same_file(const char* filename1, const char* filename2)
{
char md5string[2][MD5_DIGEST_LENGTH*2+1];
memset(md5string, 0, sizeof(md5string));
md5_file(filename1, md5string[0]);
md5_file(filename2, md5string[1]);
if(0==strcmp(md5string[0], md5string[1]))
{
return 1;
}
else
{
return 0;
}
}
int g_test_foregin_read_OK=0;
void foreign_key_test_entry_cb(int table_id,const char* table_line,void* u_para)
{
int rule_id=-1, not_care=0, tag=0;
int is_valid=0;
char file1_origin_name[256], file2_origin_name[256];
char file1_localname[256], file2_localname[256];
char end[16];
memset(file1_localname, 0, sizeof(file1_localname));
memset(file2_localname, 0, sizeof(file2_localname));
sscanf(table_line, "%d\t%d\t%d\t%d\t%s\t%s\t\%s\t%s\t%s",&rule_id, &not_care, &tag, &is_valid
, file1_origin_name, file1_localname
, file2_origin_name, file2_localname
, end);
EXPECT_STREQ(end, "End");
EXPECT_TRUE(is_same_file(file1_origin_name, file1_localname));
EXPECT_TRUE(is_same_file(file2_origin_name, file2_localname));
g_test_foregin_read_OK=1;
return;
}
TEST_F(MaatCmdTest, SetFile)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;
int ret=0, table_id=0;
const char* table_name="TEST_FOREIGN_KEY";
table_id=Maat_table_register(feather, table_name);
ASSERT_GT(table_id, 0);
ret=Maat_table_callback_register(feather, table_id,
NULL,
foreign_key_test_entry_cb,
NULL,
NULL);
ASSERT_EQ(ret, 1);
const char* file1_name="./testdata/digest_test.data", *file2_name="./testdata/mesa_logo.jpg";
char* file_buff=NULL, file1_key[256], file2_key[256];
size_t file_size=0;
prepare_file_to_set(file1_name, &file_buff, &file_size, file1_key, sizeof(file1_key));
Maat_cmd_set_file(feather, file1_key, file_buff, file_size, MAAT_OP_ADD);
free(file_buff);
file_buff=NULL;
prepare_file_to_set(file2_name, &file_buff, &file_size, file2_key, sizeof(file2_key));
Maat_cmd_set_file(feather, file2_key, file_buff, file_size, MAAT_OP_ADD);
free(file_buff);
file_buff=NULL;
g_test_foregin_read_OK=0;
char line[1024];
int tag=0;
struct Maat_line_t line_rule;
line_rule.label_id=0;
line_rule.rule_id=(int)Maat_cmd_incrby(feather,"TEST_PLUG_SEQ", 1);
line_rule.table_name=table_name;
snprintf(line, sizeof(line),"%d\t2\t%d\t1\t%s\tredis://%s\t%s\tredis://%s\tEnd",line_rule.rule_id, tag
,file1_name, file1_key
,file2_name, file2_key);
line_rule.table_line=line;
line_rule.expire_after=0;
ret=Maat_cmd_set_line(feather, &line_rule, MAAT_OP_ADD);
EXPECT_EQ(ret, 1);
usleep(WAIT_FOR_EFFECTIVE_US);//wait for callback triggered.
EXPECT_EQ(g_test_foregin_read_OK, 1);
return;
}
int main(int argc, char ** argv)
{
@@ -972,9 +1124,9 @@ int main(int argc, char ** argv)
int scan_detail=0;
::testing::InitGoogleTest(&argc, argv);
logger=MESA_create_runtime_log_handle(log_file,0);
g_logger=MESA_create_runtime_log_handle(log_file,0);
g_feather=Maat_feather(g_iThreadNum, table_info_path, logger);
g_feather=Maat_feather(g_iThreadNum, table_info_path, g_logger);
Maat_set_feather_opt(g_feather,MAAT_OPT_INSTANCE_NAME,"demo", strlen("demo")+1);
Maat_set_feather_opt(g_feather,MAAT_OPT_DECRYPT_KEY,decrypt_key, strlen(decrypt_key)+1);
Maat_set_feather_opt(g_feather, MAAT_OPT_JSON_FILE_PATH, json_path, strlen(json_path)+1);