Debian Codegraph @

unittest/gunit/libmysqlgcs/xcom/gcs_parameters-t.cc

raw symbols SCIP
1 /* Copyright (c) 2016, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #include <string>
25 #include <vector>
26
27 #include "gcs_base_test.h"
28
29 #include "gcs_message_stage_lz4.h"
30 #include "gcs_message_stage_split.h"
31
32 using std::vector;
33
34 namespace gcs_parameters_unittest {
35
36 class GcsParametersTest : public GcsBaseTest {
37 protected:
38 GcsParametersTest() : m_gcs(nullptr) {}
39
40 void SetUp() override {
41 m_gcs = Gcs_xcom_interface::get_interface();
42
43 // convenience alias to specialized version of Gcs_interface.
44 m_xcs = static_cast<Gcs_xcom_interface *>(m_gcs);
45
46 // These are all parameters and are all valid
47 m_params.add_parameter("group_name", "ola");
48 m_params.add_parameter("local_node", "127.0.0.1:24844");
49 m_params.add_parameter("peer_nodes", "127.0.0.1:24844,127.0.0.1:24845");
50 m_params.add_parameter("bootstrap_group", "true");
51 m_params.add_parameter("poll_spin_loops", "100");
52 m_params.add_parameter("compression", "on");
53 m_params.add_parameter("compression_threshold", "1024");
54 m_params.add_parameter("ip_allowlist", "127.0.0.1,192.168.1.0/24");
55 m_params.add_parameter("non_member_expel_timeout", "5");
56 m_params.add_parameter("suspicions_processing_period", "25");
57 m_params.add_parameter("member_expel_timeout", "120");
58 m_params.add_parameter("join_attempts", "3");
59 m_params.add_parameter("join_sleep_time", "5");
60 m_params.add_parameter("fragmentation", "on");
61 m_params.add_parameter("fragmentation_threshold", "1024");
62 }
63
64 void TearDown() override {
65 // fake factory cleanup member function
66 static_cast<Gcs_xcom_interface *>(m_gcs)->cleanup();
67 }
68
69 Gcs_interface *m_gcs;
70 Gcs_xcom_interface *m_xcs;
71 Gcs_interface_parameters m_params;
72
73 void do_check_params() {
74 enum_gcs_error err = m_gcs->initialize(m_params);
75 ASSERT_EQ(err, GCS_NOK);
76 err = m_gcs->finalize();
77 // initialization failed, and thus so will finalization
78 ASSERT_EQ(err, GCS_NOK);
79 }
80
81 void do_check_ok_params() {
82 enum_gcs_error err = m_gcs->initialize(m_params);
83 ASSERT_EQ(err, GCS_OK);
84 err = m_gcs->finalize();
85 // initialization succeeded, and thus so will finalization
86 ASSERT_EQ(err, GCS_OK);
87 }
88 };
89
90 /*
91 This file contains a bunch of test for BUG#22901408.
92
93 Checks default values for compression, does sanity checks, etc.
94 */
95 TEST_F(GcsParametersTest, ParametersCompression) {
96 enum_gcs_error err;
97
98 // --------------------------------------------------------
99 // Compression default values
100 // --------------------------------------------------------
101 Gcs_interface_parameters implicit_values;
102 implicit_values.add_parameter("group_name", "ola");
103 implicit_values.add_parameter("peer_nodes",
104 "127.0.0.1:24844,127.0.0.1:24845");
105 implicit_values.add_parameter("local_node", "127.0.0.1:24844");
106 implicit_values.add_parameter("bootstrap_group", "true");
107 implicit_values.add_parameter("poll_spin_loops", "100");
108
109 err = m_gcs->initialize(implicit_values);
110
111 ASSERT_EQ(err, GCS_OK);
112
113 const Gcs_interface_parameters &init_params =
114 m_xcs->get_initialization_parameters();
115
116 // compression is ON by default
117 ASSERT_TRUE(init_params.get_parameter("compression")->compare("on") == 0);
118
119 // compression_threshold is set to the default
120 std::stringstream ss;
121 ss << Gcs_message_stage_lz4::DEFAULT_THRESHOLD;
122 ASSERT_TRUE(
123 init_params.get_parameter("compression_threshold")->compare(ss.str()) ==
124 0);
125
126 // finalize the interface
127 err = m_gcs->finalize();
128
129 ASSERT_EQ(err, GCS_OK);
130
131 // --------------------------------------------------------
132 // Compression explicit values
133 // --------------------------------------------------------
134 std::string compression = "off";
135 std::string compression_threshold = "1";
136
137 Gcs_interface_parameters explicit_values;
138 explicit_values.add_parameter("group_name", "ola");
139 explicit_values.add_parameter("peer_nodes",
140 "127.0.0.1:24844,127.0.0.1:24845");
141 explicit_values.add_parameter("local_node", "127.0.0.1:24844");
142 explicit_values.add_parameter("bootstrap_group", "true");
143 explicit_values.add_parameter("poll_spin_loops", "100");
144 explicit_values.add_parameter("compression", compression);
145 explicit_values.add_parameter("compression_threshold", compression_threshold);
146
147 err = m_gcs->initialize(explicit_values);
148
149 const Gcs_interface_parameters &init_params2 =
150 m_xcs->get_initialization_parameters();
151
152 ASSERT_EQ(err, GCS_OK);
153
154 // compression is ON by default
155 ASSERT_TRUE(init_params2.get_parameter("compression")->compare(compression) ==
156 0);
157
158 // compression is set to the value we explicitly configured
159 ASSERT_TRUE(init_params2.get_parameter("compression_threshold")
160 ->compare(compression_threshold) == 0);
161
162 err = m_gcs->finalize();
163
164 ASSERT_EQ(err, GCS_OK);
165 }
166
167 /*
168 Checks default values for fragmentation, does sanity checks, etc.
169 */
170 TEST_F(GcsParametersTest, ParametersFragmentation) {
171 enum_gcs_error err;
172
173 // --------------------------------------------------------
174 // Fragmentation default values
175 // --------------------------------------------------------
176 Gcs_interface_parameters implicit_values;
177 implicit_values.add_parameter("group_name", "ola");
178 implicit_values.add_parameter("peer_nodes",
179 "127.0.0.1:24844,127.0.0.1:24845");
180 implicit_values.add_parameter("local_node", "127.0.0.1:24844");
181 implicit_values.add_parameter("bootstrap_group", "true");
182 implicit_values.add_parameter("poll_spin_loops", "100");
183
184 err = m_gcs->initialize(implicit_values);
185
186 ASSERT_EQ(err, GCS_OK);
187
188 const Gcs_interface_parameters &init_params =
189 m_xcs->get_initialization_parameters();
190
191 // fragmentation is ON by default
192 ASSERT_TRUE(init_params.get_parameter("fragmentation")->compare("on") == 0);
193
194 // fragmentation_threshold is set to the default
195 std::stringstream ss;
196 ss << Gcs_message_stage_split_v2::DEFAULT_THRESHOLD;
197 ASSERT_TRUE(
198 init_params.get_parameter("fragmentation_threshold")->compare(ss.str()) ==
199 0);
200
201 // finalize the interface
202 err = m_gcs->finalize();
203
204 ASSERT_EQ(err, GCS_OK);
205
206 // --------------------------------------------------------
207 // Fragmentation explicit values
208 // --------------------------------------------------------
209 std::string fragmentation = "off";
210 std::string fragmentation_threshold = "1";
211
212 Gcs_interface_parameters explicit_values;
213 explicit_values.add_parameter("group_name", "ola");
214 explicit_values.add_parameter("peer_nodes",
215 "127.0.0.1:24844,127.0.0.1:24845");
216 explicit_values.add_parameter("local_node", "127.0.0.1:24844");
217 explicit_values.add_parameter("bootstrap_group", "true");
218 explicit_values.add_parameter("poll_spin_loops", "100");
219 explicit_values.add_parameter("fragmentation", fragmentation);
220 explicit_values.add_parameter("fragmentation_threshold",
221 fragmentation_threshold);
222
223 err = m_gcs->initialize(explicit_values);
224
225 const Gcs_interface_parameters &init_params2 =
226 m_xcs->get_initialization_parameters();
227
228 ASSERT_EQ(err, GCS_OK);
229
230 // fragmentation is ON by default
231 ASSERT_TRUE(
232 init_params2.get_parameter("fragmentation")->compare(fragmentation) == 0);
233
234 // fragmentation is set to the value we explicitly configured
235 ASSERT_TRUE(init_params2.get_parameter("fragmentation_threshold")
236 ->compare(fragmentation_threshold) == 0);
237
238 err = m_gcs->finalize();
239
240 ASSERT_EQ(err, GCS_OK);
241 }
242
243 TEST_F(GcsParametersTest, SanityParameters) {
244 // initialize the interface
245 enum_gcs_error err = m_gcs->initialize(m_params);
246
247 ASSERT_EQ(err, GCS_OK);
248
249 // finalize the interface
250 err = m_gcs->finalize();
251
252 ASSERT_EQ(err, GCS_OK);
253 }
254
255 TEST_F(GcsParametersTest, AbsentGroupName) {
256 Gcs_interface_parameters params;
257 params.add_parameter("peer_nodes", "127.0.0.1:24844,127.0.0.1:24845");
258 params.add_parameter("local_node", "127.0.0.1:24844");
259 params.add_parameter("bootstrap_group", "true");
260 params.add_parameter("poll_spin_loops", "100");
261
262 enum_gcs_error err = m_gcs->initialize(params);
263 ASSERT_EQ(err, GCS_NOK);
264 err = m_gcs->finalize();
265 // initialization failed, and thus so will finalization
266 ASSERT_EQ(err, GCS_NOK);
267 }
268
269 TEST_F(GcsParametersTest, AbsentPeerNodes) {
270 Gcs_interface_parameters params;
271 params.add_parameter("group_name", "ola");
272 params.add_parameter("local_node", "127.0.0.1:24844");
273 params.add_parameter("bootstrap_group", "true");
274 params.add_parameter("poll_spin_loops", "100");
275
276 enum_gcs_error err = m_gcs->initialize(params);
277 ASSERT_EQ(err, GCS_NOK);
278 err = m_gcs->finalize();
279 // initialization failed, and thus so will finalization
280 ASSERT_EQ(err, GCS_NOK);
281 }
282
283 TEST_F(GcsParametersTest, AbsentLocalNode) {
284 Gcs_interface_parameters params;
285 params.add_parameter("group_name", "ola");
286 params.add_parameter("peer_nodes", "127.0.0.1:24844,127.0.0.1:24845");
287 params.add_parameter("bootstrap_group", "true");
288 params.add_parameter("poll_spin_loops", "100");
289
290 enum_gcs_error err = m_gcs->initialize(params);
291 ASSERT_EQ(err, GCS_NOK);
292 err = m_gcs->finalize();
293 // initialization failed, and thus so will finalization
294 ASSERT_EQ(err, GCS_NOK);
295 }
296
297 TEST_F(GcsParametersTest, InvalidPeerNodes) {
298 std::string *p =
299 const_cast<std::string *>(m_params.get_parameter("peer_nodes"));
300 std::string save = *p;
301
302 // invalid peer
303 *p = "127.0.0.1 24844,127.0.0.1 24845";
304
305 enum_gcs_error err = m_gcs->initialize(m_params);
306 ASSERT_EQ(err, GCS_NOK);
307 err = m_gcs->finalize();
308 // initialization failed, and thus so will finalization
309 ASSERT_EQ(err, GCS_NOK);
310
311 *p = save;
312 }
313
314 TEST_F(GcsParametersTest, InvalidLocalNode) {
315 std::string *p =
316 const_cast<std::string *>(m_params.get_parameter("local_node"));
317 std::string save = *p;
318
319 // invalid peer
320 *p = "127.0.0.1 24844";
321 do_check_params();
322 *p = save;
323 }
324
325 TEST_F(GcsParametersTest, InvalidPollSpinLoops) {
326 std::string *p =
327 const_cast<std::string *>(m_params.get_parameter("poll_spin_loops"));
328 std::string save = *p;
329
330 *p = "Invalid";
331 do_check_params();
332 *p = save;
333 }
334
335 TEST_F(GcsParametersTest, InvalidCompressionThreshold) {
336 std::string *p = const_cast<std::string *>(
337 m_params.get_parameter("compression_threshold"));
338 std::string save = *p;
339
340 *p = "Invalid";
341 do_check_params();
342 *p = save;
343 }
344
345 TEST_F(GcsParametersTest, InvalidFragmentationThreshold) {
346 std::string *p = const_cast<std::string *>(
347 m_params.get_parameter("fragmentation_threshold"));
348 std::string save = *p;
349
350 *p = "Invalid";
351 do_check_params();
352 *p = save;
353 }
354
355 TEST_F(GcsParametersTest, InvalidLocalNodeAddress) {
356 std::string *p =
357 const_cast<std::string *>(m_params.get_parameter("local_node"));
358 std::string save = *p;
359
360 *p = "127.0";
361 do_check_params();
362 *p = save;
363 }
364
365 TEST_F(GcsParametersTest, InvalidAllowlistIPMask) {
366 std::string *p =
367 const_cast<std::string *>(m_params.get_parameter("ip_allowlist"));
368 std::string save = *p;
369
370 *p = "192.168.1.1/33";
371 do_check_params();
372 *p = save;
373 }
374
375 TEST_F(GcsParametersTest, InvalidAllowlistIP) {
376 std::string *p =
377 const_cast<std::string *>(m_params.get_parameter("ip_allowlist"));
378 std::string save = *p;
379
380 *p = "192.168.1.256/24";
381 do_check_params();
382 *p = save;
383 }
384
385 TEST_F(GcsParametersTest, InvalidAllowlistIPs) {
386 std::string *p =
387 const_cast<std::string *>(m_params.get_parameter("ip_allowlist"));
388 std::string save = *p;
389
390 *p = "192.168.1.222/24,255.257.256.255";
391 do_check_params();
392 *p = save;
393 }
394
395 TEST_F(GcsParametersTest, HalfBakedIP) {
396 std::string *p =
397 const_cast<std::string *>(m_params.get_parameter("ip_allowlist"));
398 std::string save = *p;
399
400 *p = "192.168.";
401 do_check_params();
402 *p = save;
403 }
404
405 TEST_F(GcsParametersTest, InvalidLocalNode_IP_not_found) {
406 std::string *p =
407 const_cast<std::string *>(m_params.get_parameter("local_node"));
408 std::string save = *p;
409
410 *p = "8.8.8.8:24844";
411 do_check_params();
412
413 *p = "128.0.3.4:12345";
414 do_check_params();
415
416 *p = "localhost:12345";
417 do_check_ok_params();
418
419 *p = save;
420 }
421
422 TEST_F(GcsParametersTest, InvalidNonMemberExpelTimeout) {
423 std::string *p = const_cast<std::string *>(
424 m_params.get_parameter("non_member_expel_timeout"));
425 std::string save = *p;
426
427 *p = "Invalid";
428 do_check_params();
429
430 *p = "-1";
431 do_check_params();
432
433 *p = "3.5";
434 do_check_params();
435
436 *p = save;
437 }
438
439 TEST_F(GcsParametersTest, InvalidSuspicionsProcessingPeriod) {
440 std::string *p = const_cast<std::string *>(
441 m_params.get_parameter("suspicions_processing_period"));
442 std::string save = *p;
443
444 *p = "Invalid";
445 do_check_params();
446
447 *p = "-1";
448 do_check_params();
449
450 *p = "3.5";
451 do_check_params();
452
453 *p = save;
454 }
455
456 TEST_F(GcsParametersTest, InvalidMemberExpelTimeout) {
457 std::string *p =
458 const_cast<std::string *>(m_params.get_parameter("member_expel_timeout"));
459 std::string save = *p;
460
461 *p = "Invalid";
462 do_check_params();
463
464 *p = "-1";
465 do_check_params();
466
467 *p = "3.5";
468 do_check_params();
469
470 *p = save;
471 }
472
473 TEST_F(GcsParametersTest, InvalidJoinAttempts) {
474 std::string *p =
475 const_cast<std::string *>(m_params.get_parameter("join_attempts"));
476 std::string save = *p;
477
478 *p = "Invalid";
479 do_check_params();
480 *p = save;
481 }
482
483 TEST_F(GcsParametersTest, InvalidJoinSleepTime) {
484 std::string *p =
485 const_cast<std::string *>(m_params.get_parameter("join_sleep_time"));
486 std::string save = *p;
487
488 *p = "Invalid";
489 do_check_params();
490 *p = save;
491 }
492
493 } // namespace gcs_parameters_unittest