MCPcopy Create free account
hub / github.com/apache/brpc / TEST_F

Function TEST_F

test/brpc_memcache_unittest.cpp:100–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98};
99
100TEST_F(MemcacheTest, sanity) {
101 if (g_mc_pid < 0) {
102 puts("Skipped due to absence of memcached");
103 return;
104 }
105 brpc::ChannelOptions options;
106 options.protocol = brpc::PROTOCOL_MEMCACHE;
107 brpc::Channel channel;
108 ASSERT_EQ(0, channel.Init("0.0.0.0:" MEMCACHED_PORT, &options));
109 brpc::MemcacheRequest request;
110 brpc::MemcacheResponse response;
111 brpc::Controller cntl;
112
113 // Clear all contents in MC which is still holding older data after
114 // restarting in Ubuntu 18.04 (mc=1.5.6)
115 request.Flush(0);
116 channel.CallMethod(NULL, &cntl, &request, &response, NULL);
117 ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
118 ASSERT_TRUE(response.PopFlush());
119
120 cntl.Reset();
121 request.Clear();
122 request.Get("hello");
123 channel.CallMethod(NULL, &cntl, &request, &response, NULL);
124 ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
125 std::string value;
126 uint32_t flags = 0;
127 uint64_t cas_value = 0;
128 ASSERT_FALSE(response.PopGet(&value, &flags, &cas_value));
129 ASSERT_EQ("Not found", response.LastError());
130
131 cntl.Reset();
132 request.Clear();
133 request.Set("hello", "world", 0xdeadbeef, 10, 0);
134 channel.CallMethod(NULL, &cntl, &request, &response, NULL);
135 ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
136 ASSERT_TRUE(response.PopSet(&cas_value)) << response.LastError();
137 ASSERT_EQ("", response.LastError());
138
139 cntl.Reset();
140 request.Clear();
141 request.Get("hello");
142 channel.CallMethod(NULL, &cntl, &request, &response, NULL);
143 ASSERT_FALSE(cntl.Failed());
144 ASSERT_TRUE(response.PopGet(&value, &flags, &cas_value));
145 ASSERT_EQ("", response.LastError());
146 ASSERT_EQ("world", value);
147 ASSERT_EQ(0xdeadbeef, flags);
148 std::cout << "cas_value=" << cas_value << std::endl;
149
150 cntl.Reset();
151 request.Clear();
152 request.Set("hello", "world2", 0xdeadbeef, 10,
153 cas_value/*intended match*/);
154 channel.CallMethod(NULL, &cntl, &request, &response, NULL);
155 ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();
156 uint64_t cas_value2 = 0;
157 ASSERT_TRUE(response.PopSet(&cas_value2)) << response.LastError();

Callers

nothing calls this directly

Calls 15

ErrorTextMethod · 0.80
PopFlushMethod · 0.80
PopGetMethod · 0.80
PopSetMethod · 0.80
DecrementMethod · 0.80
PopIncrementMethod · 0.80
PopDecrementMethod · 0.80
PopVersionMethod · 0.80
InitMethod · 0.45
FlushMethod · 0.45
CallMethodMethod · 0.45
FailedMethod · 0.45

Tested by

no test coverage detected