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

170 lines
5 KiB
C++
Raw Normal View History

2021-12-16 09:07:40 +00:00
/**
2021-12-16 12:16:35 +00:00
* @file cluster.cpp
2021-12-16 09:07:40 +00:00
* @author slguan (slguan@taosdata.com)
* @brief DNODE module cluster-msg tests
* @version 0.1
* @date 2021-12-15
2021-12-06 10:21:14 +00:00
*
2021-12-16 09:07:40 +00:00
* @copyright Copyright (c) 2021
2021-12-06 10:21:14 +00:00
*
*/
#include "deploy.h"
class DndTestCluster : public ::testing::Test {
protected:
2021-12-16 10:35:28 +00:00
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
SServer* pServer = createServer(path, fqdn, port, firstEp);
ASSERT(pServer);
return pServer;
}
2021-12-06 10:21:14 +00:00
static void SetUpTestSuite() {
2021-12-16 10:35:28 +00:00
initLog("/tmp/tdlog");
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
const char* fqdn = "localhost";
const char* firstEp = "localhost:9030";
pServer = CreateServer("/tmp/dnode_test_cluster", fqdn, 9030, firstEp);
pClient = createClient("root", "taosdata", fqdn, 9030);
taosMsleep(1100);
2021-12-06 10:21:14 +00:00
}
static void TearDownTestSuite() {
2021-12-13 09:06:04 +00:00
stopServer(pServer);
2021-12-06 10:21:14 +00:00
dropClient(pClient);
2021-12-16 10:35:28 +00:00
pServer = NULL;
pClient = NULL;
2021-12-06 10:21:14 +00:00
}
static SServer* pServer;
static SClient* pClient;
static int32_t connId;
2021-12-16 10:35:28 +00:00
public:
void SetUp() override {}
void TearDown() override {}
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
pShow->type = showType;
if (db != NULL) {
strcpy(pShow->db, db);
}
SRpcMsg showRpcMsg = {0};
showRpcMsg.pCont = pShow;
showRpcMsg.contLen = sizeof(SShowMsg);
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
sendMsg(pClient, &showRpcMsg);
ASSERT_NE(pClient->pRsp, nullptr);
ASSERT_EQ(pClient->pRsp->code, 0);
ASSERT_NE(pClient->pRsp->pCont, nullptr);
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
ASSERT_NE(pShowRsp, nullptr);
pShowRsp->showId = htonl(pShowRsp->showId);
pMeta = &pShowRsp->tableMeta;
pMeta->numOfTags = htonl(pMeta->numOfTags);
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
pMeta->sversion = htonl(pMeta->sversion);
pMeta->tversion = htonl(pMeta->tversion);
pMeta->tuid = htobe64(pMeta->tuid);
2021-12-06 10:21:14 +00:00
pMeta->suid = htobe64(pMeta->suid);
2021-12-16 10:35:28 +00:00
showId = pShowRsp->showId;
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
EXPECT_NE(pShowRsp->showId, 0);
EXPECT_STREQ(pMeta->tbFname, showName);
2021-12-06 10:21:14 +00:00
EXPECT_EQ(pMeta->numOfTags, 0);
2021-12-16 10:35:28 +00:00
EXPECT_EQ(pMeta->numOfColumns, columns);
2021-12-06 10:21:14 +00:00
EXPECT_EQ(pMeta->precision, 0);
EXPECT_EQ(pMeta->tableType, 0);
2021-12-16 10:35:28 +00:00
EXPECT_EQ(pMeta->update, 0);
2021-12-06 10:21:14 +00:00
EXPECT_EQ(pMeta->sversion, 0);
EXPECT_EQ(pMeta->tversion, 0);
2021-12-16 10:35:28 +00:00
EXPECT_EQ(pMeta->tuid, 0);
2021-12-06 10:21:14 +00:00
EXPECT_EQ(pMeta->suid, 0);
2021-12-16 10:35:28 +00:00
}
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
SSchema* pSchema = &pMeta->pSchema[index];
2021-12-17 06:20:32 +00:00
pSchema->bytes = htonl(pSchema->bytes);
2021-12-06 10:21:14 +00:00
EXPECT_EQ(pSchema->colId, 0);
2021-12-16 10:35:28 +00:00
EXPECT_EQ(pSchema->type, type);
EXPECT_EQ(pSchema->bytes, bytes);
EXPECT_STREQ(pSchema->name, name);
}
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
void SendThenCheckShowRetrieveMsg(int32_t rows) {
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
pRetrieve->showId = htonl(showId);
pRetrieve->free = 0;
SRpcMsg retrieveRpcMsg = {0};
retrieveRpcMsg.pCont = pRetrieve;
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
sendMsg(pClient, &retrieveRpcMsg);
ASSERT_NE(pClient->pRsp, nullptr);
ASSERT_EQ(pClient->pRsp->code, 0);
ASSERT_NE(pClient->pRsp->pCont, nullptr);
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
ASSERT_NE(pRetrieveRsp, nullptr);
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
EXPECT_EQ(pRetrieveRsp->useconds, 0);
// EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRetrieveRsp->compressed, 0);
EXPECT_EQ(pRetrieveRsp->compLen, 0);
pData = pRetrieveRsp->data;
pos = 0;
2021-12-06 10:21:14 +00:00
}
2021-12-16 10:35:28 +00:00
void CheckInt32() {
int32_t data = *((int32_t*)(pData + pos));
2021-12-06 10:21:14 +00:00
pos += sizeof(int32_t);
2021-12-16 10:35:28 +00:00
EXPECT_GT(data, 0);
}
void CheckTimestamp() {
int64_t data = *((int64_t*)(pData + pos));
pos += sizeof(int64_t);
EXPECT_GT(data, 0);
}
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
void CheckBinary(int32_t len) {
2021-12-06 10:21:14 +00:00
pos += sizeof(VarDataLenT);
2021-12-16 10:35:28 +00:00
char* data = (char*)(pData + pos);
pos += len;
}
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
int32_t showId;
STableMetaMsg* pMeta;
SRetrieveTableRsp* pRetrieveRsp;
char* pData;
int32_t pos;
};
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
SServer* DndTestCluster::pServer;
SClient* DndTestCluster::pClient;
int32_t DndTestCluster::connId;
2021-12-06 10:21:14 +00:00
2021-12-16 10:35:28 +00:00
TEST_F(DndTestCluster, 01_ShowCluster) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "show cluster", 3, NULL);
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "id");
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
2021-12-17 06:20:32 +00:00
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
2021-12-16 10:35:28 +00:00
SendThenCheckShowRetrieveMsg(1);
CheckInt32();
CheckBinary(TSDB_CLUSTER_ID_LEN);
CheckTimestamp();
2021-12-06 10:21:14 +00:00
}