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

154 lines
3.9 KiB
C++
Raw Normal View History

2021-12-29 12:42:52 +00:00
/**
2022-01-04 12:18:09 +00:00
* @file bnode.cpp
2021-12-29 12:42:52 +00:00
* @author slguan (slguan@taosdata.com)
2022-01-04 12:18:09 +00:00
* @brief MNODE module bnode tests
* @version 1.0
* @date 2022-01-05
2021-12-29 12:42:52 +00:00
*
2022-01-04 12:18:09 +00:00
* @copyright Copyright (c) 2022
2021-12-29 12:42:52 +00:00
*
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-29 12:42:52 +00:00
2022-01-04 12:36:54 +00:00
class MndTestBnode : public ::testing::Test {
2021-12-29 12:42:52 +00:00
public:
void SetUp() override {}
void TearDown() override {}
public:
static void SetUpTestSuite() {
2022-01-04 12:18:09 +00:00
test.Init("/tmp/mnode_test_bnode1", 9018);
2021-12-29 12:42:52 +00:00
const char* fqdn = "localhost";
2022-01-04 12:18:09 +00:00
const char* firstEp = "localhost:9018";
2021-12-29 12:42:52 +00:00
2022-01-04 12:18:09 +00:00
server2.Start("/tmp/mnode_test_bnode2", fqdn, 9019, firstEp);
2021-12-29 12:42:52 +00:00
taosMsleep(300);
}
static void TearDownTestSuite() {
server2.Stop();
test.Cleanup();
}
static Testbase test;
static TestServer server2;
};
2022-01-04 12:36:54 +00:00
Testbase MndTestBnode::test;
TestServer MndTestBnode::server2;
2021-12-29 12:42:52 +00:00
2022-01-04 12:36:54 +00:00
TEST_F(MndTestBnode, 01_Show_Bnode) {
2021-12-29 12:42:52 +00:00
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
CHECK_META("show bnodes", 3);
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_TIMESTAMP, 8, "create_time");
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 0);
}
2022-01-04 12:36:54 +00:00
TEST_F(MndTestBnode, 02_Create_Bnode_Invalid_Id) {
2021-12-29 12:42:52 +00:00
{
int32_t contLen = sizeof(SMCreateBnodeMsg);
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
CHECK_META("show bnodes", 3);
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_TIMESTAMP, 8, "create_time");
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1);
2022-01-04 12:18:09 +00:00
CheckBinary("localhost:9018", TSDB_EP_LEN);
2021-12-29 12:42:52 +00:00
CheckTimestamp();
}
}
2022-01-04 12:36:54 +00:00
TEST_F(MndTestBnode, 03_Create_Bnode_Invalid_Id) {
2021-12-29 12:42:52 +00:00
{
int32_t contLen = sizeof(SMCreateBnodeMsg);
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
}
}
2022-01-04 12:36:54 +00:00
TEST_F(MndTestBnode, 04_Create_Bnode) {
2021-12-29 12:42:52 +00:00
{
// create dnode
int32_t contLen = sizeof(SCreateDnodeMsg);
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
strcpy(pReq->fqdn, "localhost");
2022-01-04 12:18:09 +00:00
pReq->port = htonl(9019);
2021-12-29 12:42:52 +00:00
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
taosMsleep(1300);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 2);
}
{
// create bnode
int32_t contLen = sizeof(SMCreateBnodeMsg);
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 2);
CheckInt16(1);
CheckInt16(2);
2022-01-04 12:18:09 +00:00
CheckBinary("localhost:9018", TSDB_EP_LEN);
CheckBinary("localhost:9019", TSDB_EP_LEN);
2021-12-29 12:42:52 +00:00
CheckTimestamp();
CheckTimestamp();
}
{
// drop bnode
int32_t contLen = sizeof(SMDropBnodeMsg);
SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1);
2022-01-04 12:18:09 +00:00
CheckBinary("localhost:9018", TSDB_EP_LEN);
2021-12-29 12:42:52 +00:00
CheckTimestamp();
}
}