profile.cpp 14.5 KB
Newer Older
S
Shengliang Guan 已提交
1
/**
S
Shengliang Guan 已提交
2
 * @file profile.cpp
S
Shengliang Guan 已提交
3 4 5 6
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module profile-msg tests
 * @version 0.1
 * @date 2021-12-15
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2021
S
Shengliang Guan 已提交
9 10 11
 *
 */

S
Shengliang Guan 已提交
12
#include "deploy.h"
S
Shengliang Guan 已提交
13

S
Shengliang Guan 已提交
14
class DndTestProfile : public ::testing::Test {
S
Shengliang Guan 已提交
15
 protected:
S
Shengliang Guan 已提交
16 17 18 19 20
  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;
  }
S
Shengliang Guan 已提交
21 22

  static void SetUpTestSuite() {
S
Shengliang Guan 已提交
23
    initLog("/tmp/tdlog");
S
Shengliang Guan 已提交
24

S
Shengliang Guan 已提交
25 26 27 28 29
    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);
S
Shengliang Guan 已提交
30
  }
S
Shengliang Guan 已提交
31 32

  static void TearDownTestSuite() {
S
Shengliang Guan 已提交
33
    stopServer(pServer);
S
Shengliang Guan 已提交
34
    dropClient(pClient);
S
Shengliang Guan 已提交
35 36
    pServer = NULL;
    pClient = NULL;
S
Shengliang Guan 已提交
37 38
  }

S
Shengliang Guan 已提交
39 40
  static SServer* pServer;
  static SClient* pClient;
S
Shengliang Guan 已提交
41
  static int32_t  connId;
S
Shengliang Guan 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

 public:
  void SetUp() 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 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;
S
Shengliang Guan 已提交
172 173
};

S
Shengliang Guan 已提交
174 175
SServer* DndTestProfile::pServer;
SClient* DndTestProfile::pClient;
S
Shengliang Guan 已提交
176
int32_t  DndTestProfile::connId;
S
Shengliang Guan 已提交
177

S
Shengliang Guan 已提交
178
TEST_F(DndTestProfile, 01_ConnectMsg) {
S
Shengliang Guan 已提交
179 180
  ASSERT_NE(pClient, nullptr);

S
Shengliang Guan 已提交
181 182
  SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
  pReq->pid = htonl(1234);
S
Shengliang Guan 已提交
183
  strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
184 185 186 187 188 189 190 191
  strcpy(pReq->db, "");

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SConnectMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;

  sendMsg(pClient, &rpcMsg);
S
Shengliang Guan 已提交
192 193
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
S
Shengliang Guan 已提交
194

S
Shengliang Guan 已提交
195
  SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
S
Shengliang Guan 已提交
196
  ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
197 198 199
  pRsp->acctId = htonl(pRsp->acctId);
  pRsp->clusterId = htonl(pRsp->clusterId);
  pRsp->connId = htonl(pRsp->connId);
S
Shengliang Guan 已提交
200
  pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);
S
Shengliang Guan 已提交
201 202 203

  EXPECT_EQ(pRsp->acctId, 1);
  EXPECT_GT(pRsp->clusterId, 0);
S
Shengliang Guan 已提交
204
  EXPECT_EQ(pRsp->connId, 1);
S
Shengliang Guan 已提交
205
  EXPECT_EQ(pRsp->superUser, 1);
S
Shengliang Guan 已提交
206 207 208

  EXPECT_EQ(pRsp->epSet.inUse, 0);
  EXPECT_EQ(pRsp->epSet.numOfEps, 1);
S
Shengliang Guan 已提交
209
  EXPECT_EQ(pRsp->epSet.port[0], 9080);
S
Shengliang Guan 已提交
210
  EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
S
Shengliang Guan 已提交
211 212

  connId = pRsp->connId;
S
Shengliang Guan 已提交
213 214
}

S
Shengliang Guan 已提交
215
TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
S
Shengliang Guan 已提交
216 217 218 219
  ASSERT_NE(pClient, nullptr);

  SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
  pReq->pid = htonl(1234);
S
Shengliang Guan 已提交
220
  strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234
  strcpy(pReq->db, "invalid_db");

  SRpcMsg rpcMsg = {0};
  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_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB);
  ASSERT_EQ(pMsg->contLen, 0);
}

