catalogTests.cpp 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

D
dapan1121 已提交
16
#include <gtest/gtest.h>
17 18 19 20 21 22 23 24 25
#include <tglobal.h>
#include <iostream>
#pragma GCC diagnostic ignored "-Wwrite-strings"

#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"

D
dapan1121 已提交
26
#include "taos.h"
27
#include "tdef.h"
D
dapan1121 已提交
28 29 30
#include "tvariant.h"
#include "catalog.h"
#include "tep.h"
D
ut test  
dapan1121 已提交
31
#include "trpc.h"
D
dapan1121 已提交
32 33
#include "stub.h"
#include "addr_any.h"
D
dapan1121 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

typedef struct SAppInstInfo {
  int64_t           numOfConns;
  SCorEpSet         mgmtEp;
} SAppInstInfo;

typedef struct STscObj {
  char               user[TSDB_USER_LEN];
  char               pass[TSDB_PASSWORD_LEN];
  char               acctId[TSDB_ACCT_ID_LEN];
  char               db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
  uint32_t           connId;
  uint64_t           id;       // ref ID returned by taosAddRef
//  struct SSqlObj    *sqlList;
  void              *pTransporter;
  pthread_mutex_t    mutex;     // used to protect the operation on db
  int32_t            numOfReqs; // number of sqlObj from this tscObj
  SAppInstInfo      *pAppInfo;
} STscObj;
53

D
dapan1121 已提交
54
namespace {
55

D
ut test  
dapan1121 已提交
56 57 58 59 60 61 62 63 64 65
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
  SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
  strcpy(pReq->db, "1.db1");
  pReq->numOfVgroups = htonl(2);
  pReq->cacheBlockSize = htonl(16);
  pReq->totalBlocks = htonl(10);
  pReq->daysPerFile = htonl(10);
  pReq->daysToKeep0 = htonl(3650);
  pReq->daysToKeep1 = htonl(3650);
  pReq->daysToKeep2 = htonl(3650);
S
Shengliang Guan 已提交
66 67
  pReq->minRows = htonl(100);
  pReq->maxRows = htonl(4096);
D
ut test  
dapan1121 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81
  pReq->commitTime = htonl(3600);
  pReq->fsyncPeriod = htonl(3000);
  pReq->walLevel = 1;
  pReq->precision = 0;
  pReq->compression = 2;
  pReq->replications = 1;
  pReq->quorum = 1;
  pReq->update = 0;
  pReq->cacheLastRow = 0;
  pReq->ignoreExist = 1;
  
  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SCreateDbMsg);
H
Hongze Cheng 已提交
82
  rpcMsg.msgType = TDMT_MND_CREATE_DB;
D
ut test  
dapan1121 已提交
83 84 85 86 87 88 89 90

  SRpcMsg rpcRsp = {0};

  rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp);

  ASSERT_EQ(rpcRsp.code, 0);
}

D
dapan1121 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
void __rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
  SUseDbRsp *rspMsg = NULL; //todo

  return;
}


void initTestEnv() {
  static Stub stub;
  stub.set(rpcSendRecv, __rpcSendRecv);
  {
    AddrAny any("libtransport.so");
    std::map<std::string,void*> result;
    any.get_global_func_addr_dynsym("^rpcSendRecv$", result);
    for (const auto& f : result) {
      stub.set(f.second, __rpcSendRecv);
    }
  }
}


112 113
}

D
dapan1121 已提交
114 115 116
TEST(testCase, normalCase) {
  STscObj* pConn = (STscObj *)taos_connect("127.0.0.1", "root", "taosdata", NULL, 0);
  assert(pConn != NULL);
117

D
dapan1121 已提交
118
  char *clusterId = "cluster1";
D
ut test  
dapan1121 已提交
119
  char *dbname = "1.db1";
D
dapan1121 已提交
120 121 122 123
  char *tablename = "table1";
  struct SCatalog* pCtg = NULL;
  void *mockPointer = (void *)0x1;
  SVgroupInfo vgInfo = {0};
124

125
  initQueryModuleMsgHandle();
D
ut test  
dapan1121 已提交
126 127

  sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
D
dapan1121 已提交
128 129 130
  
  int32_t code = catalogInit(NULL);
  ASSERT_EQ(code, 0);
131

D
dapan1121 已提交
132 133
  code = catalogGetHandle(clusterId, &pCtg);
  ASSERT_EQ(code, 0);
134

D
dapan1121 已提交
135 136
  code = catalogGetTableHashVgroup(pCtg, pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet, dbname, tablename, &vgInfo);
  ASSERT_EQ(code, 0);
137

D
dapan1121 已提交
138 139
  taos_close(pConn);
}
140 141 142 143 144 145


int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
D
dapan1121 已提交
146 147 148