TD-10431 refact dnode test
This commit is contained in:
parent
a628054f51
commit
5b08678f30
|
@ -5,16 +5,16 @@ add_subdirectory(acct)
|
||||||
# add_subdirectory(balance)
|
# add_subdirectory(balance)
|
||||||
add_subdirectory(cluster)
|
add_subdirectory(cluster)
|
||||||
add_subdirectory(db)
|
add_subdirectory(db)
|
||||||
#add_subdirectory(dnode)
|
add_subdirectory(dnode)
|
||||||
# add_subdirectory(func)
|
# add_subdirectory(func)
|
||||||
# add_subdirectory(mnode)
|
# add_subdirectory(mnode)
|
||||||
#add_subdirectory(profile)
|
add_subdirectory(profile)
|
||||||
add_subdirectory(show)
|
add_subdirectory(show)
|
||||||
#add_subdirectory(stb)
|
add_subdirectory(stb)
|
||||||
# add_subdirectory(sync)
|
# add_subdirectory(sync)
|
||||||
# add_subdirectory(telem)
|
# add_subdirectory(telem)
|
||||||
# add_subdirectory(trans)
|
# add_subdirectory(trans)
|
||||||
#add_subdirectory(user)
|
add_subdirectory(user)
|
||||||
#add_subdirectory(vgroup)
|
add_subdirectory(vgroup)
|
||||||
|
|
||||||
add_subdirectory(sut)
|
add_subdirectory(sut)
|
||||||
|
|
|
@ -1,24 +1,8 @@
|
||||||
add_executable(dnode_test_dnode "")
|
aux_source_directory(. DTEST_SRC)
|
||||||
|
add_executable(dnode_test_dnode ${DTEST_SRC})
|
||||||
target_sources(dnode_test_dnode
|
|
||||||
PRIVATE
|
|
||||||
"dnode.cpp"
|
|
||||||
"../sut/deploy.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode_test_dnode
|
dnode_test_dnode
|
||||||
PUBLIC dnode
|
PUBLIC sut
|
||||||
PUBLIC util
|
|
||||||
PUBLIC os
|
|
||||||
PUBLIC gtest_main
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(dnode_test_dnode
|
|
||||||
PUBLIC
|
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -9,189 +9,62 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deploy.h"
|
#include "base.h"
|
||||||
|
|
||||||
class DndTestDnode : public ::testing::Test {
|
class DndTestDnode : public ::testing::Test {
|
||||||
public:
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetUpTestSuite() {
|
|
||||||
initLog("/tmp/tdlog");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9041";
|
|
||||||
pServer1 = CreateServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
|
||||||
pServer2 = CreateServer("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
|
||||||
pServer3 = CreateServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
|
||||||
pServer4 = CreateServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
|
||||||
pServer5 = CreateServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
|
||||||
pClient = createClient("root", "taosdata", fqdn, 9041);
|
|
||||||
taosMsleep(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
|
||||||
stopServer(pServer1);
|
|
||||||
stopServer(pServer2);
|
|
||||||
stopServer(pServer3);
|
|
||||||
stopServer(pServer4);
|
|
||||||
stopServer(pServer5);
|
|
||||||
dropClient(pClient);
|
|
||||||
pServer1 = NULL;
|
|
||||||
pServer2 = NULL;
|
|
||||||
pServer3 = NULL;
|
|
||||||
pServer4 = NULL;
|
|
||||||
pServer5 = NULL;
|
|
||||||
pClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SServer* pServer1;
|
|
||||||
static SServer* pServer2;
|
|
||||||
static SServer* pServer3;
|
|
||||||
static SServer* pServer4;
|
|
||||||
static SServer* pServer5;
|
|
||||||
static SClient* pClient;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
void TearDown() override {}
|
void TearDown() override {}
|
||||||
|
|
||||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
public:
|
||||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
static void SetUpTestSuite() {
|
||||||
pShow->type = showType;
|
test.Init("/tmp/dnode_test_dnode1", 9041);
|
||||||
strcpy(pShow->db, "");
|
const char* fqdn = "localhost";
|
||||||
|
const char* firstEp = "localhost:9041";
|
||||||
|
|
||||||
SRpcMsg showRpcMsg = {0};
|
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||||
showRpcMsg.pCont = pShow;
|
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||||
|
taosMsleep(300);
|
||||||
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);
|
|
||||||
pMeta->suid = htobe64(pMeta->suid);
|
|
||||||
|
|
||||||
showId = pShowRsp->showId;
|
|
||||||
|
|
||||||
EXPECT_NE(pShowRsp->showId, 0);
|
|
||||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
||||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
||||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
||||||
EXPECT_EQ(pMeta->precision, 0);
|
|
||||||
EXPECT_EQ(pMeta->tableType, 0);
|
|
||||||
EXPECT_EQ(pMeta->update, 0);
|
|
||||||
EXPECT_EQ(pMeta->sversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tuid, 0);
|
|
||||||
EXPECT_EQ(pMeta->suid, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
static void TearDownTestSuite() {
|
||||||
SSchema* pSchema = &pMeta->pSchema[index];
|
server2.Stop();
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
server3.Stop();
|
||||||
EXPECT_EQ(pSchema->colId, 0);
|
server4.Stop();
|
||||||
EXPECT_EQ(pSchema->type, type);
|
server5.Stop();
|
||||||
EXPECT_EQ(pSchema->bytes, bytes);
|
test.Cleanup();
|
||||||
EXPECT_STREQ(pSchema->name, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
static Testbase test;
|
||||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
static TestServer server2;
|
||||||
pRetrieve->showId = htonl(showId);
|
static TestServer server3;
|
||||||
pRetrieve->free = 0;
|
static TestServer server4;
|
||||||
|
static TestServer server5;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt16(int16_t val) {
|
|
||||||
int16_t data = *((int16_t*)(pData + pos));
|
|
||||||
pos += sizeof(int16_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt64(int64_t val) {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckTimestamp() {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_GT(data, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBinary(const char* val, int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
EXPECT_STREQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t showId;
|
|
||||||
STableMetaMsg* pMeta;
|
|
||||||
SRetrieveTableRsp* pRetrieveRsp;
|
|
||||||
char* pData;
|
|
||||||
int32_t pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SServer* DndTestDnode::pServer1;
|
Testbase DndTestDnode::test;
|
||||||
SServer* DndTestDnode::pServer2;
|
TestServer DndTestDnode::server2;
|
||||||
SServer* DndTestDnode::pServer3;
|
TestServer DndTestDnode::server3;
|
||||||
SServer* DndTestDnode::pServer4;
|
TestServer DndTestDnode::server4;
|
||||||
SServer* DndTestDnode::pServer5;
|
TestServer DndTestDnode::server5;
|
||||||
SClient* DndTestDnode::pClient;
|
|
||||||
|
|
||||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
CHECK_META("show dnodes", 7);
|
||||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
|
||||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
||||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
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");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
|
@ -202,40 +75,36 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
||||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg));
|
int32_t contLen = sizeof(SCfgDnodeMsg);
|
||||||
|
|
||||||
|
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(1);
|
pReq->dnodeId = htonl(1);
|
||||||
strcpy(pReq->config, "ddebugflag 131");
|
strcpy(pReq->config, "ddebugflag 131");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONFIG_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCfgDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONFIG_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
{
|
{
|
||||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->ep, "localhost:9042");
|
strcpy(pReq->ep, "localhost:9042");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMsleep(1300);
|
taosMsleep(1300);
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
|
||||||
SendThenCheckShowRetrieveMsg(2);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
|
CHECK_META("show dnodes", 7);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckInt16(2);
|
CheckInt16(2);
|
||||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||||
|
@ -252,22 +121,21 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckBinary("", 24);
|
CheckBinary("", 24);
|
||||||
|
|
||||||
{
|
{
|
||||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
|
int32_t contLen = sizeof(SDropDnodeMsg);
|
||||||
|
|
||||||
|
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(2);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SDropDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
CHECK_META("show dnodes", 7);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
|
@ -277,53 +145,44 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckBinary("", 24);
|
CheckBinary("", 24);
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->ep, "localhost:9043");
|
strcpy(pReq->ep, "localhost:9043");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->ep, "localhost:9044");
|
strcpy(pReq->ep, "localhost:9044");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->ep, "localhost:9045");
|
strcpy(pReq->ep, "localhost:9045");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMsleep(1300);
|
taosMsleep(1300);
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
SendThenCheckShowRetrieveMsg(4);
|
CHECK_META("show dnodes", 7);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 4);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckInt16(3);
|
CheckInt16(3);
|
||||||
CheckInt16(4);
|
CheckInt16(4);
|
||||||
|
@ -355,31 +214,18 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
|
|
||||||
// restart
|
// restart
|
||||||
uInfo("stop all server");
|
uInfo("stop all server");
|
||||||
stopServer(pServer1);
|
test.Restart();
|
||||||
stopServer(pServer2);
|
server2.Restart();
|
||||||
stopServer(pServer3);
|
server3.Restart();
|
||||||
stopServer(pServer4);
|
server4.Restart();
|
||||||
stopServer(pServer5);
|
server5.Restart();
|
||||||
pServer1 = NULL;
|
|
||||||
pServer2 = NULL;
|
|
||||||
pServer3 = NULL;
|
|
||||||
pServer4 = NULL;
|
|
||||||
pServer5 = NULL;
|
|
||||||
|
|
||||||
uInfo("start all server");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9041";
|
|
||||||
pServer1 = startServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
|
||||||
pServer3 = startServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
|
||||||
pServer4 = startServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
|
||||||
pServer5 = startServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
|
||||||
|
|
||||||
uInfo("all server is running");
|
|
||||||
|
|
||||||
taosMsleep(1300);
|
taosMsleep(1300);
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
SendThenCheckShowRetrieveMsg(4);
|
CHECK_META("show dnodes", 7);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 4);
|
||||||
|
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckInt16(3);
|
CheckInt16(3);
|
||||||
CheckInt16(4);
|
CheckInt16(4);
|
||||||
|
|
|
@ -1,24 +1,8 @@
|
||||||
add_executable(dnode_test_profile "")
|
aux_source_directory(. PROFILE_SRC)
|
||||||
|
add_executable(dnode_test_profile ${PROFILE_SRC})
|
||||||
target_sources(dnode_test_profile
|
|
||||||
PRIVATE
|
|
||||||
"profile.cpp"
|
|
||||||
"../sut/deploy.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode_test_profile
|
dnode_test_profile
|
||||||
PUBLIC dnode
|
PUBLIC sut
|
||||||
PUBLIC util
|
|
||||||
PUBLIC os
|
|
||||||
PUBLIC gtest_main
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(dnode_test_profile
|
|
||||||
PUBLIC
|
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -9,188 +9,35 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deploy.h"
|
#include "base.h"
|
||||||
|
|
||||||
class DndTestProfile : public ::testing::Test {
|
class DndTestProfile : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_profile", 9080); }
|
||||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
static void TearDownTestSuite() { test.Cleanup(); }
|
||||||
ASSERT(pServer);
|
|
||||||
return pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetUpTestSuite() {
|
static Testbase test;
|
||||||
initLog("/tmp/tdlog");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9080";
|
|
||||||
pServer = CreateServer("/tmp/dnode_test_profile", fqdn, 9080, firstEp);
|
|
||||||
pClient = createClient("root", "taosdata", fqdn, 9080);
|
|
||||||
taosMsleep(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
|
||||||
stopServer(pServer);
|
|
||||||
dropClient(pClient);
|
|
||||||
pServer = NULL;
|
|
||||||
pClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SServer* pServer;
|
|
||||||
static SClient* pClient;
|
|
||||||
static int32_t connId;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
void TearDown() override {}
|
void TearDown() override {}
|
||||||
|
|
||||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
int32_t connId;
|
||||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
||||||
pShow->type = showType;
|
|
||||||
strcpy(pShow->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);
|
|
||||||
pMeta->suid = htobe64(pMeta->suid);
|
|
||||||
|
|
||||||
showId = pShowRsp->showId;
|
|
||||||
|
|
||||||
EXPECT_NE(pShowRsp->showId, 0);
|
|
||||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
||||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
||||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
||||||
EXPECT_EQ(pMeta->precision, 0);
|
|
||||||
EXPECT_EQ(pMeta->tableType, 0);
|
|
||||||
EXPECT_EQ(pMeta->update, 0);
|
|
||||||
EXPECT_EQ(pMeta->sversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tuid, 0);
|
|
||||||
EXPECT_EQ(pMeta->suid, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
|
||||||
SSchema* pSchema = &pMeta->pSchema[index];
|
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
|
||||||
EXPECT_EQ(pSchema->colId, 0);
|
|
||||||
EXPECT_EQ(pSchema->type, type);
|
|
||||||
EXPECT_EQ(pSchema->bytes, bytes);
|
|
||||||
EXPECT_STREQ(pSchema->name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt16(int16_t val) {
|
|
||||||
int16_t data = *((int16_t*)(pData + pos));
|
|
||||||
pos += sizeof(int16_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt32(int32_t val) {
|
|
||||||
int32_t data = *((int32_t*)(pData + pos));
|
|
||||||
pos += sizeof(int32_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt64(int64_t val) {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckTimestamp() {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_GT(data, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBinary(const char* val, int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
EXPECT_STREQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IgnoreBinary(int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t showId;
|
|
||||||
STableMetaMsg* pMeta;
|
|
||||||
SRetrieveTableRsp* pRetrieveRsp;
|
|
||||||
char* pData;
|
|
||||||
int32_t pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SServer* DndTestProfile::pServer;
|
Testbase DndTestProfile::test;
|
||||||
SClient* DndTestProfile::pClient;
|
|
||||||
int32_t DndTestProfile::connId;
|
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 01_ConnectMsg) {
|
TEST_F(DndTestProfile, 01_ConnectMsg) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
int32_t contLen = sizeof(SConnectMsg);
|
||||||
|
|
||||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
strcpy(pReq->db, "");
|
strcpy(pReq->db, "");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -213,37 +60,32 @@ TEST_F(DndTestProfile, 01_ConnectMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
int32_t contLen = sizeof(SConnectMsg);
|
||||||
|
|
||||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
strcpy(pReq->db, "invalid_db");
|
strcpy(pReq->db, "invalid_db");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB);
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB);
|
||||||
ASSERT_EQ(pMsg->contLen, 0);
|
ASSERT_EQ(pMsg->contLen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "show connections", 7);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "");
|
||||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "connId");
|
CHECK_META("show connections", 7);
|
||||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId");
|
||||||
CheckSchema(2, TSDB_DATA_TYPE_BINARY, TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, "program");
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
||||||
CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "pid");
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, "program");
|
||||||
CheckSchema(4, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "pid");
|
||||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
|
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
||||||
CheckSchema(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");
|
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
|
||||||
|
CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
CheckInt32(1);
|
CheckInt32(1);
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN);
|
CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN);
|
||||||
|
@ -254,23 +96,18 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||||
|
|
||||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(connId);
|
pReq->connId = htonl(connId);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
pReq->numOfQueries = htonl(0);
|
pReq->numOfQueries = htonl(0);
|
||||||
pReq->numOfStreams = htonl(0);
|
pReq->numOfStreams = htonl(0);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -295,57 +132,44 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 05_KillConnMsg) {
|
TEST_F(DndTestProfile, 05_KillConnMsg) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
|
int32_t contLen = sizeof(SKillConnMsg);
|
||||||
|
|
||||||
|
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(connId);
|
pReq->connId = htonl(connId);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SKillConnMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||||
|
|
||||||
|
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(connId);
|
pReq->connId = htonl(connId);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
pReq->numOfQueries = htonl(0);
|
pReq->numOfQueries = htonl(0);
|
||||||
pReq->numOfStreams = htonl(0);
|
pReq->numOfStreams = htonl(0);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION);
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION);
|
||||||
ASSERT_EQ(pMsg->contLen, 0);
|
ASSERT_EQ(pMsg->contLen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
int32_t contLen = sizeof(SConnectMsg);
|
||||||
|
|
||||||
|
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
strcpy(pReq->db, "");
|
strcpy(pReq->db, "");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -369,58 +193,43 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
int32_t contLen = sizeof(SKillConnMsg);
|
||||||
|
|
||||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
|
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(2345);
|
pReq->connId = htonl(2345);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SKillConnMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
|
int32_t contLen = sizeof(SKillQueryMsg);
|
||||||
|
|
||||||
|
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(connId);
|
pReq->connId = htonl(connId);
|
||||||
pReq->queryId = htonl(1234);
|
pReq->queryId = htonl(1234);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SKillQueryMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
ASSERT_EQ(pMsg->contLen, 0);
|
ASSERT_EQ(pMsg->contLen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||||
|
|
||||||
|
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(connId);
|
pReq->connId = htonl(connId);
|
||||||
pReq->pid = htonl(1234);
|
pReq->pid = htonl(1234);
|
||||||
pReq->numOfQueries = htonl(0);
|
pReq->numOfQueries = htonl(0);
|
||||||
pReq->numOfStreams = htonl(0);
|
pReq->numOfStreams = htonl(0);
|
||||||
strcpy(pReq->app, "dnode_test_profile");
|
strcpy(pReq->app, "dnode_test_profile");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
|
@ -446,39 +255,36 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
||||||
ASSERT_NE(pClient, nullptr);
|
int32_t contLen = sizeof(SKillQueryMsg);
|
||||||
|
|
||||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
|
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||||
pReq->connId = htonl(2345);
|
pReq->connId = htonl(2345);
|
||||||
pReq->queryId = htonl(1234);
|
pReq->queryId = htonl(1234);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SKillQueryMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, "show queries", 14);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, "");
|
||||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "queryId");
|
CHECK_META("show queries", 14);
|
||||||
CheckSchema(1, TSDB_DATA_TYPE_INT, 4, "connId");
|
|
||||||
CheckSchema(2, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
|
||||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
|
||||||
CheckSchema(4, TSDB_DATA_TYPE_BINARY, 22 + VARSTR_HEADER_SIZE, "qid");
|
|
||||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "created_time");
|
|
||||||
CheckSchema(6, TSDB_DATA_TYPE_BIGINT, 8, "time");
|
|
||||||
CheckSchema(7, TSDB_DATA_TYPE_BINARY, 18 + VARSTR_HEADER_SIZE, "sql_obj_id");
|
|
||||||
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "pid");
|
|
||||||
CheckSchema(9, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "ep");
|
|
||||||
CheckSchema(10, TSDB_DATA_TYPE_BOOL, 1, "stable_query");
|
|
||||||
CheckSchema(11, TSDB_DATA_TYPE_INT, 4, "sub_queries");
|
|
||||||
CheckSchema(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info");
|
|
||||||
CheckSchema(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql");
|
|
||||||
|
|
||||||
SendThenCheckShowRetrieveMsg(0);
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "connId");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
||||||
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
||||||
|
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 22 + VARSTR_HEADER_SIZE, "qid");
|
||||||
|
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "created_time");
|
||||||
|
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BIGINT, 8, "time");
|
||||||
|
CHECK_SCHEMA(7, TSDB_DATA_TYPE_BINARY, 18 + VARSTR_HEADER_SIZE, "sql_obj_id");
|
||||||
|
CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "pid");
|
||||||
|
CHECK_SCHEMA(9, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "ep");
|
||||||
|
CHECK_SCHEMA(10, TSDB_DATA_TYPE_BOOL, 1, "stable_query");
|
||||||
|
CHECK_SCHEMA(11, TSDB_DATA_TYPE_INT, 4, "sub_queries");
|
||||||
|
CHECK_SCHEMA(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info");
|
||||||
|
CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,8 @@
|
||||||
add_executable(dnode_test_stb "")
|
aux_source_directory(. STB_SRC)
|
||||||
|
add_executable(dnode_test_stb ${STB_SRC})
|
||||||
target_sources(dnode_test_stb
|
|
||||||
PRIVATE
|
|
||||||
"stb.cpp"
|
|
||||||
"../sut/deploy.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode_test_stb
|
dnode_test_stb
|
||||||
PUBLIC dnode
|
PUBLIC sut
|
||||||
PUBLIC util
|
|
||||||
PUBLIC os
|
|
||||||
PUBLIC gtest_main
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(dnode_test_stb
|
|
||||||
PUBLIC
|
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -9,176 +9,27 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deploy.h"
|
#include "base.h"
|
||||||
|
|
||||||
class DndTestStb : public ::testing::Test {
|
class DndTestStb : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_stb", 9101); }
|
||||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
static void TearDownTestSuite() { test.Cleanup(); }
|
||||||
ASSERT(pServer);
|
|
||||||
return pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetUpTestSuite() {
|
static Testbase test;
|
||||||
initLog("/tmp/tdlog");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9101";
|
|
||||||
pServer = CreateServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
|
||||||
pClient = createClient("root", "taosdata", fqdn, 9101);
|
|
||||||
taosMsleep(1100);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
|
||||||
stopServer(pServer);
|
|
||||||
dropClient(pClient);
|
|
||||||
pServer = NULL;
|
|
||||||
pClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SServer* pServer;
|
|
||||||
static SClient* pClient;
|
|
||||||
static int32_t connId;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
void TearDown() override {}
|
void TearDown() override {}
|
||||||
|
|
||||||
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);
|
|
||||||
pMeta->suid = htobe64(pMeta->suid);
|
|
||||||
|
|
||||||
showId = pShowRsp->showId;
|
|
||||||
|
|
||||||
EXPECT_NE(pShowRsp->showId, 0);
|
|
||||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
||||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
||||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
||||||
EXPECT_EQ(pMeta->precision, 0);
|
|
||||||
EXPECT_EQ(pMeta->tableType, 0);
|
|
||||||
EXPECT_EQ(pMeta->update, 0);
|
|
||||||
EXPECT_EQ(pMeta->sversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tuid, 0);
|
|
||||||
EXPECT_EQ(pMeta->suid, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
|
||||||
SSchema* pSchema = &pMeta->pSchema[index];
|
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
|
||||||
EXPECT_EQ(pSchema->colId, 0);
|
|
||||||
EXPECT_EQ(pSchema->type, type);
|
|
||||||
EXPECT_EQ(pSchema->bytes, bytes);
|
|
||||||
EXPECT_STREQ(pSchema->name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt8(int8_t val) {
|
|
||||||
int8_t data = *((int8_t*)(pData + pos));
|
|
||||||
pos += sizeof(int8_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt16(int16_t val) {
|
|
||||||
int16_t data = *((int16_t*)(pData + pos));
|
|
||||||
pos += sizeof(int16_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt32(int32_t val) {
|
|
||||||
int32_t data = *((int32_t*)(pData + pos));
|
|
||||||
pos += sizeof(int32_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt64(int64_t val) {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckTimestamp() {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_GT(data, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBinary(const char* val, int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
EXPECT_STREQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t showId;
|
|
||||||
STableMetaMsg* pMeta;
|
|
||||||
SRetrieveTableRsp* pRetrieveRsp;
|
|
||||||
char* pData;
|
|
||||||
int32_t pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SServer* DndTestStb::pServer;
|
Testbase DndTestStb::test;
|
||||||
SClient* DndTestStb::pClient;
|
|
||||||
int32_t DndTestStb::connId;
|
|
||||||
|
|
||||||
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
{
|
{
|
||||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
int32_t contLen = sizeof(SCreateDbMsg);
|
||||||
|
|
||||||
|
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->db, "1.d1");
|
strcpy(pReq->db, "1.d1");
|
||||||
pReq->numOfVgroups = htonl(2);
|
pReq->numOfVgroups = htonl(2);
|
||||||
pReq->cacheBlockSize = htonl(16);
|
pReq->cacheBlockSize = htonl(16);
|
||||||
|
@ -200,13 +51,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
pReq->cacheLastRow = 0;
|
pReq->cacheLastRow = 0;
|
||||||
pReq->ignoreExist = 1;
|
pReq->ignoreExist = 1;
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
@ -214,9 +59,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
{
|
{
|
||||||
int32_t cols = 2;
|
int32_t cols = 2;
|
||||||
int32_t tags = 3;
|
int32_t tags = 3;
|
||||||
int32_t size = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
|
int32_t contLen = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
|
||||||
|
|
||||||
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(size);
|
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->name, "1.d1.stb");
|
strcpy(pReq->name, "1.d1.stb");
|
||||||
pReq->numOfTags = htonl(tags);
|
pReq->numOfTags = htonl(tags);
|
||||||
pReq->numOfColumns = htonl(cols);
|
pReq->numOfColumns = htonl(cols);
|
||||||
|
@ -261,24 +106,21 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
strcpy(pSchema->name, "tag3");
|
strcpy(pSchema->name, "tag3");
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_STB, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = size;
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_STB;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
CHECK_META("show stables", 4);
|
||||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
|
||||||
CheckSchema(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
|
||||||
CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
|
||||||
|
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
||||||
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
CheckInt32(2);
|
CheckInt32(2);
|
||||||
|
@ -286,16 +128,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
|
|
||||||
// ----- meta ------
|
// ----- meta ------
|
||||||
{
|
{
|
||||||
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(sizeof(STableInfoMsg));
|
int32_t contLen = sizeof(STableInfoMsg);
|
||||||
|
|
||||||
|
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->tableFname, "1.d1.stb");
|
strcpy(pReq->tableFname, "1.d1.stb");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_TABLE_META, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(STableInfoMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_TABLE_META;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
@ -336,39 +174,31 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// restart
|
// restart
|
||||||
stopServer(pServer);
|
test.Restart();
|
||||||
pServer = NULL;
|
|
||||||
|
|
||||||
uInfo("start all server");
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||||
|
CHECK_META("show stables", 4);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9101";
|
|
||||||
pServer = startServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
|
||||||
|
|
||||||
uInfo("all server is running");
|
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
|
||||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
CheckInt32(2);
|
CheckInt32(2);
|
||||||
CheckInt32(3);
|
CheckInt32(3);
|
||||||
|
|
||||||
{
|
{
|
||||||
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(sizeof(SDropStbMsg));
|
int32_t contLen = sizeof(SDropStbMsg);
|
||||||
|
|
||||||
|
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->name, "1.d1.stb");
|
strcpy(pReq->name, "1.d1.stb");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_STB, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SDropStbMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_STB;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||||
SendThenCheckShowRetrieveMsg(0);
|
CHECK_META("show stables", 4);
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,8 @@
|
||||||
add_executable(dnode_test_user "")
|
aux_source_directory(. USER_SRC)
|
||||||
|
add_executable(dnode_test_user ${USER_SRC})
|
||||||
target_sources(dnode_test_user
|
|
||||||
PRIVATE
|
|
||||||
"user.cpp"
|
|
||||||
"../sut/deploy.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode_test_user
|
dnode_test_user
|
||||||
PUBLIC dnode
|
PUBLIC sut
|
||||||
PUBLIC util
|
|
||||||
PUBLIC os
|
|
||||||
PUBLIC gtest_main
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(dnode_test_user
|
|
||||||
PUBLIC
|
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -9,168 +9,34 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deploy.h"
|
#include "base.h"
|
||||||
|
|
||||||
class DndTestUser : public ::testing::Test {
|
class DndTestUser : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); }
|
||||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
static void TearDownTestSuite() { test.Cleanup(); }
|
||||||
ASSERT(pServer);
|
|
||||||
return pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetUpTestSuite() {
|
static Testbase test;
|
||||||
initLog("/tmp/tdlog");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9140";
|
|
||||||
pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
|
||||||
pClient = createClient("root", "taosdata", fqdn, 9140);
|
|
||||||
taosMsleep(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
|
||||||
stopServer(pServer);
|
|
||||||
dropClient(pClient);
|
|
||||||
pServer = NULL;
|
|
||||||
pClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SServer* pServer;
|
|
||||||
static SClient* pClient;
|
|
||||||
static int32_t connId;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
void TearDown() override {}
|
void TearDown() override {}
|
||||||
|
|
||||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
|
||||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
||||||
pShow->type = showType;
|
|
||||||
strcpy(pShow->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);
|
|
||||||
pMeta->suid = htobe64(pMeta->suid);
|
|
||||||
|
|
||||||
showId = pShowRsp->showId;
|
|
||||||
|
|
||||||
EXPECT_NE(pShowRsp->showId, 0);
|
|
||||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
||||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
||||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
||||||
EXPECT_EQ(pMeta->precision, 0);
|
|
||||||
EXPECT_EQ(pMeta->tableType, 0);
|
|
||||||
EXPECT_EQ(pMeta->update, 0);
|
|
||||||
EXPECT_EQ(pMeta->sversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tuid, 0);
|
|
||||||
EXPECT_EQ(pMeta->suid, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
|
||||||
SSchema* pSchema = &pMeta->pSchema[index];
|
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
|
||||||
EXPECT_EQ(pSchema->colId, 0);
|
|
||||||
EXPECT_EQ(pSchema->type, type);
|
|
||||||
EXPECT_EQ(pSchema->bytes, bytes);
|
|
||||||
EXPECT_STREQ(pSchema->name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt16(int16_t val) {
|
|
||||||
int16_t data = *((int16_t*)(pData + pos));
|
|
||||||
pos += sizeof(int16_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt64(int64_t val) {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckTimestamp() {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_GT(data, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBinary(const char* val, int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
EXPECT_STREQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t showId;
|
|
||||||
STableMetaMsg* pMeta;
|
|
||||||
SRetrieveTableRsp* pRetrieveRsp;
|
|
||||||
char* pData;
|
|
||||||
int32_t pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SServer* DndTestUser::pServer;
|
Testbase DndTestUser::test;
|
||||||
SClient* DndTestUser::pClient;
|
|
||||||
int32_t DndTestUser::connId;
|
|
||||||
|
|
||||||
TEST_F(DndTestUser, 01_ShowUser) {
|
TEST_F(DndTestUser, 01_ShowUser) {
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
CHECK_META("show users", 4);
|
||||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
|
||||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
||||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
SendThenCheckShowRetrieveMsg(1);
|
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("super", 10);
|
CheckBinary("super", 10);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
|
@ -179,39 +45,35 @@ TEST_F(DndTestUser, 01_ShowUser) {
|
||||||
|
|
||||||
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||||
{
|
{
|
||||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
int32_t contLen = sizeof(SCreateUserMsg);
|
||||||
|
|
||||||
|
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->user, "u1");
|
strcpy(pReq->user, "u1");
|
||||||
strcpy(pReq->pass, "p1");
|
strcpy(pReq->pass, "p1");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateUserMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
int32_t contLen = sizeof(SCreateUserMsg);
|
||||||
|
|
||||||
|
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->user, "u2");
|
strcpy(pReq->user, "u2");
|
||||||
strcpy(pReq->pass, "p2");
|
strcpy(pReq->pass, "p2");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateUserMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||||
SendThenCheckShowRetrieveMsg(3);
|
CHECK_META("show users", 4);
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 3);
|
||||||
|
|
||||||
CheckBinary("u1", TSDB_USER_LEN);
|
CheckBinary("u1", TSDB_USER_LEN);
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("u2", TSDB_USER_LEN);
|
CheckBinary("u2", TSDB_USER_LEN);
|
||||||
|
@ -226,22 +88,23 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
|
|
||||||
{
|
{
|
||||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
int32_t contLen = sizeof(SAlterUserMsg);
|
||||||
|
|
||||||
|
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->user, "u1");
|
strcpy(pReq->user, "u1");
|
||||||
strcpy(pReq->pass, "p2");
|
strcpy(pReq->pass, "p2");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_USER, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SAlterUserMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
||||||
SendThenCheckShowRetrieveMsg(3);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||||
|
CHECK_META("show users", 4);
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 3);
|
||||||
|
|
||||||
CheckBinary("u1", TSDB_USER_LEN);
|
CheckBinary("u1", TSDB_USER_LEN);
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("u2", TSDB_USER_LEN);
|
CheckBinary("u2", TSDB_USER_LEN);
|
||||||
|
@ -256,21 +119,22 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
|
|
||||||
{
|
{
|
||||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
int32_t contLen = sizeof(SDropUserMsg);
|
||||||
|
|
||||||
|
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||||
strcpy(pReq->user, "u1");
|
strcpy(pReq->user, "u1");
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_USER, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SDropUserMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
||||||
SendThenCheckShowRetrieveMsg(2);
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||||
|
CHECK_META("show users", 4);
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("u2", TSDB_USER_LEN);
|
CheckBinary("u2", TSDB_USER_LEN);
|
||||||
CheckBinary("super", 10);
|
CheckBinary("super", 10);
|
||||||
|
@ -281,19 +145,14 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
|
|
||||||
// restart
|
// restart
|
||||||
stopServer(pServer);
|
test.Restart();
|
||||||
pServer = NULL;
|
|
||||||
|
|
||||||
uInfo("start all server");
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||||
|
CHECK_META("show users", 4);
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
test.SendShowRetrieveMsg();
|
||||||
const char* firstEp = "localhost:9140";
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
pServer = startServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
|
||||||
|
|
||||||
uInfo("all server is running");
|
|
||||||
|
|
||||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
||||||
SendThenCheckShowRetrieveMsg(2);
|
|
||||||
CheckBinary("root", TSDB_USER_LEN);
|
CheckBinary("root", TSDB_USER_LEN);
|
||||||
CheckBinary("u2", TSDB_USER_LEN);
|
CheckBinary("u2", TSDB_USER_LEN);
|
||||||
CheckBinary("super", 10);
|
CheckBinary("super", 10);
|
||||||
|
|
|
@ -1,24 +1,8 @@
|
||||||
add_executable(dnode_test_vgroup "")
|
aux_source_directory(. VGROUP_SRC)
|
||||||
|
add_executable(dnode_test_vgroup ${VGROUP_SRC})
|
||||||
target_sources(dnode_test_vgroup
|
|
||||||
PRIVATE
|
|
||||||
"vgroup.cpp"
|
|
||||||
"../sut/deploy.cpp"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode_test_vgroup
|
dnode_test_vgroup
|
||||||
PUBLIC dnode
|
PUBLIC sut
|
||||||
PUBLIC util
|
|
||||||
PUBLIC os
|
|
||||||
PUBLIC gtest_main
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(dnode_test_vgroup
|
|
||||||
PUBLIC
|
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
|
|
|
@ -9,177 +9,28 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "deploy.h"
|
#include "base.h"
|
||||||
|
|
||||||
class DndTestVgroup : public ::testing::Test {
|
class DndTestVgroup : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vgroup", 9150); }
|
||||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
static void TearDownTestSuite() { test.Cleanup(); }
|
||||||
ASSERT(pServer);
|
|
||||||
return pServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetUpTestSuite() {
|
static Testbase test;
|
||||||
initLog("/tmp/tdlog");
|
|
||||||
|
|
||||||
const char* fqdn = "localhost";
|
|
||||||
const char* firstEp = "localhost:9150";
|
|
||||||
pServer = CreateServer("/tmp/dnode_test_vgroup", fqdn, 9150, firstEp);
|
|
||||||
pClient = createClient("root", "taosdata", fqdn, 9150);
|
|
||||||
taosMsleep(1100);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void TearDownTestSuite() {
|
|
||||||
stopServer(pServer);
|
|
||||||
dropClient(pClient);
|
|
||||||
pServer = NULL;
|
|
||||||
pClient = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SServer* pServer;
|
|
||||||
static SClient* pClient;
|
|
||||||
static int32_t connId;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetUp() override {}
|
void SetUp() override {}
|
||||||
void TearDown() override {}
|
void TearDown() override {}
|
||||||
|
|
||||||
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);
|
|
||||||
pMeta->suid = htobe64(pMeta->suid);
|
|
||||||
|
|
||||||
showId = pShowRsp->showId;
|
|
||||||
|
|
||||||
EXPECT_NE(pShowRsp->showId, 0);
|
|
||||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
||||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
||||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
||||||
EXPECT_EQ(pMeta->precision, 0);
|
|
||||||
EXPECT_EQ(pMeta->tableType, 0);
|
|
||||||
EXPECT_EQ(pMeta->update, 0);
|
|
||||||
EXPECT_EQ(pMeta->sversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tversion, 0);
|
|
||||||
EXPECT_EQ(pMeta->tuid, 0);
|
|
||||||
EXPECT_EQ(pMeta->suid, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
|
||||||
SSchema* pSchema = &pMeta->pSchema[index];
|
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
|
||||||
EXPECT_EQ(pSchema->colId, 0);
|
|
||||||
EXPECT_EQ(pSchema->type, type);
|
|
||||||
EXPECT_EQ(pSchema->bytes, bytes);
|
|
||||||
EXPECT_STREQ(pSchema->name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt8(int8_t val) {
|
|
||||||
int8_t data = *((int8_t*)(pData + pos));
|
|
||||||
pos += sizeof(int8_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt16(int16_t val) {
|
|
||||||
int16_t data = *((int16_t*)(pData + pos));
|
|
||||||
pos += sizeof(int16_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt32(int32_t val) {
|
|
||||||
int32_t data = *((int32_t*)(pData + pos));
|
|
||||||
pos += sizeof(int32_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckInt64(int64_t val) {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_EQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckTimestamp() {
|
|
||||||
int64_t data = *((int64_t*)(pData + pos));
|
|
||||||
pos += sizeof(int64_t);
|
|
||||||
EXPECT_GT(data, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBinary(const char* val, int32_t len) {
|
|
||||||
pos += sizeof(VarDataLenT);
|
|
||||||
char* data = (char*)(pData + pos);
|
|
||||||
pos += len;
|
|
||||||
EXPECT_STREQ(data, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t showId;
|
|
||||||
STableMetaMsg* pMeta;
|
|
||||||
SRetrieveTableRsp* pRetrieveRsp;
|
|
||||||
char* pData;
|
|
||||||
int32_t pos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SServer* DndTestVgroup::pServer;
|
Testbase DndTestVgroup::test;
|
||||||
SClient* DndTestVgroup::pClient;
|
|
||||||
int32_t DndTestVgroup::connId;
|
|
||||||
|
|
||||||
TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(sizeof(SCreateVnodeMsg));
|
int32_t contLen = sizeof(SCreateVnodeMsg);
|
||||||
|
|
||||||
|
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->vgId = htonl(2);
|
pReq->vgId = htonl(2);
|
||||||
pReq->dnodeId = htonl(1);
|
pReq->dnodeId = htonl(1);
|
||||||
strcpy(pReq->db, "1.d1");
|
strcpy(pReq->db, "1.d1");
|
||||||
|
@ -209,13 +60,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
pReplica->port = htons(9150);
|
pReplica->port = htons(9150);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SCreateVnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +68,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(sizeof(SAlterVnodeMsg));
|
int32_t contLen = sizeof(SAlterVnodeMsg);
|
||||||
|
|
||||||
|
SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->vgId = htonl(2);
|
pReq->vgId = htonl(2);
|
||||||
pReq->dnodeId = htonl(1);
|
pReq->dnodeId = htonl(1);
|
||||||
strcpy(pReq->db, "1.d1");
|
strcpy(pReq->db, "1.d1");
|
||||||
|
@ -253,13 +100,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
pReplica->port = htons(9150);
|
pReplica->port = htons(9150);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen);
|
||||||
rpcMsg.pCont = pReq;
|
|
||||||
rpcMsg.contLen = sizeof(SAlterVnodeMsg);
|
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_VNODE_IN;
|
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
@ -267,7 +108,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(sizeof(SDropVnodeMsg));
|
int32_t contLen = sizeof(SDropVnodeMsg);
|
||||||
|
|
||||||
|
SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->vgId = htonl(2);
|
pReq->vgId = htonl(2);
|
||||||
pReq->dnodeId = htonl(1);
|
pReq->dnodeId = htonl(1);
|
||||||
strcpy(pReq->db, "1.d1");
|
strcpy(pReq->db, "1.d1");
|
||||||
|
@ -278,8 +121,7 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||||
rpcMsg.contLen = sizeof(SDropVnodeMsg);
|
rpcMsg.contLen = sizeof(SDropVnodeMsg);
|
||||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
|
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
|
||||||
|
|
||||||
sendMsg(pClient, &rpcMsg);
|
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen);
|
||||||
SRpcMsg* pMsg = pClient->pRsp;
|
|
||||||
ASSERT_NE(pMsg, nullptr);
|
ASSERT_NE(pMsg, nullptr);
|
||||||
ASSERT_EQ(pMsg->code, 0);
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue