patch 4.0
This commit is contained in:
@ -29,24 +29,28 @@
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace common {
|
||||
class TestAllocator : public ObIAllocator {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
class TestAllocator: public ObIAllocator
|
||||
{
|
||||
public:
|
||||
virtual void* alloc(const int64_t size) override
|
||||
virtual void *alloc(const int64_t size) override
|
||||
{
|
||||
return std::malloc(size);
|
||||
}
|
||||
virtual void free(void* ptr) override
|
||||
virtual void free(void *ptr) override
|
||||
{
|
||||
return std::free(ptr);
|
||||
}
|
||||
virtual void* alloc(const int64_t size, const ObMemAttr& /* not used */)
|
||||
virtual void *alloc(const int64_t size, const ObMemAttr &/* not used */)
|
||||
{
|
||||
return std::malloc(size);
|
||||
}
|
||||
};
|
||||
class TestURowID {
|
||||
class TestURowID
|
||||
{
|
||||
public:
|
||||
// void SetUp() override {}
|
||||
// void TearDown() override {}
|
||||
@ -79,7 +83,7 @@ public:
|
||||
pk_val.set_number(test_number);
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
const char* test_str = "hello, this is a test";
|
||||
const char *test_str = "hello, this is a test";
|
||||
pk_val.set_char(ObString(strlen(test_str), test_str));
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
@ -94,25 +98,33 @@ public:
|
||||
|
||||
ObTimeZoneInfo time_zone_info;
|
||||
time_zone_info.set_timezone("+8:00");
|
||||
ObTimeConvertCtx time_convert_ctx(&time_zone_info, ObTimeConverter::COMPAT_OLD_NLS_DATE_FORMAT, true);
|
||||
ObTimeConvertCtx time_convert_ctx(&time_zone_info,
|
||||
ObTimeConverter::COMPAT_OLD_NLS_DATE_FORMAT,
|
||||
true);
|
||||
|
||||
ObOTimestampData otime_data;
|
||||
ObScale scale;
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampTZType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampTZType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_tz(otime_data);
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampNanoType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampNanoType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_nano(otime_data);
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampNanoType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampNanoType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_nano(otime_data);
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
@ -124,7 +136,8 @@ public:
|
||||
|
||||
scale = 99;
|
||||
ObIntervalDSValue ds_value;
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_interval_ds("000000012 11:11:11", ds_value, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_interval_ds("000000012 11:11:11",
|
||||
ds_value, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val));
|
||||
|
||||
ObURowIDData urowid_data;
|
||||
@ -133,7 +146,7 @@ public:
|
||||
int64_t pos = urowid_data.get_pk_content_offset();
|
||||
int i = 0;
|
||||
ObObj tmp_obj;
|
||||
for (; pos < urowid_data.rowid_len_;) {
|
||||
for(; pos < urowid_data.rowid_len_;) {
|
||||
ASSERT_EQ(urowid_data.get_pk_type(pos), pk_vals.at(i).get_type());
|
||||
ASSERT_EQ(OB_SUCCESS, urowid_data.get_pk_value(pk_vals.at(i).get_type(), pos, tmp_obj));
|
||||
ASSERT_EQ(tmp_obj, pk_vals.at(i));
|
||||
@ -144,37 +157,39 @@ public:
|
||||
|
||||
void set_and_get_pk()
|
||||
{
|
||||
#define TEST_SET_AND_GET_VAL(val, val_len) \
|
||||
do { \
|
||||
pk_vals.reset(); \
|
||||
urowid_data.reset(); \
|
||||
ObObj tmp_obj; \
|
||||
int64_t urowid_version = ObURowIDData::PK_ROWID_VERSION; \
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val)); \
|
||||
#define TEST_SET_AND_GET_VAL(val, val_len) \
|
||||
do { \
|
||||
pk_vals.reset(); \
|
||||
urowid_data.reset(); \
|
||||
ObObj tmp_obj; \
|
||||
int64_t urowid_version = ObURowIDData::PK_ROWID_VERSION; \
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(pk_val)); \
|
||||
ASSERT_EQ(OB_SUCCESS, urowid_data.set_rowid_content(pk_vals, ObURowIDData::PK_ROWID_VERSION, allocator)); \
|
||||
int64_t tmp_pos = urowid_data.get_pk_content_offset(); \
|
||||
ASSERT_EQ(urowid_version, urowid_data.get_version()); \
|
||||
ASSERT_TRUE(urowid_data.is_valid_urowid()); \
|
||||
ASSERT_EQ(val_len + 1, urowid_data.get_obj_size(val)); \
|
||||
ASSERT_EQ(tmp_pos + val_len + 1, urowid_data.get_buf_len()); \
|
||||
ASSERT_EQ(urowid_data.get_pk_type(tmp_pos), val.get_type()); \
|
||||
ASSERT_EQ(tmp_pos, urowid_data.get_pk_content_offset() + 1); \
|
||||
ASSERT_EQ(OB_SUCCESS, urowid_data.get_pk_value(val.get_type(), tmp_pos, tmp_obj)); \
|
||||
ASSERT_EQ(tmp_obj, val); \
|
||||
test_encode_decode(pk_vals, urowid_data); \
|
||||
\
|
||||
ObObj urowid_obj; \
|
||||
ObURowIDData urowid2; \
|
||||
urowid_obj.set_urowid(urowid_data); \
|
||||
pk_vals.reset(); \
|
||||
tmp_obj.reset(); \
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(urowid_obj)); \
|
||||
int64_t tmp_pos = urowid_data.get_pk_content_offset(); \
|
||||
ASSERT_EQ(urowid_version, urowid_data.get_version()); \
|
||||
ASSERT_TRUE(urowid_data.is_valid_urowid()); \
|
||||
ASSERT_EQ(val_len + 1, urowid_data.get_obj_size(val)); \
|
||||
ASSERT_EQ(tmp_pos + val_len + 1, urowid_data.get_buf_len()); \
|
||||
ASSERT_EQ(urowid_data.get_pk_type(tmp_pos), val.get_type()); \
|
||||
ASSERT_EQ(tmp_pos, urowid_data.get_pk_content_offset() + 1); \
|
||||
ASSERT_EQ(OB_SUCCESS, \
|
||||
urowid_data.get_pk_value(val.get_type(), tmp_pos, tmp_obj)); \
|
||||
ASSERT_EQ(tmp_obj, val); \
|
||||
test_encode_decode(pk_vals, urowid_data); \
|
||||
\
|
||||
ObObj urowid_obj; \
|
||||
ObURowIDData urowid2; \
|
||||
urowid_obj.set_urowid(urowid_data); \
|
||||
pk_vals.reset(); \
|
||||
tmp_obj.reset(); \
|
||||
ASSERT_EQ(OB_SUCCESS, pk_vals.push_back(urowid_obj)); \
|
||||
ASSERT_EQ(OB_SUCCESS, urowid2.set_rowid_content(pk_vals, ObURowIDData::PK_ROWID_VERSION, allocator)); \
|
||||
ASSERT_TRUE(urowid2.is_valid_urowid()); \
|
||||
tmp_pos = urowid2.get_pk_content_offset(); \
|
||||
ASSERT_EQ(ObURowIDType, urowid2.get_pk_type(tmp_pos)); \
|
||||
ASSERT_EQ(OB_SUCCESS, urowid2.get_pk_value(urowid_obj.get_type(), tmp_pos, tmp_obj)); \
|
||||
ASSERT_TRUE(urowid_data == tmp_obj.get_urowid()); \
|
||||
ASSERT_TRUE(urowid2.is_valid_urowid()); \
|
||||
tmp_pos = urowid2.get_pk_content_offset(); \
|
||||
ASSERT_EQ(ObURowIDType, urowid2.get_pk_type(tmp_pos)); \
|
||||
ASSERT_EQ(OB_SUCCESS, \
|
||||
urowid2.get_pk_value(urowid_obj.get_type(), tmp_pos, tmp_obj)); \
|
||||
ASSERT_TRUE(urowid_data == tmp_obj.get_urowid()); \
|
||||
} while (0);
|
||||
|
||||
ObURowIDData urowid_data;
|
||||
@ -221,7 +236,7 @@ public:
|
||||
pk_val.set_number_float(test_number);
|
||||
TEST_SET_AND_GET_VAL(pk_val, 4 + sizeof(uint32_t) * test_number.get_desc().len_);
|
||||
|
||||
const char* test_str = "hello, this is a test";
|
||||
const char *test_str = "hello, this is a test";
|
||||
pk_val.set_char(ObString(strlen(test_str), test_str));
|
||||
TEST_SET_AND_GET_VAL(pk_val, 5 + strlen(test_str));
|
||||
|
||||
@ -236,25 +251,33 @@ public:
|
||||
|
||||
ObTimeZoneInfo time_zone_info;
|
||||
time_zone_info.set_timezone("+8:00");
|
||||
ObTimeConvertCtx time_convert_ctx(&time_zone_info, ObTimeConverter::COMPAT_OLD_NLS_DATE_FORMAT, true);
|
||||
ObTimeConvertCtx time_convert_ctx(&time_zone_info,
|
||||
ObTimeConverter::COMPAT_OLD_NLS_DATE_FORMAT,
|
||||
true);
|
||||
|
||||
ObOTimestampData otime_data;
|
||||
ObScale scale;
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampTZType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampTZType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_tz(otime_data);
|
||||
TEST_SET_AND_GET_VAL(pk_val, 12);
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampLTZType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampLTZType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_ltz(otime_data);
|
||||
TEST_SET_AND_GET_VAL(pk_val, 10);
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS,
|
||||
ObTimeConverter::str_to_otimestamp(
|
||||
"2020-02-24 21:37:25", time_convert_ctx, ObTimestampNanoType, otime_data, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_otimestamp("2020-02-24 21:37:25",
|
||||
time_convert_ctx,
|
||||
ObTimestampNanoType,
|
||||
otime_data,
|
||||
scale));
|
||||
pk_val.set_timestamp_nano(otime_data);
|
||||
TEST_SET_AND_GET_VAL(pk_val, 10);
|
||||
|
||||
@ -266,16 +289,17 @@ public:
|
||||
|
||||
scale = 99;
|
||||
ObIntervalDSValue ds_value;
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_interval_ds("000000012 11:11:11", ds_value, scale));
|
||||
ASSERT_EQ(OB_SUCCESS, ObTimeConverter::str_to_interval_ds("000000012 11:11:11",
|
||||
ds_value, scale));
|
||||
pk_val.set_interval_ds(ds_value);
|
||||
TEST_SET_AND_GET_VAL(pk_val, 12);
|
||||
}
|
||||
|
||||
void test_encode_decode(ObIArray<ObObj>& pk_vals, ObURowIDData& urowid_data)
|
||||
void test_encode_decode(ObIArray<ObObj> &pk_vals, ObURowIDData &urowid_data)
|
||||
{
|
||||
TestAllocator allocator;
|
||||
const int64_t encode_buf_len = urowid_data.needed_base64_buffer_size();
|
||||
char* encode_buf = (char*)allocator.alloc(encode_buf_len);
|
||||
char *encode_buf = (char *)allocator.alloc(encode_buf_len);
|
||||
int64_t encoded_len = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, urowid_data.get_base64_str(encode_buf, encode_buf_len, encoded_len));
|
||||
ASSERT_EQ(encoded_len, encode_buf_len);
|
||||
@ -283,12 +307,13 @@ public:
|
||||
// const int64_t decode_buf_len = ObURowIDData::needed_urowid_buf_size(encoded_len);
|
||||
// char *decode_buf = (char *)allocator.alloc(decode_buf_len);
|
||||
ObURowIDData decode_data;
|
||||
ASSERT_EQ(OB_SUCCESS, ObURowIDData::decode2urowid(encode_buf, encoded_len, allocator, decode_data));
|
||||
ASSERT_EQ(OB_SUCCESS, ObURowIDData::decode2urowid(encode_buf, encoded_len,
|
||||
allocator, decode_data));
|
||||
ASSERT_EQ(decode_data, urowid_data);
|
||||
|
||||
int64_t decode_pos = decode_data.get_pk_content_offset();
|
||||
int64_t i = 0;
|
||||
for (; decode_pos < decode_data.rowid_len_;) {
|
||||
for(; decode_pos < decode_data.rowid_len_; ) {
|
||||
ObObjType obj_type = decode_data.get_pk_type(decode_pos);
|
||||
ASSERT_EQ(obj_type, pk_vals.at(i).get_type());
|
||||
ObObj tmp_obj;
|
||||
@ -340,17 +365,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
TEST(TestURowID, single_urowid_test)
|
||||
{
|
||||
TEST(TestURowID, single_urowid_test) {
|
||||
TestAllocator alloc;
|
||||
const char* str = "*AAEWLlcAAABnYXJuaXNoIG51bWJlciB0ZWFyaW5nIG1hbnRsaW5nIGFjY3VzdG9tcyBleHRyZW1lcyBiYXNlbHkgY3Jhemlse"
|
||||
"SBlbGRlciB0YXJkaWVzIHByZW1pc2UtCwAAAAACCkcywAAAAAAA";
|
||||
// bug: https://work.aone.alibaba-inc.com/issue/31597994
|
||||
const char *str = "*AAEWLlcAAABnYXJuaXNoIG51bWJlciB0ZWFyaW5nIG1hbnRsaW5nIGFjY3VzdG9tcyBleHRyZW1lcyBiYXNlbHkgY3JhemlseSBlbGRlciB0YXJkaWVzIHByZW1pc2UtCwAAAAACCkcywAAAAAAA";
|
||||
ObURowIDData dec_data;
|
||||
ASSERT_EQ(OB_SUCCESS, ObURowIDData::decode2urowid(str, strlen(str), alloc, dec_data));
|
||||
}
|
||||
|
||||
TEST(TestURowID, set_and_get_pk)
|
||||
{
|
||||
TEST(TestURowID, set_and_get_pk) {
|
||||
TestURowID urowid_test;
|
||||
urowid_test.set_and_get_pk();
|
||||
}
|
||||
@ -359,8 +382,7 @@ void decode_output()
|
||||
{
|
||||
TestAllocator alloc;
|
||||
// const char *str = "*AAIPAQEAwHsAAAAACgEAAAAAAAAA";
|
||||
const char* str = "*AAEWLlcAAABnYXJuaXNoIG51bWJlciB0ZWFyaW5nIG1hbnRsaW5nIGFjY3VzdG9tcyBleHRyZW1lcyBiYXNlbHkgY3Jhemlse"
|
||||
"SBlbGRlciB0YXJkaWVzIHByZW1pc2UtCwAAAAACCkcywAAAAAAA";
|
||||
const char *str = "*AAEWLlcAAABnYXJuaXNoIG51bWJlciB0ZWFyaW5nIG1hbnRsaW5nIGFjY3VzdG9tcyBleHRyZW1lcyBiYXNlbHkgY3JhemlseSBlbGRlciB0YXJkaWVzIHByZW1pc2UtCwAAAAACCkcywAAAAAAA";
|
||||
ObURowIDData dec_data;
|
||||
ASSERT_EQ(OB_SUCCESS, ObURowIDData::decode2urowid(str, strlen(str), alloc, dec_data));
|
||||
|
||||
@ -375,24 +397,24 @@ void decode_output()
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestURowID, multi_set_and_get)
|
||||
{
|
||||
TEST(TestURowID, multi_set_and_get) {
|
||||
TestURowID urowid_test;
|
||||
urowid_test.multi_set_and_get();
|
||||
}
|
||||
|
||||
TEST(TestURowID, cmp)
|
||||
{
|
||||
TEST(TestURowID, cmp) {
|
||||
TestURowID urowid_test;
|
||||
urowid_test.test_urowid_cmp();
|
||||
}
|
||||
} // namespace common
|
||||
} // end namespace oceanbase
|
||||
} // end namesapce common
|
||||
} // end namespace oceanbase
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
system("rm -rf test_urowid.log");
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
OB_LOGGER.set_file_name("test_urowid.log", true);
|
||||
oceanbase::common::decode_output();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user