rocksdb: Small refactoring before migrating to gtest

Summary: These changes are necessary to make tests look more generic, and avoid feature conflicts with gtest.

Test Plan:
Make sure no build errors, and all test are passing.
```
% make check
```

Reviewers: igor, meyering

Reviewed By: meyering

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D35145
main
Igor Sugak 10 years ago
parent bd4963e64d
commit 95344346af
  1. 2
      db/file_indexer_test.cc
  2. 3
      db/perf_context_test.cc
  3. 3
      db/prefix_test.cc
  4. 3
      table/cuckoo_table_reader_test.cc
  5. 20
      table/table_test.cc
  6. 94
      util/ldb_cmd.cc
  7. 4
      util/ldb_cmd.h
  8. 4
      util/ldb_cmd_execute_result.h
  9. 9
      utilities/merge_operators/string_append/stringappend_test.cc

@ -41,7 +41,7 @@ class IntComparator : public Comparator {
void FindShortSuccessor(std::string* key) const override {}
};
struct FileIndexerTest {
class FileIndexerTest {
public:
FileIndexerTest()
: kNumLevels(4), files(new std::vector<FileMetaData*>[kNumLevels]) {}

@ -544,6 +544,5 @@ int main(int argc, char** argv) {
std::cout << kDbName << "\n";
rocksdb::test::RunAllTests();
return 0;
return rocksdb::test::RunAllTests();
}

@ -495,8 +495,7 @@ int main(int argc, char** argv) {
ParseCommandLineFlags(&argc, &argv, true);
std::cout << kDbName << "\n";
rocksdb::test::RunAllTests();
return 0;
return rocksdb::test::RunAllTests();
}
#endif // GFLAGS

@ -535,8 +535,7 @@ TEST(CuckooReaderTest, TestReadPerformance) {
int main(int argc, char** argv) {
ParseCommandLineFlags(&argc, &argv, true);
rocksdb::test::RunAllTests();
return 0;
return rocksdb::test::RunAllTests();
}
#endif // GFLAGS.

@ -698,9 +698,9 @@ class FixedOrLessPrefixTransform : public SliceTransform {
}
};
class Harness {
class HarnessTest {
public:
Harness()
HarnessTest()
: ioptions_(options_), constructor_(nullptr),
write_buffer_(options_.db_write_buffer_size) {}
@ -793,7 +793,7 @@ class Harness {
ioptions_ = ImmutableCFOptions(options_);
}
~Harness() {
~HarnessTest() {
delete constructor_;
}
@ -1951,7 +1951,7 @@ TEST(GeneralTableTest, ApproximateOffsetOfCompressed) {
}
}
TEST(Harness, Randomized) {
TEST(HarnessTest, Randomized) {
std::vector<TestArgs> args = GenerateArgList();
for (unsigned int i = 0; i < args.size(); i++) {
Init(args[i]);
@ -1972,7 +1972,7 @@ TEST(Harness, Randomized) {
}
}
TEST(Harness, RandomizedLongDB) {
TEST(HarnessTest, RandomizedLongDB) {
Random rnd(test::RandomSeed());
TestArgs args = { DB_TEST, false, 16, kNoCompression, 0 };
Init(args);
@ -2031,7 +2031,7 @@ TEST(MemTableTest, Simple) {
}
// Test the empty key
TEST(Harness, SimpleEmptyKey) {
TEST(HarnessTest, SimpleEmptyKey) {
auto args = GenerateArgList();
for (const auto& arg : args) {
Init(arg);
@ -2041,7 +2041,7 @@ TEST(Harness, SimpleEmptyKey) {
}
}
TEST(Harness, SimpleSingle) {
TEST(HarnessTest, SimpleSingle) {
auto args = GenerateArgList();
for (const auto& arg : args) {
Init(arg);
@ -2051,7 +2051,7 @@ TEST(Harness, SimpleSingle) {
}
}
TEST(Harness, SimpleMulti) {
TEST(HarnessTest, SimpleMulti) {
auto args = GenerateArgList();
for (const auto& arg : args) {
Init(arg);
@ -2063,7 +2063,7 @@ TEST(Harness, SimpleMulti) {
}
}
TEST(Harness, SimpleSpecialKey) {
TEST(HarnessTest, SimpleSpecialKey) {
auto args = GenerateArgList();
for (const auto& arg : args) {
Init(arg);
@ -2073,7 +2073,7 @@ TEST(Harness, SimpleSpecialKey) {
}
}
TEST(Harness, FooterTests) {
TEST(HarnessTest, FooterTests) {
{
// upconvert legacy block based
std::string encoded;

@ -195,10 +195,10 @@ bool LDBCommand::ParseIntOption(const map<string, string>& options,
value = stoi(itr->second);
return true;
} catch(const invalid_argument&) {
exec_state = LDBCommandExecuteResult::FAILED(option +
exec_state = LDBCommandExecuteResult::Failed(option +
" has an invalid value.");
} catch(const out_of_range&) {
exec_state = LDBCommandExecuteResult::FAILED(option +
exec_state = LDBCommandExecuteResult::Failed(option +
" has a value out-of-range.");
}
}
@ -235,7 +235,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
use_table_options = true;
table_options.filter_policy.reset(NewBloomFilterPolicy(bits));
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOOM_BITS +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_BLOOM_BITS +
" must be > 0.");
}
}
@ -246,7 +246,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
use_table_options = true;
table_options.block_size = block_size;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_BLOCK_SIZE +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_BLOCK_SIZE +
" must be > 0.");
}
}
@ -277,7 +277,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
opt.compression = kLZ4HCCompression;
} else {
// Unknown compression.
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Unknown compression level: " + comp);
}
}
@ -288,7 +288,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
if (db_write_buffer_size >= 0) {
opt.db_write_buffer_size = db_write_buffer_size;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_DB_WRITE_BUFFER_SIZE +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_DB_WRITE_BUFFER_SIZE +
" must be >= 0.");
}
}
@ -299,7 +299,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
if (write_buffer_size > 0) {
opt.write_buffer_size = write_buffer_size;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_WRITE_BUFFER_SIZE +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_WRITE_BUFFER_SIZE +
" must be > 0.");
}
}
@ -309,7 +309,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
if (file_size > 0) {
opt.target_file_size_base = file_size;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_FILE_SIZE +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_FILE_SIZE +
" must be > 0.");
}
}
@ -326,7 +326,7 @@ Options LDBCommand::PrepareOptionsForOpenDB() {
NewFixedPrefixTransform(static_cast<size_t>(fix_prefix_len)));
} else {
exec_state_ =
LDBCommandExecuteResult::FAILED(ARG_FIX_PREFIX_LEN + " must be > 0.");
LDBCommandExecuteResult::Failed(ARG_FIX_PREFIX_LEN + " must be > 0.");
}
}
@ -436,7 +436,7 @@ void CompactorCommand::DoCommand() {
}
db_->CompactRange(begin, end);
exec_state_ = LDBCommandExecuteResult::SUCCEED("");
exec_state_ = LDBCommandExecuteResult::Succeed("");
delete begin;
delete end;
@ -568,7 +568,7 @@ ManifestDumpCommand::ManifestDumpCommand(const vector<string>& params,
if (itr != options.end()) {
path_ = itr->second;
if (path_.empty()) {
exec_state_ = LDBCommandExecuteResult::FAILED("--path: missing pathname");
exec_state_ = LDBCommandExecuteResult::Failed("--path: missing pathname");
}
}
}
@ -585,7 +585,7 @@ void ManifestDumpCommand::DoCommand() {
// containing the db for files of the form MANIFEST_[0-9]+
DIR* d = opendir(db_path_.c_str());
if (d == nullptr) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
db_path_ + " is not a directory");
return;
}
@ -602,7 +602,7 @@ void ManifestDumpCommand::DoCommand() {
manifestfile = db_path_ + "/" + std::string(entry->d_name);
found = true;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Multiple MANIFEST files found; use --path to select one");
closedir(d);
return;
@ -637,7 +637,7 @@ ListColumnFamiliesCommand::ListColumnFamiliesCommand(
: LDBCommand(options, flags, false, {}) {
if (params.size() != 1) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"dbname must be specified for the list_column_families command");
} else {
dbname_ = params[0];
@ -780,7 +780,7 @@ void InternalDumpCommand::DoCommand() {
// Cast as DBImpl to get internal iterator
DBImpl* idb = dynamic_cast<DBImpl*>(db_);
if (!idb) {
exec_state_ = LDBCommandExecuteResult::FAILED("DB is not DBImpl");
exec_state_ = LDBCommandExecuteResult::Failed("DB is not DBImpl");
return;
}
string rtype1,rtype2,row,val;
@ -792,7 +792,7 @@ void InternalDumpCommand::DoCommand() {
ScopedArenaIterator iter(idb->TEST_NewInternalIterator(&arena));
Status st = iter->status();
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED("Iterator error:"
exec_state_ = LDBCommandExecuteResult::Failed("Iterator error:"
+ st.ToString());
}
@ -899,10 +899,10 @@ DBDumperCommand::DBDumperCommand(const vector<string>& params,
try {
max_keys_ = stoi(itr->second);
} catch(const invalid_argument&) {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has an invalid value");
} catch(const out_of_range&) {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has a value out-of-range");
}
}
@ -961,7 +961,7 @@ void DBDumperCommand::DoCommand() {
Iterator* iter = db_->NewIterator(ReadOptions());
Status st = iter->status();
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED("Iterator error."
exec_state_ = LDBCommandExecuteResult::Failed("Iterator error."
+ st.ToString());
}
@ -1094,7 +1094,7 @@ ReduceDBLevelsCommand::ReduceDBLevelsCommand(const vector<string>& params,
print_old_levels_ = IsFlagPresent(flags, ARG_PRINT_OLD_LEVELS);
if(new_levels_ <= 0) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
" Use --" + ARG_NEW_LEVELS + " to specify a new level number\n");
}
}
@ -1165,7 +1165,7 @@ Status ReduceDBLevelsCommand::GetOldNumOfLevels(Options& opt,
void ReduceDBLevelsCommand::DoCommand() {
if (new_levels_ <= 1) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Invalid number of levels.\n");
return;
}
@ -1175,7 +1175,7 @@ void ReduceDBLevelsCommand::DoCommand() {
int old_level_num = -1;
st = GetOldNumOfLevels(opt, &old_level_num);
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
return;
}
@ -1201,7 +1201,7 @@ void ReduceDBLevelsCommand::DoCommand() {
EnvOptions soptions;
st = VersionSet::ReduceNumberOfLevels(db_path_, &opt, soptions, new_levels_);
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
return;
}
}
@ -1224,7 +1224,7 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand(
exec_state_);
if (old_compaction_style_ != kCompactionStyleLevel &&
old_compaction_style_ != kCompactionStyleUniversal) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Use --" + ARG_OLD_COMPACTION_STYLE + " to specify old compaction " +
"style. Check ldb help for proper compaction style value.\n");
return;
@ -1234,14 +1234,14 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand(
exec_state_);
if (new_compaction_style_ != kCompactionStyleLevel &&
new_compaction_style_ != kCompactionStyleUniversal) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Use --" + ARG_NEW_COMPACTION_STYLE + " to specify new compaction " +
"style. Check ldb help for proper compaction style value.\n");
return;
}
if (new_compaction_style_ == old_compaction_style_) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Old compaction style is the same as new compaction style. "
"Nothing to do.\n");
return;
@ -1249,7 +1249,7 @@ ChangeCompactionStyleCommand::ChangeCompactionStyleCommand(
if (old_compaction_style_ == kCompactionStyleUniversal &&
new_compaction_style_ == kCompactionStyleLevel) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Convert from universal compaction to level compaction. "
"Nothing to do.\n");
return;
@ -1320,14 +1320,14 @@ void ChangeCompactionStyleCommand::DoCommand() {
// level 0 should have only 1 file
if (i == 0 && num_files != 1) {
exec_state_ = LDBCommandExecuteResult::FAILED("Number of db files at "
exec_state_ = LDBCommandExecuteResult::Failed("Number of db files at "
"level 0 after compaction is " + ToString(num_files) +
", not 1.\n");
return;
}
// other levels should have no file
if (i > 0 && num_files != 0) {
exec_state_ = LDBCommandExecuteResult::FAILED("Number of db files at "
exec_state_ = LDBCommandExecuteResult::Failed("Number of db files at "
"level " + ToString(i) + " after compaction is " +
ToString(num_files) + ", not 0.\n");
return;
@ -1395,7 +1395,7 @@ void DumpWalFile(std::string wal_file, bool print_header, bool print_values,
Status status = env_->NewSequentialFile(wal_file, &file, soptions);
if (!status.ok()) {
if (exec_state) {
*exec_state = LDBCommandExecuteResult::FAILED("Failed to open WAL file " +
*exec_state = LDBCommandExecuteResult::Failed("Failed to open WAL file " +
status.ToString());
} else {
cerr << "Error: Failed to open WAL file " << status.ToString()
@ -1459,7 +1459,7 @@ WALDumperCommand::WALDumperCommand(const vector<string>& params,
print_header_ = IsFlagPresent(flags, ARG_PRINT_HEADER);
print_values_ = IsFlagPresent(flags, ARG_PRINT_VALUE);
if (wal_file_.empty()) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Argument " + ARG_WAL_FILE + " must be specified.");
}
}
@ -1486,7 +1486,7 @@ GetCommand::GetCommand(const vector<string>& params,
ARG_VALUE_HEX})) {
if (params.size() != 1) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"<key> must be specified for the get command");
} else {
key_ = params.at(0);
@ -1512,7 +1512,7 @@ void GetCommand::DoCommand() {
fprintf(stdout, "%s\n",
(is_value_hex_ ? StringToHex(value) : value).c_str());
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
}
@ -1527,7 +1527,7 @@ ApproxSizeCommand::ApproxSizeCommand(const vector<string>& params,
if (options.find(ARG_FROM) != options.end()) {
start_key_ = options.find(ARG_FROM)->second;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_FROM +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_FROM +
" must be specified for approxsize command");
return;
}
@ -1535,7 +1535,7 @@ ApproxSizeCommand::ApproxSizeCommand(const vector<string>& params,
if (options.find(ARG_TO) != options.end()) {
end_key_ = options.find(ARG_TO)->second;
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_TO +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_TO +
" must be specified for approxsize command");
return;
}
@ -1563,7 +1563,7 @@ void ApproxSizeCommand::DoCommand() {
/* Weird that GetApproximateSizes() returns void, although documentation
* says that it returns a Status object.
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
*/
}
@ -1577,10 +1577,10 @@ BatchPutCommand::BatchPutCommand(const vector<string>& params,
ARG_CREATE_IF_MISSING})) {
if (params.size() < 2) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"At least one <key> <value> pair must be specified batchput.");
} else if (params.size() % 2 != 0) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"Equal number of <key>s and <value>s must be specified for batchput.");
} else {
for (size_t i = 0; i < params.size(); i += 2) {
@ -1612,7 +1612,7 @@ void BatchPutCommand::DoCommand() {
if (st.ok()) {
fprintf(stdout, "OK\n");
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
}
@ -1656,10 +1656,10 @@ ScanCommand::ScanCommand(const vector<string>& params,
try {
max_keys_scanned_ = stoi(itr->second);
} catch(const invalid_argument&) {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has an invalid value");
} catch(const out_of_range&) {
exec_state_ = LDBCommandExecuteResult::FAILED(ARG_MAX_KEYS +
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has a value out-of-range");
}
}
@ -1729,7 +1729,7 @@ void ScanCommand::DoCommand() {
}
}
if (!it->status().ok()) { // Check for any errors found during the scan
exec_state_ = LDBCommandExecuteResult::FAILED(it->status().ToString());
exec_state_ = LDBCommandExecuteResult::Failed(it->status().ToString());
}
delete it;
}
@ -1742,7 +1742,7 @@ DeleteCommand::DeleteCommand(const vector<string>& params,
BuildCmdLineOptions({ARG_HEX, ARG_KEY_HEX, ARG_VALUE_HEX})) {
if (params.size() != 1) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"KEY must be specified for the delete command");
} else {
key_ = params.at(0);
@ -1763,7 +1763,7 @@ void DeleteCommand::DoCommand() {
if (st.ok()) {
fprintf(stdout, "OK\n");
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
}
@ -1775,7 +1775,7 @@ PutCommand::PutCommand(const vector<string>& params,
ARG_CREATE_IF_MISSING})) {
if (params.size() != 2) {
exec_state_ = LDBCommandExecuteResult::FAILED(
exec_state_ = LDBCommandExecuteResult::Failed(
"<key> and <value> must be specified for the put command");
} else {
key_ = params.at(0);
@ -1804,7 +1804,7 @@ void PutCommand::DoCommand() {
if (st.ok()) {
fprintf(stdout, "OK\n");
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
}
@ -1922,7 +1922,7 @@ void CheckConsistencyCommand::DoCommand() {
if (st.ok()) {
fprintf(stdout, "OK\n");
} else {
exec_state_ = LDBCommandExecuteResult::FAILED(st.ToString());
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
}
}

@ -111,7 +111,7 @@ public:
DoCommand();
if (exec_state_.IsNotStarted()) {
exec_state_ = LDBCommandExecuteResult::SUCCEED("");
exec_state_ = LDBCommandExecuteResult::Succeed("");
}
if (db_ != nullptr) {
@ -243,7 +243,7 @@ protected:
}
if (!st.ok()) {
string msg = st.ToString();
exec_state_ = LDBCommandExecuteResult::FAILED(msg);
exec_state_ = LDBCommandExecuteResult::Failed(msg);
}
options_ = opt;

@ -52,11 +52,11 @@ public:
return state_ == EXEC_FAILED;
}
static LDBCommandExecuteResult SUCCEED(std::string msg) {
static LDBCommandExecuteResult Succeed(std::string msg) {
return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
}
static LDBCommandExecuteResult FAILED(std::string msg) {
static LDBCommandExecuteResult Failed(std::string msg) {
return LDBCommandExecuteResult(EXEC_FAILED, msg);
}

@ -576,20 +576,21 @@ TEST(StringAppendOperatorTest, SimpleTestNullDelimiter) {
} // namespace rocksdb
int main(int arc, char** argv) {
int main(int argc, char** argv) {
// Run with regular database
int result;
{
fprintf(stderr, "Running tests with regular db and operator.\n");
StringAppendOperatorTest::SetOpenDbFunction(&OpenNormalDb);
rocksdb::test::RunAllTests();
result = rocksdb::test::RunAllTests();
}
// Run with TTL
{
fprintf(stderr, "Running tests with ttl db and generic operator.\n");
StringAppendOperatorTest::SetOpenDbFunction(&OpenTtlDb);
rocksdb::test::RunAllTests();
result |=rocksdb::test::RunAllTests();
}
return 0;
return result;
}

Loading…
Cancel
Save