Skip to content

Commit 78f527f

Browse files
committed
db: Add a unit test to check configuration validation
1 parent 56bf12c commit 78f527f

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,7 @@ if(WITH_TESTS)
14051405
db/compaction/compaction_service_test.cc
14061406
db/compaction/tiered_compaction_test.cc
14071407
db/comparator_db_test.cc
1408+
db/configuration_validation_test.cc
14081409
db/corruption_test.cc
14091410
db/cuckoo_table_db_test.cc
14101411
db/db_readonly_with_timestamp_test.cc
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include <set>
2+
3+
#include "port/port.h"
4+
#include "rocksdb/convenience.h"
5+
#include "rocksdb/db.h"
6+
#include "rocksdb/db_crashtest_use_case.h"
7+
#include "rocksdb/env.h"
8+
#include "rocksdb/options.h"
9+
#include "rocksdb/status.h"
10+
#include "rocksdb/table.h"
11+
#include "rocksdb/use_case.h"
12+
#include "test_util/testharness.h"
13+
14+
namespace ROCKSDB_NAMESPACE {
15+
class ConfigurationValidationTest : public testing::Test {
16+
public:
17+
ConfigurationValidationTest() {
18+
env_ = Env::Default();
19+
db_name_ = test::PerThreadDBPath("configuration_validation_test");
20+
}
21+
22+
std::string db_name_;
23+
Env* env_;
24+
};
25+
26+
TEST_F(ConfigurationValidationTest, DBCrashtestValidConfiguration) {
27+
Options options;
28+
options.create_if_missing = true;
29+
// setting options according to the default_params config in db_crashtest
30+
// TODO: set table options
31+
options.memtable_protection_bytes_per_key = 4;
32+
options.max_background_compactions = 20;
33+
options.max_bytes_for_level_base = 10485760;
34+
options.max_write_buffer_number = 3;
35+
options.max_open_files = -1;
36+
options.recycle_log_file_num = 1;
37+
options.max_subcompactions = 4;
38+
options.target_file_size_base = 2097152;
39+
options.target_file_size_multiplier = 2;
40+
options.write_buffer_size = 128 * 1024 * 1024;
41+
options.periodic_compaction_seconds = 100;
42+
options.stats_dump_period_sec = 600;
43+
options.max_manifest_file_size = 2 * 16384;
44+
options.bytes_per_sync = 0;
45+
options.wal_bytes_per_sync = 0;
46+
options.db_write_buffer_size = 1024 * 1024;
47+
options.max_write_batch_group_size_bytes = 16 * 1024 * 1024;
48+
options.level_compaction_dynamic_level_bytes = true;
49+
options.max_write_buffer_size_to_maintain = 2 * 1024 * 1024;
50+
options.memtable_prefix_bloom_size_ratio = 0.5;
51+
options.wal_compression = CompressionType::kZSTD;
52+
options.verify_sst_unique_id_in_manifest = true;
53+
options.allow_data_in_errors = true;
54+
options.min_write_buffer_number_to_merge = 2;
55+
options.preserve_internal_time_seconds = 3600;
56+
DBOptions db_options(options);
57+
ConfigOptions cfg_opts(db_options);
58+
std::set<std::string> valid_opts;
59+
std::set<std::string> invalid_opts;
60+
DBCrashtestUseCase db_crashtest_use_case;
61+
Status valid = UseCase::ValidateOptions(cfg_opts, "rocksdb.DBCrashtestUseCase", options, valid_opts, invalid_opts);
62+
ASSERT_EQ(valid, Status::OK());
63+
ASSERT_TRUE(invalid_opts.empty());
64+
}
65+
66+
TEST_F(ConfigurationValidationTest, DBCrashtestInvalidConfiguration) {
67+
Options options;
68+
options.create_if_missing = true;
69+
// using default rocksdb options (unless changed) should be invalid
70+
DBOptions db_options(options);
71+
ConfigOptions cfg_opts(db_options);
72+
std::set<std::string> valid_opts;
73+
std::set<std::string> invalid_opts;
74+
DBCrashtestUseCase db_crashtest_use_case;
75+
Status valid = UseCase::ValidateOptions(cfg_opts, "rocksdb.DBCrashtestUseCase", options, valid_opts, invalid_opts);
76+
ASSERT_EQ(valid, Status::InvalidArgument());
77+
ASSERT_FALSE(invalid_opts.empty());
78+
}
79+
} // namespace ROCKSDB_NAMESPACE
80+
81+
int main(int argc, char** argv) {
82+
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
83+
::testing::InitGoogleTest(&argc, argv);
84+
return RUN_ALL_TESTS();
85+
}

0 commit comments

Comments
 (0)