[FEAT MERGE] patch obkv feature from 42x
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
storage_unittest(test_hfilter_parser table/test_hfilter_parser.cpp)
|
||||
storage_unittest(test_query_response_time mysql/test_query_response_time.cpp)
|
||||
storage_unittest(test_create_executor table/test_create_executor.cpp)
|
||||
storage_unittest(test_table_audit table/test_table_audit.cpp)
|
||||
storage_unittest(test_table_aggregation table/test_table_aggregation.cpp)
|
||||
storage_unittest(test_table_sess_pool table/test_table_sess_pool.cpp)
|
||||
storage_unittest(test_ttl_util table/test_ttl_util.cpp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 OceanBase
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
@ -135,16 +135,22 @@ public:
|
||||
ObArenaAllocator allocator_;
|
||||
MockSchemaService schema_service_;
|
||||
ObSchemaGetterGuard schema_guard_;
|
||||
ObReqTimeGuard req_timeinfo_guard_;
|
||||
ObKvSchemaCacheGuard schema_cache_guard_;
|
||||
ObTableApiSessGuard sess_guard_;
|
||||
ObTableSchema table_schema_;
|
||||
ObColumnSchemaV2 columns_[3];
|
||||
ObDASTableLocMeta loc_meta_;
|
||||
private:
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(TestCreateExecutor);
|
||||
};
|
||||
|
||||
TestCreateExecutor::TestCreateExecutor()
|
||||
: allocator_()
|
||||
: allocator_(),
|
||||
loc_meta_(allocator_)
|
||||
{
|
||||
loc_meta_.route_policy_ = ObRoutePolicyType::POLICY_TYPE_MAX;
|
||||
}
|
||||
|
||||
void TestCreateExecutor::SetUp()
|
||||
@ -158,8 +164,18 @@ void TestCreateExecutor::SetUp()
|
||||
ObTenantBase tbase(1);
|
||||
static ObDataAccessService instance;
|
||||
tbase.inner_set(&instance);
|
||||
// init plan cache
|
||||
static ObPlanCache plan_cache;
|
||||
plan_cache.init(OB_PLAN_CACHE_BUCKET_NUMBER, 1);
|
||||
plan_cache.set_mem_limit_pct(20);
|
||||
plan_cache.set_mem_high_pct(90);
|
||||
plan_cache.set_mem_low_pct(50);
|
||||
// register cache obj
|
||||
ObLibCacheRegister::register_cache_objs();
|
||||
tbase.inner_set(&plan_cache);
|
||||
ASSERT_EQ(OB_SUCCESS, tbase.init());
|
||||
ObTenantEnv::set_tenant(&tbase);
|
||||
ASSERT_EQ(OB_SUCCESS, schema_cache_guard_.init(1, table_schema_.get_table_id(), table_schema_.get_schema_version(), schema_guard_));
|
||||
}
|
||||
|
||||
void TestCreateExecutor::TearDown()
|
||||
@ -167,23 +183,31 @@ void TestCreateExecutor::TearDown()
|
||||
MTL_CTX()=nullptr;
|
||||
}
|
||||
|
||||
|
||||
ObTableApiSessNodeVal g_sess_node_val(NULL, 500);
|
||||
void TestCreateExecutor::fake_ctx_init_common(ObTableCtx &fake_ctx, ObTableSchema *table_schema)
|
||||
{
|
||||
fake_ctx.schema_guard_ = &schema_guard_;
|
||||
fake_ctx.table_schema_ = table_schema;
|
||||
fake_ctx.schema_cache_guard_ = &schema_cache_guard_;
|
||||
fake_ctx.tenant_id_ = table_schema->get_tenant_id();
|
||||
fake_ctx.database_id_ = table_schema->get_database_id();
|
||||
fake_ctx.table_name_ = table_schema->get_table_name();
|
||||
fake_ctx.ref_table_id_ = table_schema->get_table_id();
|
||||
fake_ctx.index_table_id_ = fake_ctx.ref_table_id_;
|
||||
fake_ctx.index_tablet_id_ = table_schema->get_table_id();
|
||||
fake_ctx.sess_guard_.sess_node_val_ = &g_sess_node_val;
|
||||
fake_ctx.sess_guard_ = &sess_guard_;
|
||||
fake_ctx.sess_guard_->sess_node_val_ = &g_sess_node_val;
|
||||
g_sess_node_val.is_inited_ = true;
|
||||
g_sess_node_val.sess_info_.test_init(0, 0, 0, NULL);
|
||||
g_sess_node_val.sess_info_.load_all_sys_vars(schema_guard_);
|
||||
fake_ctx.init_physical_plan_ctx(0, 1);
|
||||
fake_ctx.loc_meta_.route_policy_ = ObRoutePolicyType::READONLY_ZONE_FIRST;
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.construct_column_items());
|
||||
ObTableIndexInfo index_info;
|
||||
index_info.index_schema_ = table_schema;
|
||||
index_info.data_table_id_ = fake_ctx.ref_table_id_;
|
||||
index_info.index_table_id_ = index_info.data_table_id_;
|
||||
index_info.loc_meta_ = &loc_meta_;
|
||||
fake_ctx.table_index_info_.push_back(index_info);
|
||||
}
|
||||
|
||||
TEST_F(TestCreateExecutor, scan)
|
||||
@ -194,10 +218,12 @@ TEST_F(TestCreateExecutor, scan)
|
||||
// init ctx
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
fake_ctx.set_entity(&entity);
|
||||
fake_ctx.operation_type_ = ObTableOperationType::Type::GET;
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_get());
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ASSERT_EQ(columns_[i].get_column_id(), fake_ctx.select_col_ids_.at(i));
|
||||
}
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -226,9 +252,9 @@ TEST_F(TestCreateExecutor, insert)
|
||||
ObTableCtx fake_ctx(allocator_);
|
||||
ObExprFrameInfo fake_expr_info(allocator_);
|
||||
// init ctx
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert());
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -257,10 +283,10 @@ TEST_F(TestCreateExecutor, delete)
|
||||
ObTableCtx fake_ctx(allocator_);
|
||||
ObExprFrameInfo fake_expr_info(allocator_);
|
||||
// init ctx
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_delete());
|
||||
ASSERT_EQ(3, fake_ctx.select_col_ids_.count());
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -307,10 +333,9 @@ TEST_F(TestCreateExecutor, update)
|
||||
entity.set_property(ObString::make_string("C2"), obj);
|
||||
// init ctx
|
||||
fake_ctx.set_entity(&entity);
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_update());
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(4, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -355,9 +380,9 @@ TEST_F(TestCreateExecutor, insertup)
|
||||
entity.set_property(ObString::make_string("C2"), obj);
|
||||
// init ctx
|
||||
fake_ctx.set_entity(&entity);
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert_up(false));
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(4, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -385,9 +410,9 @@ TEST_F(TestCreateExecutor, replace)
|
||||
ObTableCtx fake_ctx(allocator_);
|
||||
ObExprFrameInfo fake_expr_info(allocator_);
|
||||
// init ctx
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_replace());
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
|
||||
@ -424,9 +449,9 @@ TEST_F(TestCreateExecutor, refresh_exprs_frame)
|
||||
obj.set_int(1235);
|
||||
entity.set_property(ObString::make_string("C2"), obj);
|
||||
// init ctx
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert());
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_items_for_cg());
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::alloc_exprs_memory(fake_ctx, fake_expr_info));
|
||||
fake_ctx.set_expr_info(&fake_expr_info);
|
||||
@ -452,35 +477,13 @@ TEST_F(TestCreateExecutor, refresh_exprs_frame)
|
||||
ASSERT_EQ(101, objs[2].get_int());
|
||||
}
|
||||
|
||||
// table context
|
||||
TEST_F(TestCreateExecutor, cons_column_type)
|
||||
{
|
||||
ObColumnSchemaV2 col_schema;
|
||||
// prepare data
|
||||
col_schema.set_data_type(ObVarcharType);
|
||||
col_schema.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
|
||||
ObAccuracy acc(1);
|
||||
col_schema.set_accuracy(acc);
|
||||
uint32_t res_flag = ObRawExprUtils::calc_column_result_flag(col_schema);
|
||||
|
||||
ObTableColumnInfo column_info;
|
||||
ObTableCtx fake_ctx(allocator_);
|
||||
schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_info(col_schema, column_info));
|
||||
ASSERT_EQ(ObVarcharType, column_info.type_.get_type());
|
||||
ASSERT_EQ(res_flag, column_info.type_.get_result_flag());
|
||||
ASSERT_EQ(CS_TYPE_UTF8MB4_GENERAL_CI, column_info.type_.get_collation_type());
|
||||
ASSERT_EQ(CS_LEVEL_IMPLICIT, column_info.type_.get_collation_level());
|
||||
ASSERT_EQ(1, column_info.type_.get_accuracy().get_length());
|
||||
}
|
||||
|
||||
TEST_F(TestCreateExecutor, generate_key_range)
|
||||
{
|
||||
ObTableCtx fake_ctx(allocator_);
|
||||
fake_ctx_init_common(fake_ctx, &table_schema_);
|
||||
// prepare data
|
||||
ObArray<ObNewRange> scan_ranges;
|
||||
ObArray<ObString> scan_ranges_columns;
|
||||
ObObj pk_objs_start[1];
|
||||
pk_objs_start[0].set_int(0);
|
||||
ObObj pk_objs_end[1];
|
||||
@ -491,7 +494,8 @@ TEST_F(TestCreateExecutor, generate_key_range)
|
||||
range.border_flag_.set_inclusive_start();
|
||||
range.border_flag_.set_inclusive_end();
|
||||
scan_ranges.push_back(range);
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.generate_key_range(scan_ranges));
|
||||
scan_ranges_columns.push_back("C1");
|
||||
ASSERT_EQ(OB_SUCCESS, fake_ctx.generate_key_range(scan_ranges_columns, scan_ranges));
|
||||
// primary key range
|
||||
ASSERT_EQ(1, fake_ctx.get_key_ranges().count());
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 OceanBase
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
|
831
unittest/observer/table/test_table_audit.cpp
Normal file
831
unittest/observer/table/test_table_audit.cpp
Normal file
@ -0,0 +1,831 @@
|
||||
/**
|
||||
* Copyright (c) 2024 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public // 获取private成员
|
||||
#define protected public // 获取protect成员
|
||||
#include "share/table/ob_table.h"
|
||||
#include "observer/table/ob_table_filter.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::table;
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::share;
|
||||
using namespace oceanbase::observer;
|
||||
using namespace oceanbase::table::hfilter;
|
||||
using namespace oceanbase::sql::stmt;
|
||||
|
||||
class TestTableAudit: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
TestTableAudit();
|
||||
virtual ~TestTableAudit() {}
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
public:
|
||||
template<typename... Args>
|
||||
void construct_prop_names(const char *col, Args... args);
|
||||
void construct_prop_names(){}
|
||||
template<typename... Args>
|
||||
void construct_select_names(const char *col, Args... args);
|
||||
void construct_select_names(){}
|
||||
template<typename... Args>
|
||||
void construct_range_names(const char *col, Args... args);
|
||||
void construct_range_names(){}
|
||||
private:
|
||||
ObTableEntity entity_;
|
||||
ObTableQuery query_;
|
||||
private:
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(TestTableAudit);
|
||||
};
|
||||
|
||||
TestTableAudit::TestTableAudit()
|
||||
{
|
||||
}
|
||||
|
||||
void TestTableAudit::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void TestTableAudit::TearDown()
|
||||
{
|
||||
entity_.reset();
|
||||
query_.reset();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void TestTableAudit::construct_prop_names(const char *col, Args... args) {
|
||||
entity_.properties_names_.push_back(ObString::make_string(col));
|
||||
construct_prop_names(args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void TestTableAudit::construct_select_names(const char *col, Args... args) {
|
||||
query_.select_columns_.push_back(ObString::make_string(col));
|
||||
construct_select_names(args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void TestTableAudit::construct_range_names(const char *col, Args... args) {
|
||||
query_.scan_range_columns_.push_back(ObString::make_string(col));
|
||||
construct_range_names(args...);
|
||||
}
|
||||
|
||||
// 测试:表名为空
|
||||
TEST_F(TestTableAudit, singleOpStmt1)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_empty_string();
|
||||
ObTableOperation op;
|
||||
op.entity_ = &entity_;
|
||||
op.operation_type_ = ObTableOperationType::INSERT;
|
||||
construct_prop_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "insert (null) \"c1\", \"c2\", \"c3\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:列名为空
|
||||
TEST_F(TestTableAudit, singleOpStmt2)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
ObTableOperation op;
|
||||
op.entity_ = &entity_;
|
||||
op.operation_type_ = ObTableOperationType::INSERT;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "insert test ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:buf为空
|
||||
TEST_F(TestTableAudit, singleOpStmt3)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char *buf = nullptr;
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
ObTableOperation op;
|
||||
op.entity_ = &entity_;
|
||||
op.operation_type_ = ObTableOperationType::INSERT;
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
ASSERT_EQ(0, pos);
|
||||
}
|
||||
|
||||
// 测试:buf长度不足
|
||||
TEST_F(TestTableAudit, singleOpStmt4)
|
||||
{
|
||||
const int64_t buf_len = 1;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
ObTableOperation op;
|
||||
op.entity_ = &entity_;
|
||||
op.operation_type_ = ObTableOperationType::INSERT;
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
ASSERT_EQ(0, pos);
|
||||
|
||||
const int64_t buf_len2 = 10;
|
||||
char buf2[buf_len2] = {0};
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, op.generate_stmt(table_name, buf2, buf_len2, pos));
|
||||
}
|
||||
|
||||
// 测试:操作类型
|
||||
TEST_F(TestTableAudit, singleOpStmt5)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
ObTableOperation op;
|
||||
op.entity_ = &entity_;
|
||||
|
||||
// get
|
||||
op.operation_type_ = ObTableOperationType::GET;
|
||||
construct_prop_names("c1");
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "get test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// insert
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::INSERT;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "insert test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// delete
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::DEL;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "delete test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// update
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::UPDATE;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "update test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// insertOrUpdate
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::INSERT_OR_UPDATE;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "insertOrUpdate test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// replace
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::REPLACE;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "replace test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// increment
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::INCREMENT;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "increment test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// append
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::APPEND;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "append test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// checkAndInsertUp
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::CHECK_AND_INSERT_UP;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "checkAndInsertUp test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// put
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::PUT;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "put test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// unknown
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::TTL;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "unknown test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// unknown
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::SCAN;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "unknown test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// unknown
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::TRIGGER;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "unknown test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
|
||||
// unknown
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
op.operation_type_ = ObTableOperationType::INVALID;
|
||||
ASSERT_EQ(OB_SUCCESS, op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "unknown test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(op.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:表名为空
|
||||
TEST_F(TestTableAudit, queryStmt1)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_empty_string();
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
construct_range_names("c1", "c2", "c3");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
ASSERT_EQ(OB_SUCCESS, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "query (null) \"c1\", \"c2\", \"c3\" range:\"c1\", \"c2\", \"c3\" index:idx";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(query_.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:select column为空
|
||||
TEST_F(TestTableAudit, queryStmt2)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
construct_range_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "query test range:\"c1\", \"c2\", \"c3\" index:idx";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(query_.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:scan column为空
|
||||
TEST_F(TestTableAudit, queryStmt3)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "query test \"c1\", \"c2\", \"c3\" range: index:idx";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(query_.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:scan column为空
|
||||
TEST_F(TestTableAudit, queryStmt4)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "query test \"c1\", \"c2\", \"c3\" range: index:idx";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(query_.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:index name为空
|
||||
TEST_F(TestTableAudit, queryStmt5)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
construct_range_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "query test \"c1\", \"c2\", \"c3\" range:\"c1\", \"c2\", \"c3\" index:(null)";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(query_.get_stmt_length(table_name), pos);
|
||||
}
|
||||
|
||||
// 测试:buf为空
|
||||
TEST_F(TestTableAudit, queryStmt6)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char *buf = nullptr;
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
construct_range_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
ASSERT_EQ(0, pos);
|
||||
}
|
||||
|
||||
// 测试:buf长度不足
|
||||
TEST_F(TestTableAudit, queryStmt7)
|
||||
{
|
||||
const int64_t buf_len = 1;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
query_.index_name_ = ObString::make_string("idx");
|
||||
construct_select_names("c1", "c2", "c3");
|
||||
construct_range_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, query_.generate_stmt(table_name, buf, buf_len, pos));
|
||||
ASSERT_EQ(0, pos);
|
||||
|
||||
const int64_t buf_len2 = 10;
|
||||
char buf2[buf_len2] = {0};
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, query_.generate_stmt(table_name, buf2, buf_len2, pos));
|
||||
|
||||
const int64_t buf_len3 = 30;
|
||||
char buf3[buf_len3] = {0};
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, query_.generate_stmt(table_name, buf3, buf_len3, pos));
|
||||
|
||||
const int64_t buf_len4 = 30;
|
||||
char buf4[buf_len4] = {0};
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, query_.generate_stmt(table_name, buf4, buf_len4, pos));
|
||||
}
|
||||
|
||||
// 测试:get_compare_op_name
|
||||
TEST_F(TestTableAudit, get_compare_op_name)
|
||||
{
|
||||
ASSERT_STRCASEEQ("EQUAL", FilterUtils::get_compare_op_name(CompareOperator::EQUAL));
|
||||
ASSERT_STRCASEEQ("GREATER", FilterUtils::get_compare_op_name(CompareOperator::GREATER));
|
||||
ASSERT_STRCASEEQ("GREATER_OR_EQUAL", FilterUtils::get_compare_op_name(CompareOperator::GREATER_OR_EQUAL));
|
||||
ASSERT_STRCASEEQ("LESS", FilterUtils::get_compare_op_name(CompareOperator::LESS));
|
||||
ASSERT_STRCASEEQ("LESS_OR_EQUAL", FilterUtils::get_compare_op_name(CompareOperator::LESS_OR_EQUAL));
|
||||
ASSERT_STRCASEEQ("NO_OP", FilterUtils::get_compare_op_name(CompareOperator::NO_OP));
|
||||
ASSERT_STRCASEEQ("NOT_EQUAL", FilterUtils::get_compare_op_name(CompareOperator::NOT_EQUAL));
|
||||
ASSERT_STRCASEEQ("IS", FilterUtils::get_compare_op_name(CompareOperator::IS));
|
||||
ASSERT_STRCASEEQ("IS_NOT", FilterUtils::get_compare_op_name(CompareOperator::IS_NOT));
|
||||
}
|
||||
|
||||
// 测试:RowFilter
|
||||
TEST_F(TestTableAudit, RowFilter)
|
||||
{
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
RowFilter filter(CompareOperator::EQUAL, &cmp);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "RowFilter EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:QualifierFilter
|
||||
TEST_F(TestTableAudit, QualifierFilter)
|
||||
{
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
QualifierFilter filter(CompareOperator::EQUAL, &cmp);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "QualifierFilter EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:ValueFilter
|
||||
TEST_F(TestTableAudit, ValueFilter)
|
||||
{
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
ValueFilter filter(CompareOperator::EQUAL, &cmp);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "ValueFilter EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:FilterList
|
||||
TEST_F(TestTableAudit, FilterList)
|
||||
{
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
ValueFilter vfilter1(CompareOperator::EQUAL, &cmp);
|
||||
ValueFilter vfilter2(CompareOperator::GREATER, &cmp);
|
||||
// FilterListAND
|
||||
FilterListAND and_filter(FilterListBase::Operator::MUST_PASS_ALL);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, and_filter.filters_.push_back(&vfilter1));
|
||||
ASSERT_EQ(OB_SUCCESS, and_filter.filters_.push_back(&vfilter2));
|
||||
ASSERT_EQ(OB_SUCCESS, and_filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "FilterListAND AND ValueFilter EQUAL, ValueFilter GREATER";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(and_filter.get_format_filter_string_length(), pos);
|
||||
|
||||
// FilterListOR
|
||||
FilterListOR or_filter(FilterListBase::Operator::MUST_PASS_ALL);
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, or_filter.filters_.push_back(&vfilter1));
|
||||
ASSERT_EQ(OB_SUCCESS, or_filter.filters_.push_back(&vfilter2));
|
||||
ASSERT_EQ(OB_SUCCESS, or_filter.get_format_filter_string(buf, buf_len, pos));
|
||||
result = "FilterListOR AND ValueFilter EQUAL, ValueFilter GREATER";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(or_filter.get_format_filter_string_length(), pos);
|
||||
|
||||
// ObTableFilterListAnd
|
||||
ObTableFilterListAnd tb_and_filter(FilterListBase::Operator::MUST_PASS_ALL);
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, tb_and_filter.filters_.push_back(&vfilter1));
|
||||
ASSERT_EQ(OB_SUCCESS, tb_and_filter.filters_.push_back(&vfilter2));
|
||||
ASSERT_EQ(OB_SUCCESS, tb_and_filter.get_format_filter_string(buf, buf_len, pos));
|
||||
result = "ObTableFilterListAnd AND ValueFilter EQUAL, ValueFilter GREATER";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(tb_and_filter.get_format_filter_string_length(), pos);
|
||||
|
||||
// ObTableFilterListOr
|
||||
ObTableFilterListOr tb_or_filter(FilterListBase::Operator::MUST_PASS_ALL);
|
||||
pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, tb_or_filter.filters_.push_back(&vfilter1));
|
||||
ASSERT_EQ(OB_SUCCESS, tb_or_filter.filters_.push_back(&vfilter2));
|
||||
ASSERT_EQ(OB_SUCCESS, tb_or_filter.get_format_filter_string(buf, buf_len, pos));
|
||||
result = "ObTableFilterListOr AND ValueFilter EQUAL, ValueFilter GREATER";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(tb_or_filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, tb_or_filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, tb_or_filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:SkipFilter
|
||||
TEST_F(TestTableAudit, SkipFilter)
|
||||
{
|
||||
SkipFilter filter(nullptr);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "SkipFilter ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
ValueFilter vfilter(CompareOperator::EQUAL, &cmp);
|
||||
filter.filter_ = &vfilter;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
result = "SkipFilter ValueFilter EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:WhileMatchFilter
|
||||
TEST_F(TestTableAudit, WhileMatchFilter)
|
||||
{
|
||||
WhileMatchFilter filter(nullptr);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "WhileMatchFilter ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
ValueFilter vfilter(CompareOperator::EQUAL, &cmp);
|
||||
filter.filter_ = &vfilter;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
result = "WhileMatchFilter ValueFilter EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:SingleColumnValueFilter
|
||||
TEST_F(TestTableAudit, SingleColumnValueFilter)
|
||||
{
|
||||
ObString family = ObString::make_string("family1");
|
||||
ObString qualifier = ObString::make_string("qualifier1");
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
SingleColumnValueFilter filter(family, qualifier, CompareOperator::EQUAL, &cmp);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "SingleColumnValueFilter family1 qualifier1 EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:PageFilter
|
||||
TEST_F(TestTableAudit, PageFilter)
|
||||
{
|
||||
PageFilter filter(1);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "PageFilter";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:ColumnCountGetFilter
|
||||
TEST_F(TestTableAudit, ColumnCountGetFilter)
|
||||
{
|
||||
ColumnCountGetFilter filter(1);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "ColumnCountGetFilter";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:CheckAndMutateFilter
|
||||
TEST_F(TestTableAudit, CheckAndMutateFilter)
|
||||
{
|
||||
ObString family = ObString::make_string("family1");
|
||||
ObString qualifier = ObString::make_string("qualifier1");
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
CheckAndMutateFilter filter(family, qualifier, CompareOperator::EQUAL, &cmp, false);
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "CheckAndMutateFilter family1 qualifier1 EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试:ObTableCompareFilter
|
||||
TEST_F(TestTableAudit, ObTableCompareFilter)
|
||||
{
|
||||
Comparable cmp(ObString::make_string("hello"));
|
||||
ObTableCompareFilter filter(CompareOperator::EQUAL, &cmp);
|
||||
ObTableComparator comparator(ObString::make_string("c1"), ObString::make_string("hello"));
|
||||
filter.comparator_ = &comparator;
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, filter.get_format_filter_string(buf, buf_len, pos));
|
||||
const char *result = "ObTableCompareFilter c1 EQUAL";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(filter.get_format_filter_string_length(), pos);
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, filter.get_format_filter_string(nullptr, buf_len, pos));
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, filter.get_format_filter_string(buf, 0, pos));
|
||||
}
|
||||
|
||||
// 测试: ObTableAuditUtils
|
||||
TEST_F(TestTableAudit, ObTableAuditUtils)
|
||||
{
|
||||
ASSERT_EQ(StmtType::T_KV_GET, ObTableAuditUtils::get_stmt_type(ObTableOperationType::GET));
|
||||
ASSERT_EQ(StmtType::T_KV_INSERT, ObTableAuditUtils::get_stmt_type(ObTableOperationType::INSERT));
|
||||
ASSERT_EQ(StmtType::T_KV_DELETE, ObTableAuditUtils::get_stmt_type(ObTableOperationType::DEL));
|
||||
ASSERT_EQ(StmtType::T_KV_UPDATE, ObTableAuditUtils::get_stmt_type(ObTableOperationType::UPDATE));
|
||||
ASSERT_EQ(StmtType::T_KV_INSERT_OR_UPDATE, ObTableAuditUtils::get_stmt_type(ObTableOperationType::INSERT_OR_UPDATE));
|
||||
ASSERT_EQ(StmtType::T_KV_REPLACE, ObTableAuditUtils::get_stmt_type(ObTableOperationType::REPLACE));
|
||||
ASSERT_EQ(StmtType::T_KV_INCREMENT, ObTableAuditUtils::get_stmt_type(ObTableOperationType::INCREMENT));
|
||||
ASSERT_EQ(StmtType::T_KV_APPEND, ObTableAuditUtils::get_stmt_type(ObTableOperationType::APPEND));
|
||||
ASSERT_EQ(StmtType::T_KV_PUT, ObTableAuditUtils::get_stmt_type(ObTableOperationType::PUT));
|
||||
ASSERT_EQ(StmtType::T_MAX, ObTableAuditUtils::get_stmt_type((ObTableOperationType::Type)-1)); // Test for invalid input
|
||||
}
|
||||
|
||||
// 测试: ObTableAuditMultiOp
|
||||
TEST_F(TestTableAudit, ObTableAuditMultiOp)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObTableOperationType::Type op_type = ObTableOperationType::Type::INSERT;
|
||||
ObSEArray<ObTableOperation, 8> ops;
|
||||
ObTableAuditMultiOp multi_op(op_type, ops);
|
||||
// test1: empty table name
|
||||
ObString table_name = ObString::make_empty_string();
|
||||
ASSERT_EQ(OB_SUCCESS, multi_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "multi insert (null) ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(multi_op.get_stmt_length(table_name), pos);
|
||||
// test2: unknow operation type
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
table_name = ObString::make_string("test");
|
||||
multi_op.op_type_ = (ObTableOperationType::Type) - 1;
|
||||
table_name = ObString::make_empty_string();
|
||||
ASSERT_EQ(OB_SUCCESS, multi_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "multi unknown (null) ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(multi_op.get_stmt_length(table_name), pos);
|
||||
// test3: empty prop name
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
ObTableOperation op;
|
||||
op.set_type(op_type);
|
||||
op.set_entity(entity_);
|
||||
ASSERT_EQ(OB_SUCCESS, ops.push_back(op));
|
||||
table_name = ObString::make_string("test");
|
||||
multi_op.op_type_ = ObTableOperationType::Type::INSERT;
|
||||
ASSERT_EQ(OB_SUCCESS, multi_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "multi insert test ";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(multi_op.get_stmt_length(table_name), pos);
|
||||
// test4: one prop name
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
ops.reset();
|
||||
construct_prop_names("c1");
|
||||
ASSERT_EQ(OB_SUCCESS, ops.push_back(op));
|
||||
table_name = ObString::make_string("test");
|
||||
multi_op.op_type_ = ObTableOperationType::Type::INSERT;
|
||||
ASSERT_EQ(OB_SUCCESS, multi_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "multi insert test \"c1\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(multi_op.get_stmt_length(table_name), pos);
|
||||
// test5: three prop name
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
ops.reset();
|
||||
entity_.reset();
|
||||
construct_prop_names("c1", "c2", "c3");
|
||||
ASSERT_EQ(OB_SUCCESS, ops.push_back(op));
|
||||
table_name = ObString::make_string("test");
|
||||
multi_op.op_type_ = ObTableOperationType::Type::INSERT;
|
||||
ASSERT_EQ(OB_SUCCESS, multi_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "multi insert test \"c1\", \"c2\", \"c3\"";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(multi_op.get_stmt_length(table_name), pos);
|
||||
// test6: buf not enough
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, multi_op.generate_stmt(table_name, buf, 0, pos));
|
||||
// test7: buf is null
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, multi_op.generate_stmt(table_name, nullptr, buf_len, pos));
|
||||
// test8: bug length too short
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, multi_op.generate_stmt(table_name, buf, 7, pos));
|
||||
}
|
||||
|
||||
// 测试: ObTableAuditRedisOp
|
||||
TEST_F(TestTableAudit, ObTableAuditRedisOp)
|
||||
{
|
||||
const int64_t buf_len = 128;
|
||||
char buf[buf_len] = {0};
|
||||
int64_t pos = 0;
|
||||
ObString table_name = ObString::make_string("test");
|
||||
ObString cmd_name = ObString::make_string("set");
|
||||
ObTableAuditRedisOp redis_op(cmd_name);
|
||||
// test1: empty table name
|
||||
table_name = ObString::make_empty_string();
|
||||
ASSERT_EQ(OB_SUCCESS, redis_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
const char *result = "set";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(redis_op.get_stmt_length(table_name), pos);
|
||||
// test2: empty cmd name
|
||||
MEMSET(buf, 0, buf_len);
|
||||
pos = 0;
|
||||
cmd_name = ObString::make_empty_string();
|
||||
ObTableAuditRedisOp redis_op1(cmd_name);
|
||||
ASSERT_EQ(OB_SUCCESS, redis_op.generate_stmt(table_name, buf, buf_len, pos));
|
||||
result = "(null)";
|
||||
ASSERT_STRCASEEQ(result, buf);
|
||||
ASSERT_EQ(strlen(result), pos);
|
||||
ASSERT_EQ(redis_op.get_stmt_length(table_name), pos);
|
||||
// test3: buf not enough
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, redis_op.generate_stmt(table_name, buf, 0, pos));
|
||||
// test4: buf is null
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, redis_op.generate_stmt(table_name, nullptr, buf_len, pos));
|
||||
// test5: bug length too short
|
||||
ASSERT_EQ(OB_BUF_NOT_ENOUGH, redis_op.generate_stmt(table_name, buf, 7, pos));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
OB_LOGGER.set_file_name("test_table_audit.log", true);
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
40
unittest/observer/table/test_table_group_commit.cpp
Normal file
40
unittest/observer/table/test_table_group_commit.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public // 获取private成员
|
||||
#define protected public // 获取protect成员
|
||||
#include "observer/table/group/ob_table_tenant_group.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::table;
|
||||
|
||||
class TestTableGroupCommit: public ::testing::Test
|
||||
{
|
||||
public:
|
||||
static const int64_t DEFAULT_MAX_GROUP_SIZE;
|
||||
static const int64_t DEFAULT_MIN_GROUP_SIZE;
|
||||
TestTableGroupCommit() {};
|
||||
virtual ~TestTableGroupCommit() {}
|
||||
public:
|
||||
ObTableGroupCommitMgr mgr_;
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(TestTableGroupCommit);
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
OB_LOGGER.set_file_name("test_table_group.log", true);
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 OceanBase
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2023 OceanBase
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
|
146
unittest/observer/tableapi/test_redis_parser.cpp
Normal file
146
unittest/observer/tableapi/test_redis_parser.cpp
Normal file
@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Copyright (c) 2024 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "src/share/table/ob_redis_parser.h"
|
||||
#include "src/share/ob_errno.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace table
|
||||
{
|
||||
class TestRedisParser : public::testing::Test
|
||||
{
|
||||
public:
|
||||
TestRedisParser() {}
|
||||
virtual ~TestRedisParser() {}
|
||||
virtual void SetUp() {}
|
||||
virtual void TearDown() {}
|
||||
};
|
||||
|
||||
TEST_F(TestRedisParser, test_decode_inline) {
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString redis_msg = "Monitor\r\n";
|
||||
ObString method;
|
||||
ObArray<ObString> args;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
ASSERT_EQ(0, args.size());
|
||||
ObString expected = "MONITOR";
|
||||
ASSERT_EQ(method == expected, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_decode_array) {
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString redis_msg = "*2\r\n$3\r\nGET\r\n$6\r\nfoobar\r\n";
|
||||
ObString method;
|
||||
ObArray<ObString> args;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
ASSERT_EQ(1, args.size());
|
||||
ObString expected1 = "GET";
|
||||
ASSERT_EQ(method == expected1, true);
|
||||
ObString expected2 = "foobar";
|
||||
ASSERT_EQ(args[0] == expected2, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_decode_err) {
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString method;
|
||||
ObArray<ObString> args;
|
||||
// invalid length
|
||||
ObString redis_msg = "*3\r\n$3\r\nGET\r\n$6\r\nfoobar\r\n";
|
||||
ASSERT_EQ(OB_KV_REDIS_PARSE_ERROR, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
redis_msg = "*1\r\n$3\r\nGET\r\n$6\r\nfoobar\r\n";
|
||||
ASSERT_EQ(OB_KV_REDIS_PARSE_ERROR, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
|
||||
// invalid end char
|
||||
redis_msg = "$2\r\n$3\r\nGET\r\n$6\nfoobar\r\n";
|
||||
ASSERT_EQ(OB_KV_REDIS_PARSE_ERROR, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
redis_msg = "Monitor\n";
|
||||
ASSERT_EQ(OB_KV_REDIS_PARSE_ERROR, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
|
||||
// invalid header
|
||||
redis_msg = "-2\r\n$3\r\nGET\r\n$6\nfoobar\r\n";
|
||||
ASSERT_EQ(OB_KV_REDIS_PARSE_ERROR, ObRedisParser::decode(allocator, redis_msg, method, args));
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_encode_simple_string)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString str = "OK";
|
||||
ObString encoded;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_simple_string(allocator, str, encoded));
|
||||
ObString expected = "+OK\r\n";
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_encode_simple_error)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString str = "ERR";
|
||||
ObString encoded;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_error(allocator, str, encoded));
|
||||
ObString expected = "-ERR\r\n";
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_encode_integer)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
int64_t i = 1234568789;
|
||||
ObString encoded;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_integer(allocator, i, encoded));
|
||||
ObString expected = ":1234568789\r\n";
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
|
||||
i = -1234568789;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_integer(allocator, i, encoded));
|
||||
expected = ":-1234568789\r\n";
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_encode_bulk_string)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObString str = "This is a bulk string";
|
||||
ObString encoded;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_bulk_string(allocator, str, encoded));
|
||||
ObString expected = "$21\r\nThis is a bulk string\r\n";
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
}
|
||||
|
||||
TEST_F(TestRedisParser, test_encode_array)
|
||||
{
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObArray<ObString> arr;
|
||||
ASSERT_EQ(OB_SUCCESS, arr.push_back("hello world"));
|
||||
ASSERT_EQ(OB_SUCCESS, arr.push_back("foobarbaz"));
|
||||
ObString encoded;
|
||||
ASSERT_EQ(OB_SUCCESS, ObRedisParser::encode_array(allocator, arr, encoded));
|
||||
ObString expected = "*2\r\n$11\r\nhello world\r\n$9\r\nfoobarbaz\r\n";
|
||||
std::cout << expected.ptr() << std::endl;
|
||||
std::cout << encoded.ptr() << std::endl;
|
||||
ASSERT_EQ(expected == encoded, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
OB_LOGGER.set_file_name("test_redis_parser.log", true);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Reference in New Issue
Block a user