show.cpp 3.0 KB
Newer Older
S
Shengliang Guan 已提交
1
/**
S
Shengliang Guan 已提交
2
 * @file show.cpp
S
Shengliang Guan 已提交
3
 * @author slguan (slguan@taosdata.com)
S
Shengliang Guan 已提交
4 5 6
 * @brief MNODE module show tests
 * @version 1.0
 * @date 2022-01-06
S
Shengliang Guan 已提交
7
 *
S
Shengliang Guan 已提交
8
 * @copyright Copyright (c) 2022
S
Shengliang Guan 已提交
9 10 11
 *
 */

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

S
Shengliang Guan 已提交
14
class MndTestShow : public ::testing::Test {
S
Shengliang Guan 已提交
15
 protected:
S
Shengliang Guan 已提交
16
  static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); }
S
Shengliang Guan 已提交
17
  static void TearDownTestSuite() { test.Cleanup(); }
S
Shengliang Guan 已提交
18

S
Shengliang Guan 已提交
19
  static Testbase test;
S
Shengliang Guan 已提交
20

S
Shengliang Guan 已提交
21 22 23 24
 public:
  void SetUp() override {}
  void TearDown() override {}
};
S
Shengliang Guan 已提交
25

S
Shengliang Guan 已提交
26
Testbase MndTestShow::test;
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
S
Shengliang Guan 已提交
29 30
  SShowReq showReq = {0};
  showReq.type = TSDB_MGMT_TABLE_MAX;
S
Shengliang Guan 已提交
31

S
Shengliang Guan 已提交
32 33 34 35
  int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSShowReq(pReq, contLen, &showReq);
  tFreeSShowReq(&showReq);
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
37 38 39
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
S
Shengliang Guan 已提交
40 41
}

S
Shengliang Guan 已提交
42
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
S
Shengliang Guan 已提交
43 44
  SShowReq showReq = {0};
  showReq.type = TSDB_MGMT_TABLE_START;
S
Shengliang Guan 已提交
45

S
Shengliang Guan 已提交
46 47 48 49
  int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSShowReq(pReq, contLen, &showReq);
  tFreeSShowReq(&showReq);
S
Shengliang Guan 已提交
50

S
Shengliang Guan 已提交
51 52 53
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
S
Shengliang Guan 已提交
54
}
S
Shengliang Guan 已提交
55

S
Shengliang Guan 已提交
56
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
S
Shengliang Guan 已提交
57 58 59 60
  SConnectReq connectReq = {0};
  connectReq.pid = 1234;
  strcpy(connectReq.app, "mnode_test_show");
  strcpy(connectReq.db, "");
S
Shengliang Guan 已提交
61

S
Shengliang Guan 已提交
62 63 64
  int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
  void*   pReq = rpcMallocCont(contLen);
  tSerializeSConnectReq(pReq, contLen, &connectReq);
S
Shengliang Guan 已提交
65

S
Shengliang Guan 已提交
66 67 68
  SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
  ASSERT_NE(pRsp, nullptr);
  ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
69

S
Shengliang Guan 已提交
70
  test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
S
Shengliang Guan 已提交
71

S
Shengliang Guan 已提交
72
  STableMetaRsp* pMeta = test.GetShowMeta();
D
dapan1121 已提交
73
  EXPECT_STREQ(pMeta->tbName, "show connections");
S
Shengliang Guan 已提交
74 75 76 77 78 79 80 81 82 83
  EXPECT_EQ(pMeta->numOfTags, 0);
  EXPECT_EQ(pMeta->numOfColumns, 7);
  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);

S
Shengliang Guan 已提交
84
  test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
85 86 87 88 89 90 91 92 93

  SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp();
  EXPECT_EQ(pRetrieveRsp->numOfRows, 1);
  EXPECT_EQ(pRetrieveRsp->useconds, 0);
  EXPECT_EQ(pRetrieveRsp->completed, 1);
  EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
  EXPECT_EQ(pRetrieveRsp->compressed, 0);
  EXPECT_EQ(pRetrieveRsp->compLen, 0);
}
S
Shengliang Guan 已提交
94 95

TEST_F(MndTestShow, 04_ShowMsg_Cluster) {
S
Shengliang Guan 已提交
96
  test.SendShowMetaReq(TSDB_MGMT_TABLE_CLUSTER, "");
S
Shengliang Guan 已提交
97 98 99 100 101
  CHECK_META( "show cluster", 3);
  CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id");
  CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
  CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");

S
Shengliang Guan 已提交
102
  test.SendShowRetrieveReq();
S
Shengliang Guan 已提交
103 104 105 106 107 108
  EXPECT_EQ(test.GetShowRows(), 1);

  IgnoreInt64();
  IgnoreBinary(TSDB_CLUSTER_ID_LEN);
  CheckTimestamp();
}