From 924fc72141c632478489c8213717680de3eca4b0 Mon Sep 17 00:00:00 2001
From: Irene Zhang <iyzhang@myst.cs.washington.edu>
Date: Thu, 25 Jun 2015 16:52:56 -0700
Subject: [PATCH] fixing some bugs and checking in new test cases for backend
 stores

---
 Makefile                                      |  2 +-
 store/common/backend/lockserver.cc            |  3 --
 store/common/backend/lockserver.h             |  4 --
 store/common/backend/tests/Rules.mk           |  4 +-
 store/common/backend/tests/lockserver-test.cc | 14 ++---
 .../common/backend/tests/versionstore-test.cc | 51 +++++--------------
 store/txnstore/Rules.mk                       |  2 +-
 store/txnstore/txn-proto.proto                |  2 +-
 8 files changed, 25 insertions(+), 57 deletions(-)

diff --git a/Makefile b/Makefile
index aae1194..e1e7753 100644
--- a/Makefile
+++ b/Makefile
@@ -125,7 +125,7 @@ include lib/Rules.mk
 include replication/common/Rules.mk
 include replication/vr/Rules.mk
 include store/common/Rules.mk
-#include store/txnstore/Rules.mk
+include store/txnstore/Rules.mk
 include store/qwstore/Rules.mk
 
 ##################################################################
diff --git a/store/common/backend/lockserver.cc b/store/common/backend/lockserver.cc
index 56a5632..2c05127 100644
--- a/store/common/backend/lockserver.cc
+++ b/store/common/backend/lockserver.cc
@@ -11,8 +11,6 @@
 
 using namespace std;
 
-namespace spanstore {
-
 LockServer::LockServer()
 {
     readers = 0;
@@ -280,4 +278,3 @@ LockServer::releaseForWrite(const string &lock, uint64_t holder)
     }
 }
 
-} // namespace spanstore
diff --git a/store/common/backend/lockserver.h b/store/common/backend/lockserver.h
index e9fe6db..bb2c8a1 100644
--- a/store/common/backend/lockserver.h
+++ b/store/common/backend/lockserver.h
@@ -42,8 +42,6 @@
 #include <unordered_map>
 #include <unordered_set>
 
-namespace spanstore {
-
 #define LOCK_WAIT_TIMEOUT 5000
 
 class LockServer
@@ -100,6 +98,4 @@ private:
     uint64_t writers;
 };
 
-} // namespace spanstore
-
 #endif /* _LOCK_SERVER_H_ */
diff --git a/store/common/backend/tests/Rules.mk b/store/common/backend/tests/Rules.mk
index d2bb153..e53ac75 100644
--- a/store/common/backend/tests/Rules.mk
+++ b/store/common/backend/tests/Rules.mk
@@ -4,7 +4,9 @@ d := $(dir $(lastword $(MAKEFILE_LIST)))
 # gtest-based tests
 #
 GTEST_SRCS += $(addprefix $(d), \
-		kvstore-test.cc, versionstore-test.cc, lockserver-test.cc)
+		kvstore-test.cc \
+		versionstore-test.cc \
+		lockserver-test.cc)
 
 $(d)kvstore-test: $(o)kvstore-test.o $(LIB-transport) $(LIB-common) $(LIB-backend) $(GTEST_MAIN)
 
diff --git a/store/common/backend/tests/lockserver-test.cc b/store/common/backend/tests/lockserver-test.cc
index 853da46..b41e670 100644
--- a/store/common/backend/tests/lockserver-test.cc
+++ b/store/common/backend/tests/lockserver-test.cc
@@ -28,7 +28,7 @@
  *
  **********************************************************************/
 
-#include "store/common/backend/versionstore.h"
+#include "store/common/backend/lockserver.h"
 
 #include <gtest/gtest.h>
 
@@ -36,16 +36,16 @@ TEST(LockServer, ReadLock)
 {
     LockServer s;
 
-    EXPECT_TRUE(s.LockForRead("x", 1));
-    EXPECT_TRUE(s.LockForRead("x", 2));   
-    EXPECT_FALSE(s.LockForWrite("x", 3));
+    EXPECT_TRUE(s.lockForRead("x", 1));
+    EXPECT_TRUE(s.lockForRead("x", 2));   
+    EXPECT_FALSE(s.lockForWrite("x", 3));
 }
 
 TEST(LockServer, WriteLock)
 {
     LockServer s;
     
-    EXPECT_TRUE(s.LockForWrite("x", 1));
-    EXPECT_FALSE(s.LockForRead("x", 2));   
-    EXPECT_FALSE(s.LockForWrite("x", 3));    
+    EXPECT_TRUE(s.lockForWrite("x", 1));
+    EXPECT_FALSE(s.lockForRead("x", 2));   
+    EXPECT_FALSE(s.lockForWrite("x", 3));    
 }
