1 #include <boost/shared_ptr.hpp>
2 #include <gtest/gtest.h>
6 #include "protobufrpc.h"
9 using namespace kvstore;
10 using namespace bicker;
11 using namespace kvrpc;
13 /* http://code.google.com/p/googletest/wiki/GoogleTestPrimer */
15 class KVTest : public ::testing::Test
19 :_kv_client("127.0.0.1", "9090")
21 vector<string> data_dirs;
22 data_dirs.push_back("/tmp");
24 shared_ptr<Service> service(new KeyValueRpcService(new BDBBackend(data_dirs)));
25 _rpc_server.registerService(9090, service);
30 &ProtoBufRpcServer::run,
37 _rpc_server.shutdown();
38 _server_thread->join();
42 ProtoBufRpcServer _rpc_server;
43 KeyValueClient _kv_client;
44 shared_ptr<thread> _server_thread;
48 TEST_F(KVTest, PutTest)
50 ASSERT_TRUE(_kv_client.Put("test", "value"));
52 ASSERT_TRUE(_kv_client.Get("test", &value));
53 ASSERT_EQ(value, "value");
56 TEST_F(KVTest, MedPutTest)
58 string test_value(1024*10, '6');
59 ASSERT_TRUE(_kv_client.Put("test", test_value));
61 ASSERT_TRUE(_kv_client.Get("test", &value));
62 ASSERT_TRUE(value == test_value);
65 TEST_F(KVTest, BigPutTest)
67 string test_value(1024*1024*10, '6');
68 ASSERT_TRUE(_kv_client.Put("test", test_value));
70 ASSERT_TRUE(_kv_client.Get("test", &value));
71 ASSERT_EQ(value.size(), test_value.size());
72 ASSERT_TRUE(value == test_value);
75 TEST_F(KVTest, LoopPutTest)
77 string test_value(1024*1024, '6');
79 for (int i = 0; i < 10; ++i)
83 ASSERT_TRUE(_kv_client.Put(key.str(), test_value));
85 ASSERT_TRUE(_kv_client.Get(key.str(), &value));
86 ASSERT_TRUE(value == test_value);
90 TEST_F(KVTest, EmptyTest)
93 ASSERT_FALSE(_kv_client.Get("test", &value));
102 ::testing::InitGoogleTest(&argc, argv);
103 return RUN_ALL_TESTS();