Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 34 | #include <memory> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 35 | |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 36 | #include <grpc/grpc.h> |
| 37 | #include <grpc/support/thd.h> |
| 38 | #include <grpc/support/time.h> |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 39 | #include <grpc++/channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 40 | #include <grpc++/client_context.h> |
| 41 | #include <grpc++/create_channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 42 | #include <grpc++/server.h> |
| 43 | #include <grpc++/server_builder.h> |
| 44 | #include <grpc++/server_context.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 45 | #include <gtest/gtest.h> |
| 46 | |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 47 | #include "test/core/util/port.h" |
| 48 | #include "test/core/util/test_config.h" |
| 49 | #include "test/cpp/util/echo_duplicate.grpc.pb.h" |
| 50 | #include "test/cpp/util/echo.grpc.pb.h" |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 51 | #include "test/cpp/util/string_ref_helper.h" |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 52 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 53 | #ifdef GPR_POSIX_SOCKET |
| 54 | #include "src/core/iomgr/pollset_posix.h" |
| 55 | #endif |
| 56 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 57 | using grpc::cpp::test::util::EchoRequest; |
| 58 | using grpc::cpp::test::util::EchoResponse; |
| 59 | using std::chrono::system_clock; |
| 60 | |
| 61 | namespace grpc { |
| 62 | namespace testing { |
| 63 | |
| 64 | namespace { |
| 65 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 66 | void* tag(int i) { return (void*)(intptr_t)i; } |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 67 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 68 | #ifdef GPR_POSIX_SOCKET |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 69 | static int assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds, |
| 70 | int timeout) { |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 71 | GPR_ASSERT(timeout == 0); |
| 72 | return poll(pfds, nfds, timeout); |
| 73 | } |
| 74 | |
| 75 | class PollOverride { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 76 | public: |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 77 | PollOverride(grpc_poll_function_type f) { |
| 78 | prev_ = grpc_poll_function; |
| 79 | grpc_poll_function = f; |
| 80 | } |
| 81 | |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 82 | ~PollOverride() { grpc_poll_function = prev_; } |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | grpc_poll_function_type prev_; |
| 86 | }; |
| 87 | |
| 88 | class PollingCheckRegion : public PollOverride { |
| 89 | public: |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 90 | explicit PollingCheckRegion(bool allow_blocking) |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 91 | : PollOverride(allow_blocking ? poll : assert_non_blocking_poll) {} |
| 92 | }; |
| 93 | #else |
| 94 | class PollingCheckRegion { |
| 95 | public: |
| 96 | explicit PollingCheckRegion(bool allow_blocking) {} |
| 97 | }; |
| 98 | #endif |
| 99 | |
| 100 | class Verifier : public PollingCheckRegion { |
| 101 | public: |
| 102 | explicit Verifier(bool spin) : PollingCheckRegion(!spin), spin_(spin) {} |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 103 | Verifier& Expect(int i, bool expect_ok) { |
| 104 | expectations_[tag(i)] = expect_ok; |
| 105 | return *this; |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 106 | } |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 107 | void Verify(CompletionQueue* cq) { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 108 | GPR_ASSERT(!expectations_.empty()); |
| 109 | while (!expectations_.empty()) { |
| 110 | bool ok; |
| 111 | void* got_tag; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 112 | if (spin_) { |
| 113 | for (;;) { |
| 114 | auto r = cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)); |
| 115 | if (r == CompletionQueue::TIMEOUT) continue; |
| 116 | if (r == CompletionQueue::GOT_EVENT) break; |
| 117 | gpr_log(GPR_ERROR, "unexpected result from AsyncNext"); |
| 118 | abort(); |
| 119 | } |
| 120 | } else { |
| 121 | EXPECT_TRUE(cq->Next(&got_tag, &ok)); |
| 122 | } |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 123 | auto it = expectations_.find(got_tag); |
| 124 | EXPECT_TRUE(it != expectations_.end()); |
| 125 | EXPECT_EQ(it->second, ok); |
| 126 | expectations_.erase(it); |
| 127 | } |
| 128 | } |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 129 | void Verify(CompletionQueue* cq, |
| 130 | std::chrono::system_clock::time_point deadline) { |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 131 | if (expectations_.empty()) { |
| 132 | bool ok; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 133 | void* got_tag; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 134 | if (spin_) { |
| 135 | while (std::chrono::system_clock::now() < deadline) { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 136 | EXPECT_EQ( |
| 137 | cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)), |
| 138 | CompletionQueue::TIMEOUT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 139 | } |
| 140 | } else { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 141 | EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), |
| 142 | CompletionQueue::TIMEOUT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 143 | } |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 144 | } else { |
| 145 | while (!expectations_.empty()) { |
| 146 | bool ok; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 147 | void* got_tag; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 148 | if (spin_) { |
| 149 | for (;;) { |
| 150 | GPR_ASSERT(std::chrono::system_clock::now() < deadline); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 151 | auto r = |
| 152 | cq->AsyncNext(&got_tag, &ok, gpr_time_0(GPR_CLOCK_REALTIME)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 153 | if (r == CompletionQueue::TIMEOUT) continue; |
| 154 | if (r == CompletionQueue::GOT_EVENT) break; |
| 155 | gpr_log(GPR_ERROR, "unexpected result from AsyncNext"); |
| 156 | abort(); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 157 | } |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 158 | } else { |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 159 | EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), |
| 160 | CompletionQueue::GOT_EVENT); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 161 | } |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 162 | auto it = expectations_.find(got_tag); |
| 163 | EXPECT_TRUE(it != expectations_.end()); |
| 164 | EXPECT_EQ(it->second, ok); |
| 165 | expectations_.erase(it); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | std::map<void*, bool> expectations_; |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 172 | bool spin_; |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 173 | }; |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 174 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 175 | class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 176 | protected: |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 177 | AsyncEnd2endTest() {} |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 178 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 179 | void SetUp() GRPC_OVERRIDE { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 180 | int port = grpc_pick_unused_port_or_die(); |
| 181 | server_address_ << "localhost:" << port; |
vjpai | 017ed62 | 2015-12-09 10:42:54 -0800 | [diff] [blame] | 182 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 183 | // Setup server |
| 184 | ServerBuilder builder; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 185 | builder.AddListeningPort(server_address_.str(), |
| 186 | grpc::InsecureServerCredentials()); |
Craig Tiller | 15f383c | 2016-01-07 12:45:32 -0800 | [diff] [blame^] | 187 | builder.RegisterService(&service_); |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 188 | cq_ = builder.AddCompletionQueue(); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 189 | server_ = builder.BuildAndStart(); |
| 190 | } |
| 191 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 192 | void TearDown() GRPC_OVERRIDE { |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 193 | server_->Shutdown(); |
| 194 | void* ignored_tag; |
| 195 | bool ignored_ok; |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 196 | cq_->Shutdown(); |
| 197 | while (cq_->Next(&ignored_tag, &ignored_ok)) |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 198 | ; |
| 199 | } |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 200 | |
| 201 | void ResetStub() { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 202 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 203 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Nicolas "Pixel" Noble | 7fa5167 | 2015-09-02 02:29:09 +0200 | [diff] [blame] | 204 | stub_ = grpc::cpp::test::util::TestService::NewStub(channel); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 207 | void SendRpc(int num_rpcs) { |
| 208 | for (int i = 0; i < num_rpcs; i++) { |
| 209 | EchoRequest send_request; |
| 210 | EchoRequest recv_request; |
| 211 | EchoResponse send_response; |
| 212 | EchoResponse recv_response; |
| 213 | Status recv_status; |
| 214 | |
| 215 | ClientContext cli_ctx; |
| 216 | ServerContext srv_ctx; |
| 217 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 218 | |
| 219 | send_request.set_message("Hello"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 220 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 221 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 222 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 223 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 224 | cq_.get(), tag(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 225 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 226 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 227 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 228 | |
| 229 | send_response.set_message(recv_request.message()); |
| 230 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 231 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 232 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 233 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 234 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 235 | |
| 236 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 237 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 241 | std::unique_ptr<ServerCompletionQueue> cq_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 242 | std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_; |
| 243 | std::unique_ptr<Server> server_; |
| 244 | grpc::cpp::test::util::TestService::AsyncService service_; |
| 245 | std::ostringstream server_address_; |
| 246 | }; |
| 247 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 248 | TEST_P(AsyncEnd2endTest, SimpleRpc) { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 249 | ResetStub(); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 250 | SendRpc(1); |
| 251 | } |
Yang Gao | bb84a30 | 2015-02-12 23:30:12 -0800 | [diff] [blame] | 252 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 253 | TEST_P(AsyncEnd2endTest, SequentialRpcs) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 254 | ResetStub(); |
| 255 | SendRpc(10); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 256 | } |
| 257 | |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 258 | // Test a simple RPC using the async version of Next |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 259 | TEST_P(AsyncEnd2endTest, AsyncNextRpc) { |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 260 | ResetStub(); |
| 261 | |
| 262 | EchoRequest send_request; |
| 263 | EchoRequest recv_request; |
| 264 | EchoResponse send_response; |
| 265 | EchoResponse recv_response; |
| 266 | Status recv_status; |
| 267 | |
| 268 | ClientContext cli_ctx; |
| 269 | ServerContext srv_ctx; |
| 270 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 271 | |
| 272 | send_request.set_message("Hello"); |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 273 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 274 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 275 | |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 276 | std::chrono::system_clock::time_point time_now( |
Craig Tiller | f51199f | 2015-05-08 09:32:53 -0700 | [diff] [blame] | 277 | std::chrono::system_clock::now()); |
| 278 | std::chrono::system_clock::time_point time_limit( |
| 279 | std::chrono::system_clock::now() + std::chrono::seconds(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 280 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
| 281 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 282 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 283 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 284 | cq_.get(), tag(2)); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 285 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 286 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get(), time_limit); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 287 | EXPECT_EQ(send_request.message(), recv_request.message()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 288 | |
| 289 | send_response.set_message(recv_request.message()); |
| 290 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 291 | Verifier(GetParam()) |
| 292 | .Expect(3, true) |
| 293 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 294 | |
| 295 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 296 | Verifier(GetParam()) |
| 297 | .Expect(4, true) |
| 298 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 299 | |
| 300 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 301 | EXPECT_TRUE(recv_status.ok()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 302 | } |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 303 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 304 | // Two pings and a final pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 305 | TEST_P(AsyncEnd2endTest, SimpleClientStreaming) { |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 306 | ResetStub(); |
| 307 | |
| 308 | EchoRequest send_request; |
| 309 | EchoRequest recv_request; |
| 310 | EchoResponse send_response; |
| 311 | EchoResponse recv_response; |
| 312 | Status recv_status; |
| 313 | ClientContext cli_ctx; |
| 314 | ServerContext srv_ctx; |
| 315 | ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 316 | |
| 317 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 318 | std::unique_ptr<ClientAsyncWriter<EchoRequest> > cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 319 | stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1))); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 320 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 321 | service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 322 | tag(2)); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 323 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 324 | Verifier(GetParam()).Expect(2, true).Expect(1, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 325 | |
| 326 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 327 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 328 | |
| 329 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 330 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 331 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 332 | |
| 333 | cli_stream->Write(send_request, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 334 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 335 | |
| 336 | srv_stream.Read(&recv_request, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 337 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 338 | |
| 339 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 340 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 341 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 342 | |
| 343 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 344 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 345 | |
| 346 | send_response.set_message(recv_request.message()); |
| 347 | srv_stream.Finish(send_response, Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 348 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 349 | |
| 350 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 351 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 352 | |
| 353 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 354 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 357 | // One ping, two pongs. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 358 | TEST_P(AsyncEnd2endTest, SimpleServerStreaming) { |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 359 | ResetStub(); |
| 360 | |
| 361 | EchoRequest send_request; |
| 362 | EchoRequest recv_request; |
| 363 | EchoResponse send_response; |
| 364 | EchoResponse recv_response; |
| 365 | Status recv_status; |
| 366 | ClientContext cli_ctx; |
| 367 | ServerContext srv_ctx; |
| 368 | ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx); |
| 369 | |
| 370 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 371 | std::unique_ptr<ClientAsyncReader<EchoResponse> > cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 372 | stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1))); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 373 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 374 | service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream, |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 375 | cq_.get(), cq_.get(), tag(2)); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 376 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 377 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 378 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 379 | |
| 380 | send_response.set_message(recv_request.message()); |
| 381 | srv_stream.Write(send_response, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 382 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 383 | |
| 384 | cli_stream->Read(&recv_response, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 385 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 386 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 387 | |
| 388 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 389 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 390 | |
| 391 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 392 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 393 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 394 | |
| 395 | srv_stream.Finish(Status::OK, tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 396 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 397 | |
| 398 | cli_stream->Read(&recv_response, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 399 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 400 | |
| 401 | cli_stream->Finish(&recv_status, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 402 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 403 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 404 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | // One ping, one pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 408 | TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) { |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 409 | ResetStub(); |
| 410 | |
| 411 | EchoRequest send_request; |
| 412 | EchoRequest recv_request; |
| 413 | EchoResponse send_response; |
| 414 | EchoResponse recv_response; |
| 415 | Status recv_status; |
| 416 | ClientContext cli_ctx; |
| 417 | ServerContext srv_ctx; |
| 418 | ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 419 | |
| 420 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 421 | std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse> > |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 422 | cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1))); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 423 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 424 | service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 425 | tag(2)); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 426 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 427 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 428 | |
| 429 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 430 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 431 | |
| 432 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 433 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 434 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 435 | |
| 436 | send_response.set_message(recv_request.message()); |
| 437 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 438 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 439 | |
| 440 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 441 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 442 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 443 | |
| 444 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 445 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 446 | |
| 447 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 448 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 449 | |
| 450 | srv_stream.Finish(Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 451 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 452 | |
| 453 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 454 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 455 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 456 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 459 | // Metadata tests |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 460 | TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 461 | ResetStub(); |
| 462 | |
| 463 | EchoRequest send_request; |
| 464 | EchoRequest recv_request; |
| 465 | EchoResponse send_response; |
| 466 | EchoResponse recv_response; |
| 467 | Status recv_status; |
| 468 | |
| 469 | ClientContext cli_ctx; |
| 470 | ServerContext srv_ctx; |
| 471 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 472 | |
| 473 | send_request.set_message("Hello"); |
| 474 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 475 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 476 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 477 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
| 478 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 479 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 480 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 481 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 482 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 483 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 484 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 485 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 486 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 487 | EXPECT_EQ(meta1.second, |
| 488 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 489 | EXPECT_EQ(meta2.second, |
| 490 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 491 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 492 | |
| 493 | send_response.set_message(recv_request.message()); |
| 494 | response_writer.Finish(send_response, Status::OK, tag(3)); |
| 495 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 496 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 497 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 498 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 499 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 500 | |
| 501 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 502 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 505 | TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 506 | ResetStub(); |
| 507 | |
| 508 | EchoRequest send_request; |
| 509 | EchoRequest recv_request; |
| 510 | EchoResponse send_response; |
| 511 | EchoResponse recv_response; |
| 512 | Status recv_status; |
| 513 | |
| 514 | ClientContext cli_ctx; |
| 515 | ServerContext srv_ctx; |
| 516 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 517 | |
| 518 | send_request.set_message("Hello"); |
| 519 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 520 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 521 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 522 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 523 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 524 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 525 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 526 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 527 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 528 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 529 | srv_ctx.AddInitialMetadata(meta1.first, meta1.second); |
| 530 | srv_ctx.AddInitialMetadata(meta2.first, meta2.second); |
| 531 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 532 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 533 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 534 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 535 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 536 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 537 | EXPECT_EQ(meta1.second, |
| 538 | ToString(server_initial_metadata.find(meta1.first)->second)); |
| 539 | EXPECT_EQ(meta2.second, |
| 540 | ToString(server_initial_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 541 | EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 542 | |
| 543 | send_response.set_message(recv_request.message()); |
| 544 | response_writer.Finish(send_response, Status::OK, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 545 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 546 | |
| 547 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 548 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 549 | |
| 550 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 551 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 554 | TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 555 | ResetStub(); |
| 556 | |
| 557 | EchoRequest send_request; |
| 558 | EchoRequest recv_request; |
| 559 | EchoResponse send_response; |
| 560 | EchoResponse recv_response; |
| 561 | Status recv_status; |
| 562 | |
| 563 | ClientContext cli_ctx; |
| 564 | ServerContext srv_ctx; |
| 565 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 566 | |
| 567 | send_request.set_message("Hello"); |
| 568 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 569 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 570 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 571 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 572 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 573 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 574 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 575 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 576 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 577 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 578 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 579 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 580 | |
| 581 | send_response.set_message(recv_request.message()); |
| 582 | srv_ctx.AddTrailingMetadata(meta1.first, meta1.second); |
| 583 | srv_ctx.AddTrailingMetadata(meta2.first, meta2.second); |
| 584 | response_writer.Finish(send_response, Status::OK, tag(4)); |
| 585 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 586 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 587 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 588 | response_reader->Finish(&recv_response, &recv_status, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 589 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 590 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 591 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 592 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 593 | EXPECT_EQ(meta1.second, |
| 594 | ToString(server_trailing_metadata.find(meta1.first)->second)); |
| 595 | EXPECT_EQ(meta2.second, |
| 596 | ToString(server_trailing_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 597 | EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 600 | TEST_P(AsyncEnd2endTest, MetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 601 | ResetStub(); |
| 602 | |
| 603 | EchoRequest send_request; |
| 604 | EchoRequest recv_request; |
| 605 | EchoResponse send_response; |
| 606 | EchoResponse recv_response; |
| 607 | Status recv_status; |
| 608 | |
| 609 | ClientContext cli_ctx; |
| 610 | ServerContext srv_ctx; |
| 611 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 612 | |
| 613 | send_request.set_message("Hello"); |
| 614 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 615 | std::pair<grpc::string, grpc::string> meta2( |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 616 | "key2-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 617 | grpc::string("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 618 | std::pair<grpc::string, grpc::string> meta3("key3", "val3"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 619 | std::pair<grpc::string, grpc::string> meta6( |
| 620 | "key4-bin", |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 621 | grpc::string("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 622 | 14)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 623 | std::pair<grpc::string, grpc::string> meta5("key5", "val5"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 624 | std::pair<grpc::string, grpc::string> meta4( |
| 625 | "key6-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 626 | grpc::string( |
| 627 | "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 628 | |
| 629 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 630 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
| 631 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 632 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 633 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 634 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 635 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 636 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 637 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 638 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 639 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 640 | EXPECT_EQ(meta1.second, |
| 641 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 642 | EXPECT_EQ(meta2.second, |
| 643 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 644 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 645 | |
| 646 | srv_ctx.AddInitialMetadata(meta3.first, meta3.second); |
| 647 | srv_ctx.AddInitialMetadata(meta4.first, meta4.second); |
| 648 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 649 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 650 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 651 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 652 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 653 | EXPECT_EQ(meta3.second, |
| 654 | ToString(server_initial_metadata.find(meta3.first)->second)); |
| 655 | EXPECT_EQ(meta4.second, |
| 656 | ToString(server_initial_metadata.find(meta4.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 657 | EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 658 | |
| 659 | send_response.set_message(recv_request.message()); |
| 660 | srv_ctx.AddTrailingMetadata(meta5.first, meta5.second); |
| 661 | srv_ctx.AddTrailingMetadata(meta6.first, meta6.second); |
| 662 | response_writer.Finish(send_response, Status::OK, tag(5)); |
| 663 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 664 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 665 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 666 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 667 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 668 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 669 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 670 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 671 | EXPECT_EQ(meta5.second, |
| 672 | ToString(server_trailing_metadata.find(meta5.first)->second)); |
| 673 | EXPECT_EQ(meta6.second, |
| 674 | ToString(server_trailing_metadata.find(meta6.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 675 | EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 676 | } |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 677 | |
| 678 | // Server uses AsyncNotifyWhenDone API to check for cancellation |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 679 | TEST_P(AsyncEnd2endTest, ServerCheckCancellation) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 680 | ResetStub(); |
| 681 | |
| 682 | EchoRequest send_request; |
| 683 | EchoRequest recv_request; |
| 684 | EchoResponse send_response; |
| 685 | EchoResponse recv_response; |
| 686 | Status recv_status; |
| 687 | |
| 688 | ClientContext cli_ctx; |
| 689 | ServerContext srv_ctx; |
| 690 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 691 | |
| 692 | send_request.set_message("Hello"); |
| 693 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 694 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 695 | |
| 696 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 697 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 698 | cq_.get(), tag(2)); |
| 699 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 700 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 701 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 702 | |
| 703 | cli_ctx.TryCancel(); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 704 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 705 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 706 | |
| 707 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 708 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 709 | |
| 710 | EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code()); |
| 711 | } |
| 712 | |
| 713 | // Server uses AsyncNotifyWhenDone API to check for normal finish |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 714 | TEST_P(AsyncEnd2endTest, ServerCheckDone) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 715 | ResetStub(); |
| 716 | |
| 717 | EchoRequest send_request; |
| 718 | EchoRequest recv_request; |
| 719 | EchoResponse send_response; |
| 720 | EchoResponse recv_response; |
| 721 | Status recv_status; |
| 722 | |
| 723 | ClientContext cli_ctx; |
| 724 | ServerContext srv_ctx; |
| 725 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 726 | |
| 727 | send_request.set_message("Hello"); |
| 728 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 729 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 730 | |
| 731 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 732 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 733 | cq_.get(), tag(2)); |
| 734 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 735 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 736 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 737 | |
| 738 | send_response.set_message(recv_request.message()); |
| 739 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 740 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
| 741 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 742 | EXPECT_FALSE(srv_ctx.IsCancelled()); |
| 743 | |
| 744 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 745 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 746 | |
| 747 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 748 | EXPECT_TRUE(recv_status.ok()); |
| 749 | } |
| 750 | |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 751 | TEST_P(AsyncEnd2endTest, UnimplementedRpc) { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 752 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 753 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 754 | std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub; |
Nicolas "Pixel" Noble | 7fa5167 | 2015-09-02 02:29:09 +0200 | [diff] [blame] | 755 | stub = grpc::cpp::test::util::UnimplementedService::NewStub(channel); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 756 | EchoRequest send_request; |
| 757 | EchoResponse recv_response; |
| 758 | Status recv_status; |
| 759 | |
| 760 | ClientContext cli_ctx; |
| 761 | send_request.set_message("Hello"); |
| 762 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 763 | stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get())); |
| 764 | |
| 765 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 766 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 767 | |
| 768 | EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code()); |
| 769 | EXPECT_EQ("", recv_status.error_message()); |
| 770 | } |
| 771 | |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 772 | INSTANTIATE_TEST_CASE_P(AsyncEnd2end, AsyncEnd2endTest, |
| 773 | ::testing::Values(false, true)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 774 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 775 | } // namespace |
| 776 | } // namespace testing |
| 777 | } // namespace grpc |
| 778 | |
| 779 | int main(int argc, char** argv) { |
| 780 | grpc_test_init(argc, argv); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 781 | ::testing::InitGoogleTest(&argc, argv); |
Yang Gao | c4b6ffb | 2015-04-23 16:35:24 -0700 | [diff] [blame] | 782 | return RUN_ALL_TESTS(); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 783 | } |