Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
murgatroid99 | 3466c4b | 2016-01-12 10:26:04 -0800 | [diff] [blame] | 3 | * Copyright 2015-2016, 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 | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 36 | #include <grpc++/channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 37 | #include <grpc++/client_context.h> |
| 38 | #include <grpc++/create_channel.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 39 | #include <grpc++/server.h> |
| 40 | #include <grpc++/server_builder.h> |
| 41 | #include <grpc++/server_context.h> |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame^] | 42 | #include <grpc/grpc.h> |
| 43 | #include <grpc/support/thd.h> |
| 44 | #include <grpc/support/time.h> |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 45 | #include <gtest/gtest.h> |
| 46 | |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 47 | #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" |
| 48 | #include "src/proto/grpc/testing/echo.grpc.pb.h" |
Sree Kuchibhotla | b0d0c8e | 2016-01-13 22:52:17 -0800 | [diff] [blame^] | 49 | #include "test/core/util/port.h" |
| 50 | #include "test/core/util/test_config.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 | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 57 | using grpc::testing::EchoRequest; |
| 58 | using grpc::testing::EchoResponse; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 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 | |
| 183 | // It is currently unsupported to mix sync and async services |
| 184 | // in the same server, so first test that (for coverage) |
| 185 | ServerBuilder build_bad; |
| 186 | build_bad.AddListeningPort(server_address_.str(), |
Craig Tiller | 620e965 | 2015-12-14 12:02:50 -0800 | [diff] [blame] | 187 | grpc::InsecureServerCredentials()); |
vjpai | 017ed62 | 2015-12-09 10:42:54 -0800 | [diff] [blame] | 188 | build_bad.RegisterAsyncService(&service_); |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 189 | grpc::testing::EchoTestService::Service sync_service; |
vjpai | 017ed62 | 2015-12-09 10:42:54 -0800 | [diff] [blame] | 190 | build_bad.RegisterService(&sync_service); |
| 191 | GPR_ASSERT(build_bad.BuildAndStart() == nullptr); |
| 192 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 193 | // Setup server |
| 194 | ServerBuilder builder; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 195 | builder.AddListeningPort(server_address_.str(), |
| 196 | grpc::InsecureServerCredentials()); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 197 | builder.RegisterAsyncService(&service_); |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 198 | cq_ = builder.AddCompletionQueue(); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 199 | server_ = builder.BuildAndStart(); |
| 200 | } |
| 201 | |
Craig Tiller | cf133f4 | 2015-02-26 14:05:56 -0800 | [diff] [blame] | 202 | void TearDown() GRPC_OVERRIDE { |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 203 | server_->Shutdown(); |
| 204 | void* ignored_tag; |
| 205 | bool ignored_ok; |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 206 | cq_->Shutdown(); |
| 207 | while (cq_->Next(&ignored_tag, &ignored_ok)) |
Craig Tiller | 492968f | 2015-02-18 13:14:03 -0800 | [diff] [blame] | 208 | ; |
| 209 | } |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 210 | |
| 211 | void ResetStub() { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 212 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 213 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 214 | stub_ = grpc::testing::EchoTestService::NewStub(channel); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 217 | void SendRpc(int num_rpcs) { |
| 218 | for (int i = 0; i < num_rpcs; i++) { |
| 219 | EchoRequest send_request; |
| 220 | EchoRequest recv_request; |
| 221 | EchoResponse send_response; |
| 222 | EchoResponse recv_response; |
| 223 | Status recv_status; |
| 224 | |
| 225 | ClientContext cli_ctx; |
| 226 | ServerContext srv_ctx; |
| 227 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 228 | |
| 229 | send_request.set_message("Hello"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 230 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 231 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 232 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 233 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 234 | cq_.get(), tag(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 235 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 236 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 237 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 238 | |
| 239 | send_response.set_message(recv_request.message()); |
| 240 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 241 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 242 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 243 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 244 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 245 | |
| 246 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 247 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 251 | std::unique_ptr<ServerCompletionQueue> cq_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 252 | std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 253 | std::unique_ptr<Server> server_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 254 | grpc::testing::EchoTestService::AsyncService service_; |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 255 | std::ostringstream server_address_; |
| 256 | }; |
| 257 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 258 | TEST_P(AsyncEnd2endTest, SimpleRpc) { |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 259 | ResetStub(); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 260 | SendRpc(1); |
| 261 | } |
Yang Gao | bb84a30 | 2015-02-12 23:30:12 -0800 | [diff] [blame] | 262 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 263 | TEST_P(AsyncEnd2endTest, SequentialRpcs) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 264 | ResetStub(); |
| 265 | SendRpc(10); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 266 | } |
| 267 | |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 268 | // Test a simple RPC using the async version of Next |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 269 | TEST_P(AsyncEnd2endTest, AsyncNextRpc) { |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 270 | ResetStub(); |
| 271 | |
| 272 | EchoRequest send_request; |
| 273 | EchoRequest recv_request; |
| 274 | EchoResponse send_response; |
| 275 | EchoResponse recv_response; |
| 276 | Status recv_status; |
| 277 | |
| 278 | ClientContext cli_ctx; |
| 279 | ServerContext srv_ctx; |
| 280 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 281 | |
| 282 | send_request.set_message("Hello"); |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 283 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 284 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 285 | |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 286 | std::chrono::system_clock::time_point time_now( |
Craig Tiller | f51199f | 2015-05-08 09:32:53 -0700 | [diff] [blame] | 287 | std::chrono::system_clock::now()); |
| 288 | std::chrono::system_clock::time_point time_limit( |
| 289 | std::chrono::system_clock::now() + std::chrono::seconds(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 290 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
| 291 | Verifier(GetParam()).Verify(cq_.get(), time_now); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 292 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 293 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 294 | cq_.get(), tag(2)); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 295 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 296 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get(), time_limit); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 297 | EXPECT_EQ(send_request.message(), recv_request.message()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 298 | |
| 299 | send_response.set_message(recv_request.message()); |
| 300 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 301 | Verifier(GetParam()) |
| 302 | .Expect(3, true) |
| 303 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 304 | |
| 305 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 306 | Verifier(GetParam()) |
| 307 | .Expect(4, true) |
| 308 | .Verify(cq_.get(), std::chrono::system_clock::time_point::max()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 309 | |
| 310 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 311 | EXPECT_TRUE(recv_status.ok()); |
vjpai | 7aadf46 | 2015-03-16 23:58:44 -0700 | [diff] [blame] | 312 | } |
Yang Gao | 757afae | 2015-03-17 15:49:26 -0700 | [diff] [blame] | 313 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 314 | // Two pings and a final pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 315 | TEST_P(AsyncEnd2endTest, SimpleClientStreaming) { |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 316 | ResetStub(); |
| 317 | |
| 318 | EchoRequest send_request; |
| 319 | EchoRequest recv_request; |
| 320 | EchoResponse send_response; |
| 321 | EchoResponse recv_response; |
| 322 | Status recv_status; |
| 323 | ClientContext cli_ctx; |
| 324 | ServerContext srv_ctx; |
| 325 | ServerAsyncReader<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 326 | |
| 327 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 328 | std::unique_ptr<ClientAsyncWriter<EchoRequest> > cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 329 | stub_->AsyncRequestStream(&cli_ctx, &recv_response, cq_.get(), tag(1))); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 330 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 331 | service_.RequestRequestStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 332 | tag(2)); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 333 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 334 | Verifier(GetParam()).Expect(2, true).Expect(1, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 335 | |
| 336 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 337 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 338 | |
| 339 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 340 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 341 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 342 | |
| 343 | cli_stream->Write(send_request, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 344 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 345 | |
| 346 | srv_stream.Read(&recv_request, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 347 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 348 | |
| 349 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 350 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 351 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 352 | |
| 353 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 354 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 355 | |
| 356 | send_response.set_message(recv_request.message()); |
| 357 | srv_stream.Finish(send_response, Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 358 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 359 | |
| 360 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 361 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 362 | |
| 363 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 364 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 005f18a | 2015-02-13 10:22:33 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 367 | // One ping, two pongs. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 368 | TEST_P(AsyncEnd2endTest, SimpleServerStreaming) { |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 369 | ResetStub(); |
| 370 | |
| 371 | EchoRequest send_request; |
| 372 | EchoRequest recv_request; |
| 373 | EchoResponse send_response; |
| 374 | EchoResponse recv_response; |
| 375 | Status recv_status; |
| 376 | ClientContext cli_ctx; |
| 377 | ServerContext srv_ctx; |
| 378 | ServerAsyncWriter<EchoResponse> srv_stream(&srv_ctx); |
| 379 | |
| 380 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 381 | std::unique_ptr<ClientAsyncReader<EchoResponse> > cli_stream( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 382 | stub_->AsyncResponseStream(&cli_ctx, send_request, cq_.get(), tag(1))); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 383 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 384 | service_.RequestResponseStream(&srv_ctx, &recv_request, &srv_stream, |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 385 | cq_.get(), cq_.get(), tag(2)); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 386 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 387 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 388 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 389 | |
| 390 | send_response.set_message(recv_request.message()); |
| 391 | srv_stream.Write(send_response, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 392 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 393 | |
| 394 | cli_stream->Read(&recv_response, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 395 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 396 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 397 | |
| 398 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 399 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 400 | |
| 401 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 402 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 403 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 404 | |
| 405 | srv_stream.Finish(Status::OK, tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 406 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 407 | |
| 408 | cli_stream->Read(&recv_response, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 409 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 410 | |
| 411 | cli_stream->Finish(&recv_status, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 412 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 413 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 414 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 0e0d8e1 | 2015-02-13 14:40:41 -0800 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | // One ping, one pong. |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 418 | TEST_P(AsyncEnd2endTest, SimpleBidiStreaming) { |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 419 | ResetStub(); |
| 420 | |
| 421 | EchoRequest send_request; |
| 422 | EchoRequest recv_request; |
| 423 | EchoResponse send_response; |
| 424 | EchoResponse recv_response; |
| 425 | Status recv_status; |
| 426 | ClientContext cli_ctx; |
| 427 | ServerContext srv_ctx; |
| 428 | ServerAsyncReaderWriter<EchoResponse, EchoRequest> srv_stream(&srv_ctx); |
| 429 | |
| 430 | send_request.set_message("Hello"); |
Yang Gao | da699b8 | 2015-02-18 01:10:22 -0800 | [diff] [blame] | 431 | std::unique_ptr<ClientAsyncReaderWriter<EchoRequest, EchoResponse> > |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 432 | cli_stream(stub_->AsyncBidiStream(&cli_ctx, cq_.get(), tag(1))); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 433 | |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 434 | service_.RequestBidiStream(&srv_ctx, &srv_stream, cq_.get(), cq_.get(), |
| 435 | tag(2)); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 436 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 437 | Verifier(GetParam()).Expect(1, true).Expect(2, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 438 | |
| 439 | cli_stream->Write(send_request, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 440 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 441 | |
| 442 | srv_stream.Read(&recv_request, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 443 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 444 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 445 | |
| 446 | send_response.set_message(recv_request.message()); |
| 447 | srv_stream.Write(send_response, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 448 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 449 | |
| 450 | cli_stream->Read(&recv_response, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 451 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 452 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 453 | |
| 454 | cli_stream->WritesDone(tag(7)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 455 | Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 456 | |
| 457 | srv_stream.Read(&recv_request, tag(8)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 458 | Verifier(GetParam()).Expect(8, false).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 459 | |
| 460 | srv_stream.Finish(Status::OK, tag(9)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 461 | Verifier(GetParam()).Expect(9, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 462 | |
| 463 | cli_stream->Finish(&recv_status, tag(10)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 464 | Verifier(GetParam()).Expect(10, true).Verify(cq_.get()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 465 | |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 466 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | c05b6cb | 2015-02-13 00:34:10 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 469 | // Metadata tests |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 470 | TEST_P(AsyncEnd2endTest, ClientInitialMetadataRpc) { |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 471 | ResetStub(); |
| 472 | |
| 473 | EchoRequest send_request; |
| 474 | EchoRequest recv_request; |
| 475 | EchoResponse send_response; |
| 476 | EchoResponse recv_response; |
| 477 | Status recv_status; |
| 478 | |
| 479 | ClientContext cli_ctx; |
| 480 | ServerContext srv_ctx; |
| 481 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 482 | |
| 483 | send_request.set_message("Hello"); |
| 484 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 485 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 486 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 487 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
| 488 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 489 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 490 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 491 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 492 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 493 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 494 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 495 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 496 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 497 | EXPECT_EQ(meta1.second, |
| 498 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 499 | EXPECT_EQ(meta2.second, |
| 500 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 501 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 502 | |
| 503 | send_response.set_message(recv_request.message()); |
| 504 | response_writer.Finish(send_response, Status::OK, tag(3)); |
| 505 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 506 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 507 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 508 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 509 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 510 | |
| 511 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 512 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 406b32f | 2015-02-13 16:25:33 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 515 | TEST_P(AsyncEnd2endTest, ServerInitialMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 516 | ResetStub(); |
| 517 | |
| 518 | EchoRequest send_request; |
| 519 | EchoRequest recv_request; |
| 520 | EchoResponse send_response; |
| 521 | EchoResponse recv_response; |
| 522 | Status recv_status; |
| 523 | |
| 524 | ClientContext cli_ctx; |
| 525 | ServerContext srv_ctx; |
| 526 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 527 | |
| 528 | send_request.set_message("Hello"); |
| 529 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 530 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 531 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 532 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 533 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 534 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 535 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 536 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 537 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 538 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 539 | srv_ctx.AddInitialMetadata(meta1.first, meta1.second); |
| 540 | srv_ctx.AddInitialMetadata(meta2.first, meta2.second); |
| 541 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 542 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 543 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 544 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 545 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 546 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 547 | EXPECT_EQ(meta1.second, |
| 548 | ToString(server_initial_metadata.find(meta1.first)->second)); |
| 549 | EXPECT_EQ(meta2.second, |
| 550 | ToString(server_initial_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 551 | EXPECT_EQ(static_cast<size_t>(2), server_initial_metadata.size()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 552 | |
| 553 | send_response.set_message(recv_request.message()); |
| 554 | response_writer.Finish(send_response, Status::OK, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 555 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 556 | |
| 557 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 558 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 559 | |
| 560 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 561 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 564 | TEST_P(AsyncEnd2endTest, ServerTrailingMetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 565 | ResetStub(); |
| 566 | |
| 567 | EchoRequest send_request; |
| 568 | EchoRequest recv_request; |
| 569 | EchoResponse send_response; |
| 570 | EchoResponse recv_response; |
| 571 | Status recv_status; |
| 572 | |
| 573 | ClientContext cli_ctx; |
| 574 | ServerContext srv_ctx; |
| 575 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 576 | |
| 577 | send_request.set_message("Hello"); |
| 578 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
| 579 | std::pair<grpc::string, grpc::string> meta2("key2", "val2"); |
| 580 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 581 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 582 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 583 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 584 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 585 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 586 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 587 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 588 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 589 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 590 | |
| 591 | send_response.set_message(recv_request.message()); |
| 592 | srv_ctx.AddTrailingMetadata(meta1.first, meta1.second); |
| 593 | srv_ctx.AddTrailingMetadata(meta2.first, meta2.second); |
| 594 | response_writer.Finish(send_response, Status::OK, tag(4)); |
| 595 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 596 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 597 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 598 | response_reader->Finish(&recv_response, &recv_status, tag(5)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 599 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 600 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 601 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 602 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 603 | EXPECT_EQ(meta1.second, |
| 604 | ToString(server_trailing_metadata.find(meta1.first)->second)); |
| 605 | EXPECT_EQ(meta2.second, |
| 606 | ToString(server_trailing_metadata.find(meta2.first)->second)); |
vjpai | d5577aa | 2015-02-18 22:26:48 -0800 | [diff] [blame] | 607 | EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 608 | } |
| 609 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 610 | TEST_P(AsyncEnd2endTest, MetadataRpc) { |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 611 | ResetStub(); |
| 612 | |
| 613 | EchoRequest send_request; |
| 614 | EchoRequest recv_request; |
| 615 | EchoResponse send_response; |
| 616 | EchoResponse recv_response; |
| 617 | Status recv_status; |
| 618 | |
| 619 | ClientContext cli_ctx; |
| 620 | ServerContext srv_ctx; |
| 621 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 622 | |
| 623 | send_request.set_message("Hello"); |
| 624 | std::pair<grpc::string, grpc::string> meta1("key1", "val1"); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 625 | std::pair<grpc::string, grpc::string> meta2( |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 626 | "key2-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 627 | 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] | 628 | std::pair<grpc::string, grpc::string> meta3("key3", "val3"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 629 | std::pair<grpc::string, grpc::string> meta6( |
| 630 | "key4-bin", |
Vijay Pai | 92a928f | 2015-03-26 16:30:22 -0400 | [diff] [blame] | 631 | 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] | 632 | 14)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 633 | std::pair<grpc::string, grpc::string> meta5("key5", "val5"); |
Craig Tiller | 47c83fd | 2015-02-21 22:45:35 -0800 | [diff] [blame] | 634 | std::pair<grpc::string, grpc::string> meta4( |
| 635 | "key6-bin", |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 636 | grpc::string( |
| 637 | "\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] | 638 | |
| 639 | cli_ctx.AddMetadata(meta1.first, meta1.second); |
| 640 | cli_ctx.AddMetadata(meta2.first, meta2.second); |
| 641 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 642 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 643 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 644 | |
Craig Tiller | 06cf3cc | 2015-05-13 13:11:01 -0700 | [diff] [blame] | 645 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 646 | cq_.get(), tag(2)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 647 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 648 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 649 | auto client_initial_metadata = srv_ctx.client_metadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 650 | EXPECT_EQ(meta1.second, |
| 651 | ToString(client_initial_metadata.find(meta1.first)->second)); |
| 652 | EXPECT_EQ(meta2.second, |
| 653 | ToString(client_initial_metadata.find(meta2.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 654 | EXPECT_GE(client_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 655 | |
| 656 | srv_ctx.AddInitialMetadata(meta3.first, meta3.second); |
| 657 | srv_ctx.AddInitialMetadata(meta4.first, meta4.second); |
| 658 | response_writer.SendInitialMetadata(tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 659 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 660 | response_reader->ReadInitialMetadata(tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 661 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 662 | auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 663 | EXPECT_EQ(meta3.second, |
| 664 | ToString(server_initial_metadata.find(meta3.first)->second)); |
| 665 | EXPECT_EQ(meta4.second, |
| 666 | ToString(server_initial_metadata.find(meta4.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 667 | EXPECT_GE(server_initial_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 668 | |
| 669 | send_response.set_message(recv_request.message()); |
| 670 | srv_ctx.AddTrailingMetadata(meta5.first, meta5.second); |
| 671 | srv_ctx.AddTrailingMetadata(meta6.first, meta6.second); |
| 672 | response_writer.Finish(send_response, Status::OK, tag(5)); |
| 673 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 674 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 675 | |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 676 | response_reader->Finish(&recv_response, &recv_status, tag(6)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 677 | Verifier(GetParam()).Expect(6, true).Verify(cq_.get()); |
Yang Gao | 3a5e549 | 2015-02-18 14:32:38 -0800 | [diff] [blame] | 678 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 679 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 680 | auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); |
yang-g | e21908f | 2015-08-25 13:47:51 -0700 | [diff] [blame] | 681 | EXPECT_EQ(meta5.second, |
| 682 | ToString(server_trailing_metadata.find(meta5.first)->second)); |
| 683 | EXPECT_EQ(meta6.second, |
| 684 | ToString(server_trailing_metadata.find(meta6.first)->second)); |
Craig Tiller | 8bf2dca | 2015-07-10 13:08:41 -0700 | [diff] [blame] | 685 | EXPECT_GE(server_trailing_metadata.size(), static_cast<size_t>(2)); |
Yang Gao | 2b7f537 | 2015-02-18 00:45:53 -0800 | [diff] [blame] | 686 | } |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 687 | |
| 688 | // Server uses AsyncNotifyWhenDone API to check for cancellation |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 689 | TEST_P(AsyncEnd2endTest, ServerCheckCancellation) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 690 | ResetStub(); |
| 691 | |
| 692 | EchoRequest send_request; |
| 693 | EchoRequest recv_request; |
| 694 | EchoResponse send_response; |
| 695 | EchoResponse recv_response; |
| 696 | Status recv_status; |
| 697 | |
| 698 | ClientContext cli_ctx; |
| 699 | ServerContext srv_ctx; |
| 700 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 701 | |
| 702 | send_request.set_message("Hello"); |
| 703 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 704 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 705 | |
| 706 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 707 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 708 | cq_.get(), tag(2)); |
| 709 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 710 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 711 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 712 | |
| 713 | cli_ctx.TryCancel(); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 714 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 715 | EXPECT_TRUE(srv_ctx.IsCancelled()); |
| 716 | |
| 717 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 718 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 719 | |
| 720 | EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code()); |
| 721 | } |
| 722 | |
| 723 | // Server uses AsyncNotifyWhenDone API to check for normal finish |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 724 | TEST_P(AsyncEnd2endTest, ServerCheckDone) { |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 725 | ResetStub(); |
| 726 | |
| 727 | EchoRequest send_request; |
| 728 | EchoRequest recv_request; |
| 729 | EchoResponse send_response; |
| 730 | EchoResponse recv_response; |
| 731 | Status recv_status; |
| 732 | |
| 733 | ClientContext cli_ctx; |
| 734 | ServerContext srv_ctx; |
| 735 | grpc::ServerAsyncResponseWriter<EchoResponse> response_writer(&srv_ctx); |
| 736 | |
| 737 | send_request.set_message("Hello"); |
| 738 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 739 | stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); |
| 740 | |
| 741 | srv_ctx.AsyncNotifyWhenDone(tag(5)); |
| 742 | service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), |
| 743 | cq_.get(), tag(2)); |
| 744 | |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 745 | Verifier(GetParam()).Expect(2, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 746 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 747 | |
| 748 | send_response.set_message(recv_request.message()); |
| 749 | response_writer.Finish(send_response, Status::OK, tag(3)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 750 | Verifier(GetParam()).Expect(3, true).Verify(cq_.get()); |
| 751 | Verifier(GetParam()).Expect(5, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 752 | EXPECT_FALSE(srv_ctx.IsCancelled()); |
| 753 | |
| 754 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 755 | Verifier(GetParam()).Expect(4, true).Verify(cq_.get()); |
yang-g | b335256 | 2015-08-04 14:42:06 -0700 | [diff] [blame] | 756 | |
| 757 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 758 | EXPECT_TRUE(recv_status.ok()); |
| 759 | } |
| 760 | |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 761 | TEST_P(AsyncEnd2endTest, UnimplementedRpc) { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 762 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 763 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 764 | std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub; |
| 765 | stub = grpc::testing::UnimplementedService::NewStub(channel); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 766 | EchoRequest send_request; |
| 767 | EchoResponse recv_response; |
| 768 | Status recv_status; |
| 769 | |
| 770 | ClientContext cli_ctx; |
| 771 | send_request.set_message("Hello"); |
| 772 | std::unique_ptr<ClientAsyncResponseReader<EchoResponse> > response_reader( |
| 773 | stub->AsyncUnimplemented(&cli_ctx, send_request, cq_.get())); |
| 774 | |
| 775 | response_reader->Finish(&recv_response, &recv_status, tag(4)); |
Craig Tiller | 8f7bff7 | 2015-08-17 13:23:14 -0700 | [diff] [blame] | 776 | Verifier(GetParam()).Expect(4, false).Verify(cq_.get()); |
yang-g | 9b7757d | 2015-08-13 11:15:53 -0700 | [diff] [blame] | 777 | |
| 778 | EXPECT_EQ(StatusCode::UNIMPLEMENTED, recv_status.error_code()); |
| 779 | EXPECT_EQ("", recv_status.error_message()); |
| 780 | } |
| 781 | |
Craig Tiller | 4c06b82 | 2015-08-06 08:41:31 -0700 | [diff] [blame] | 782 | INSTANTIATE_TEST_CASE_P(AsyncEnd2end, AsyncEnd2endTest, |
| 783 | ::testing::Values(false, true)); |
Craig Tiller | 69f90e6 | 2015-08-06 08:32:35 -0700 | [diff] [blame] | 784 | |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 785 | } // namespace |
| 786 | } // namespace testing |
| 787 | } // namespace grpc |
| 788 | |
| 789 | int main(int argc, char** argv) { |
| 790 | grpc_test_init(argc, argv); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 791 | ::testing::InitGoogleTest(&argc, argv); |
Yang Gao | c4b6ffb | 2015-04-23 16:35:24 -0700 | [diff] [blame] | 792 | return RUN_ALL_TESTS(); |
Craig Tiller | 0220cf1 | 2015-02-12 17:39:26 -0800 | [diff] [blame] | 793 | } |