dmnode.cpp 6.2 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * @file dmnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module mnode tests
 * @version 1.0
 * @date 2022-01-07
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

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

S
Shengliang Guan 已提交
19
  static Testbase test;
S
Shengliang Guan 已提交
20 21 22 23 24 25

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

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

S
Shengliang Guan 已提交
28
TEST_F(DndTestMnode, 01_Create_Mnode) {
S
Shengliang Guan 已提交
29
  {
S
Shengliang Guan 已提交
30 31 32 33 34 35
    SDCreateMnodeReq createReq = {0};
    createReq.dnodeId = 2;
    createReq.replica = 1;
    createReq.replicas[0].id = 1;
    createReq.replicas[0].port = 9113;
    strcpy(createReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
36

S
Shengliang Guan 已提交
37 38 39
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
40 41 42 43 44

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
  }
S
Shengliang Guan 已提交
45

S
Shengliang Guan 已提交
46
  {
S
Shengliang Guan 已提交
47 48 49 50 51 52
    SDCreateMnodeReq createReq = {0};
    createReq.dnodeId = 1;
    createReq.replica = 1;
    createReq.replicas[0].id = 2;
    createReq.replicas[0].port = 9113;
    strcpy(createReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
53

S
Shengliang Guan 已提交
54 55 56
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
57

S
Shengliang Guan 已提交
58 59 60 61
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
  }
S
Shengliang Guan 已提交
62

S
Shengliang Guan 已提交
63
  {
S
Shengliang Guan 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76
    SDCreateMnodeReq createReq = {0};
    createReq.dnodeId = 1;
    createReq.replica = 2;
    createReq.replicas[0].id = 1;
    createReq.replicas[0].port = 9113;
    strcpy(createReq.replicas[0].fqdn, "localhost");
    createReq.replicas[1].id = 1;
    createReq.replicas[1].port = 9114;
    strcpy(createReq.replicas[1].fqdn, "localhost");

    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
77 78 79 80 81

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
  }
S
Shengliang Guan 已提交
82 83 84
}

TEST_F(DndTestMnode, 02_Alter_Mnode) {
S
Shengliang Guan 已提交
85 86 87 88 89 90 91
  {
    SDAlterMnodeReq alterReq = {0};
    alterReq.dnodeId = 2;
    alterReq.replica = 1;
    alterReq.replicas[0].id = 1;
    alterReq.replicas[0].port = 9113;
    strcpy(alterReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
92

S
Shengliang Guan 已提交
93 94 95
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
S
Shengliang Guan 已提交
96

S
Shengliang Guan 已提交
97
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
S
Shengliang Guan 已提交
98
    ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
99
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
S
Shengliang Guan 已提交
100 101 102
  }

  {
S
Shengliang Guan 已提交
103 104 105 106 107 108
    SDAlterMnodeReq alterReq = {0};
    alterReq.dnodeId = 1;
    alterReq.replica = 1;
    alterReq.replicas[0].id = 2;
    alterReq.replicas[0].port = 9113;
    strcpy(alterReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
109

S
Shengliang Guan 已提交
110 111 112
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
S
Shengliang Guan 已提交
113

S
Shengliang Guan 已提交
114
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
S
Shengliang Guan 已提交
115
    ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
116
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
S
Shengliang Guan 已提交
117 118 119
  }

  {
S
Shengliang Guan 已提交
120 121 122 123 124 125
    SDAlterMnodeReq alterReq = {0};
    alterReq.dnodeId = 1;
    alterReq.replica = 1;
    alterReq.replicas[0].id = 1;
    alterReq.replicas[0].port = 9113;
    strcpy(alterReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
126

S
Shengliang Guan 已提交
127 128 129
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
S
Shengliang Guan 已提交
130

S
Shengliang Guan 已提交
131
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
S
Shengliang Guan 已提交
132
    ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
133
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
134 135 136 137 138
  }
}

TEST_F(DndTestMnode, 03_Drop_Mnode) {
  {
S
Shengliang Guan 已提交
139 140
    SDDropMnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
141

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

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

  {
S
Shengliang Guan 已提交
152 153
    SDDropMnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
154

S
Shengliang Guan 已提交
155 156 157
    int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
158 159 160 161 162 163 164

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
165 166
    SDDropMnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
167

S
Shengliang Guan 已提交
168 169 170
    int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
171 172 173 174 175 176 177

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
  }

  {
S
Shengliang Guan 已提交
178 179 180 181 182 183
    SDAlterMnodeReq alterReq = {0};
    alterReq.dnodeId = 1;
    alterReq.replica = 1;
    alterReq.replicas[0].id = 1;
    alterReq.replicas[0].port = 9113;
    strcpy(alterReq.replicas[0].fqdn, "localhost");
S
Shengliang Guan 已提交
184

S
Shengliang Guan 已提交
185 186 187
    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
S
Shengliang Guan 已提交
188

S
Shengliang Guan 已提交
189
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
S
Shengliang Guan 已提交
190 191 192 193 194
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
  }

  {
S
Shengliang Guan 已提交
195 196 197 198 199 200 201 202 203 204
    SDCreateMnodeReq createReq = {0};
    createReq.dnodeId = 1;
    createReq.replica = 2;
    createReq.replicas[0].id = 1;
    createReq.replicas[0].port = 9113;
    strcpy(createReq.replicas[0].fqdn, "localhost");

    int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
205 206 207 208 209

    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }
S
Shengliang Guan 已提交
210
}