vnodeApiTests.cpp 2.5 KB
Newer Older
H
more  
Hongze Cheng 已提交
1 2 3
#include <gtest/gtest.h>
#include <iostream>

H
more  
Hongze Cheng 已提交
4 5 6
#include "vnode.h"

TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
H
more  
Hongze Cheng 已提交
7 8
  GTEST_ASSERT_GE(vnodeInit(), 0);

H
more  
Hongze Cheng 已提交
9 10 11 12
  // Create and open a vnode
  SVnode *pVnode = vnodeOpen("vnode1", NULL);
  ASSERT_NE(pVnode, nullptr);

H
more  
Hongze Cheng 已提交
13 14 15 16 17 18 19
  tb_uid_t suid = 1638166374163;
  {
    // Create a super table
    STSchema *pSchema = NULL;
    STSchema *pTagSchema = NULL;
    char      tbname[128] = "st";

H
more  
Hongze Cheng 已提交
20 21
    SArray *  pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *));
    SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
H
more  
Hongze Cheng 已提交
22

H
more  
Hongze Cheng 已提交
23
    int      zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
H
more  
Hongze Cheng 已提交
24 25 26 27 28 29
    SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
    pMsg->contLen = zs;
    pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));

    void **pBuf = &(pMsg->pCont);

H
more  
Hongze Cheng 已提交
30 31
    vnodeBuildReq(pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
    META_CLEAR_TB_CFG(&vCreateSTbReq);
H
more  
Hongze Cheng 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    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);
H
more  
Hongze Cheng 已提交
51
        SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(0, tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
H
more  
Hongze Cheng 已提交
52

H
more  
Hongze Cheng 已提交
53
        int      tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
H
more  
Hongze Cheng 已提交
54 55 56 57 58
        SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
        pMsg->contLen = tz;
        pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
        void **pBuf = &(pMsg->pCont);

H
more  
Hongze Cheng 已提交
59 60
        vnodeBuildReq(pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
        META_CLEAR_TB_CFG(&vCreateCTbReq);
H
more  
Hongze Cheng 已提交
61 62 63 64 65 66 67 68 69 70 71 72
      }

      vnodeProcessWMsgs(pVnode, pMsgs);

      for (int j = 0; j < batch; j++) {
        SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs);
        free(pMsg);
      }

      taosArrayClear(pMsgs);
    }
  }
H
more  
Hongze Cheng 已提交
73

H
more  
Hongze Cheng 已提交
74 75
  // Close the vnode
  vnodeClose(pVnode);
H
more  
Hongze Cheng 已提交
76 77

  vnodeClear();
H
more  
Hongze Cheng 已提交
78
}
H
more  
Hongze Cheng 已提交
79 80 81 82 83 84 85 86 87 88 89

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);
}