Eliminate use of 'using namespace std'. Also remove a number of ADL references to std functions.

Summary: Reduce use of argument-dependent name lookup in RocksDB.

Test Plan: 'make check' passed.

Reviewers: andrewkr

Reviewed By: andrewkr

Subscribers: leveldb, andrewkr, dhruba

Differential Revision: https://reviews.facebook.net/D58203
main
Aaron Orenstein 8 years ago
parent 26adaad438
commit 2073cf3775
  1. 7
      db/auto_roll_logger.cc
  2. 52
      db/auto_roll_logger_test.cc
  3. 2
      db/column_family_test.cc
  4. 8
      db/db_impl.cc
  5. 2
      db/db_test.cc
  6. 11
      db/transaction_log_impl.cc
  7. 10
      db/version_set.cc
  8. 13
      port/win/xpress_win.cc
  9. 5
      tools/db_stress.cc
  10. 697
      tools/ldb_cmd.cc
  11. 49
      util/autovector_test.cc
  12. 4
      util/cache_test.cc
  13. 2
      util/env_hdfs.cc
  14. 4
      utilities/backupable/backupable_db_test.cc
  15. 39
      utilities/redis/redis_lists_test.cc

@ -6,8 +6,6 @@
#include "db/auto_roll_logger.h" #include "db/auto_roll_logger.h"
#include "util/mutexlock.h" #include "util/mutexlock.h"
using namespace std;
namespace rocksdb { namespace rocksdb {
// -- AutoRollLogger // -- AutoRollLogger
@ -47,7 +45,8 @@ void AutoRollLogger::RollLogFile() {
env_->RenameFile(log_fname_, old_fname); env_->RenameFile(log_fname_, old_fname);
} }
string AutoRollLogger::ValistToString(const char* format, va_list args) const { std::string AutoRollLogger::ValistToString(const char* format,
va_list args) const {
// Any log messages longer than 1024 will get truncated. // Any log messages longer than 1024 will get truncated.
// The user is responsible for chopping longer messages into multi line log // The user is responsible for chopping longer messages into multi line log
static const int MAXBUFFERSIZE = 1024; static const int MAXBUFFERSIZE = 1024;
@ -112,7 +111,7 @@ void AutoRollLogger::LogHeader(const char* format, va_list args) {
// strings // strings
va_list tmp; va_list tmp;
va_copy(tmp, args); va_copy(tmp, args);
string data = ValistToString(format, tmp); std::string data = ValistToString(format, tmp);
va_end(tmp); va_end(tmp);
MutexLock l(&mutex_); MutexLock l(&mutex_);

@ -19,8 +19,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
using namespace std;
namespace rocksdb { namespace rocksdb {
class AutoRollLoggerTest : public testing::Test { class AutoRollLoggerTest : public testing::Test {
@ -40,23 +38,22 @@ class AutoRollLoggerTest : public testing::Test {
Env::Default()->CreateDir(kTestDir); Env::Default()->CreateDir(kTestDir);
} }
void RollLogFileBySizeTest(AutoRollLogger* logger, void RollLogFileBySizeTest(AutoRollLogger* logger, size_t log_max_size,
size_t log_max_size, const std::string& log_message);
const string& log_message); uint64_t RollLogFileByTimeTest(AutoRollLogger* logger, size_t time,
uint64_t RollLogFileByTimeTest(AutoRollLogger* logger, const std::string& log_message);
size_t time,
const string& log_message);
static const string kSampleMessage; static const std::string kSampleMessage;
static const string kTestDir; static const std::string kTestDir;
static const string kLogFile; static const std::string kLogFile;
static Env* env; static Env* env;
}; };
const string AutoRollLoggerTest::kSampleMessage( const std::string AutoRollLoggerTest::kSampleMessage(
"this is the message to be written to the log file!!"); "this is the message to be written to the log file!!");
const string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test"); const std::string AutoRollLoggerTest::kTestDir(test::TmpDir() + "/db_log_test");
const string AutoRollLoggerTest::kLogFile(test::TmpDir() + "/db_log_test/LOG"); const std::string AutoRollLoggerTest::kLogFile(test::TmpDir() +
"/db_log_test/LOG");
Env* AutoRollLoggerTest::env = Env::Default(); Env* AutoRollLoggerTest::env = Env::Default();
// In this test we only want to Log some simple log message with // In this test we only want to Log some simple log message with
@ -86,7 +83,7 @@ void GetFileCreateTime(const std::string& fname, uint64_t* file_ctime) {
void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger, void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger,
size_t log_max_size, size_t log_max_size,
const string& log_message) { const std::string& log_message) {
logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL); logger->SetInfoLogLevel(InfoLogLevel::INFO_LEVEL);
// measure the size of each message, which is supposed // measure the size of each message, which is supposed
// to be equal or greater than log_message.size() // to be equal or greater than log_message.size()
@ -111,7 +108,7 @@ void AutoRollLoggerTest::RollLogFileBySizeTest(AutoRollLogger* logger,
} }
uint64_t AutoRollLoggerTest::RollLogFileByTimeTest( uint64_t AutoRollLoggerTest::RollLogFileByTimeTest(
AutoRollLogger* logger, size_t time, const string& log_message) { AutoRollLogger* logger, size_t time, const std::string& log_message) {
uint64_t expected_create_time; uint64_t expected_create_time;
uint64_t actual_create_time; uint64_t actual_create_time;
uint64_t total_log_size; uint64_t total_log_size;
@ -361,13 +358,13 @@ TEST_F(AutoRollLoggerTest, InfoLogLevel) {
// Test the logger Header function for roll over logs // Test the logger Header function for roll over logs
// We expect the new logs creates as roll over to carry the headers specified // We expect the new logs creates as roll over to carry the headers specified
static std::vector<string> GetOldFileNames(const string& path) { static std::vector<std::string> GetOldFileNames(const std::string& path) {
std::vector<string> ret; std::vector<std::string> ret;
const string dirname = path.substr(/*start=*/ 0, path.find_last_of("/")); const std::string dirname = path.substr(/*start=*/0, path.find_last_of("/"));
const string fname = path.substr(path.find_last_of("/") + 1); const std::string fname = path.substr(path.find_last_of("/") + 1);
std::vector<string> children; std::vector<std::string> children;
Env::Default()->GetChildren(dirname, &children); Env::Default()->GetChildren(dirname, &children);
// We know that the old log files are named [path]<something> // We know that the old log files are named [path]<something>
@ -382,12 +379,13 @@ static std::vector<string> GetOldFileNames(const string& path) {
} }
// Return the number of lines where a given pattern was found in the file // Return the number of lines where a given pattern was found in the file
static size_t GetLinesCount(const string& fname, const string& pattern) { static size_t GetLinesCount(const std::string& fname,
stringstream ssbuf; const std::string& pattern) {
string line; std::stringstream ssbuf;
std::string line;
size_t count = 0; size_t count = 0;
ifstream inFile(fname.c_str()); std::ifstream inFile(fname.c_str());
ssbuf << inFile.rdbuf(); ssbuf << inFile.rdbuf();
while (getline(ssbuf, line)) { while (getline(ssbuf, line)) {
@ -426,7 +424,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
} }
} }
const string newfname = logger.TEST_log_fname(); const std::string newfname = logger.TEST_log_fname();
// Log enough data to cause a roll over // Log enough data to cause a roll over
int i = 0; int i = 0;
@ -466,7 +464,7 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
[](char ch) { return ch == '/'; }, '\\'); [](char ch) { return ch == '/'; }, '\\');
std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir; std::string deleteCmd = "if exist " + testDir + " rd /s /q " + testDir;
#else #else
string deleteCmd = "rm -rf " + kTestDir; std::string deleteCmd = "rm -rf " + kTestDir;
#endif #endif
ASSERT_EQ(system(deleteCmd.c_str()), 0); ASSERT_EQ(system(deleteCmd.c_str()), 0);
options.max_log_file_size = 100 * 1024 * 1024; options.max_log_file_size = 100 * 1024 * 1024;

@ -447,7 +447,7 @@ TEST_F(ColumnFamilyTest, AddDrop) {
std::vector<std::string> families; std::vector<std::string> families;
ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families)); ASSERT_OK(DB::ListColumnFamilies(db_options_, dbname_, &families));
sort(families.begin(), families.end()); std::sort(families.begin(), families.end());
ASSERT_TRUE(families == ASSERT_TRUE(families ==
std::vector<std::string>({"default", "four", "three"})); std::vector<std::string>({"default", "four", "three"}));
} }

@ -909,9 +909,11 @@ void DBImpl::PurgeObsoleteFiles(const JobContext& state) {
// dedup state.candidate_files so we don't try to delete the same // dedup state.candidate_files so we don't try to delete the same
// file twice // file twice
sort(candidate_files.begin(), candidate_files.end(), CompareCandidateFile); std::sort(candidate_files.begin(), candidate_files.end(),
candidate_files.erase(unique(candidate_files.begin(), candidate_files.end()), CompareCandidateFile);
candidate_files.end()); candidate_files.erase(
std::unique(candidate_files.begin(), candidate_files.end()),
candidate_files.end());
std::vector<std::string> old_info_log_files; std::vector<std::string> old_info_log_files;
InfoLogPrefix info_log_prefix(!db_options_.db_log_dir.empty(), dbname_); InfoLogPrefix info_log_prefix(!db_options_.db_log_dir.empty(), dbname_);

@ -2681,7 +2681,7 @@ TEST_F(DBTest, GroupCommitTest) {
for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) { for (int i = 0; i < kGCNumThreads * kGCNumKeys; ++i) {
expected_db.push_back(ToString(i)); expected_db.push_back(ToString(i));
} }
sort(expected_db.begin(), expected_db.end()); std::sort(expected_db.begin(), expected_db.end());
Iterator* itr = db_->NewIterator(ReadOptions()); Iterator* itr = db_->NewIterator(ReadOptions());
itr->SeekToFirst(); itr->SeekToFirst();

@ -8,8 +8,8 @@
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#endif #endif
#include <inttypes.h>
#include "db/transaction_log_impl.h" #include "db/transaction_log_impl.h"
#include <inttypes.h>
#include "db/write_batch_internal.h" #include "db/write_batch_internal.h"
#include "util/file_reader_writer.h" #include "util/file_reader_writer.h"
@ -250,7 +250,7 @@ void TransactionLogIteratorImpl::UpdateCurrentWriteBatch(const Slice& record) {
// currentBatchSeq_ can only change here // currentBatchSeq_ can only change here
assert(currentLastSeq_ <= versions_->LastSequence()); assert(currentLastSeq_ <= versions_->LastSequence());
currentBatch_ = move(batch); currentBatch_ = std::move(batch);
isValid_ = true; isValid_ = true;
currentStatus_ = Status::OK(); currentStatus_ = Status::OK();
} }
@ -262,10 +262,9 @@ Status TransactionLogIteratorImpl::OpenLogReader(const LogFile* logFile) {
return s; return s;
} }
assert(file); assert(file);
currentLogReader_.reset(new log::Reader(options_->info_log, currentLogReader_.reset(new log::Reader(
std::move(file), &reporter_, options_->info_log, std::move(file), &reporter_,
read_options_.verify_checksums_, 0, read_options_.verify_checksums_, 0, logFile->LogNumber()));
logFile->LogNumber()));
return Status::OK(); return Status::OK();
} }
} // namespace rocksdb } // namespace rocksdb

