From 7ba5c355813ce003760297b63be399f73aec40db Mon Sep 17 00:00:00 2001 From: mrambacher Date: Tue, 21 Nov 2023 18:39:14 -0500 Subject: [PATCH] Add unit tests And make GetOptionString also call SerializePrintableOptions. --- HISTORY.md | 2 +- options/configurable.cc | 3 +++ options/options_test.cc | 46 +++++++++++++++++++++++++++++++++++++++++ test_util/testutil.h | 1 + 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index bae5d64f90..c469c62ead 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ ### New Features * Added ConfigOptions::compare_to. When set, this value causes only values that have been changed to be part of the serialized output (#648). +* Use the Options infrastructure to generate the LOG output. Add the SerializePrintableOptions method and deprecate GetPrintableOptions ### Enhancements * Added a kUseBaseAddress flag and GetBaseOffset flag to OptionTypeInfo. If this flag is set and a function is used for processing options, the function is passed the base address of the struct rather than the specific field (#397) @@ -14,7 +15,6 @@ ### Miscellaneous * Remove leftover references to ROCKSDB_LITE (#755). - ## Hazlenut 2.7.0 (27/10/2023) Based on RocksDB 8.1.1 diff --git a/options/configurable.cc b/options/configurable.cc index a7e45388d6..659c952c16 100644 --- a/options/configurable.cc +++ b/options/configurable.cc @@ -475,6 +475,9 @@ Status Configurable::GetOptionString(const ConfigOptions& config_options, result->clear(); Status s = ConfigurableHelper::SerializeOptions(config_options, *this, "", &props); + if (s.ok() && config_options.IsPrintable()) { + s = SerializePrintableOptions(config_options, "", &props); + } if (s.ok()) { *result = config_options.ToString("", props); } diff --git a/options/options_test.cc b/options/options_test.cc index cc578eeaf0..d1132ad2bc 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -2462,6 +2462,52 @@ TEST_F(OptionsTest, SerializeChangedOptionsCompareLoosely) { ASSERT_EQ(copy_str, props.begin()->second.c_str()); } +TEST_F(OptionsTest, SerializePrintableDBOptions) { + Random rnd(302); + DBOptions base; + ConfigOptions cfg_opts; + std::string opts_str, print_str; + DBOptions copy; + OptionProperties props; + + test::RandomInitDBOptions(&base, &rnd); + ASSERT_OK(GetStringFromDBOptions(cfg_opts, base, &opts_str)); + cfg_opts.depth = ConfigOptions::kDepthPrintable; + ASSERT_OK(GetStringFromDBOptions(cfg_opts, base, &print_str)); + if (print_str != opts_str) { + ASSERT_NOK(GetDBOptionsFromString(cfg_opts, DBOptions(), print_str, ©)); + } + ASSERT_OK(cfg_opts.ToProps(print_str, &props)); + cfg_opts.ignore_unknown_options = true; + ASSERT_OK(GetDBOptionsFromString(cfg_opts, DBOptions(), print_str, ©)); + ASSERT_OK(RocksDBOptionsParser::VerifyDBOptions(cfg_opts, base, copy)); +} + +TEST_F(OptionsTest, SerializePrintableCFOptions) { + Random rnd(302); + DBOptions db_opts; + ColumnFamilyOptions base, copy; + ConfigOptions cfg_opts; + std::string opts_str, print_str; + OptionProperties props; + + test::RandomInitCFOptions(&base, db_opts, &rnd); + base.table_factory.reset( + NewBlockBasedTableFactory(test::RandomBlockBasedTableOptions(&rnd))); + ASSERT_OK(GetStringFromColumnFamilyOptions(cfg_opts, base, &opts_str)); + cfg_opts.depth = ConfigOptions::kDepthPrintable; + ASSERT_OK(GetStringFromColumnFamilyOptions(cfg_opts, base, &print_str)); + if (print_str != opts_str) { + ASSERT_NOK(GetColumnFamilyOptionsFromString(cfg_opts, ColumnFamilyOptions(), + print_str, ©)); + } + ASSERT_OK(cfg_opts.ToProps(print_str, &props)); + cfg_opts.ignore_unknown_options = true; + ASSERT_OK(GetColumnFamilyOptionsFromString(cfg_opts, ColumnFamilyOptions(), + print_str, ©)); + ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(cfg_opts, base, copy)); +} + const static std::string kCustomEnvName = "Custom"; const static std::string kCustomEnvProp = "env=" + kCustomEnvName; diff --git a/test_util/testutil.h b/test_util/testutil.h index 686817c445..d33973c945 100644 --- a/test_util/testutil.h +++ b/test_util/testutil.h @@ -825,6 +825,7 @@ CompactionFilterFactory* RandomCompactionFilterFactory(Random* rnd); const SliceTransform* RandomSliceTransform(Random* rnd, int pre_defined = -1); TableFactory* RandomTableFactory(Random* rnd, int pre_defined = -1); +BlockBasedTableOptions RandomBlockBasedTableOptions(Random* rnd); std::string RandomName(Random* rnd, const size_t len);