56
56
DSN_DECLARE_string (cluster_root);
57
57
DSN_DECLARE_string (meta_state_service_type);
58
58
59
- namespace dsn {
60
- namespace replication {
59
+ namespace dsn ::replication {
61
60
62
61
namespace {
63
62
64
- const std::vector<std::string> keys = {
65
- dsn::replica_envs::MANUAL_COMPACT_ONCE_TRIGGER_TIME,
66
- dsn::replica_envs::MANUAL_COMPACT_ONCE_TARGET_LEVEL,
67
- dsn::replica_envs::MANUAL_COMPACT_ONCE_BOTTOMMOST_LEVEL_COMPACTION,
68
- dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME,
69
- dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TARGET_LEVEL,
70
- dsn::replica_envs::MANUAL_COMPACT_PERIODIC_BOTTOMMOST_LEVEL_COMPACTION,
71
- dsn::replica_envs::ROCKSDB_USAGE_SCENARIO,
72
- dsn::replica_envs::ROCKSDB_CHECKPOINT_RESERVE_MIN_COUNT,
73
- dsn::replica_envs::ROCKSDB_CHECKPOINT_RESERVE_TIME_SECONDS};
74
- const std::vector<std::string> values = {
75
- " 1712846598" ,
76
- " 6" ,
77
- dsn::replica_envs::MANUAL_COMPACT_BOTTOMMOST_LEVEL_COMPACTION_FORCE,
78
- " 1712846598" ,
79
- " -1" ,
80
- dsn::replica_envs::MANUAL_COMPACT_BOTTOMMOST_LEVEL_COMPACTION_SKIP,
81
- dsn::replica_envs::ROCKSDB_ENV_USAGE_SCENARIO_NORMAL,
82
- " 1" ,
83
- " 0" };
84
-
85
- const std::vector<std::string> del_keys = {dsn::replica_envs::MANUAL_COMPACT_ONCE_TRIGGER_TIME,
86
- dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME,
87
- dsn::replica_envs::ROCKSDB_USAGE_SCENARIO};
88
- const std::set<std::string> del_keys_set = {dsn::replica_envs::MANUAL_COMPACT_ONCE_TRIGGER_TIME,
89
- dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME,
90
- dsn::replica_envs::ROCKSDB_USAGE_SCENARIO};
91
-
92
- const std::string clear_prefix = " rocksdb" ;
93
-
94
63
// If `str` is <prefix>.xxx, return <prefix>; otherwise return empty string("").
95
64
std::string acquire_prefix (const std::string &str)
96
65
{
@@ -258,6 +227,28 @@ class server_state_test
258
227
259
228
void meta_service_test_app::app_envs_basic_test ()
260
229
{
230
+ static const std::vector<std::string> kValues = {
231
+ " 1712846598" ,
232
+ " 6" ,
233
+ dsn::replica_envs::MANUAL_COMPACT_BOTTOMMOST_LEVEL_COMPACTION_FORCE,
234
+ " 1712846598" ,
235
+ " -1" ,
236
+ dsn::replica_envs::MANUAL_COMPACT_BOTTOMMOST_LEVEL_COMPACTION_SKIP,
237
+ dsn::replica_envs::ROCKSDB_ENV_USAGE_SCENARIO_NORMAL,
238
+ " 1" ,
239
+ " 0" };
240
+
241
+ static const std::vector<std::string> kKeys = {
242
+ dsn::replica_envs::MANUAL_COMPACT_ONCE_TRIGGER_TIME,
243
+ dsn::replica_envs::MANUAL_COMPACT_ONCE_TARGET_LEVEL,
244
+ dsn::replica_envs::MANUAL_COMPACT_ONCE_BOTTOMMOST_LEVEL_COMPACTION,
245
+ dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME,
246
+ dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TARGET_LEVEL,
247
+ dsn::replica_envs::MANUAL_COMPACT_PERIODIC_BOTTOMMOST_LEVEL_COMPACTION,
248
+ dsn::replica_envs::ROCKSDB_USAGE_SCENARIO,
249
+ dsn::replica_envs::ROCKSDB_CHECKPOINT_RESERVE_MIN_COUNT,
250
+ dsn::replica_envs::ROCKSDB_CHECKPOINT_RESERVE_TIME_SECONDS};
251
+
261
252
server_state_test test;
262
253
test.load_apps ({" test_app1" ,
263
254
" test_set_app_envs_not_found" ,
@@ -299,17 +290,17 @@ void meta_service_test_app::app_envs_basic_test()
299
290
// Normal case for setting envs.
300
291
std::cout << " test server_state::set_app_envs(success)..." << std::endl;
301
292
{
302
- test.test_set_app_envs (" test_app1" , keys, values , ERR_OK);
293
+ test.test_set_app_envs (" test_app1" , kKeys , kValues , ERR_OK);
303
294
304
295
const auto &app = test.get_app (" test_app1" );
305
296
ASSERT_TRUE (app);
306
297
307
- for (size_t idx = 0 ; idx < keys .size (); ++idx) {
308
- const auto &key = keys [idx];
298
+ for (size_t idx = 0 ; idx < kKeys .size (); ++idx) {
299
+ const auto &key = kKeys [idx];
309
300
310
301
// Every env should be inserted.
311
302
ASSERT_EQ (1 , app->envs .count (key));
312
- ASSERT_EQ (values [idx], app->envs .at (key));
303
+ ASSERT_EQ (kValues [idx], app->envs .at (key));
313
304
}
314
305
}
315
306
@@ -342,25 +333,31 @@ void meta_service_test_app::app_envs_basic_test()
342
333
343
334
#undef TEST_DEL_APP_ENVS_FAILED
344
335
336
+ static const std::vector<std::string> kDelKeyList = {
337
+ dsn::replica_envs::MANUAL_COMPACT_ONCE_TRIGGER_TIME,
338
+ dsn::replica_envs::MANUAL_COMPACT_PERIODIC_TRIGGER_TIME,
339
+ dsn::replica_envs::ROCKSDB_USAGE_SCENARIO};
340
+ static const std::set<std::string> kDelKeySet (kDelKeyList .begin (), kDelKeyList .end ());
341
+
345
342
// Normal case for deleting envs.
346
343
std::cout << " test server_state::del_app_envs(success)..." << std::endl;
347
344
{
348
- test.test_del_app_envs (" test_app1" , del_keys , ERR_OK);
345
+ test.test_del_app_envs (" test_app1" , kDelKeyList , ERR_OK);
349
346
350
347
const auto &app = test.get_app (" test_app1" );
351
348
ASSERT_TRUE (app);
352
349
353
- for (size_t idx = 0 ; idx < keys .size (); ++idx) {
354
- const std::string &key = keys [idx];
355
- if (del_keys_set .count (key) > 0 ) {
356
- // The env in `del_keys_set ` should be deleted.
350
+ for (size_t idx = 0 ; idx < kKeys .size (); ++idx) {
351
+ const std::string &key = kKeys [idx];
352
+ if (kDelKeySet .count (key) > 0 ) {
353
+ // The env in `kDelKeySet ` should be deleted.
357
354
ASSERT_EQ (0 , app->envs .count (key));
358
355
continue ;
359
356
}
360
357
361
- // The env should still exist if it is not in `del_keys_set `.
358
+ // The env should still exist if it is not in `kDelKeySet `.
362
359
ASSERT_EQ (1 , app->envs .count (key));
363
- ASSERT_EQ (values [idx], app->envs .at (key));
360
+ ASSERT_EQ (kValues [idx], app->envs .at (key));
364
361
}
365
362
}
366
363
@@ -396,28 +393,29 @@ void meta_service_test_app::app_envs_basic_test()
396
393
{
397
394
// Test specifying prefix.
398
395
{
399
- test.test_clear_app_envs (" test_app1" , clear_prefix, ERR_OK);
396
+ static const std::string kClearPrefix = " rocksdb" ;
397
+ test.test_clear_app_envs (" test_app1" , kClearPrefix , ERR_OK);
400
398
401
399
const auto &app = test.get_app (" test_app1" );
402
400
ASSERT_TRUE (app);
403
401
404
- for (size_t idx = 0 ; idx < keys .size (); ++idx) {
405
- const std::string &key = keys [idx];
406
- if (del_keys_set .count (key) > 0 ) {
402
+ for (size_t idx = 0 ; idx < kKeys .size (); ++idx) {
403
+ const std::string &key = kKeys [idx];
404
+ if (kDelKeySet .count (key) > 0 ) {
407
405
// The env should have been deleted during test for `del_app_envs`.
408
406
ASSERT_EQ (0 , app->envs .count (key));
409
407
continue ;
410
408
}
411
409
412
- if (acquire_prefix (key) == clear_prefix ) {
410
+ if (acquire_prefix (key) == kClearPrefix ) {
413
411
// The env with specified prefix should be deleted.
414
412
ASSERT_EQ (0 , app->envs .count (key));
415
413
continue ;
416
414
}
417
415
418
416
// Otherwise, the env should still exist.
419
417
ASSERT_EQ (1 , app->envs .count (key));
420
- ASSERT_EQ (values [idx], app->envs .at (key));
418
+ ASSERT_EQ (kValues [idx], app->envs .at (key));
421
419
}
422
420
}
423
421
@@ -434,5 +432,4 @@ void meta_service_test_app::app_envs_basic_test()
434
432
}
435
433
}
436
434
437
- } // namespace replication
438
- } // namespace dsn
435
+ } // namespace dsn::replication
0 commit comments