void test_with_index_dump(MEM_POOL* mem_pool) { system("rm -rf /tmp/binlog"); system("rm -rf /tmp/log"); system("rm -rf /tmp/storage"); db_initialize(mem_pool); //构造数据 uint16 sid = 0; uint32 docid = 0; int32 ret; uint16 field_count = 5; enum field_types types[5] = {HI_TYPE_STRING,HI_TYPE_LONG,HI_TYPE_TINY,HI_TYPE_LONGLONG,HI_TYPE_DOUBLE}; //将第一个段填满 while(sid == 0) { ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); } sid = 0; //建hash索引,然后unload load 验证 ret = db_ensure_index("hello","HI_TYPE_STRING",HI_KEY_ALG_HASH,HI_TYPE_STRING, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); struct low_data_struct* data = (struct low_data_struct*)mem_pool_malloc(mem_pool,sizeof(struct low_data_struct)); get_low_data(data,HI_TYPE_STRING,mem_pool); struct list_head* index_equal_ret = db_index_equal_query("hello",get_time_hint(mem_pool),data,mem_pool); struct segment_query_rowids* node; list_for_each_entry(node,index_equal_ret,rowids_list) { if(node->sid == 0) ASSERT_EQ(node->rowids->rowid_num,10); else if(node->sid == 1) ASSERT_EQ(node->rowids->rowid_num,1); else FAIL(); } ret = db_unload_segment("hello",sid,mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); index_equal_ret = db_index_equal_query("hello",get_time_hint(mem_pool),data,mem_pool); list_for_each_entry(node,index_equal_ret,rowids_list) { ASSERT_EQ(node->rowids->rowid_num,1); ASSERT_EQ(node->sid,1); }
//简单测试 void test_single_dump(MEM_POOL* mem_pool) { system("rm -rf /tmp/binlog"); system("rm -rf /tmp/log"); system("rm -rf /tmp/storage"); db_initialize(mem_pool); //构造数据 uint16 sid = 0; uint32 docid = 0; int32 ret; uint16 field_count = 5; enum field_types types[5] = {HI_TYPE_STRING,HI_TYPE_LONG,HI_TYPE_TINY,HI_TYPE_LONGLONG,HI_TYPE_DOUBLE}; //将第一个段填满 while(sid == 0) { ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); } sid = 0; docid = 10; //验证是否可查询 uint32 i; for(i=0; i<docid; i++) ASSERT_EQ(1,verify_row_data(db_data_query_row("hello",sid,i,mem_pool),field_count,types)); ret = db_unload_segment("hello",sid,mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); //验证是否可查询 for(i=0; i<docid; i++) ASSERT_EQ(0,verify_row_data(db_data_query_row("hello",sid,i,mem_pool),field_count,types)); char segment_file_name[FILENAME_MAX_LENGTH]; memset(segment_file_name,0,sizeof(segment_file_name)); sprintf(segment_file_name,"%s/hello/hello_segment_000000_dump",get_db()->work_space); ret = db_load_segment("hello",sid,segment_file_name,mem_pool); //验证是否可查询 for(i=0; i<docid; i++) ASSERT_EQ(1,verify_row_data(db_data_query_row("hello",sid,i,mem_pool),field_count,types)); db_release(); }
static void * get_row_data_at_cursor(GtkTreeView *tv) { GtkTreePath *path; void *data = NULL; g_return_val_if_fail(tv, NULL); gtk_tree_view_get_cursor(tv, &path, NULL); if (path) { GtkTreeModel *model; GtkTreeIter iter; model = gtk_tree_view_get_model(tv); if (gtk_tree_model_get_iter(model, &iter, path)) { data = get_row_data(model, &iter); } gtk_tree_path_free(path); } return data; }
void index_create_test(MEM_POOL* mem_pool) { system("rm -rf /tmp/binlog"); system("rm -rf /tmp/log"); system("rm -rf /tmp/storage"); int32 ret; db_initialize(mem_pool); //先创建表,再建索引,再插数据 ret = db_ensure_index("hello","HI_TYPE_STRING",HI_KEY_ALG_HASH,HI_TYPE_STRING,mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); uint16 field_count = 3; enum field_types types[5] = {HI_TYPE_STRING,HI_TYPE_LONG,HI_TYPE_TINY,HI_TYPE_LONGLONG,HI_TYPE_DOUBLE}; //构造数据 uint16 sid = 0; uint32 docid = 0; struct low_data_struct* new_data = (struct low_data_struct*)mem_pool_malloc(mem_pool,sizeof(struct low_data_struct)); get_low_data(new_data,HI_TYPE_STRING,mem_pool); ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); struct list_head* index_equal_ret = NULL; index_equal_ret = db_index_equal_query("hello",get_time_hint(mem_pool),new_data,mem_pool); struct segment_query_rowids* node; list_for_each_entry(node,index_equal_ret,rowids_list){ ASSERT_EQ(node->sid,0); ASSERT_EQ(node->rowids->rowid_num,1); ASSERT_EQ(node->rowids->head->rowid_array[0],0); }
static inline struct download * get_source(GtkTreeIter *iter) { return get_row_data(GTK_TREE_MODEL(store_sources), iter); }
static inline struct fileinfo_data * get_fileinfo_data(GtkTreeIter *iter) { return get_row_data(GTK_TREE_MODEL(store_files), iter); }
void data_insert_test(MEM_POOL* mem_pool) { system("rm -rf /tmp/binlog"); system("rm -rf /tmp/log"); system("rm -rf /tmp/storage"); db_initialize(mem_pool); //构造数据 uint16 sid = 0; uint32 docid = 0; int32 ret; uint16 field_count = 3; enum field_types types[5] = {HI_TYPE_STRING,HI_TYPE_LONG,HI_TYPE_TINY,HI_TYPE_LONGLONG,HI_TYPE_DOUBLE}; ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); struct row_data* query_row_ret = NULL; struct low_data_struct* query_col_ret = NULL; query_row_ret = db_data_query_row("hello",sid,docid,mem_pool); ASSERT_EQ(1,verify_row_data(query_row_ret,field_count,types)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_STRING",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_STRING)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONG",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_LONG)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_TINY",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_TINY)); //不同的列数量 field_count = 5; ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); query_row_ret = db_data_query_row("hello",sid,docid,mem_pool); ASSERT_EQ(1,verify_row_data(query_row_ret,field_count,types)); //表名不对 query_row_ret = db_data_query_row("world",sid,docid,mem_pool); ASSERT_EQ(0,verify_row_data(query_row_ret,field_count,types)); //sid不对 query_row_ret = db_data_query_row("hello",sid+1,docid,mem_pool); ASSERT_EQ(0,verify_row_data(query_row_ret,field_count,types)); //docid不对 query_row_ret = db_data_query_row("hello",sid,docid+1,mem_pool); ASSERT_EQ(0,verify_row_data(query_row_ret,field_count,types)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_STRING",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_STRING)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONG",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_LONG)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONGLONG",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_TINY",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_TINY)); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_DOUBLE",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_DOUBLE)); //表名不对 query_col_ret = db_data_query_col("world",sid,"HI_TYPE_DOUBLE",docid,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_DOUBLE)); //sid不对 query_col_ret = db_data_query_col("hello",sid+1,"HI_TYPE_LONGLONG",docid,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); //docid不对 query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONGLONG",docid+1,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); //列名不对 query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LON",docid,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_LONG)); //列名不对 query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONG",docid,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); //换一个表名 field_count = 3; ret = db_insert("world", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); ASSERT_EQ(sid,0); ASSERT_EQ(docid,0); query_row_ret = db_data_query_row("world",sid,docid,mem_pool); ASSERT_EQ(1,verify_row_data(query_row_ret,field_count,types)); query_col_ret = db_data_query_col("world",sid,"HI_TYPE_STRING",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_STRING)); query_col_ret = db_data_query_col("world",sid,"HI_TYPE_LONG",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_LONG)); query_col_ret = db_data_query_col("world",sid,"HI_TYPE_TINY",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_TINY)); db_release(); }
void data_update_test(MEM_POOL* mem_pool) { system("rm -rf /tmp/binlog"); system("rm -rf /tmp/log"); system("rm -rf /tmp/storage"); db_initialize(mem_pool); uint16 field_count = 3; enum field_types types[5] = {HI_TYPE_STRING,HI_TYPE_LONG,HI_TYPE_TINY,HI_TYPE_LONGLONG,HI_TYPE_DOUBLE}; //构造数据 uint16 sid = 0; uint32 docid = 0; int32 ret; ret = db_insert("hello", &sid, &docid,get_row_data(field_count,types,mem_pool), DOCID_BY_SELF, mem_pool); struct low_data_struct* new_data = (struct low_data_struct*)mem_pool_malloc(mem_pool,sizeof(struct low_data_struct)); get_low_data(new_data,HI_TYPE_STRING,mem_pool); struct low_data_struct* old_data = NULL; memset(new_data->field_name,0,20); strcpy(new_data->field_name,"HI_TYPE_LONG"); //更新已有的列 ret = db_update("hello",sid,docid,new_data,&old_data,mem_pool); ASSERT_EQ(MILE_RETURN_SUCCESS,ret); ASSERT_EQ(1,verify_low_data(old_data,HI_TYPE_LONG)); //查询一列 struct low_data_struct* query_col_ret = NULL; query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONG",docid,mem_pool); ASSERT_STREQ(query_col_ret->field_name,"HI_TYPE_LONG"); query_col_ret->field_name = (char*)mem_pool_malloc(mem_pool,20); strcpy(query_col_ret->field_name,"HI_TYPE_STRING"); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_STRING)); //更新不存在的列 query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONGLONG",docid,mem_pool); ASSERT_EQ(0,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); get_low_data(new_data,HI_TYPE_LONGLONG,mem_pool); ret = db_update("hello",sid,docid,new_data,&old_data,mem_pool); query_col_ret = db_data_query_col("hello",sid,"HI_TYPE_LONGLONG",docid,mem_pool); ASSERT_EQ(1,verify_low_data(query_col_ret,HI_TYPE_LONGLONG)); //更新不存在的段 ret = db_update("hello",sid+1,docid,new_data,&old_data,mem_pool); ASSERT_EQ(ERROR_SEGMENT_NOT_INIT,ret); //更新不存在的docid ret = db_update("hello",sid,docid+1,new_data,&old_data,mem_pool); ASSERT_EQ(ERROR_EXCEED_CURRENT,ret); ASSERT_EQ(0,verify_low_data(old_data,HI_TYPE_STRING)); //更新不存在的表名 ret = db_update("world",sid,docid,new_data,&old_data,mem_pool); ASSERT_EQ(ret,ERROR_TABLE_NOT_EXIT); db_release(); }