-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ConfigTest.cpp
245 lines (230 loc) · 9.07 KB
/
ConfigTest.cpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/* Copyright (c) 2018 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "base/Base.h"
#include "graph/test/TestBase.h"
#include "graph/test/TestEnv.h"
#include "meta/ClientBasedGflagsManager.h"
#include "meta/test/TestUtils.h"
DECLARE_int32(load_data_interval_secs);
namespace nebula {
namespace graph {
class ConfigTest : public TestBase {
protected:
void SetUp() override {
TestBase::SetUp();
// ...
}
void TearDown() override {
// ...
TestBase::TearDown();
}
};
std::vector<meta::cpp2::ConfigItem> mockRegisterGflags() {
std::vector<meta::cpp2::ConfigItem> configItems;
{
auto module = meta::cpp2::ConfigModule::STORAGE;
auto type = meta::cpp2::ConfigType::INT64;
int64_t value = 0L;
configItems.emplace_back(meta::toThriftConfigItem(module, "k0", type,
meta::cpp2::ConfigMode::IMMUTABLE,
meta::toThriftValueStr(type, value)));
configItems.emplace_back(meta::toThriftConfigItem(module, "k1", type,
meta::cpp2::ConfigMode::MUTABLE,
meta::toThriftValueStr(type, value)));
}
{
auto module = meta::cpp2::ConfigModule::STORAGE;
auto type = meta::cpp2::ConfigType::BOOL;
auto mode = meta::cpp2::ConfigMode::MUTABLE;
bool value = false;
configItems.emplace_back(meta::toThriftConfigItem(module, "k2", type, mode,
meta::toThriftValueStr(type, value)));
}
{
auto module = meta::cpp2::ConfigModule::META;
auto mode = meta::cpp2::ConfigMode::MUTABLE;
auto type = meta::cpp2::ConfigType::DOUBLE;
double value = 1.0;
configItems.emplace_back(meta::toThriftConfigItem(module, "k1", type, mode,
meta::toThriftValueStr(type, value)));
}
{
auto module = meta::cpp2::ConfigModule::META;
auto mode = meta::cpp2::ConfigMode::MUTABLE;
auto type = meta::cpp2::ConfigType::STRING;
std::string value = "nebula";
configItems.emplace_back(meta::toThriftConfigItem(module, "k2", type, mode,
meta::toThriftValueStr(type, value)));
}
{
auto type = meta::cpp2::ConfigType::STRING;
auto mode = meta::cpp2::ConfigMode::MUTABLE;
std::string value = "nebula";
configItems.emplace_back(meta::toThriftConfigItem(meta::cpp2::ConfigModule::GRAPH, "k3",
type, mode, meta::toThriftValueStr(type, value)));
configItems.emplace_back(meta::toThriftConfigItem(meta::cpp2::ConfigModule::META, "k3",
type, mode, meta::toThriftValueStr(type, value)));
configItems.emplace_back(meta::toThriftConfigItem(meta::cpp2::ConfigModule::STORAGE, "k3",
type, mode, meta::toThriftValueStr(type, value)));
}
return configItems;
}
TEST_F(ConfigTest, ConfigTest) {
auto client = gEnv->getClient();
ASSERT_NE(nullptr, client);
auto configItems = mockRegisterGflags();
auto ret = gEnv->gflagsManager()->registerGflags(std::move(configItems));
ASSERT_TRUE(ret.ok());
// set/get without declaration
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES storage:notRegistered=123";
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
query = "GET VARIABLES storage:notRegistered";
code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
// update immutable config will fail, read-only
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES storage:k0=123";
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES storage:k0";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>>
expected { {"STORAGE", "k0", "INT64", "IMMUTABLE", "0"} };
ASSERT_TRUE(verifyResult(resp, expected));
}
// set and get config after declaration
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES storage:k1=123";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES storage:k1";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>>
expected { {"STORAGE", "k1", "INT64", "MUTABLE", "123"} };
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES meta:k1=3.14";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES meta:k1";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>>
expected { {"META", "k1", "DOUBLE", "MUTABLE", "3.140000"} };
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES storage:k2=True";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES storage:k2";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>> expected {
{"STORAGE", "k2", "BOOL", "MUTABLE", "True"}
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES meta:k2=abc";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES meta:k2";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>> expected {
{"META", "k2", "STRING", "MUTABLE", "abc"}
};
ASSERT_TRUE(verifyResult(resp, expected));
}
// list configs in a specified module
{
cpp2::ExecutionResponse resp;
std::string query = "SHOW VARIABLES storage";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
ASSERT_EQ(4, resp.get_rows()->size());
}
{
cpp2::ExecutionResponse resp;
std::string query = "SHOW VARIABLES meta";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
ASSERT_EQ(3, resp.get_rows()->size());
}
// set and get a config of all module
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES k3=vesoft";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES k3";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>> expected {
{"GRAPH", "k3", "STRING", "MUTABLE", "vesoft"},
{"META", "k3", "STRING", "MUTABLE", "vesoft"},
{"STORAGE", "k3", "STRING", "MUTABLE", "vesoft"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
{
cpp2::ExecutionResponse resp;
std::string query = "UPDATE VARIABLES graph:k3=abc";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
query = "UPDATE VARIABLES meta:k3=bcd";
code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
query = "UPDATE VARIABLES storage:k3=cde";
code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "GET VARIABLES k3";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 5>> expected {
{"GRAPH", "k3", "STRING", "MUTABLE", "abc"},
{"META", "k3", "STRING", "MUTABLE", "bcd"},
{"STORAGE", "k3", "STRING", "MUTABLE", "cde"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
}
} // namespace graph
} // namespace nebula