TDengine/source/dnode/mnode/impl/test/db/db.cpp

242 lines
6.8 KiB
C++
Raw Normal View History

2021-12-16 09:05:13 +00:00
/**
2021-12-16 12:16:35 +00:00
* @file db.cpp
2021-12-16 09:05:13 +00:00
* @author slguan (slguan@taosdata.com)
2022-01-08 04:57:46 +00:00
* @brief MNODE module db tests
* @version 1.0
* @date 2022-01-11
2021-12-15 06:20:49 +00:00
*
2022-01-08 04:57:46 +00:00
* @copyright Copyright (c) 2022
2021-12-15 06:20:49 +00:00
*
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-15 06:20:49 +00:00
2022-01-08 04:57:46 +00:00
class MndTestDb : public ::testing::Test {
2021-12-15 06:20:49 +00:00
protected:
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_db", 9030); }
2022-01-11 01:33:25 +00:00
static void TearDownTestSuite() { test.Cleanup(); }
2021-12-15 06:20:49 +00:00
2022-01-11 01:33:25 +00:00
static Testbase test;
2021-12-15 06:20:49 +00:00
public:
void SetUp() override {}
void TearDown() override {}
};
2022-01-11 01:33:25 +00:00
Testbase MndTestDb::test;
2021-12-15 06:20:49 +00:00
2022-01-08 04:57:46 +00:00
TEST_F(MndTestDb, 01_ShowDb) {
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-15 06:20:49 +00:00
}
2022-10-09 08:50:52 +00:00
#if 0
2022-01-08 04:57:46 +00:00
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
2021-12-15 06:20:49 +00:00
{
2022-02-12 09:14:33 +00:00
SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d1");
createReq.numOfVgroups = 2;
2022-04-25 13:12:03 +00:00
createReq.buffer = -1;
createReq.pageSize = -1;
createReq.pages = -1;
2022-04-28 07:30:23 +00:00
createReq.daysPerFile = 1000;
createReq.daysToKeep0 = 3650;
createReq.daysToKeep1 = 3650;
createReq.daysToKeep2 = 3650;
2022-02-12 09:14:33 +00:00
createReq.minRows = 100;
createReq.maxRows = 4096;
createReq.walFsyncPeriod = 3000;
2022-02-12 09:14:33 +00:00
createReq.walLevel = 1;
createReq.precision = 0;
createReq.compression = 2;
createReq.replications = 1;
2022-04-20 01:47:38 +00:00
createReq.strict = 1;
createReq.cacheLast = 0;
2022-02-12 09:14:33 +00:00
createReq.ignoreExist = 1;
2022-04-28 07:30:23 +00:00
createReq.numOfStables = 0;
2022-04-15 02:12:29 +00:00
createReq.numOfRetensions = 0;
2022-02-12 09:14:33 +00:00
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
2021-12-15 06:20:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-15 06:20:49 +00:00
}
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-15 06:20:49 +00:00
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_VGROUP, "ins_vgroups", "1.d1");
2021-12-22 08:38:20 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-16 06:02:39 +00:00
2021-12-15 08:56:56 +00:00
{
2022-02-14 07:27:38 +00:00
SAlterDbReq alterdbReq = {0};
strcpy(alterdbReq.db, "1.d1");
2022-05-06 09:28:58 +00:00
2022-04-25 13:12:03 +00:00
alterdbReq.buffer = 12;
2022-05-06 09:28:58 +00:00
alterdbReq.pageSize = -1;
alterdbReq.pages = -1;
alterdbReq.daysPerFile = -1;
alterdbReq.daysToKeep0 = -1;
alterdbReq.daysToKeep1 = -1;
alterdbReq.daysToKeep2 = -1;
alterdbReq.walFsyncPeriod = 4000;
2022-02-14 07:27:38 +00:00
alterdbReq.walLevel = 2;
2022-05-06 09:28:58 +00:00
alterdbReq.strict = 1;
alterdbReq.cacheLast = 1;
2022-05-06 09:28:58 +00:00
alterdbReq.replications = 1;
2022-02-14 07:27:38 +00:00
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
2021-12-15 06:20:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_OPS_NOT_SUPPORT);
2021-12-15 08:56:56 +00:00
}
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-15 06:20:49 +00:00
2021-12-24 02:27:59 +00:00
// restart
test.Restart();
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-24 02:27:59 +00:00
{
2022-02-14 07:27:38 +00:00
SDropDbReq dropdbReq = {0};
strcpy(dropdbReq.db, "1.d1");
2021-12-24 02:27:59 +00:00
2022-02-14 07:27:38 +00:00
int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
2021-12-24 02:27:59 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-01-27 01:33:44 +00:00
2022-02-14 07:27:38 +00:00
SDropDbRsp dropdbRsp = {0};
tDeserializeSDropDbRsp(pRsp->pCont, pRsp->contLen, &dropdbRsp);
EXPECT_STREQ(dropdbRsp.db, "1.d1");
2021-12-24 02:27:59 +00:00
}
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-16 09:05:13 +00:00
}
2022-10-09 08:50:52 +00:00
#endif
2021-12-16 09:05:13 +00:00
2022-01-08 04:57:46 +00:00
TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
2021-12-16 09:05:13 +00:00
{
2022-02-12 09:14:33 +00:00
SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d2");
createReq.numOfVgroups = 2;
2022-04-25 13:12:03 +00:00
createReq.buffer = -1;
createReq.pageSize = -1;
createReq.pages = -1;
2022-04-28 07:30:23 +00:00
createReq.daysPerFile = 1000;
createReq.daysToKeep0 = 3650;
createReq.daysToKeep1 = 3650;
createReq.daysToKeep2 = 3650;
2022-02-12 09:14:33 +00:00
createReq.minRows = 100;
createReq.maxRows = 4096;
createReq.walFsyncPeriod = 3000;
2022-02-12 09:14:33 +00:00
createReq.walLevel = 1;
createReq.precision = 0;
createReq.compression = 2;
createReq.replications = 1;
2022-04-20 01:47:38 +00:00
createReq.strict = 1;
createReq.cacheLast = 0;
2022-02-12 09:14:33 +00:00
createReq.ignoreExist = 1;
2022-04-28 07:30:23 +00:00
createReq.numOfStables = 0;
2022-04-15 02:12:29 +00:00
createReq.numOfRetensions = 0;
2022-02-12 09:14:33 +00:00
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
2021-12-16 09:05:13 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-16 09:05:13 +00:00
}
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DB, "ins_databases", "");
2022-04-15 02:12:29 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-16 09:05:13 +00:00
2022-01-27 01:33:44 +00:00
uint64_t d2_uid = 0;
2021-12-16 09:05:13 +00:00
{
2022-02-14 07:27:38 +00:00
SUseDbReq usedbReq = {0};
strcpy(usedbReq.db, "1.d2");
usedbReq.vgVersion = -1;
2021-12-22 08:38:20 +00:00
2022-02-14 07:27:38 +00:00
int32_t contLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSUseDbReq(pReq, contLen, &usedbReq);
2021-12-16 09:05:13 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_USE_DB, pReq, contLen);
2021-12-16 09:05:13 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
2022-02-14 07:27:38 +00:00
SUseDbRsp usedbRsp = {0};
tDeserializeSUseDbRsp(pMsg->pCont, pMsg->contLen, &usedbRsp);
EXPECT_STREQ(usedbRsp.db, "1.d2");
EXPECT_EQ(usedbRsp.vgVersion, 1);
EXPECT_EQ(usedbRsp.vgNum, 2);
EXPECT_EQ(usedbRsp.hashMethod, 1);
d2_uid = usedbRsp.uid;
2021-12-16 09:05:13 +00:00
{
2022-02-14 07:27:38 +00:00
SVgroupInfo* pInfo = (SVgroupInfo*)taosArrayGet(usedbRsp.pVgroupInfos, 0);
pInfo->vgId = pInfo->vgId;
pInfo->hashBegin = pInfo->hashBegin;
pInfo->hashEnd = pInfo->hashEnd;
2021-12-16 09:05:13 +00:00
EXPECT_GT(pInfo->vgId, 0);
EXPECT_EQ(pInfo->hashBegin, 0);
2021-12-16 10:04:07 +00:00
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX / 2 - 1);
2022-03-08 09:22:21 +00:00
EXPECT_EQ(pInfo->epSet.inUse, 0);
EXPECT_EQ(pInfo->epSet.numOfEps, 1);
SEp* pAddr = &pInfo->epSet.eps[0];
2022-01-08 04:57:46 +00:00
EXPECT_EQ(pAddr->port, 9030);
2021-12-16 09:05:13 +00:00
EXPECT_STREQ(pAddr->fqdn, "localhost");
}
{
2022-02-14 07:27:38 +00:00
SVgroupInfo* pInfo = (SVgroupInfo*)taosArrayGet(usedbRsp.pVgroupInfos, 1);
pInfo->vgId = pInfo->vgId;
pInfo->hashBegin = pInfo->hashBegin;
pInfo->hashEnd = pInfo->hashEnd;
2021-12-16 09:05:13 +00:00
EXPECT_GT(pInfo->vgId, 0);
2021-12-16 10:04:07 +00:00
EXPECT_EQ(pInfo->hashBegin, UINT32_MAX / 2);
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX);
2022-03-08 09:22:21 +00:00
EXPECT_EQ(pInfo->epSet.inUse, 0);
EXPECT_EQ(pInfo->epSet.numOfEps, 1);
SEp* pAddr = &pInfo->epSet.eps[0];
2022-01-08 04:57:46 +00:00
EXPECT_EQ(pAddr->port, 9030);
2021-12-16 09:05:13 +00:00
EXPECT_STREQ(pAddr->fqdn, "localhost");
}
2022-02-14 07:27:38 +00:00
tFreeSUsedbRsp(&usedbRsp);
2021-12-16 09:05:13 +00:00
}
2022-01-10 07:15:37 +00:00
{
2022-02-14 07:27:38 +00:00
SDropDbReq dropdbReq = {0};
strcpy(dropdbReq.db, "1.d2");
2022-01-10 07:15:37 +00:00
2022-02-14 07:27:38 +00:00
int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
2022-01-10 07:15:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-01-27 01:33:44 +00:00
2022-02-14 07:27:38 +00:00
SDropDbRsp dropdbRsp = {0};
tDeserializeSDropDbRsp(pRsp->pCont, pRsp->contLen, &dropdbRsp);
EXPECT_STREQ(dropdbRsp.db, "1.d2");
EXPECT_EQ(dropdbRsp.uid, d2_uid);
2022-01-10 07:15:37 +00:00
}
2021-12-16 09:05:13 +00:00
}