|
|
|
@ -25,13 +25,12 @@ |
|
|
|
|
#include "util/random.h" |
|
|
|
|
|
|
|
|
|
using namespace rocksdb; |
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
namespace rocksdb { |
|
|
|
|
|
|
|
|
|
class RedisListsTest : public testing::Test { |
|
|
|
|
public: |
|
|
|
|
static const string kDefaultDbName; |
|
|
|
|
static const std::string kDefaultDbName; |
|
|
|
|
static Options options; |
|
|
|
|
|
|
|
|
|
RedisListsTest() { |
|
|
|
@ -39,7 +38,7 @@ class RedisListsTest : public testing::Test { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const string RedisListsTest::kDefaultDbName = |
|
|
|
|
const std::string RedisListsTest::kDefaultDbName = |
|
|
|
|
test::TmpDir() + "/redis_lists_test"; |
|
|
|
|
Options RedisListsTest::options = Options(); |
|
|
|
|
|
|
|
|
@ -60,7 +59,7 @@ void AssertListEq(const std::vector<std::string>& result, |
|
|
|
|
TEST_F(RedisListsTest, SimpleTest) { |
|
|
|
|
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)
|
|
|
|
|
ASSERT_EQ(redis.PushRight("k1", "v1"), 1); |
|
|
|
@ -89,7 +88,7 @@ TEST_F(RedisListsTest, SimpleTest) { |
|
|
|
|
TEST_F(RedisListsTest, SimpleTest2) { |
|
|
|
|
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
|
|
|
|
|
ASSERT_EQ(redis.PushLeft("k1", "v3"), 1); |
|
|
|
@ -118,7 +117,7 @@ TEST_F(RedisListsTest, SimpleTest2) { |
|
|
|
|
TEST_F(RedisListsTest, IndexTest) { |
|
|
|
|
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)
|
|
|
|
|
tempv = "yo"; |
|
|
|
@ -177,7 +176,7 @@ TEST_F(RedisListsTest, IndexTest) { |
|
|
|
|
TEST_F(RedisListsTest, RangeTest) { |
|
|
|
|
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])
|
|
|
|
|
redis.PushRight("k1", "v1"); |
|
|
|
@ -260,7 +259,7 @@ TEST_F(RedisListsTest, RangeTest) { |
|
|
|
|
TEST_F(RedisListsTest, InsertTest) { |
|
|
|
|
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)
|
|
|
|
|
ASSERT_EQ(redis.InsertBefore("k1", "non-exist", "a"), 0); |
|
|
|
@ -344,7 +343,7 @@ TEST_F(RedisListsTest, InsertTest) { |
|
|
|
|
TEST_F(RedisListsTest, SetTest) { |
|
|
|
|
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)
|
|
|
|
|
ASSERT_EQ(redis.Set("k1", 7, "a"), false); |
|
|
|
@ -440,7 +439,7 @@ TEST_F(RedisListsTest, SetTest) { |
|
|
|
|
TEST_F(RedisListsTest, InsertPushSetTest) { |
|
|
|
|
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
|
|
|
|
|
// Will result in [newbegin, z, a, aftera, x, newend]
|
|
|
|
@ -532,7 +531,7 @@ TEST_F(RedisListsTest, InsertPushSetTest) { |
|
|
|
|
TEST_F(RedisListsTest, TrimPopTest) { |
|
|
|
|
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
|
|
|
|
|
// Will result in [newbegin, z, a, aftera, x, newend]
|
|
|
|
@ -602,7 +601,7 @@ TEST_F(RedisListsTest, TrimPopTest) { |
|
|
|
|
TEST_F(RedisListsTest, RemoveTest) { |
|
|
|
|
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
|
|
|
|
|
// 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_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
|
|
|
|
|
{ |
|
|
|
@ -768,12 +767,12 @@ int manual_redis_test(bool destructive){ |
|
|
|
|
|
|
|
|
|
std::string command; |
|
|
|
|
while(true) { |
|
|
|
|
cin >> command; |
|
|
|
|
std::cin >> command; |
|
|
|
|
MakeUpper(&command); |
|
|
|
|
|
|
|
|
|
if (command == "LINSERT") { |
|
|
|
|
std::string k, t, p, v; |
|
|
|
|
cin >> k >> t >> p >> v; |
|
|
|
|
std::cin >> k >> t >> p >> v; |
|
|
|
|
MakeUpper(&t); |
|
|
|
|
if (t=="BEFORE") { |
|
|
|
|
std::cout << redis.InsertBefore(k, p, v) << std::endl; |
|
|
|
@ -791,13 +790,13 @@ int manual_redis_test(bool destructive){ |
|
|
|
|
} else if (command == "LPOP") { |
|
|
|
|
std::string k; |
|
|
|
|
std::cin >> k; |
|
|
|
|
string res; |
|
|
|
|
std::string res; |
|
|
|
|
redis.PopLeft(k, &res); |
|
|
|
|
std::cout << res << std::endl; |
|
|
|
|
} else if (command == "RPOP") { |
|
|
|
|
std::string k; |
|
|
|
|
std::cin >> k; |
|
|
|
|
string res; |
|
|
|
|
std::string res; |
|
|
|
|
redis.PopRight(k, &res); |
|
|
|
|
std::cout << res << std::endl; |
|
|
|
|
} else if (command == "LREM") { |
|
|
|
@ -829,18 +828,18 @@ int manual_redis_test(bool destructive){ |
|
|
|
|
std::string k; |
|
|
|
|
int idx; |
|
|
|
|
std::string v; |
|
|
|
|
cin >> k >> idx >> v; |
|
|
|
|
std::cin >> k >> idx >> v; |
|
|
|
|
redis.Set(k, idx, v); |
|
|
|
|
} else if (command == "LINDEX") { |
|
|
|
|
std::string k; |
|
|
|
|
int idx; |
|
|
|
|
std::cin >> k >> idx; |
|
|
|
|
string res; |
|
|
|
|
std::string res; |
|
|
|
|
redis.Index(k, idx, &res); |
|
|
|
|
std::cout << res << std::endl; |
|
|
|
|
} else if (command == "PRINT") { // Added by Deon
|
|
|
|
|
std::string k; |
|
|
|
|
cin >> k; |
|
|
|
|
std::cin >> k; |
|
|
|
|
redis.Print(k); |
|
|
|
|
} else if (command == "QUIT") { |
|
|
|
|
return 0; |
|
|
|
|