Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
And make GetOptionString also call SerializePrintableOptions.
  • Loading branch information
mrambacher committed Nov 21, 2023
1 parent 1455983 commit 7ba5c35
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions options/configurable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
46 changes: 46 additions & 0 deletions options/options_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, &copy));
}
ASSERT_OK(cfg_opts.ToProps(print_str, &props));
cfg_opts.ignore_unknown_options = true;
ASSERT_OK(GetDBOptionsFromString(cfg_opts, DBOptions(), print_str, &copy));
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, &copy));
}
ASSERT_OK(cfg_opts.ToProps(print_str, &props));
cfg_opts.ignore_unknown_options = true;
ASSERT_OK(GetColumnFamilyOptionsFromString(cfg_opts, ColumnFamilyOptions(),
print_str, &copy));
ASSERT_OK(RocksDBOptionsParser::VerifyCFOptions(cfg_opts, base, copy));
}

const static std::string kCustomEnvName = "Custom";
const static std::string kCustomEnvProp = "env=" + kCustomEnvName;

Expand Down
1 change: 1 addition & 0 deletions test_util/testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7ba5c35

Please sign in to comment.