TDengine/source/dnode/mgmt/impl/test/dnode/dnode.cpp

262 lines
6.6 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)
2021-12-16 09:07:40 +00:00
* @brief DNODE module dnode-msg tests
2021-12-16 09:05:13 +00:00
* @version 0.1
2021-12-16 09:07:40 +00:00
* @date 2021-12-15
2021-12-12 06:46:31 +00:00
*
2021-12-16 09:05:13 +00:00
* @copyright Copyright (c) 2021
2021-12-12 06:46:31 +00:00
*
*/
2021-12-22 10:39:32 +00:00
#include "base.h"
2021-12-12 06:46:31 +00:00
class DndTestDnode : 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() {
2021-12-22 10:39:32 +00:00
test.Init("/tmp/dnode_test_dnode1", 9041);
2021-12-12 06:46:31 +00:00
const char* fqdn = "localhost";
2021-12-15 06:54:54 +00:00
const char* firstEp = "localhost:9041";
2021-12-22 10:39:32 +00:00
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, 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
2021-12-22 10:39:32 +00:00
Testbase DndTestDnode::test;
TestServer DndTestDnode::server2;
TestServer DndTestDnode::server3;
TestServer DndTestDnode::server4;
TestServer DndTestDnode::server5;
2021-12-12 13:55:43 +00:00
2021-12-22 10:39:32 +00:00
TEST_F(DndTestDnode, 01_ShowDnode) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7);
2021-12-12 13:55:43 +00:00
2021-12-22 10:39:32 +00:00
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
2021-12-12 06:46:31 +00:00
2021-12-22 10:39:32 +00:00
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 1);
2021-12-12 06:46:31 +00:00
2021-12-12 13:55:43 +00:00
CheckInt16(1);
2021-12-15 06:54:54 +00:00
CheckBinary("localhost:9041", TSDB_EP_LEN);
2021-12-12 13:55:43 +00:00
CheckInt16(0);
2021-12-29 13:03:08 +00:00
CheckInt16(16);
2021-12-12 13:55:43 +00:00
CheckBinary("ready", 10);
CheckTimestamp();
CheckBinary("", 24);
2021-12-12 06:46:31 +00:00
}
2021-12-15 08:56:56 +00:00
TEST_F(DndTestDnode, 02_ConfigDnode) {
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SCfgDnodeMsg);
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen);
2021-12-13 07:35:33 +00:00
pReq->dnodeId = htonl(1);
strcpy(pReq->config, "ddebugflag 131");
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen);
2021-12-13 07:35:33 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
2021-12-16 10:04:07 +00:00
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
2021-12-16 06:02:39 +00:00
{
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SCreateDnodeMsg);
2021-12-12 06:46:31 +00:00
2021-12-22 10:39:32 +00:00
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
2021-12-28 05:43:11 +00:00
strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9042);
2021-12-12 06:46:31 +00:00
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
2021-12-16 06:02:39 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
2021-12-12 06:46:31 +00:00
2021-12-12 13:55:43 +00:00
taosMsleep(1300);
2021-12-22 10:39:32 +00:00
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-12 13:55:43 +00:00
CheckInt16(1);
CheckInt16(2);
2021-12-15 06:54:54 +00:00
CheckBinary("localhost:9041", TSDB_EP_LEN);
CheckBinary("localhost:9042", TSDB_EP_LEN);
2021-12-12 13:55:43 +00:00
CheckInt16(0);
CheckInt16(0);
2021-12-29 13:03:08 +00:00
CheckInt16(16);
CheckInt16(16);
2021-12-12 13:55:43 +00:00
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckTimestamp();
CheckTimestamp();
CheckBinary("", 24);
CheckBinary("", 24);
2021-12-12 06:46:31 +00:00
2021-12-16 06:02:39 +00:00
{
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SDropDnodeMsg);
2021-12-12 06:46:31 +00:00
2021-12-22 10:39:32 +00:00
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
2021-12-12 06:46:31 +00:00
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen);
2021-12-16 06:02:39 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
2021-12-12 06:46:31 +00:00
2021-12-22 10:39:32 +00:00
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 1);
2021-12-13 06:48:10 +00:00
CheckInt16(1);
2021-12-15 06:54:54 +00:00
CheckBinary("localhost:9041", TSDB_EP_LEN);
2021-12-13 06:48:10 +00:00
CheckInt16(0);
2021-12-29 13:03:08 +00:00
CheckInt16(16);
2021-12-13 06:48:10 +00:00
CheckBinary("ready", 10);
CheckTimestamp();
CheckBinary("", 24);
2021-12-12 06:46:31 +00:00
2021-12-13 06:48:10 +00:00
{
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SCreateDnodeMsg);
2021-12-13 06:48:10 +00:00
2021-12-22 10:39:32 +00:00
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
2021-12-28 05:43:11 +00:00
strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9043);
2021-12-13 06:48:10 +00:00
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
2021-12-13 06:48:10 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
2021-12-12 06:46:31 +00:00
{
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SCreateDnodeMsg);
2021-12-13 06:48:10 +00:00
2021-12-22 10:39:32 +00:00
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
2021-12-28 05:43:11 +00:00
strcpy(pReq->fqdn, "localhost");
2021-12-28 09:38:15 +00:00
pReq->port = htonl(9044);
2021-12-13 06:48:10 +00:00
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
2021-12-13 06:48:10 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
2021-12-12 06:46:31 +00:00
2021-12-13 06:48:10 +00:00
{
2021-12-22 10:39:32 +00:00
int32_t contLen = sizeof(SCreateDnodeMsg);
2021-12-13 06:48:10 +00:00
2021-12-22 10:39:32 +00:00
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
2021-12-28 05:43:11 +00:00
strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9045);
2021-12-13 06:48:10 +00:00
2021-12-24 07:00:51 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
2021-12-13 06:48:10 +00:00
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
2021-12-12 06:46:31 +00:00
}
2021-12-13 06:48:10 +00:00
taosMsleep(1300);
2021-12-22 10:39:32 +00:00
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 4);
2021-12-13 06:48:10 +00:00
CheckInt16(1);
CheckInt16(3);
CheckInt16(4);
CheckInt16(5);
2021-12-15 06:54:54 +00:00
CheckBinary("localhost:9041", TSDB_EP_LEN);
CheckBinary("localhost:9043", TSDB_EP_LEN);
CheckBinary("localhost:9044", TSDB_EP_LEN);
CheckBinary("localhost:9045", TSDB_EP_LEN);
2021-12-13 06:48:10 +00:00
CheckInt16(0);
CheckInt16(0);
CheckInt16(0);
CheckInt16(0);
2021-12-29 13:03:08 +00:00
CheckInt16(16);
CheckInt16(16);
CheckInt16(16);
CheckInt16(16);
2021-12-13 06:48:10 +00:00
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckBinary("", 24);
CheckBinary("", 24);
CheckBinary("", 24);
CheckBinary("", 24);
2021-12-13 09:06:04 +00:00
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);
2021-12-22 10:39:32 +00:00
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 4);
2021-12-14 10:07:29 +00:00
CheckInt16(1);
CheckInt16(3);
CheckInt16(4);
CheckInt16(5);
2021-12-15 06:54:54 +00:00
CheckBinary("localhost:9041", TSDB_EP_LEN);
CheckBinary("localhost:9043", TSDB_EP_LEN);
CheckBinary("localhost:9044", TSDB_EP_LEN);
CheckBinary("localhost:9045", TSDB_EP_LEN);
2021-12-14 10:07:29 +00:00
CheckInt16(0);
CheckInt16(0);
CheckInt16(0);
CheckInt16(0);
2021-12-29 13:03:08 +00:00
CheckInt16(16);
CheckInt16(16);
CheckInt16(16);
CheckInt16(16);
2021-12-14 10:07:29 +00:00
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckBinary("ready", 10);
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckBinary("", 24);
CheckBinary("", 24);
CheckBinary("", 24);
CheckBinary("", 24);
2021-12-13 09:06:04 +00:00
}