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
This commit is contained in:
Igor Sugak 2015-03-16 18:08:59 -07:00
parent bd4963e64d
commit 95344346af
9 changed files with 70 additions and 72 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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