S
Shengliang Guan 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
  SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "show connections", 7);
  CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "connId");
  CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
  CheckSchema(2, TSDB_DATA_TYPE_BINARY, TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, "program");
  CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "pid");
  CheckSchema(4, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
  CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
  CheckSchema(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");

  SendThenCheckShowRetrieveMsg(1);

  CheckInt32(1);
  CheckBinary("root", TSDB_USER_LEN);
  CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN);
  CheckInt32(1234);
  IgnoreBinary(TSDB_IPv4ADDR_LEN + 6);
  CheckTimestamp();
  CheckTimestamp();
S
Shengliang Guan 已提交
254 255
}

S
Shengliang Guan 已提交
256
TEST_F(DndTestProfile, 04_HeartBeatMsg) {
S
Shengliang Guan 已提交
257 258 259
  ASSERT_NE(pClient, nullptr);

  SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
S
Shengliang Guan 已提交
260
  pReq->connId = htonl(connId);
S
Shengliang Guan 已提交
261 262 263
  pReq->pid = htonl(1234);
  pReq->numOfQueries = htonl(0);
  pReq->numOfStreams = htonl(0);
S
Shengliang Guan 已提交
264
  strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
265 266 267 268 269 270 271

  SRpcMsg rpcMsg = {0};
  rpcMsg.pCont = pReq;
  rpcMsg.contLen = sizeof(SHeartBeatMsg);
  rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;

  sendMsg(pClient, &rpcMsg);
S
Shengliang Guan 已提交
272 273
  SRpcMsg* pMsg = pClient->pRsp;
  ASSERT_NE(pMsg, nullptr);
S
Shengliang Guan 已提交
274

S
Shengliang Guan 已提交
275
  SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
S
Shengliang Guan 已提交
276 277 278 279 280 281 282 283
  ASSERT_NE(pRsp, nullptr);
  pRsp->connId = htonl(pRsp->connId);
  pRsp->queryId = htonl(pRsp->queryId);
  pRsp->streamId = htonl(pRsp->streamId);
  pRsp->totalDnodes = htonl(pRsp->totalDnodes);
  pRsp->onlineDnodes = htonl(pRsp->onlineDnodes);
  pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);

S
Shengliang Guan 已提交
284
  EXPECT_EQ(pRsp->connId, connId);
S
Shengliang Guan 已提交
285 286 287 288 289 290 291 292
  EXPECT_EQ(pRsp->queryId, 0);
  EXPECT_EQ(pRsp->streamId, 0);
  EXPECT_EQ(pRsp->totalDnodes, 1);
  EXPECT_EQ(pRsp->onlineDnodes, 1);
  EXPECT_EQ(pRsp->killConnection, 0);

  EXPECT_EQ(pRsp->epSet.inUse, 0);
  EXPECT_EQ(pRsp->epSet.numOfEps, 1);
S
Shengliang Guan 已提交
293
  EXPECT_EQ(pRsp->epSet.port[0], 9080);
S
Shengliang Guan 已提交
294 295
  EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
}
S
Shengliang Guan 已提交
296

S
Shengliang Guan 已提交
297
TEST_F(DndTestProfile, 05_KillConnMsg) {
S
Shengliang Guan 已提交
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  ASSERT_NE(pClient, nullptr);

  {
    SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
    pReq->connId = htonl(connId);

    SRpcMsg rpcMsg = {0};
    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_EQ(pMsg->code, 0);
  }

  {
    SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
    pReq->connId = htonl(connId);
    pReq->pid = htonl(1234);
    pReq->numOfQueries = htonl(0);
    pReq->numOfStreams = htonl(0);
S
Shengliang Guan 已提交
321
    strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
322 323 324 325 326 327 328 329 330

    SRpcMsg rpcMsg = {0};
    rpcMsg.pCont = pReq;
    rpcMsg.contLen = sizeof(SHeartBeatMsg);
    rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;

    sendMsg(pClient, &rpcMsg);
    SRpcMsg* pMsg = pClient->pRsp;
    ASSERT_NE(pMsg, nullptr);
S
Shengliang Guan 已提交
331
    ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION);
S
Shengliang Guan 已提交
332 333 334 335 336 337
    ASSERT_EQ(pMsg->contLen, 0);
  }

  {
    SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
    pReq->pid = htonl(1234);
S
Shengliang Guan 已提交
338
    strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    strcpy(pReq->db, "");

    SRpcMsg rpcMsg = {0};
    rpcMsg.pCont = pReq;
    rpcMsg.contLen = sizeof(SConnectMsg);
    rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;

    sendMsg(pClient, &rpcMsg);
    SRpcMsg* pMsg = pClient->pRsp;
    ASSERT_NE(pMsg, nullptr);

    SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
    ASSERT_NE(pRsp, nullptr);
    pRsp->acctId = htonl(pRsp->acctId);
    pRsp->clusterId = htonl(pRsp->clusterId);
    pRsp->connId = htonl(pRsp->connId);
    pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);

    EXPECT_EQ(pRsp->acctId, 1);
    EXPECT_GT(pRsp->clusterId, 0);
