| 156 | } |
| 157 | |
| 158 | TEST_F(RedisTest, sanity) { |
| 159 | if (g_redis_pid < 0) { |
| 160 | puts("Skipped due to absence of redis-server"); |
| 161 | return; |
| 162 | } |
| 163 | brpc::ChannelOptions options; |
| 164 | options.protocol = brpc::PROTOCOL_REDIS; |
| 165 | brpc::Channel channel; |
| 166 | ASSERT_EQ(0, channel.Init("0.0.0.0:" REDIS_SERVER_PORT, &options)); |
| 167 | brpc::RedisRequest request; |
| 168 | brpc::RedisResponse response; |
| 169 | brpc::Controller cntl; |
| 170 | |
| 171 | ASSERT_TRUE(request.AddCommand("get hello")); |
| 172 | channel.CallMethod(NULL, &cntl, &request, &response, NULL); |
| 173 | ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); |
| 174 | ASSERT_EQ(1, response.reply_size()); |
| 175 | ASSERT_EQ(brpc::REDIS_REPLY_NIL, response.reply(0).type()) |
| 176 | << response; |
| 177 | |
| 178 | cntl.Reset(); |
| 179 | request.Clear(); |
| 180 | response.Clear(); |
| 181 | request.AddCommand("set hello world"); |
| 182 | channel.CallMethod(NULL, &cntl, &request, &response, NULL); |
| 183 | ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); |
| 184 | ASSERT_EQ(1, response.reply_size()); |
| 185 | ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); |
| 186 | ASSERT_EQ("OK", response.reply(0).data()); |
| 187 | |
| 188 | cntl.Reset(); |
| 189 | request.Clear(); |
| 190 | response.Clear(); |
| 191 | ASSERT_TRUE(request.AddCommand("get hello")); |
| 192 | channel.CallMethod(NULL, &cntl, &request, &response, NULL); |
| 193 | ASSERT_FALSE(cntl.Failed()); |
| 194 | ASSERT_EQ(1, response.reply_size()); |
| 195 | ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()); |
| 196 | ASSERT_EQ("world", response.reply(0).data()); |
| 197 | |
| 198 | cntl.Reset(); |
| 199 | request.Clear(); |
| 200 | response.Clear(); |
| 201 | request.AddCommand("set hello world2"); |
| 202 | channel.CallMethod(NULL, &cntl, &request, &response, NULL); |
| 203 | ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText(); |
| 204 | ASSERT_EQ(1, response.reply_size()); |
| 205 | ASSERT_EQ(brpc::REDIS_REPLY_STATUS, response.reply(0).type()); |
| 206 | ASSERT_EQ("OK", response.reply(0).data()); |
| 207 | |
| 208 | cntl.Reset(); |
| 209 | request.Clear(); |
| 210 | response.Clear(); |
| 211 | ASSERT_TRUE(request.AddCommand("get hello")); |
| 212 | channel.CallMethod(NULL, &cntl, &request, &response, NULL); |
| 213 | ASSERT_FALSE(cntl.Failed()); |
| 214 | ASSERT_EQ(1, response.reply_size()); |
| 215 | ASSERT_EQ(brpc::REDIS_REPLY_STRING, response.reply(0).type()); |
nothing calls this directly
no test coverage detected