dbnode.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 27 28 29
/**
 * @file dbnode.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief DNODE module bnode tests
 * @version 1.0
 * @date 2022-01-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class DndTestBnode : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); }
  static void TearDownTestSuite() { test.Cleanup(); }

  static Testbase test;

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

Testbase DndTestBnode::test;

TEST_F(DndTestBnode, 01_Create_Bnode) {
  {
S
Shengliang Guan 已提交
30 31
    SDCreateBnodeReq 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_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
Shengliang Guan 已提交
39
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_INVALID_OPTION);
S
Shengliang Guan 已提交
40 41 42
  }

  {
S
Shengliang Guan 已提交
43 44
    SDCreateBnodeReq 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_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
53 54 55
  }

  {
S
Shengliang Guan 已提交
56 57
    SDCreateBnodeReq 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_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
66 67 68 69 70
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
71 72
    SDCreateBnodeReq 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 78 79
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
80 81 82 83 84
  }
}

TEST_F(DndTestBnode, 01_Drop_Bnode) {
  {
S
Shengliang Guan 已提交
85 86
    SDDropBnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
87

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

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

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

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

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

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

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

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

  test.Restart();

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

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

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

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

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

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