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
/**
 * @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:
S
shm  
Shengliang Guan 已提交
16 17 18 19
  static void SetUpTestSuite() {
    test.Init("/tmp/dnode_test_bnode", 9112);
    taosMsleep(1100);
  }
S
Shengliang Guan 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32
  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 已提交
33 34
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 2;
S
Shengliang Guan 已提交
35

36
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
37
    void*   pReq = rpcMallocCont(contLen);
38
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
39

S
Shengliang Guan 已提交
40 41
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
42
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
43 44 45
  }

  {
S
Shengliang Guan 已提交
46 47
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
48

49
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
50
    void*   pReq = rpcMallocCont(contLen);
51
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
52

S
Shengliang Guan 已提交
53 54 55
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
56 57 58
  }

  {
S
Shengliang Guan 已提交
59 60
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
61

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

S
Shengliang Guan 已提交
66 67
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
68
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
69 70 71 72 73
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
74 75
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
76

77
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
78
    void*   pReq = rpcMallocCont(contLen);
79
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
80 81
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
82
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_ALREADY_DEPLOYED);
S
Shengliang Guan 已提交
83 84 85
  }
}

S
shm  
Shengliang Guan 已提交
86
TEST_F(DndTestBnode, 02_Drop_Bnode) {
S
Shengliang Guan 已提交
87
#if 0  
S
Shengliang Guan 已提交
88
  {
S
Shengliang Guan 已提交
89 90
    SDDropBnodeReq dropReq = {0};
    dropReq.dnodeId = 2;
S
Shengliang Guan 已提交
91

92
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
93
    void*   pReq = rpcMallocCont(contLen);
94
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
95

S
Shengliang Guan 已提交
96 97
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
98
    ASSERT_EQ(pRsp->code, TSDB_CODE_INVALID_OPTION);
S
Shengliang Guan 已提交
99
  }
S
Shengliang Guan 已提交
100
#endif
S
Shengliang Guan 已提交
101
  {
S
Shengliang Guan 已提交
102 103
    SDDropBnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
104

105
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
106
    void*   pReq = rpcMallocCont(contLen);
107
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
108

S
Shengliang Guan 已提交
109 110 111
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
112 113 114
  }

  {
S
Shengliang Guan 已提交
115 116
    SDDropBnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
117

118
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
119
    void*   pReq = rpcMallocCont(contLen);
120
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
121

S
Shengliang Guan 已提交
122 123
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
124
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
125 126 127 128 129
  }

  test.Restart();

  {
S
Shengliang Guan 已提交
130 131
    SDDropBnodeReq dropReq = {0};
    dropReq.dnodeId = 1;
S
Shengliang Guan 已提交
132

133
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
S
Shengliang Guan 已提交
134
    void*   pReq = rpcMallocCont(contLen);
135
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
S
Shengliang Guan 已提交
136

S
Shengliang Guan 已提交
137 138
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
shm  
Shengliang Guan 已提交
139
    ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED);
S
Shengliang Guan 已提交
140 141 142
  }

  {
S
Shengliang Guan 已提交
143 144
    SDCreateBnodeReq createReq = {0};
    createReq.dnodeId = 1;
S
Shengliang Guan 已提交
145

146
    int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq);
S
Shengliang Guan 已提交
147
    void*   pReq = rpcMallocCont(contLen);
148
    tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &createReq);
S
Shengliang Guan 已提交
149

S
Shengliang Guan 已提交
150 151 152
    SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
S
Shengliang Guan 已提交
153
  }
S
shm  
Shengliang Guan 已提交
154
}