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

362 lines
10 KiB
C++
Raw Normal View History

2021-12-16 09:05:13 +00:00
/**
2021-12-16 12:16:35 +00:00
* @file dnode.cpp
2021-12-16 09:05:13 +00:00
* @author slguan (slguan@taosdata.com)
2022-01-06 08:57:08 +00:00
* @brief MNODE module dnode tests
* @version 1.0
* @date 2022-01-06
2021-12-12 06:46:31 +00:00
*
2022-01-06 08:57:08 +00:00
* @copyright Copyright (c) 2022
2021-12-12 06:46:31 +00:00
*
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-12 06:46:31 +00:00
2022-01-06 08:57:08 +00:00
class MndTestDnode : public ::testing::Test {
2021-12-12 13:55:43 +00:00
public:
2021-12-22 10:39:32 +00:00
void SetUp() override {}
void TearDown() override {}
2021-12-12 06:46:31 +00:00
2021-12-22 10:39:32 +00:00
public:
2021-12-12 06:46:31 +00:00
static void SetUpTestSuite() {
test.Init(TD_TMP_DIR_PATH "dnode_test_dnode1", 9023);
2021-12-12 06:46:31 +00:00
const char* fqdn = "localhost";
2022-01-06 08:57:08 +00:00
const char* firstEp = "localhost:9023";
2021-12-22 10:39:32 +00:00
// server2.Start(TD_TMP_DIR_PATH "dnode_test_dnode2", fqdn, 9024, firstEp);
// server3.Start(TD_TMP_DIR_PATH "dnode_test_dnode3", fqdn, 9025, firstEp);
// server4.Start(TD_TMP_DIR_PATH "dnode_test_dnode4", fqdn, 9026, firstEp);
// server5.Start(TD_TMP_DIR_PATH "dnode_test_dnode5", fqdn, 9027, firstEp);
2021-12-12 13:55:43 +00:00
taosMsleep(300);
2021-12-12 06:46:31 +00:00
}
static void TearDownTestSuite() {
2021-12-22 10:39:32 +00:00
server2.Stop();
server3.Stop();
server4.Stop();
server5.Stop();
test.Cleanup();
2021-12-12 13:55:43 +00:00
}
2021-12-22 10:39:32 +00:00
static Testbase test;
static TestServer server2;
static TestServer server3;
static TestServer server4;
static TestServer server5;
};
2021-12-12 06:46:31 +00:00
2022-01-06 08:57:08 +00:00
Testbase MndTestDnode::test;
TestServer MndTestDnode::server2;
TestServer MndTestDnode::server3;
TestServer MndTestDnode::server4;
TestServer MndTestDnode::server5;
2021-12-12 13:55:43 +00:00
2022-01-06 08:57:08 +00:00
TEST_F(MndTestDnode, 01_ShowDnode) {
2022-04-15 02:23:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
2021-12-12 06:46:31 +00:00
}
2022-01-06 08:57:08 +00:00
TEST_F(MndTestDnode, 02_ConfigDnode) {
2022-02-12 06:21:26 +00:00
SMCfgDnodeReq cfgReq = {0};
cfgReq.dnodeId = 1;
strcpy(cfgReq.config, "ddebugflag");
strcpy(cfgReq.value, "131");
int32_t contLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSMCfgDnodeReq(pReq, contLen, &cfgReq);
2021-12-13 07:35:33 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-13 07:35:33 +00:00
}
2022-01-06 11:13:37 +00:00
TEST_F(MndTestDnode, 03_Create_Dnode) {
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "");
createReq.port = 9024;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
}
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = -1;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
}
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 123456;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_EP);
}
2021-12-16 06:02:39 +00:00
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 9024;
2021-12-12 06:46:31 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2021-12-12 06:46:31 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-16 06:02:39 +00:00
}
2021-12-12 06:46:31 +00:00
2022-01-06 11:13:37 +00:00
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 9024;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_ALREADY_EXIST);
}
2021-12-12 13:55:43 +00:00
taosMsleep(1300);
2021-12-22 10:39:32 +00:00
2022-04-15 02:23:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2022-01-06 11:13:37 +00:00
}
TEST_F(MndTestDnode, 04_Drop_Dnode) {
{
2022-02-12 06:06:13 +00:00
SDropDnodeReq dropReq = {0};
dropReq.dnodeId = -3;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDnodeReq(pReq, contLen, &dropReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DNODE_ID);
}
{
2022-02-12 06:06:13 +00:00
SDropDnodeReq dropReq = {0};
dropReq.dnodeId = 5;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDnodeReq(pReq, contLen, &dropReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
}
2021-12-12 06:46:31 +00:00
2021-12-16 06:02:39 +00:00
{
2022-02-12 06:06:13 +00:00
SDropDnodeReq dropReq = {0};
dropReq.dnodeId = 2;
2021-12-12 06:46:31 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDnodeReq(pReq, contLen, &dropReq);
2021-12-12 06:46:31 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-16 06:02:39 +00:00
}
2021-12-12 06:46:31 +00:00
2022-01-06 11:13:37 +00:00
{
2022-02-12 06:06:13 +00:00
SDropDnodeReq dropReq = {0};
dropReq.dnodeId = 2;
2022-01-06 11:13:37 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSDropDnodeReq(pReq, contLen, &dropReq);
2022-01-06 11:13:37 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
}
2022-04-15 02:23:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
2022-01-06 11:13:37 +00:00
taosMsleep(2000);
server2.Stop();
2022-05-17 08:01:06 +00:00
server2.Start();
2022-01-06 11:13:37 +00:00
}
TEST_F(MndTestDnode, 05_Create_Drop_Restart_Dnode) {
2021-12-13 06:48:10 +00:00
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 9025;
2021-12-13 06:48:10 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2021-12-13 06:48:10 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-13 06:48:10 +00:00
}
2021-12-12 06:46:31 +00:00
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 9026;
2021-12-13 06:48:10 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2021-12-13 06:48:10 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-13 06:48:10 +00:00
}
2021-12-12 06:46:31 +00:00
2021-12-13 06:48:10 +00:00
{
2022-02-12 06:06:13 +00:00
SCreateDnodeReq createReq = {0};
strcpy(createReq.fqdn, "localhost");
createReq.port = 9027;
2021-12-13 06:48:10 +00:00
2022-02-12 06:06:13 +00:00
int32_t contLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDnodeReq(pReq, contLen, &createReq);
2021-12-13 06:48:10 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-12 06:46:31 +00:00
}
2021-12-13 06:48:10 +00:00
taosMsleep(1300);
2022-04-15 02:23:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 4);
2021-12-16 06:02:39 +00:00
// restart
2021-12-13 10:19:09 +00:00
uInfo("stop all server");
2021-12-22 10:39:32 +00:00
test.Restart();
server2.Restart();
server3.Restart();
server4.Restart();
server5.Restart();
2021-12-13 09:06:04 +00:00
2021-12-14 10:07:29 +00:00
taosMsleep(1300);
2022-04-15 02:23:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 4);
2022-05-06 14:17:56 +00:00
// alter replica
#if 0
{
SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d2");
createReq.numOfVgroups = 2;
createReq.buffer = -1;
createReq.pageSize = -1;
createReq.pages = -1;
createReq.daysPerFile = 1000;
createReq.daysToKeep0 = 3650;
createReq.daysToKeep1 = 3650;
createReq.daysToKeep2 = 3650;
createReq.minRows = 100;
createReq.maxRows = 4096;
createReq.fsyncPeriod = 3000;
createReq.walLevel = 1;
createReq.precision = 0;
createReq.compression = 2;
createReq.replications = 1;
createReq.strict = 1;
createReq.cacheLast = 0;
2022-05-06 14:17:56 +00:00
createReq.ignoreExist = 1;
createReq.numOfStables = 0;
createReq.numOfRetensions = 0;
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
test.SendShowReq(TSDB_MGMT_TABLE_DB, "user_databases", "");
EXPECT_EQ(test.GetShowRows(), 3);
}
{
SAlterDbReq alterdbReq = {0};
strcpy(alterdbReq.db, "1.d2");
alterdbReq.buffer = 12;
alterdbReq.pageSize = -1;
alterdbReq.pages = -1;
alterdbReq.daysPerFile = -1;
alterdbReq.daysToKeep0 = -1;
alterdbReq.daysToKeep1 = -1;
alterdbReq.daysToKeep2 = -1;
alterdbReq.fsyncPeriod = 4000;
alterdbReq.walLevel = 2;
alterdbReq.strict = 1;
alterdbReq.cacheLast = 1;
2022-05-06 14:17:56 +00:00
alterdbReq.replications = 3;
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterDbReq alterdbReq = {0};
strcpy(alterdbReq.db, "1.d2");
alterdbReq.buffer = 12;
alterdbReq.pageSize = -1;
alterdbReq.pages = -1;
alterdbReq.daysPerFile = -1;
alterdbReq.daysToKeep0 = -1;
alterdbReq.daysToKeep1 = -1;
alterdbReq.daysToKeep2 = -1;
alterdbReq.fsyncPeriod = 4000;
alterdbReq.walLevel = 2;
alterdbReq.strict = 1;
alterdbReq.cacheLast = 1;
2022-05-06 14:17:56 +00:00
alterdbReq.replications = 1;
int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
#endif
2021-12-13 09:06:04 +00:00
}