TDengine/source/dnode/vnode/impl/test/vnodeApiTests.cpp

90 lines
2.5 KiB
C++
Raw Normal View History

2021-11-08 05:49:26 +00:00
#include <gtest/gtest.h>
#include <iostream>
2021-11-08 05:55:51 +00:00
#include "vnode.h"
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
2021-11-29 06:06:16 +00:00
GTEST_ASSERT_GE(vnodeInit(), 0);
2021-11-08 05:55:51 +00:00
// Create and open a vnode
SVnode *pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr);
2021-11-29 07:42:17 +00:00
tb_uid_t suid = 1638166374163;
{
// Create a super table
STSchema *pSchema = NULL;
STSchema *pTagSchema = NULL;
char tbname[128] = "st";
2021-11-29 08:59:18 +00:00
SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *));
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
2021-11-29 07:42:17 +00:00
2021-11-29 08:59:18 +00:00
int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
2021-11-29 07:42:17 +00:00
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
pMsg->contLen = zs;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));
void **pBuf = &(pMsg->pCont);
2021-11-29 08:59:18 +00:00
vnodeBuildReq(pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
META_CLEAR_TB_CFG(&vCreateSTbReq);
2021-11-29 07:42:17 +00:00
taosArrayPush(pMsgs, &(pMsg));
vnodeProcessWMsgs(pVnode, pMsgs);
free(pMsg);
taosArrayClear(pMsgs);
}
{
// Create some child tables
int ntables = 1000000;
int batch = 10;
for (int i = 0; i < ntables / batch; i++) {
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));
for (int j = 0; j < batch; j++) {
SRow *pTag = NULL;
char tbname[128];
sprintf(tbname, "tb%d", i * batch + j);
2021-11-29 08:59:18 +00:00
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
2021-11-29 07:42:17 +00:00
2021-11-29 08:59:18 +00:00
int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
2021-11-29 07:42:17 +00:00
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
pMsg->contLen = tz;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
void **pBuf = &(pMsg->pCont);
2021-11-29 08:59:18 +00:00
vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
META_CLEAR_TB_CFG(&vCreateCTbReq);
2021-11-29 07:42:17 +00:00
}
vnodeProcessWMsgs(pVnode, pMsgs);
for (int j = 0; j < batch; j++) {
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs);
free(pMsg);
}
taosArrayClear(pMsgs);
}
}
2021-11-29 06:06:16 +00:00
2021-11-08 05:55:51 +00:00
// Close the vnode
vnodeClose(pVnode);
2021-11-29 06:06:16 +00:00
vnodeClear();
2021-11-08 05:49:26 +00:00
}
2021-11-26 06:49:26 +00:00
TEST(vnodeApiTest, vnode_process_create_table) {
STSchema * pSchema = NULL;
STSchema * pTagSchema = NULL;
char stname[15];
SVCreateTableReq pReq = META_INIT_STB_CFG(stname, UINT32_MAX, UINT32_MAX, 0, pSchema, pTagSchema);
int k = 10;
META_CLEAR_TB_CFG(pReq);
}