diff --git a/store/common/backend/tests/versionstore-test.cc b/store/common/backend/tests/versionstore-test.cc
index 0ea2eae..6c5f252 100644
--- a/store/common/backend/tests/versionstore-test.cc
+++ b/store/common/backend/tests/versionstore-test.cc
@@ -32,53 +32,26 @@
 
 #include <gtest/gtest.h>
 
-TEST(VersionedKVStore, Put)
-{
-    VersionedKVStore store;
-
-    EXPECT_TRUE(store.put("test1", "abc"));
-    EXPECT_TRUE(store.put("test2", "def"));
-    EXPECT_TRUE(store.put("test1", "xyz"));
-    EXPECT_TRUE(store.put("test3", "abc"));
-}
-
 TEST(VersionedKVStore, Get)
 {
     VersionedKVStore store;
-    pair<Timestamp, std::string> val;
+    std::pair<Timestamp, std::string> val;
 
-    EXPECT_TRUE(store.put("test1", "abc"));
+    store.put("test1", "abc", Timestamp(10));
     EXPECT_TRUE(store.get("test1", val));
-    EXPECT_EQ(val[1], "abc");
+    EXPECT_EQ(val.second, "abc");
+    EXPECT_EQ(Timestamp(10), val.first); 
 
-    EXPECT_TRUE(store.put("test2", "def"));
+    store.put("test2", "def", Timestamp(10));
     EXPECT_TRUE(store.get("test2", val));
-    EXPECT_EQ(val[1], "def");
+    EXPECT_EQ(val.second, "def");
+    EXPECT_EQ(Timestamp(10), val.first); 
 
-    EXPECT_TRUE(store.put("test1", "xyz"));
+    store.put("test1", "xyz", Timestamp(11));
     EXPECT_TRUE(store.get("test1", val));
-    EXPECT_EQ(val[1], "xyz");
-}
-
-TEST(VersionedKVStore, VersionedGet)
-{
-    VersionedKVStore store;
-    Timestamp time;
-    Timestamp time2;
-    std::string val;
-
-    EXPECT_TRUE(store.put("test1", "abc", time));
-    EXPECT_TRUE(store.get("test1", val, time));
-    EXPECT_EQ(val, "abc");
-
-    EXPECT_TRUE(store.put("test2", "def", time2));
-    EXPECT_TRUE(store.get("test2", val, time2));
-    EXPECT_EQ(val, "def");
-
-    EXPECT_TRUE(store.put("test1", "xyz", time2));
-    EXPECT_TRUE(store.get("test1", val, time2));
-    EXPECT_EQ(val, "xyz");
+    EXPECT_EQ(val.second, "xyz");
+    EXPECT_EQ(Timestamp(11), val.first); 
     
-    EXPECT_TRUE(store.get("test1", val, time));
-    EXPECT_EQ(val, "abc");
+    EXPECT_TRUE(store.get("test1", Timestamp(10), val));
+    EXPECT_EQ(val.second, "abc");
 }
diff --git a/store/txnstore/Rules.mk b/store/txnstore/Rules.mk
index f98767e..c8ccff2 100644
--- a/store/txnstore/Rules.mk
+++ b/store/txnstore/Rules.mk
@@ -4,7 +4,7 @@ SRCS += $(addprefix $(d), \
 	client.cc spanclient.cc lockserver.cc \
 	occstore.cc lockstore.cc server.cc)
 
-PROTOS += $(addprefix $(d), span-proto.proto)
+PROTOS += $(addprefix $(d), txn-proto.proto)
 
 OBJS-span-store := $(LIB-message) $(LIB-store) $(LIB-common) $(o)server.o \
   $(o)occstore.o $(o)lockstore.o $(o)lockserver.o $(o)span-proto.o
diff --git a/store/txnstore/txn-proto.proto b/store/txnstore/txn-proto.proto
index e73dadc..9df73b1 100644
--- a/store/txnstore/txn-proto.proto
+++ b/store/txnstore/txn-proto.proto
@@ -1,4 +1,4 @@
-import "../common/common-proto.proto";
+import "store/common/common-proto.proto";
 
 package spanstore.proto;
 
-- 
GitLab