S
Shengliang Guan 已提交
359
    EXPECT_GT(pRsp->connId, connId);
S
Shengliang Guan 已提交
360
    EXPECT_EQ(pRsp->superUser, 1);
S
Shengliang Guan 已提交
361 362 363

    EXPECT_EQ(pRsp->epSet.inUse, 0);
    EXPECT_EQ(pRsp->epSet.numOfEps, 1);
S
Shengliang Guan 已提交
364
    EXPECT_EQ(pRsp->epSet.port[0], 9080);
S
Shengliang Guan 已提交
365 366 367 368 369 370
    EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");

    connId = pRsp->connId;
  }
}

S
Shengliang Guan 已提交
371
TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
S
Shengliang Guan 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
  ASSERT_NE(pClient, nullptr);

  SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
  pReq->connId = htonl(2345);

  SRpcMsg rpcMsg = {0};
  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_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
}

S
Shengliang Guan 已提交
388
TEST_F(DndTestProfile, 07_KillQueryMsg) {
S
Shengliang Guan 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  ASSERT_NE(pClient, nullptr);

  {
    SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
    pReq->connId = htonl(connId);
    pReq->queryId = htonl(1234);

    SRpcMsg rpcMsg = {0};
    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_EQ(pMsg->code, 0);
    ASSERT_EQ(pMsg->contLen, 0);
  }

  {
    SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
    pReq->connId = htonl(connId);
    pReq->pid = htonl(1234);
    pReq->numOfQueries = htonl(0);
    pReq->numOfStreams = htonl(0);
S
Shengliang Guan 已提交
414
    strcpy(pReq->app, "dnode_test_profile");
S
Shengliang Guan 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

    SRpcMsg rpcMsg = {0};
    rpcMsg.pCont = pReq;
    rpcMsg.contLen = sizeof(SHeartBeatMsg);
    rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;

    sendMsg(pClient, &rpcMsg);
    SRpcMsg* pMsg = pClient->pRsp;
    ASSERT_NE(pMsg, nullptr);

    SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
    ASSERT_NE(pRsp, nullptr);
    pRsp->connId = htonl(pRsp->connId);
    pRsp->queryId = htonl(pRsp->queryId);
    pRsp->streamId = htonl(pRsp->streamId);
    pRsp->totalDnodes = htonl(pRsp->totalDnodes);
    pRsp->onlineDnodes = htonl(pRsp->onlineDnodes);
    pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);

    EXPECT_EQ(pRsp->connId, connId);
    EXPECT_EQ(pRsp->queryId, 1234);
    EXPECT_EQ(pRsp->streamId, 0);
    EXPECT_EQ(pRsp->totalDnodes, 1);
    EXPECT_EQ(pRsp->onlineDnodes, 1);
    EXPECT_EQ(pRsp->killConnection, 0);

    EXPECT_EQ(pRsp->epSet.inUse, 0);
    EXPECT_EQ(pRsp->epSet.numOfEps, 1);
S
Shengliang Guan 已提交
443
    EXPECT_EQ(pRsp->epSet.port[0], 9080);
S
Shengliang Guan 已提交
444 445 446 447
    EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
  }
}

S
Shengliang Guan 已提交
448
TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidCOnn) {
S
Shengliang Guan 已提交
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  ASSERT_NE(pClient, nullptr);

  SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
  pReq->connId = htonl(2345);
  pReq->queryId = htonl(1234);

  SRpcMsg rpcMsg = {0};
  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_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
}

S
Shengliang Guan 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
TEST_F(DndTestProfile, 09_KillQueryMsg) {
  SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, "show queries", 14);
  CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "queryId");
  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);
S
Shengliang Guan 已提交
484
}