dqnode.cpp 4.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/**
 * @file dqnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module qnode tests
 * @version 1.0
 * @date 2022-01-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class DndTestQnode : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); }
  static void TearDownTestSuite() { test.Cleanup(); }

  static Testbase test;

 public:
  void SetUp() override {}
  void TearDown() override {}
};

Testbase DndTestQnode::test;
S
Shengliang Guan 已提交
27

S
Shengliang Guan 已提交
28
TEST_F(DndTestQnode, 01_Create_Qnode) {
S
Shengliang Guan 已提交
29
  {
S
Shengliang Guan 已提交
30 31
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 2;
S
Shengliang Guan 已提交
32

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

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

S
Shengliang Guan 已提交
42
  {
S
Shengliang Guan 已提交
43 44
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
45

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

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

S
Shengliang Guan 已提交
55
  {
S
Shengliang Guan 已提交
56 57
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
58

S
Shengliang Guan 已提交
59 60 61
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
62

S
Shengliang Guan 已提交
63 64 65
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
66
  }
S
Shengliang Guan 已提交
67

S
Shengliang Guan 已提交
68
  test.Restart();
S
Shengliang Guan 已提交
69

S
Shengliang Guan 已提交
70
  {
S
Shengliang Guan 已提交
71 72
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
73

S
Shengliang Guan 已提交
74 75 76
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
77

S
Shengliang Guan 已提交
78 79 80
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
81
  }
S
Shengliang Guan 已提交
82 83
}

S
Shengliang Guan 已提交
84
TEST_F(DndTestQnode, 02_Drop_Qnode) {
S
Shengliang Guan 已提交
85
  {
S
Shengliang Guan 已提交
86 87
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
88

S
Shengliang Guan 已提交
89 90 91
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
92

S
Shengliang Guan 已提交
93 94
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
95
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_INVALID_OPTION);
S
Shengliang Guan 已提交
96 97 98
  }

  {
S
Shengliang Guan 已提交
99 100
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
101

S
Shengliang Guan 已提交
102 103 104
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
105

S
Shengliang Guan 已提交
106 107 108
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
109 110 111
  }

  {
S
Shengliang Guan 已提交
112 113
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
114

S
Shengliang Guan 已提交
115 116 117
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
118

S
Shengliang Guan 已提交
119 120 121
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
122 123 124 125 126
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
127 128
    SDDropQnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
129

S
Shengliang Guan 已提交
130 131 132
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
133

S
Shengliang Guan 已提交
134 135 136
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
137 138 139
  }

  {
S
Shengliang Guan 已提交
140 141
    SDCreateQnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
142

S
Shengliang Guan 已提交
143 144 145
    int32_t contLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
146

S
Shengliang Guan 已提交
147 148 149
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
150
  }
S
Shengliang Guan 已提交
151
}