Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
yang-g | 8c2be9f | 2015-08-19 16:28:09 -0700 | [diff] [blame] | 21 | #include <grpc++/channel.h> |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 22 | #include <grpc++/client_context.h> |
| 23 | #include <grpc++/create_channel.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 24 | #include <grpc++/generic/async_generic_service.h> |
| 25 | #include <grpc++/generic/generic_stub.h> |
yang-g | 17487f9 | 2016-06-03 15:21:15 -0700 | [diff] [blame] | 26 | #include <grpc++/impl/codegen/proto_utils.h> |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 27 | #include <grpc++/server.h> |
| 28 | #include <grpc++/server_builder.h> |
| 29 | #include <grpc++/server_context.h> |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 30 | #include <grpc++/support/slice.h> |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 31 | #include <grpc/grpc.h> |
| 32 | #include <grpc/support/thd.h> |
| 33 | #include <grpc/support/time.h> |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 34 | |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 35 | #include "src/proto/grpc/testing/echo.grpc.pb.h" |
yang-g | 9e2f90c | 2015-08-21 15:35:03 -0700 | [diff] [blame] | 36 | #include "test/core/util/port.h" |
| 37 | #include "test/core/util/test_config.h" |
yang-g | 9f17314 | 2016-01-15 12:46:40 -0800 | [diff] [blame] | 38 | #include "test/cpp/util/byte_buffer_proto_helper.h" |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 39 | |
Nicolas "Pixel" Noble | 3726e3d | 2017-05-10 18:33:12 +0200 | [diff] [blame] | 40 | #include <gtest/gtest.h> |
| 41 | |
Craig Tiller | 1b4e330 | 2015-12-17 16:35:00 -0800 | [diff] [blame] | 42 | using grpc::testing::EchoRequest; |
| 43 | using grpc::testing::EchoResponse; |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 44 | using std::chrono::system_clock; |
| 45 | |
| 46 | namespace grpc { |
| 47 | namespace testing { |
| 48 | namespace { |
| 49 | |
Craig Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 50 | void* tag(int i) { return (void*)(intptr_t)i; } |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 51 | |
| 52 | void verify_ok(CompletionQueue* cq, int i, bool expect_ok) { |
| 53 | bool ok; |
| 54 | void* got_tag; |
| 55 | EXPECT_TRUE(cq->Next(&got_tag, &ok)); |
| 56 | EXPECT_EQ(expect_ok, ok); |
| 57 | EXPECT_EQ(tag(i), got_tag); |
| 58 | } |
| 59 | |
Yang Gao | 005eb88 | 2015-03-11 22:17:13 -0700 | [diff] [blame] | 60 | class GenericEnd2endTest : public ::testing::Test { |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 61 | protected: |
yang-g | 4fac82b | 2016-01-15 13:15:32 -0800 | [diff] [blame] | 62 | GenericEnd2endTest() : server_host_("localhost") {} |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 63 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 64 | void SetUp() override { |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 65 | int port = grpc_pick_unused_port_or_die(); |
yang-g | 940d555 | 2015-07-31 22:11:41 -0700 | [diff] [blame] | 66 | server_address_ << server_host_ << ":" << port; |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 67 | // Setup server |
| 68 | ServerBuilder builder; |
Craig Tiller | d6c98df | 2015-08-18 09:33:44 -0700 | [diff] [blame] | 69 | builder.AddListeningPort(server_address_.str(), |
| 70 | InsecureServerCredentials()); |
Yang Gao | 4999649 | 2015-03-12 16:40:19 -0700 | [diff] [blame] | 71 | builder.RegisterAsyncGenericService(&generic_service_); |
vjpai | ba2b8ed | 2015-12-09 10:24:47 -0800 | [diff] [blame] | 72 | // Include a second call to RegisterAsyncGenericService to make sure that |
| 73 | // we get an error in the log, since it is not allowed to have 2 async |
| 74 | // generic services |
| 75 | builder.RegisterAsyncGenericService(&generic_service_); |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 76 | srv_cq_ = builder.AddCompletionQueue(); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 77 | server_ = builder.BuildAndStart(); |
| 78 | } |
| 79 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 80 | void TearDown() override { |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 81 | server_->Shutdown(); |
| 82 | void* ignored_tag; |
| 83 | bool ignored_ok; |
| 84 | cli_cq_.Shutdown(); |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 85 | srv_cq_->Shutdown(); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 86 | while (cli_cq_.Next(&ignored_tag, &ignored_ok)) |
| 87 | ; |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 88 | while (srv_cq_->Next(&ignored_tag, &ignored_ok)) |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 89 | ; |
| 90 | } |
| 91 | |
| 92 | void ResetStub() { |
yang-g | 730055d | 2015-08-27 12:29:45 -0700 | [diff] [blame] | 93 | std::shared_ptr<Channel> channel = |
Julien Boeuf | e5adc0e | 2015-10-12 14:08:10 -0700 | [diff] [blame] | 94 | CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 95 | generic_stub_.reset(new GenericStub(channel)); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 98 | void server_ok(int i) { verify_ok(srv_cq_.get(), i, true); } |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 99 | void client_ok(int i) { verify_ok(&cli_cq_, i, true); } |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 100 | void server_fail(int i) { verify_ok(srv_cq_.get(), i, false); } |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 101 | void client_fail(int i) { verify_ok(&cli_cq_, i, false); } |
| 102 | |
| 103 | void SendRpc(int num_rpcs) { |
yang-g | a044f6d | 2017-05-11 15:37:51 -0700 | [diff] [blame] | 104 | SendRpc(num_rpcs, false, gpr_inf_future(GPR_CLOCK_MONOTONIC)); |
| 105 | } |
| 106 | |
| 107 | void SendRpc(int num_rpcs, bool check_deadline, gpr_timespec deadline) { |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 108 | const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo"); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 109 | for (int i = 0; i < num_rpcs; i++) { |
| 110 | EchoRequest send_request; |
| 111 | EchoRequest recv_request; |
| 112 | EchoResponse send_response; |
| 113 | EchoResponse recv_response; |
| 114 | Status recv_status; |
| 115 | |
| 116 | ClientContext cli_ctx; |
Yang Gao | 005eb88 | 2015-03-11 22:17:13 -0700 | [diff] [blame] | 117 | GenericServerContext srv_ctx; |
Yang Gao | 4999649 | 2015-03-12 16:40:19 -0700 | [diff] [blame] | 118 | GenericServerAsyncReaderWriter stream(&srv_ctx); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 119 | |
Yang Gao | 3b3097f | 2015-04-21 11:47:45 -0700 | [diff] [blame] | 120 | // The string needs to be long enough to test heap-based slice. |
| 121 | send_request.set_message("Hello world. Hello world. Hello world."); |
yang-g | a044f6d | 2017-05-11 15:37:51 -0700 | [diff] [blame] | 122 | |
| 123 | if (check_deadline) { |
| 124 | cli_ctx.set_deadline(deadline); |
| 125 | } |
| 126 | |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 127 | std::unique_ptr<GenericClientAsyncReaderWriter> call = |
| 128 | generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1)); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 129 | client_ok(1); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 130 | std::unique_ptr<ByteBuffer> send_buffer = |
| 131 | SerializeToByteBuffer(&send_request); |
| 132 | call->Write(*send_buffer, tag(2)); |
yang-g | f64befd | 2016-03-21 14:04:10 -0700 | [diff] [blame] | 133 | // Send ByteBuffer can be destroyed after calling Write. |
| 134 | send_buffer.reset(); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 135 | client_ok(2); |
| 136 | call->WritesDone(tag(3)); |
| 137 | client_ok(3); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 138 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 139 | generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(), |
| 140 | srv_cq_.get(), tag(4)); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 141 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 142 | verify_ok(srv_cq_.get(), 4, true); |
Craig Tiller | dc31ef3 | 2015-08-25 07:11:35 -0700 | [diff] [blame] | 143 | EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length())); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 144 | EXPECT_EQ(kMethodName, srv_ctx.method()); |
yang-g | a044f6d | 2017-05-11 15:37:51 -0700 | [diff] [blame] | 145 | |
| 146 | if (check_deadline) { |
| 147 | EXPECT_TRUE(gpr_time_similar(deadline, srv_ctx.raw_deadline(), |
Craig Tiller | ff58b27 | 2017-09-21 10:40:42 -0700 | [diff] [blame] | 148 | gpr_time_from_millis(1000, GPR_TIMESPAN))); |
yang-g | a044f6d | 2017-05-11 15:37:51 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 151 | ByteBuffer recv_buffer; |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 152 | stream.Read(&recv_buffer, tag(5)); |
| 153 | server_ok(5); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 154 | EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request)); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 155 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 156 | |
| 157 | send_response.set_message(recv_request.message()); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 158 | send_buffer = SerializeToByteBuffer(&send_response); |
| 159 | stream.Write(*send_buffer, tag(6)); |
yang-g | f64befd | 2016-03-21 14:04:10 -0700 | [diff] [blame] | 160 | send_buffer.reset(); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 161 | server_ok(6); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 162 | |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 163 | stream.Finish(Status::OK, tag(7)); |
| 164 | server_ok(7); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 165 | |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 166 | recv_buffer.Clear(); |
| 167 | call->Read(&recv_buffer, tag(8)); |
| 168 | client_ok(8); |
| 169 | EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_response)); |
| 170 | |
| 171 | call->Finish(&recv_status, tag(9)); |
| 172 | client_ok(9); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 173 | |
| 174 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 175 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | CompletionQueue cli_cq_; |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 180 | std::unique_ptr<ServerCompletionQueue> srv_cq_; |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 181 | std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 182 | std::unique_ptr<grpc::GenericStub> generic_stub_; |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 183 | std::unique_ptr<Server> server_; |
Yang Gao | 4999649 | 2015-03-12 16:40:19 -0700 | [diff] [blame] | 184 | AsyncGenericService generic_service_; |
yang-g | 940d555 | 2015-07-31 22:11:41 -0700 | [diff] [blame] | 185 | const grpc::string server_host_; |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 186 | std::ostringstream server_address_; |
| 187 | }; |
| 188 | |
Yang Gao | 005eb88 | 2015-03-11 22:17:13 -0700 | [diff] [blame] | 189 | TEST_F(GenericEnd2endTest, SimpleRpc) { |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 190 | ResetStub(); |
| 191 | SendRpc(1); |
| 192 | } |
| 193 | |
Yang Gao | 005eb88 | 2015-03-11 22:17:13 -0700 | [diff] [blame] | 194 | TEST_F(GenericEnd2endTest, SequentialRpcs) { |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 195 | ResetStub(); |
| 196 | SendRpc(10); |
| 197 | } |
| 198 | |
Vijay Pai | 2046d0b | 2017-09-19 15:30:11 -0700 | [diff] [blame] | 199 | TEST_F(GenericEnd2endTest, SequentialUnaryRpcs) { |
| 200 | ResetStub(); |
| 201 | const int num_rpcs = 10; |
| 202 | const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo"); |
| 203 | for (int i = 0; i < num_rpcs; i++) { |
| 204 | EchoRequest send_request; |
| 205 | EchoRequest recv_request; |
| 206 | EchoResponse send_response; |
| 207 | EchoResponse recv_response; |
| 208 | Status recv_status; |
| 209 | |
| 210 | ClientContext cli_ctx; |
| 211 | GenericServerContext srv_ctx; |
| 212 | GenericServerAsyncReaderWriter stream(&srv_ctx); |
| 213 | |
| 214 | // The string needs to be long enough to test heap-based slice. |
| 215 | send_request.set_message("Hello world. Hello world. Hello world."); |
| 216 | |
| 217 | std::unique_ptr<ByteBuffer> cli_send_buffer = |
| 218 | SerializeToByteBuffer(&send_request); |
| 219 | std::unique_ptr<GenericClientAsyncResponseReader> call = |
| 220 | generic_stub_->PrepareUnaryCall(&cli_ctx, kMethodName, |
| 221 | *cli_send_buffer.get(), &cli_cq_); |
| 222 | call->StartCall(); |
| 223 | ByteBuffer cli_recv_buffer; |
| 224 | call->Finish(&cli_recv_buffer, &recv_status, tag(1)); |
| 225 | |
| 226 | generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(), |
| 227 | srv_cq_.get(), tag(4)); |
| 228 | |
| 229 | verify_ok(srv_cq_.get(), 4, true); |
| 230 | EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length())); |
| 231 | EXPECT_EQ(kMethodName, srv_ctx.method()); |
| 232 | |
| 233 | ByteBuffer srv_recv_buffer; |
| 234 | stream.Read(&srv_recv_buffer, tag(5)); |
| 235 | server_ok(5); |
| 236 | EXPECT_TRUE(ParseFromByteBuffer(&srv_recv_buffer, &recv_request)); |
| 237 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 238 | |
| 239 | send_response.set_message(recv_request.message()); |
| 240 | std::unique_ptr<ByteBuffer> srv_send_buffer = |
| 241 | SerializeToByteBuffer(&send_response); |
| 242 | stream.Write(*srv_send_buffer, tag(6)); |
| 243 | server_ok(6); |
| 244 | |
| 245 | stream.Finish(Status::OK, tag(7)); |
| 246 | server_ok(7); |
| 247 | |
| 248 | client_ok(1); |
| 249 | EXPECT_TRUE(ParseFromByteBuffer(&cli_recv_buffer, &recv_response)); |
| 250 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 251 | EXPECT_TRUE(recv_status.ok()); |
| 252 | } |
| 253 | } |
| 254 | |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 255 | // One ping, one pong. |
| 256 | TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { |
| 257 | ResetStub(); |
| 258 | |
Sree Kuchibhotla | 5a05f51 | 2016-01-13 22:43:20 -0800 | [diff] [blame] | 259 | const grpc::string kMethodName( |
| 260 | "/grpc.cpp.test.util.EchoTestService/BidiStream"); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 261 | EchoRequest send_request; |
| 262 | EchoRequest recv_request; |
| 263 | EchoResponse send_response; |
| 264 | EchoResponse recv_response; |
| 265 | Status recv_status; |
| 266 | ClientContext cli_ctx; |
| 267 | GenericServerContext srv_ctx; |
| 268 | GenericServerAsyncReaderWriter srv_stream(&srv_ctx); |
| 269 | |
Craig Tiller | bf6abee | 2015-07-19 22:31:04 -0700 | [diff] [blame] | 270 | cli_ctx.set_compression_algorithm(GRPC_COMPRESS_GZIP); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 271 | send_request.set_message("Hello"); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 272 | std::unique_ptr<GenericClientAsyncReaderWriter> cli_stream = |
| 273 | generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1)); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 274 | client_ok(1); |
| 275 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 276 | generic_service_.RequestCall(&srv_ctx, &srv_stream, srv_cq_.get(), |
| 277 | srv_cq_.get(), tag(2)); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 278 | |
Craig Tiller | f9e6adf | 2015-05-06 11:45:59 -0700 | [diff] [blame] | 279 | verify_ok(srv_cq_.get(), 2, true); |
Craig Tiller | dc31ef3 | 2015-08-25 07:11:35 -0700 | [diff] [blame] | 280 | EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length())); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 281 | EXPECT_EQ(kMethodName, srv_ctx.method()); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 282 | |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 283 | std::unique_ptr<ByteBuffer> send_buffer = |
| 284 | SerializeToByteBuffer(&send_request); |
| 285 | cli_stream->Write(*send_buffer, tag(3)); |
yang-g | f64befd | 2016-03-21 14:04:10 -0700 | [diff] [blame] | 286 | send_buffer.reset(); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 287 | client_ok(3); |
| 288 | |
| 289 | ByteBuffer recv_buffer; |
Yang Gao | 45c09db | 2015-03-13 15:49:35 -0700 | [diff] [blame] | 290 | srv_stream.Read(&recv_buffer, tag(4)); |
| 291 | server_ok(4); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 292 | EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request)); |
| 293 | EXPECT_EQ(send_request.message(), recv_request.message()); |
| 294 | |
| 295 | send_response.set_message(recv_request.message()); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 296 | send_buffer = SerializeToByteBuffer(&send_response); |
| 297 | srv_stream.Write(*send_buffer, tag(5)); |
yang-g | f64befd | 2016-03-21 14:04:10 -0700 | [diff] [blame] | 298 | send_buffer.reset(); |
Yang Gao | 45c09db | 2015-03-13 15:49:35 -0700 | [diff] [blame] | 299 | server_ok(5); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 300 | |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 301 | cli_stream->Read(&recv_buffer, tag(6)); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 302 | client_ok(6); |
Yang Gao | 993d540 | 2015-03-19 13:35:49 -0700 | [diff] [blame] | 303 | EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_response)); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 304 | EXPECT_EQ(send_response.message(), recv_response.message()); |
| 305 | |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 306 | cli_stream->WritesDone(tag(7)); |
| 307 | client_ok(7); |
| 308 | |
Yang Gao | 45c09db | 2015-03-13 15:49:35 -0700 | [diff] [blame] | 309 | srv_stream.Read(&recv_buffer, tag(8)); |
| 310 | server_fail(8); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 311 | |
Yang Gao | 45c09db | 2015-03-13 15:49:35 -0700 | [diff] [blame] | 312 | srv_stream.Finish(Status::OK, tag(9)); |
| 313 | server_ok(9); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 314 | |
| 315 | cli_stream->Finish(&recv_status, tag(10)); |
| 316 | client_ok(10); |
| 317 | |
| 318 | EXPECT_EQ(send_response.message(), recv_response.message()); |
Yang Gao | c1a2c31 | 2015-06-16 10:59:46 -0700 | [diff] [blame] | 319 | EXPECT_TRUE(recv_status.ok()); |
Yang Gao | 9fbbc7b | 2015-03-13 15:33:08 -0700 | [diff] [blame] | 320 | } |
| 321 | |
yang-g | a044f6d | 2017-05-11 15:37:51 -0700 | [diff] [blame] | 322 | TEST_F(GenericEnd2endTest, Deadline) { |
| 323 | ResetStub(); |
| 324 | SendRpc(1, true, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), |
| 325 | gpr_time_from_seconds(10, GPR_TIMESPAN))); |
| 326 | } |
| 327 | |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 328 | } // namespace |
| 329 | } // namespace testing |
| 330 | } // namespace grpc |
| 331 | |
| 332 | int main(int argc, char** argv) { |
| 333 | grpc_test_init(argc, argv); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 334 | ::testing::InitGoogleTest(&argc, argv); |
Yang Gao | c4b6ffb | 2015-04-23 16:35:24 -0700 | [diff] [blame] | 335 | return RUN_ALL_TESTS(); |
Yang Gao | 0cb6c25 | 2015-03-11 00:30:57 -0700 | [diff] [blame] | 336 | } |