增加set_line、timeout、incrby、select的测试用例,自测通过。
This commit is contained in:
@@ -28,12 +28,20 @@ void Maat_read_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
char ip_str[16]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
unsigned int ip_uint=0;
|
||||
int is_valid=0;
|
||||
unsigned int local_ip_nr=16820416;//192.168.0.1
|
||||
sscanf(table_line,"%d\t%s\t%d",&seq,ip_str,&entry_id);
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,ip_str,&entry_id,&is_valid);
|
||||
inet_pton(AF_INET,ip_str,&ip_uint);
|
||||
if(local_ip_nr==ip_uint)
|
||||
{
|
||||
printf("Load entry id %d SUCCESS.\n",entry_id);
|
||||
if(is_valid==1)
|
||||
{
|
||||
printf("Load entry id %d success.\n",entry_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Offload entry id %d success.\n",entry_id);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -459,28 +467,43 @@ int test_table_conjunction(Maat_feather_t feather,const char* table_name,const c
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int test_command(Maat_feather_t feather)
|
||||
void test_set_cmd_line(Maat_feather_t feather)
|
||||
{
|
||||
struct Maat_line_t line_rule;
|
||||
int ret=0;
|
||||
memset(&line_rule,0,sizeof(line_rule));
|
||||
line_rule.label_id=0;
|
||||
line_rule.rule_id=(int)Maat_cmd_incrby(feather,"TEST_PLUG_SEQ", 1);
|
||||
line_rule.table_name="QD_ENTRY_INFO";
|
||||
line_rule.table_line="1\t192.168.0.1\t101\t1";
|
||||
line_rule.expire_after=0;
|
||||
ret=Maat_cmd_set_line(feather, &line_rule, MAAT_OP_ADD);
|
||||
assert(ret==0);
|
||||
sleep(1);
|
||||
ret=Maat_cmd_set_line(feather, &line_rule, MAAT_OP_DEL);
|
||||
assert(ret==0);
|
||||
return;
|
||||
}
|
||||
int test_add_command(Maat_feather_t feather,const char* region_table,int config_id, int timeout,int label_id, const char* keywords)
|
||||
{
|
||||
const char* scan_data="Hiredis is a minimalistic C client library for the Redis database.\r\n";
|
||||
const char* table_name="HTTP_URL";
|
||||
int table_id;
|
||||
scan_status_t mid=NULL;
|
||||
|
||||
struct Maat_cmd_t* cmd=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
struct Maat_rule_t result;
|
||||
|
||||
struct Maat_region_t region;
|
||||
int group_num=1,ret=0;
|
||||
memset(&rule,0,sizeof(rule));
|
||||
rule.config_id=201;
|
||||
rule.config_id=config_id;
|
||||
|
||||
strcpy(rule.service_defined,"maat_command");
|
||||
//MUST acqire by function, because Maat_cmd_t has some hidden members.
|
||||
cmd=Maat_create_cmd(&rule, group_num);
|
||||
cmd->expire_after=timeout;
|
||||
cmd->label_id=label_id;
|
||||
memset(®ion,0,sizeof(region));
|
||||
region.region_type=REGION_EXPR;
|
||||
region.table_name=table_name;
|
||||
region.table_name=region_table;
|
||||
region.expr_rule.district=NULL;
|
||||
region.expr_rule.keywords="Hiredis&C\\bClient";
|
||||
region.expr_rule.keywords=keywords;
|
||||
region.expr_rule.expr_type=EXPR_TYPE_AND;
|
||||
region.expr_rule.match_method=MATCH_METHOD_SUB;
|
||||
region.expr_rule.hex_bin=UNCASE_PLAIN;
|
||||
@@ -493,41 +516,71 @@ int test_command(Maat_feather_t feather)
|
||||
Maat_free_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
//cmd has been saved in feather, so free before commit is allowed.
|
||||
//cmd has been saved in feather, so free cmd before commit is allowed.
|
||||
Maat_free_cmd(cmd);
|
||||
ret=Maat_cmd_commit(feather);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Commit Maat command %d failed.\n",rule.config_id);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
int test_del_command(Maat_feather_t feather,int config_id)
|
||||
{
|
||||
struct Maat_cmd_t* cmd=NULL;
|
||||
struct Maat_rule_t rule;
|
||||
int ret=0;
|
||||
memset(&rule,0,sizeof(rule));
|
||||
rule.config_id=config_id;
|
||||
cmd=Maat_create_cmd(&rule, 0);
|
||||
ret=Maat_cmd(feather, cmd, MAAT_OP_DEL);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Delete Maat command %d failed.\n",rule.config_id);
|
||||
}
|
||||
Maat_free_cmd(cmd);
|
||||
return 0;
|
||||
}
|
||||
void test_command(Maat_feather_t feather)
|
||||
{
|
||||
const char* scan_data="Hiredis is a minimalistic C client library for the Redis database.\r\n";
|
||||
const char* table_name="HTTP_URL";
|
||||
const char* keywords="Hiredis&C\\bClient";
|
||||
scan_status_t mid=NULL;
|
||||
int config_id=-1, table_id=0, ret=0;
|
||||
int output_ids[4];
|
||||
int output_id_cnt=0;
|
||||
struct Maat_rule_t result;
|
||||
int timeout=0;//seconds
|
||||
int label_id=5210;
|
||||
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
|
||||
test_add_command(feather,table_name,config_id, 0, label_id, keywords);
|
||||
sleep(1);//waiting for commands go into effect
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
&mid, 0);
|
||||
|
||||
if(ret>0&&result.config_id==rule.config_id)
|
||||
if(ret>0&&result.config_id==config_id)
|
||||
{
|
||||
printf("Test Maat add command Success %s\n",print_maat_result(&result,ret));
|
||||
printf("Test Maat add command success %s\n",print_maat_result(&result,ret));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test Maat add command failed.\n");
|
||||
}
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
memset(&rule,0,sizeof(rule));
|
||||
rule.config_id=201;
|
||||
cmd=Maat_create_cmd(&rule, 0);
|
||||
ret=Maat_cmd(feather, cmd, MAAT_OP_DEL);
|
||||
if(ret<0)
|
||||
output_id_cnt=Maat_cmd_select(feather,label_id, output_ids, 4);
|
||||
if(output_id_cnt==1&&output_ids[0]==config_id)
|
||||
{
|
||||
printf("Delete Maat command %d failed.\n",rule.config_id);
|
||||
Maat_free_cmd(cmd);
|
||||
return 0;
|
||||
printf("Test Maat select command success.\n");
|
||||
}
|
||||
Maat_free_cmd(cmd);
|
||||
else
|
||||
{
|
||||
printf("Test Maat select command label %d failed.\n",label_id);
|
||||
}
|
||||
test_del_command(feather, config_id);
|
||||
sleep(1);//waiting for commands go into effect
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
@@ -538,11 +591,24 @@ int test_command(Maat_feather_t feather)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test Maat delete command Success.\n");
|
||||
printf("Test Maat delete command success.\n");
|
||||
}
|
||||
Maat_clean_status(&mid);
|
||||
return 0;
|
||||
timeout=1;
|
||||
test_add_command(feather,table_name,config_id, timeout, label_id, keywords);
|
||||
sleep(timeout+1);
|
||||
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
|
||||
&result,NULL, 1,
|
||||
&mid, 0);
|
||||
|
||||
if(ret>0&&result.config_id==config_id)//should not hit
|
||||
{
|
||||
printf("Test Maat command timeout failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test Maat command timeout success.\n");
|
||||
}
|
||||
}
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
@@ -634,6 +700,7 @@ int main(int argc,char* argv[])
|
||||
if(1==using_redis)
|
||||
{
|
||||
test_command(feather);
|
||||
test_set_cmd_line(feather);
|
||||
}
|
||||
sleep(wait_second);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user