@ -1552,11 +1552,11 @@ void VersionStorageInfo::GenerateLevel0NonOverlapping() {
std::vector<FdWithKeyRange> level0_sorted_file( std::vector<FdWithKeyRange> level0_sorted_file(
level_files_brief_[0].files, level_files_brief_[0].files,
level_files_brief_[0].files + level_files_brief_[0].num_files); level_files_brief_[0].files + level_files_brief_[0].num_files);
sort(level0_sorted_file.begin(), level0_sorted_file.end(), std::sort(level0_sorted_file.begin(), level0_sorted_file.end(),
[this](const FdWithKeyRange & f1, const FdWithKeyRange & f2)->bool { [this](const FdWithKeyRange& f1, const FdWithKeyRange& f2) -> bool {
return (internal_comparator_->Compare(f1.smallest_key, f2.smallest_key) < return (internal_comparator_->Compare(f1.smallest_key,
0); f2.smallest_key) < 0);
}); });
for (size_t i = 1; i < level0_sorted_file.size(); ++i) { for (size_t i = 1; i < level0_sorted_file.size(); ++i) {
FdWithKeyRange& f = level0_sorted_file[i]; FdWithKeyRange& f = level0_sorted_file[i];

@ -189,9 +189,8 @@ char* Decompress(const char* input_data, size_t input_length,
if (!success) { if (!success) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << std::cerr << "XPRESS: Failed to create Decompressor LastError "
"XPRESS: Failed to create Decompressor LastError " << << GetLastError() << std::endl;
GetLastError() << std::endl;
#endif #endif
return nullptr; return nullptr;
} }
@ -215,9 +214,9 @@ char* Decompress(const char* input_data, size_t input_length,
if (lastError != ERROR_INSUFFICIENT_BUFFER) { if (lastError != ERROR_INSUFFICIENT_BUFFER) {
#ifdef _DEBUG #ifdef _DEBUG
std::cerr << std::cerr
"XPRESS: Failed to estimate decompressed buffer size LastError " << << "XPRESS: Failed to estimate decompressed buffer size LastError "
lastError << std::endl; << lastError << std::endl;
#endif #endif
return nullptr; return nullptr;
} }
@ -266,5 +265,3 @@ char* Decompress(const char* input_data, size_t input_length,
} }
#endif #endif

@ -2152,8 +2152,9 @@ class StressTest {
// this is a reopen. just assert that existing column_family_names are // this is a reopen. just assert that existing column_family_names are
// equivalent to what we remember // equivalent to what we remember
auto sorted_cfn = column_family_names_; auto sorted_cfn = column_family_names_;
sort(sorted_cfn.begin(), sorted_cfn.end()); std::sort(sorted_cfn.begin(), sorted_cfn.end());
sort(existing_column_families.begin(), existing_column_families.end()); std::sort(existing_column_families.begin(),
existing_column_families.end());
if (sorted_cfn != existing_column_families) { if (sorted_cfn != existing_column_families) {
fprintf(stderr, fprintf(stderr,
"Expected column families differ from the existing:\n"); "Expected column families differ from the existing:\n");

File diff suppressed because it is too large Load Diff

@ -5,6 +5,7 @@
#include <atomic> #include <atomic>
#include <iostream> #include <iostream>
#include <string>
#include <utility> #include <utility>
#include "rocksdb/env.h" #include "rocksdb/env.h"
@ -13,9 +14,10 @@
#include "util/testharness.h" #include "util/testharness.h"
#include "util/testutil.h" #include "util/testutil.h"
namespace rocksdb { using std::cout;
using std::endl;
using namespace std; namespace rocksdb {
class AutoVectorTest : public testing::Test {}; class AutoVectorTest : public testing::Test {};
const unsigned long kSize = 8; const unsigned long kSize = 8;
@ -197,8 +199,8 @@ TEST_F(AutoVectorTest, Iterators) {
} }
namespace { namespace {
vector<string> GetTestKeys(size_t size) { std::vector<std::string> GetTestKeys(size_t size) {
vector<string> keys; std::vector<std::string> keys;
keys.resize(size); keys.resize(size);
int index = 0; int index = 0;
@ -209,9 +211,9 @@ vector<string> GetTestKeys(size_t size) {
} }
} // namespace } // namespace
template<class TVector> template <class TVector>
void BenchmarkVectorCreationAndInsertion( void BenchmarkVectorCreationAndInsertion(
string name, size_t ops, size_t item_size, std::string name, size_t ops, size_t item_size,
const std::vector<typename TVector::value_type>& items) { const std::vector<typename TVector::value_type>& items) {
auto env = Env::Default(); auto env = Env::Default();
@ -231,7 +233,7 @@ void BenchmarkVectorCreationAndInsertion(
} }
template <class TVector> template <class TVector>
size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) { size_t BenchmarkSequenceAccess(std::string name, size_t ops, size_t elem_size) {
TVector v; TVector v;
for (const auto& item : GetTestKeys(elem_size)) { for (const auto& item : GetTestKeys(elem_size)) {
v.push_back(item); v.push_back(item);
@ -255,9 +257,9 @@ size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
return total; return total;
} }
// This test case only reports the performance between std::vector<string> // This test case only reports the performance between std::vector<std::string>
// and autovector<string>. We chose string for comparison because in most // and autovector<std::string>. We chose string for comparison because in most
// o our use cases we used std::vector<string>. // of our use cases we used std::vector<std::string>.
TEST_F(AutoVectorTest, PerfBench) { TEST_F(AutoVectorTest, PerfBench) {
// We run same operations for kOps times in order to get a more fair result. // We run same operations for kOps times in order to get a more fair result.
size_t kOps = 100000; size_t kOps = 100000;
@ -279,12 +281,10 @@ TEST_F(AutoVectorTest, PerfBench) {
// pre-generated unique keys // pre-generated unique keys
auto string_keys = GetTestKeys(kOps * 2 * kSize); auto string_keys = GetTestKeys(kOps * 2 * kSize);
for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) { for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) {
BenchmarkVectorCreationAndInsertion<vector<string>>( BenchmarkVectorCreationAndInsertion<std::vector<std::string>>(
"vector<string>", kOps, insertions, string_keys "std::vector<std::string>", kOps, insertions, string_keys);
); BenchmarkVectorCreationAndInsertion<autovector<std::string, kSize>>(
BenchmarkVectorCreationAndInsertion<autovector<string, kSize>>( "autovector<std::string>", kOps, insertions, string_keys);
"autovector<string>", kOps, insertions, string_keys
);
cout << "-----------------------------------" << endl; cout << "-----------------------------------" << endl;
} }
@ -293,14 +293,13 @@ TEST_F(AutoVectorTest, PerfBench) {
cout << "=====================================================" << endl; cout << "=====================================================" << endl;
// pre-generated unique keys // pre-generated unique keys
vector<uint64_t> int_keys(kOps * 2 * kSize); std::vector<uint64_t> int_keys(kOps * 2 * kSize);
for (size_t i = 0; i < kOps * 2 * kSize; ++i) { for (size_t i = 0; i < kOps * 2 * kSize; ++i) {
int_keys[i] = i; int_keys[i] = i;
} }
for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) { for (auto insertions : { 0ul, 1ul, kSize / 2, kSize, 2 * kSize }) {
BenchmarkVectorCreationAndInsertion<vector<uint64_t>>( BenchmarkVectorCreationAndInsertion<std::vector<uint64_t>>(
"vector<uint64_t>", kOps, insertions, int_keys "std::vector<uint64_t>", kOps, insertions, int_keys);
);
BenchmarkVectorCreationAndInsertion<autovector<uint64_t, kSize>>( BenchmarkVectorCreationAndInsertion<autovector<uint64_t, kSize>>(
"autovector<uint64_t>", kOps, insertions, int_keys "autovector<uint64_t>", kOps, insertions, int_keys
); );
@ -312,12 +311,10 @@ TEST_F(AutoVectorTest, PerfBench) {
cout << "Sequence Access Test" << endl; cout << "Sequence Access Test" << endl;
cout << "=====================================================" << endl; cout << "=====================================================" << endl;
for (auto elem_size : { kSize / 2, kSize, 2 * kSize }) { for (auto elem_size : { kSize / 2, kSize, 2 * kSize }) {
BenchmarkSequenceAccess<vector<string>>( BenchmarkSequenceAccess<std::vector<std::string>>("std::vector", kOps,
"vector", kOps, elem_size elem_size);
); BenchmarkSequenceAccess<autovector<std::string, kSize>>("autovector", kOps,
BenchmarkSequenceAccess<autovector<string, kSize>>( elem_size);
"autovector", kOps, elem_size
);
cout << "-----------------------------------" << endl; cout << "-----------------------------------" << endl;
} }
} }

@ -554,8 +554,8 @@ TEST_F(CacheTest, ApplyToAllCacheEntiresTest) {
} }
cache_->ApplyToAllCacheEntries(callback, true); cache_->ApplyToAllCacheEntries(callback, true);
sort(inserted.begin(), inserted.end()); std::sort(inserted.begin(), inserted.end());
sort(callback_state.begin(), callback_state.end()); std::sort(callback_state.begin(), callback_state.end());
ASSERT_TRUE(inserted == callback_state); ASSERT_TRUE(inserted == callback_state);
} }

@ -471,7 +471,7 @@ Status HdfsEnv::GetChildren(const std::string& path,
if (numEntries >= 0) { if (numEntries >= 0) {
for(int i = 0; i < numEntries; i++) { for(int i = 0; i < numEntries; i++) {
char* pathname = pHdfsFileInfo[i].mName; char* pathname = pHdfsFileInfo[i].mName;
char* filename = rindex(pathname, '/'); char* filename = std::rindex(pathname, '/');
if (filename != nullptr) { if (filename != nullptr) {
result->push_back(filename+1); result->push_back(filename+1);
} }

@ -197,8 +197,8 @@ class TestEnv : public EnvWrapper {
void AssertWrittenFiles(std::vector<std::string>& should_have_written) { void AssertWrittenFiles(std::vector<std::string>& should_have_written) {
MutexLock l(&mutex_); MutexLock l(&mutex_);
sort(should_have_written.begin(), should_have_written.end()); std::sort(should_have_written.begin(), should_have_written.end());
sort(written_files_.begin(), written_files_.end()); std::sort(written_files_.begin(), written_files_.end());
ASSERT_TRUE(written_files_ == should_have_written); ASSERT_TRUE(written_files_ == should_have_written);
} }

@ -25,13 +25,12 @@
#include "util/random.h" #include "util/random.h"
using namespace rocksdb; using namespace rocksdb;
using namespace std;
namespace rocksdb { namespace rocksdb {
class RedisListsTest : public testing::Test { class RedisListsTest : public testing::Test {
public: public:
static const string kDefaultDbName; static const std::string kDefaultDbName;
static Options options; static Options options;
RedisListsTest() { RedisListsTest() {
@ -39,7 +38,7 @@ class RedisListsTest : public testing::Test {
} }
}; };
const string RedisListsTest::kDefaultDbName = const std::string RedisListsTest::kDefaultDbName =
test::TmpDir() + "/redis_lists_test"; test::TmpDir() + "/redis_lists_test";
Options RedisListsTest::options = Options(); Options RedisListsTest::options = Options();
@ -60,7 +59,7 @@ void AssertListEq(const std::vector<std::string>& result,
TEST_F(RedisListsTest, SimpleTest) { TEST_F(RedisListsTest, SimpleTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Simple PushRight (should return the new length each time) // Simple PushRight (should return the new length each time)
ASSERT_EQ(redis.PushRight("k1", "v1"), 1); ASSERT_EQ(redis.PushRight("k1", "v1"), 1);
@ -89,7 +88,7 @@ TEST_F(RedisListsTest, SimpleTest) {
TEST_F(RedisListsTest, SimpleTest2) { TEST_F(RedisListsTest, SimpleTest2) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Simple PushRight // Simple PushRight
ASSERT_EQ(redis.PushLeft("k1", "v3"), 1); ASSERT_EQ(redis.PushLeft("k1", "v3"), 1);
@ -118,7 +117,7 @@ TEST_F(RedisListsTest, SimpleTest2) {
TEST_F(RedisListsTest, IndexTest) { TEST_F(RedisListsTest, IndexTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Empty Index check (return empty and should not crash or edit tempv) // Empty Index check (return empty and should not crash or edit tempv)
tempv = "yo"; tempv = "yo";
@ -177,7 +176,7 @@ TEST_F(RedisListsTest, IndexTest) {
TEST_F(RedisListsTest, RangeTest) { TEST_F(RedisListsTest, RangeTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Simple Pushes (will yield: [v6, v4, v4, v1, v2, v3]) // Simple Pushes (will yield: [v6, v4, v4, v1, v2, v3])
redis.PushRight("k1", "v1"); redis.PushRight("k1", "v1");
@ -260,7 +259,7 @@ TEST_F(RedisListsTest, RangeTest) {
TEST_F(RedisListsTest, InsertTest) { TEST_F(RedisListsTest, InsertTest) {
RedisLists redis(kDefaultDbName, options, true); RedisLists redis(kDefaultDbName, options, true);
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Insert on empty list (return 0, and do not crash) // Insert on empty list (return 0, and do not crash)
ASSERT_EQ(redis.InsertBefore("k1", "non-exist", "a"), 0); ASSERT_EQ(redis.InsertBefore("k1", "non-exist", "a"), 0);
@ -344,7 +343,7 @@ TEST_F(RedisListsTest, InsertTest) {
TEST_F(RedisListsTest, SetTest) { TEST_F(RedisListsTest, SetTest) {
RedisLists redis(kDefaultDbName, options, true); RedisLists redis(kDefaultDbName, options, true);
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Set on empty list (return false, and do not crash) // Set on empty list (return false, and do not crash)
ASSERT_EQ(redis.Set("k1", 7, "a"), false); ASSERT_EQ(redis.Set("k1", 7, "a"), false);
@ -440,7 +439,7 @@ TEST_F(RedisListsTest, SetTest) {
TEST_F(RedisListsTest, InsertPushSetTest) { TEST_F(RedisListsTest, InsertPushSetTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// A series of pushes and insertions // A series of pushes and insertions
// Will result in [newbegin, z, a, aftera, x, newend] // Will result in [newbegin, z, a, aftera, x, newend]
@ -532,7 +531,7 @@ TEST_F(RedisListsTest, InsertPushSetTest) {
TEST_F(RedisListsTest, TrimPopTest) { TEST_F(RedisListsTest, TrimPopTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// A series of pushes and insertions // A series of pushes and insertions
// Will result in [newbegin, z, a, aftera, x, newend] // Will result in [newbegin, z, a, aftera, x, newend]
@ -602,7 +601,7 @@ TEST_F(RedisListsTest, TrimPopTest) {
TEST_F(RedisListsTest, RemoveTest) { TEST_F(RedisListsTest, RemoveTest) {
RedisLists redis(kDefaultDbName, options, true); // Destructive RedisLists redis(kDefaultDbName, options, true); // Destructive
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// A series of pushes and insertions // A series of pushes and insertions
// Will result in [newbegin, z, a, aftera, x, newend, a, a] // Will result in [newbegin, z, a, aftera, x, newend, a, a]
@ -691,7 +690,7 @@ TEST_F(RedisListsTest, RemoveTest) {
// Test Multiple keys and Persistence // Test Multiple keys and Persistence
TEST_F(RedisListsTest, PersistenceMultiKeyTest) { TEST_F(RedisListsTest, PersistenceMultiKeyTest) {
string tempv; // Used below for all Index(), PopRight(), PopLeft() std::string tempv; // Used below for all Index(), PopRight(), PopLeft()
// Block one: populate a single key in the database // Block one: populate a single key in the database
{ {
@ -768,12 +767,12 @@ int manual_redis_test(bool destructive){
std::string command; std::string command;
while(true) { while(true) {
cin >> command; std::cin >> command;
MakeUpper(&command); MakeUpper(&command);
if (command == "LINSERT") { if (command == "LINSERT") {
std::string k, t, p, v; std::string k, t, p, v;
cin >> k >> t >> p >> v; std::cin >> k >> t >> p >> v;
MakeUpper(&t); MakeUpper(&t);
if (t=="BEFORE") { if (t=="BEFORE") {
std::cout << redis.InsertBefore(k, p, v) << std::endl; std::cout << redis.InsertBefore(k, p, v) << std::endl;
@ -791,13 +790,13 @@ int manual_redis_test(bool destructive){
} else if (command == "LPOP") { } else if (command == "LPOP") {
std::string k; std::string k;
std::cin >> k; std::cin >> k;
string res; std::string res;
redis.PopLeft(k, &res); redis.PopLeft(k, &res);
std::cout << res << std::endl; std::cout << res << std::endl;
} else if (command == "RPOP") { } else if (command == "RPOP") {
std::string k; std::string k;
std::cin >> k; std::cin >> k;
string res; std::string res;
redis.PopRight(k, &res); redis.PopRight(k, &res);
std::cout << res << std::endl; std::cout << res << std::endl;
} else if (command == "LREM") { } else if (command == "LREM") {
@ -829,18 +828,18 @@ int manual_redis_test(bool destructive){
std::string k; std::string k;
int idx; int idx;
std::string v; std::string v;
cin >> k >> idx >> v; std::cin >> k >> idx >> v;
redis.Set(k, idx, v); redis.Set(k, idx, v);
} else if (command == "LINDEX") { } else if (command == "LINDEX") {
std::string k; std::string k;
int idx; int idx;
std::cin >> k >> idx; std::cin >> k >> idx;
string res; std::string res;
redis.Index(k, idx, &res); redis.Index(k, idx, &res);
std::cout << res << std::endl; std::cout << res << std::endl;
} else if (command == "PRINT") { // Added by Deon } else if (command == "PRINT") { // Added by Deon
std::string k; std::string k;
cin >> k; std::cin >> k;
redis.Print(k); redis.Print(k);
} else if (command == "QUIT") { } else if (command == "QUIT") {
return 0; return 0;

Loading…
Cancel
Save