blob: 9adffab97ff582847060412424a1c557fb78be71 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * 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 Gao69fe0752015-06-01 14:32:38 -070034#include <mutex>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080035#include <thread>
yangged5e7e02015-01-06 10:16:15 -080036
Yang Gao26a49122015-05-15 17:02:56 -070037#include "src/core/security/credentials.h"
yang-g8b25f2a2015-07-21 23:54:36 -070038#include "test/core/end2end/data/ssl_test_data.h"
Nicolas Noble89219162015-04-07 18:01:18 -070039#include "test/core/util/port.h"
Craig Tiller14e60e92015-01-13 17:26:46 -080040#include "test/core/util/test_config.h"
Nicolas "Pixel" Noble0caebbf2015-04-09 23:08:51 +020041#include "test/cpp/util/echo_duplicate.grpc.pb.h"
42#include "test/cpp/util/echo.grpc.pb.h"
yangg59dfc902014-12-19 14:00:14 -080043#include <grpc++/channel_arguments.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080044#include <grpc++/channel_interface.h>
45#include <grpc++/client_context.h>
46#include <grpc++/create_channel.h>
yangg4105e2b2015-01-09 14:19:44 -080047#include <grpc++/credentials.h>
vjpaia2e1bb12015-07-15 16:49:49 -070048#include <grpc++/fixed_size_thread_pool.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080049#include <grpc++/server.h>
50#include <grpc++/server_builder.h>
yangga4b6f5d2014-12-17 15:53:12 -080051#include <grpc++/server_context.h>
Craig Tiller42bc87c2015-02-23 08:50:19 -080052#include <grpc++/server_credentials.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080053#include <grpc++/status.h>
nnoble0c475f02014-12-05 15:37:39 -080054#include <grpc++/stream.h>
Nicolas Noble89219162015-04-07 18:01:18 -070055#include <grpc++/time.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080056#include <gtest/gtest.h>
57
58#include <grpc/grpc.h>
59#include <grpc/support/thd.h>
yangged5e7e02015-01-06 10:16:15 -080060#include <grpc/support/time.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061
62using grpc::cpp::test::util::EchoRequest;
63using grpc::cpp::test::util::EchoResponse;
yangged5e7e02015-01-06 10:16:15 -080064using std::chrono::system_clock;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080065
66namespace grpc {
yangged5e7e02015-01-06 10:16:15 -080067namespace testing {
68
69namespace {
70
yang-g0b6ad7d2015-06-25 14:39:01 -070071const char* kServerCancelAfterReads = "cancel_after_reads";
72
yangged5e7e02015-01-06 10:16:15 -080073// When echo_deadline is requested, deadline seen in the ServerContext is set in
74// the response in seconds.
75void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
76 EchoResponse* response) {
77 if (request->has_param() && request->param().echo_deadline()) {
Craig Tiller354398f2015-07-13 09:16:03 -070078 gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
Nicolas Noble89219162015-04-07 18:01:18 -070079 if (context->deadline() != system_clock::time_point::max()) {
80 Timepoint2Timespec(context->deadline(), &deadline);
yangged5e7e02015-01-06 10:16:15 -080081 }
82 response->mutable_param()->set_request_deadline(deadline.tv_sec);
83 }
84}
Craig Tiller7418d012015-02-11 15:25:03 -080085
yang-g8b25f2a2015-07-21 23:54:36 -070086void CheckServerAuthContext(const ServerContext* context) {
yang-g85c04f92015-07-07 17:47:31 -070087 std::shared_ptr<const AuthContext> auth_ctx = context->auth_context();
yang-g8b25f2a2015-07-21 23:54:36 -070088 std::vector<grpc::string> ssl =
yang-gc4eef2e2015-07-06 23:26:58 -070089 auth_ctx->FindPropertyValues("transport_security_type");
yang-g8b25f2a2015-07-21 23:54:36 -070090 EXPECT_EQ(1u, ssl.size());
91 EXPECT_EQ("ssl", ssl[0]);
yang-gc4eef2e2015-07-06 23:26:58 -070092 EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
93 EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
94}
95
yangged5e7e02015-01-06 10:16:15 -080096} // namespace
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080097
yangg1456d152015-01-08 15:39:58 -080098class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080099 public:
vjpaidf551612015-07-14 13:38:44 -0700100 TestServiceImpl() : signal_client_(false), host_() {}
Vijay Pai181ef452015-07-14 13:52:48 -0700101 explicit TestServiceImpl(const grpc::string& host)
102 : signal_client_(false), host_(new grpc::string(host)) {}
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700103
yangga4b6f5d2014-12-17 15:53:12 -0800104 Status Echo(ServerContext* context, const EchoRequest* request,
Craig Tillercf133f42015-02-26 14:05:56 -0800105 EchoResponse* response) GRPC_OVERRIDE {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800106 response->set_message(request->message());
yangged5e7e02015-01-06 10:16:15 -0800107 MaybeEchoDeadline(context, request, response);
Craig Tiller822d2c72015-07-07 16:08:00 -0700108 if (host_) {
109 response->mutable_param()->set_host(*host_);
110 }
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700111 if (request->has_param() && request->param().client_cancel_after_us()) {
112 {
113 std::unique_lock<std::mutex> lock(mu_);
114 signal_client_ = true;
115 }
116 while (!context->IsCancelled()) {
David Garcia Quintasfeb67f62015-05-20 19:23:25 -0700117 gpr_sleep_until(gpr_time_add(
Craig Tiller20b5fe92015-07-06 10:43:50 -0700118 gpr_now(GPR_CLOCK_REALTIME),
Craig Tiller677c50c2015-07-13 10:49:06 -0700119 gpr_time_from_micros(request->param().client_cancel_after_us(),
120 GPR_TIMESPAN)));
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700121 }
Yang Gaoc1a2c312015-06-16 10:59:46 -0700122 return Status::CANCELLED;
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700123 } else if (request->has_param() &&
124 request->param().server_cancel_after_us()) {
David Garcia Quintasfeb67f62015-05-20 19:23:25 -0700125 gpr_sleep_until(gpr_time_add(
Craig Tiller20b5fe92015-07-06 10:43:50 -0700126 gpr_now(GPR_CLOCK_REALTIME),
Craig Tiller677c50c2015-07-13 10:49:06 -0700127 gpr_time_from_micros(request->param().server_cancel_after_us(),
128 GPR_TIMESPAN)));
Yang Gaoc1a2c312015-06-16 10:59:46 -0700129 return Status::CANCELLED;
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700130 } else {
131 EXPECT_FALSE(context->IsCancelled());
132 }
Yang Gao26a49122015-05-15 17:02:56 -0700133
134 if (request->has_param() && request->param().echo_metadata()) {
135 const std::multimap<grpc::string, grpc::string>& client_metadata =
136 context->client_metadata();
137 for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
138 client_metadata.begin();
139 iter != client_metadata.end(); ++iter) {
140 context->AddTrailingMetadata((*iter).first, (*iter).second);
141 }
142 }
yang-gc4eef2e2015-07-06 23:26:58 -0700143 if (request->has_param() && request->param().check_auth_context()) {
yang-g8b25f2a2015-07-21 23:54:36 -0700144 CheckServerAuthContext(context);
yang-gc4eef2e2015-07-06 23:26:58 -0700145 }
yang-g6f30dec2015-07-22 23:11:56 -0700146 if (request->has_param() &&
147 request->param().response_message_length() > 0) {
148 response->set_message(
149 grpc::string(request->param().response_message_length(), '\0'));
150 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800151 return Status::OK;
152 }
nnoble0c475f02014-12-05 15:37:39 -0800153
154 // Unimplemented is left unimplemented to test the returned error.
155
yangga4b6f5d2014-12-17 15:53:12 -0800156 Status RequestStream(ServerContext* context,
157 ServerReader<EchoRequest>* reader,
Craig Tillercf133f42015-02-26 14:05:56 -0800158 EchoResponse* response) GRPC_OVERRIDE {
nnoble0c475f02014-12-05 15:37:39 -0800159 EchoRequest request;
160 response->set_message("");
yang-g0b6ad7d2015-06-25 14:39:01 -0700161 int cancel_after_reads = 0;
162 const std::multimap<grpc::string, grpc::string> client_initial_metadata =
163 context->client_metadata();
164 if (client_initial_metadata.find(kServerCancelAfterReads) !=
165 client_initial_metadata.end()) {
166 std::istringstream iss(
167 client_initial_metadata.find(kServerCancelAfterReads)->second);
168 iss >> cancel_after_reads;
169 gpr_log(GPR_INFO, "cancel_after_reads %d", cancel_after_reads);
170 }
nnoble0c475f02014-12-05 15:37:39 -0800171 while (reader->Read(&request)) {
yang-g0b6ad7d2015-06-25 14:39:01 -0700172 if (cancel_after_reads == 1) {
173 gpr_log(GPR_INFO, "return cancel status");
174 return Status::CANCELLED;
175 } else if (cancel_after_reads > 0) {
176 cancel_after_reads--;
177 }
nnoble0c475f02014-12-05 15:37:39 -0800178 response->mutable_message()->append(request.message());
179 }
180 return Status::OK;
181 }
182
183 // Return 3 messages.
184 // TODO(yangg) make it generic by adding a parameter into EchoRequest
yangga4b6f5d2014-12-17 15:53:12 -0800185 Status ResponseStream(ServerContext* context, const EchoRequest* request,
Craig Tillercf133f42015-02-26 14:05:56 -0800186 ServerWriter<EchoResponse>* writer) GRPC_OVERRIDE {
nnoble0c475f02014-12-05 15:37:39 -0800187 EchoResponse response;
188 response.set_message(request->message() + "0");
189 writer->Write(response);
190 response.set_message(request->message() + "1");
191 writer->Write(response);
192 response.set_message(request->message() + "2");
193 writer->Write(response);
194
195 return Status::OK;
196 }
197
Craig Tillercf133f42015-02-26 14:05:56 -0800198 Status BidiStream(ServerContext* context,
199 ServerReaderWriter<EchoResponse, EchoRequest>* stream)
200 GRPC_OVERRIDE {
nnoble0c475f02014-12-05 15:37:39 -0800201 EchoRequest request;
202 EchoResponse response;
203 while (stream->Read(&request)) {
204 gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
205 response.set_message(request.message());
206 stream->Write(response);
207 }
208 return Status::OK;
209 }
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700210
211 bool signal_client() {
212 std::unique_lock<std::mutex> lock(mu_);
213 return signal_client_;
214 }
215
216 private:
217 bool signal_client_;
218 std::mutex mu_;
Craig Tiller822d2c72015-07-07 16:08:00 -0700219 std::unique_ptr<grpc::string> host_;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800220};
221
yangg1456d152015-01-08 15:39:58 -0800222class TestServiceImplDupPkg
223 : public ::grpc::cpp::test::util::duplicate::TestService::Service {
224 public:
225 Status Echo(ServerContext* context, const EchoRequest* request,
Craig Tillercf133f42015-02-26 14:05:56 -0800226 EchoResponse* response) GRPC_OVERRIDE {
yangg1456d152015-01-08 15:39:58 -0800227 response->set_message("no package");
228 return Status::OK;
229 }
230};
231
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800232class End2endTest : public ::testing::Test {
233 protected:
Vijay Pai181ef452015-07-14 13:52:48 -0700234 End2endTest()
235 : kMaxMessageSize_(8192), special_service_("special"), thread_pool_(2) {}
Craig Tiller7418d012015-02-11 15:25:03 -0800236
Craig Tillercf133f42015-02-26 14:05:56 -0800237 void SetUp() GRPC_OVERRIDE {
Craig Tiller35e39712015-01-12 16:41:24 -0800238 int port = grpc_pick_unused_port_or_die();
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800239 server_address_ << "localhost:" << port;
240 // Setup server
241 ServerBuilder builder;
yang-g8b25f2a2015-07-21 23:54:36 -0700242 SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key,
243 test_server1_cert};
244 SslServerCredentialsOptions ssl_opts;
245 ssl_opts.pem_root_certs = "";
246 ssl_opts.pem_key_cert_pairs.push_back(pkcp);
Yang Gaob57f72d2015-05-17 21:54:54 -0700247 builder.AddListeningPort(server_address_.str(),
yang-g8b25f2a2015-07-21 23:54:36 -0700248 SslServerCredentials(ssl_opts));
Craig Tillerf8ac5d82015-02-09 16:24:20 -0800249 builder.RegisterService(&service_);
yang-g8b25f2a2015-07-21 23:54:36 -0700250 builder.RegisterService("foo.test.youtube.com", &special_service_);
Yang Gaoc71a9d22015-05-04 00:22:12 -0700251 builder.SetMaxMessageSize(
252 kMaxMessageSize_); // For testing max message size.
Craig Tillerf8ac5d82015-02-09 16:24:20 -0800253 builder.RegisterService(&dup_pkg_service_);
Craig Tiller7418d012015-02-11 15:25:03 -0800254 builder.SetThreadPool(&thread_pool_);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800255 server_ = builder.BuildAndStart();
256 }
257
Craig Tillercf133f42015-02-26 14:05:56 -0800258 void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800259
yangg1456d152015-01-08 15:39:58 -0800260 void ResetStub() {
yang-g8b25f2a2015-07-21 23:54:36 -0700261 SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
Craig Tiller0dc5e6c2015-07-10 10:07:53 -0700262 ChannelArguments args;
yang-g8b25f2a2015-07-21 23:54:36 -0700263 args.SetSslTargetNameOverride("foo.test.google.fr");
Craig Tiller0dc5e6c2015-07-10 10:07:53 -0700264 args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test");
yang-g8b25f2a2015-07-21 23:54:36 -0700265 channel_ = CreateChannel(server_address_.str(), SslCredentials(ssl_opts),
266 args);
267 stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
yangg1456d152015-01-08 15:39:58 -0800268 }
269
yang-g8b25f2a2015-07-21 23:54:36 -0700270 std::shared_ptr<ChannelInterface> channel_;
yangg1456d152015-01-08 15:39:58 -0800271 std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800272 std::unique_ptr<Server> server_;
273 std::ostringstream server_address_;
Yang Gao3921c562015-04-30 16:07:06 -0700274 const int kMaxMessageSize_;
nnoble0c475f02014-12-05 15:37:39 -0800275 TestServiceImpl service_;
Craig Tiller822d2c72015-07-07 16:08:00 -0700276 TestServiceImpl special_service_;
yangg1456d152015-01-08 15:39:58 -0800277 TestServiceImplDupPkg dup_pkg_service_;
Vijay Pai69f24102015-07-15 12:33:37 -0700278 FixedSizeThreadPool thread_pool_;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800279};
280
yangg1456d152015-01-08 15:39:58 -0800281static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub,
282 int num_rpcs) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800283 EchoRequest request;
284 EchoResponse response;
David Garcia Quintasd7d9ce22015-06-30 23:29:03 -0700285 request.set_message("Hello hello hello hello");
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800286
287 for (int i = 0; i < num_rpcs; ++i) {
288 ClientContext context;
Craig Tillerbf6abee2015-07-19 22:31:04 -0700289 context.set_compression_algorithm(GRPC_COMPRESS_GZIP);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800290 Status s = stub->Echo(&context, request, &response);
291 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700292 EXPECT_TRUE(s.ok());
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800293 }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800294}
295
Craig Tiller822d2c72015-07-07 16:08:00 -0700296TEST_F(End2endTest, SimpleRpcWithHost) {
297 ResetStub();
298
299 EchoRequest request;
300 EchoResponse response;
301 request.set_message("Hello");
302
303 ClientContext context;
yang-g8b25f2a2015-07-21 23:54:36 -0700304 context.set_authority("foo.test.youtube.com");
Craig Tiller822d2c72015-07-07 16:08:00 -0700305 Status s = stub_->Echo(&context, request, &response);
306 EXPECT_EQ(response.message(), request.message());
307 EXPECT_TRUE(response.has_param());
yang-g8b25f2a2015-07-21 23:54:36 -0700308 EXPECT_EQ("special", response.param().host());
Craig Tiller822d2c72015-07-07 16:08:00 -0700309 EXPECT_TRUE(s.ok());
310}
311
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800312TEST_F(End2endTest, SimpleRpc) {
yangg1456d152015-01-08 15:39:58 -0800313 ResetStub();
314 SendRpc(stub_.get(), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800315}
316
317TEST_F(End2endTest, MultipleRpcs) {
yangg1456d152015-01-08 15:39:58 -0800318 ResetStub();
Craig Tiller35e39712015-01-12 16:41:24 -0800319 std::vector<std::thread*> threads;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800320 for (int i = 0; i < 10; ++i) {
yangg1456d152015-01-08 15:39:58 -0800321 threads.push_back(new std::thread(SendRpc, stub_.get(), 10));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800322 }
323 for (int i = 0; i < 10; ++i) {
324 threads[i]->join();
325 delete threads[i];
326 }
327}
328
yanggda029e32014-12-18 10:24:04 -0800329// Set a 10us deadline and make sure proper error is returned.
330TEST_F(End2endTest, RpcDeadlineExpires) {
yangg1456d152015-01-08 15:39:58 -0800331 ResetStub();
yanggda029e32014-12-18 10:24:04 -0800332 EchoRequest request;
333 EchoResponse response;
334 request.set_message("Hello");
335
336 ClientContext context;
337 std::chrono::system_clock::time_point deadline =
338 std::chrono::system_clock::now() + std::chrono::microseconds(10);
Nicolas Noble89219162015-04-07 18:01:18 -0700339 context.set_deadline(deadline);
yangg1456d152015-01-08 15:39:58 -0800340 Status s = stub_->Echo(&context, request, &response);
Yang Gaoc1a2c312015-06-16 10:59:46 -0700341 EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.error_code());
yanggda029e32014-12-18 10:24:04 -0800342}
343
yangged5e7e02015-01-06 10:16:15 -0800344// Set a long but finite deadline.
345TEST_F(End2endTest, RpcLongDeadline) {
yangg1456d152015-01-08 15:39:58 -0800346 ResetStub();
yangged5e7e02015-01-06 10:16:15 -0800347 EchoRequest request;
348 EchoResponse response;
349 request.set_message("Hello");
350
351 ClientContext context;
352 std::chrono::system_clock::time_point deadline =
353 std::chrono::system_clock::now() + std::chrono::hours(1);
Nicolas Noble89219162015-04-07 18:01:18 -0700354 context.set_deadline(deadline);
yangg1456d152015-01-08 15:39:58 -0800355 Status s = stub_->Echo(&context, request, &response);
yangged5e7e02015-01-06 10:16:15 -0800356 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700357 EXPECT_TRUE(s.ok());
yangged5e7e02015-01-06 10:16:15 -0800358}
359
360// Ask server to echo back the deadline it sees.
361TEST_F(End2endTest, EchoDeadline) {
yangg1456d152015-01-08 15:39:58 -0800362 ResetStub();
yangged5e7e02015-01-06 10:16:15 -0800363 EchoRequest request;
364 EchoResponse response;
365 request.set_message("Hello");
366 request.mutable_param()->set_echo_deadline(true);
367
368 ClientContext context;
369 std::chrono::system_clock::time_point deadline =
370 std::chrono::system_clock::now() + std::chrono::seconds(100);
Nicolas Noble89219162015-04-07 18:01:18 -0700371 context.set_deadline(deadline);
yangg1456d152015-01-08 15:39:58 -0800372 Status s = stub_->Echo(&context, request, &response);
yangged5e7e02015-01-06 10:16:15 -0800373 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700374 EXPECT_TRUE(s.ok());
yangged5e7e02015-01-06 10:16:15 -0800375 gpr_timespec sent_deadline;
376 Timepoint2Timespec(deadline, &sent_deadline);
377 // Allow 1 second error.
378 EXPECT_LE(response.param().request_deadline() - sent_deadline.tv_sec, 1);
379 EXPECT_GE(response.param().request_deadline() - sent_deadline.tv_sec, -1);
yangged5e7e02015-01-06 10:16:15 -0800380}
381
382// Ask server to echo back the deadline it sees. The rpc has no deadline.
383TEST_F(End2endTest, EchoDeadlineForNoDeadlineRpc) {
yangg1456d152015-01-08 15:39:58 -0800384 ResetStub();
yangged5e7e02015-01-06 10:16:15 -0800385 EchoRequest request;
386 EchoResponse response;
387 request.set_message("Hello");
388 request.mutable_param()->set_echo_deadline(true);
389
390 ClientContext context;
yangg1456d152015-01-08 15:39:58 -0800391 Status s = stub_->Echo(&context, request, &response);
yangged5e7e02015-01-06 10:16:15 -0800392 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700393 EXPECT_TRUE(s.ok());
Craig Tiller354398f2015-07-13 09:16:03 -0700394 EXPECT_EQ(response.param().request_deadline(),
395 gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec);
yangged5e7e02015-01-06 10:16:15 -0800396}
397
nnoble0c475f02014-12-05 15:37:39 -0800398TEST_F(End2endTest, UnimplementedRpc) {
yangg1456d152015-01-08 15:39:58 -0800399 ResetStub();
nnoble0c475f02014-12-05 15:37:39 -0800400 EchoRequest request;
401 EchoResponse response;
402 request.set_message("Hello");
403
404 ClientContext context;
yangg1456d152015-01-08 15:39:58 -0800405 Status s = stub_->Unimplemented(&context, request, &response);
Yang Gaoc1a2c312015-06-16 10:59:46 -0700406 EXPECT_FALSE(s.ok());
407 EXPECT_EQ(s.error_code(), grpc::StatusCode::UNIMPLEMENTED);
408 EXPECT_EQ(s.error_message(), "");
nnoble0c475f02014-12-05 15:37:39 -0800409 EXPECT_EQ(response.message(), "");
nnoble0c475f02014-12-05 15:37:39 -0800410}
411
412TEST_F(End2endTest, RequestStreamOneRequest) {
yangg1456d152015-01-08 15:39:58 -0800413 ResetStub();
nnoble0c475f02014-12-05 15:37:39 -0800414 EchoRequest request;
415 EchoResponse response;
416 ClientContext context;
417
Craig Tillerfd1b49b2015-02-23 12:53:39 -0800418 auto stream = stub_->RequestStream(&context, &response);
nnoble0c475f02014-12-05 15:37:39 -0800419 request.set_message("hello");
420 EXPECT_TRUE(stream->Write(request));
421 stream->WritesDone();
Craig Tillerf8ac5d82015-02-09 16:24:20 -0800422 Status s = stream->Finish();
nnoble0c475f02014-12-05 15:37:39 -0800423 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700424 EXPECT_TRUE(s.ok());
nnoble0c475f02014-12-05 15:37:39 -0800425}
426
427TEST_F(End2endTest, RequestStreamTwoRequests) {
yangg1456d152015-01-08 15:39:58 -0800428 ResetStub();
nnoble0c475f02014-12-05 15:37:39 -0800429 EchoRequest request;
430 EchoResponse response;
431 ClientContext context;
432
Craig Tillerfd1b49b2015-02-23 12:53:39 -0800433 auto stream = stub_->RequestStream(&context, &response);
nnoble0c475f02014-12-05 15:37:39 -0800434 request.set_message("hello");
435 EXPECT_TRUE(stream->Write(request));
436 EXPECT_TRUE(stream->Write(request));
437 stream->WritesDone();
Craig Tillerf8ac5d82015-02-09 16:24:20 -0800438 Status s = stream->Finish();
nnoble0c475f02014-12-05 15:37:39 -0800439 EXPECT_EQ(response.message(), "hellohello");
Yang Gaoc1a2c312015-06-16 10:59:46 -0700440 EXPECT_TRUE(s.ok());
nnoble0c475f02014-12-05 15:37:39 -0800441}
442
443TEST_F(End2endTest, ResponseStream) {
yangg1456d152015-01-08 15:39:58 -0800444 ResetStub();
nnoble0c475f02014-12-05 15:37:39 -0800445 EchoRequest request;
446 EchoResponse response;
447 ClientContext context;
448 request.set_message("hello");
449
Craig Tillerfd1b49b2015-02-23 12:53:39 -0800450 auto stream = stub_->ResponseStream(&context, request);
nnoble0c475f02014-12-05 15:37:39 -0800451 EXPECT_TRUE(stream->Read(&response));
452 EXPECT_EQ(response.message(), request.message() + "0");
453 EXPECT_TRUE(stream->Read(&response));
454 EXPECT_EQ(response.message(), request.message() + "1");
455 EXPECT_TRUE(stream->Read(&response));
456 EXPECT_EQ(response.message(), request.message() + "2");
457 EXPECT_FALSE(stream->Read(&response));
458
Craig Tiller4d0fb5f2015-02-09 16:27:22 -0800459 Status s = stream->Finish();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700460 EXPECT_TRUE(s.ok());
nnoble0c475f02014-12-05 15:37:39 -0800461}
462
463TEST_F(End2endTest, BidiStream) {
yangg1456d152015-01-08 15:39:58 -0800464 ResetStub();
nnoble0c475f02014-12-05 15:37:39 -0800465 EchoRequest request;
466 EchoResponse response;
467 ClientContext context;
468 grpc::string msg("hello");
469
Craig Tillerfd1b49b2015-02-23 12:53:39 -0800470 auto stream = stub_->BidiStream(&context);
nnoble0c475f02014-12-05 15:37:39 -0800471
472 request.set_message(msg + "0");
473 EXPECT_TRUE(stream->Write(request));
474 EXPECT_TRUE(stream->Read(&response));
475 EXPECT_EQ(response.message(), request.message());
476
477 request.set_message(msg + "1");
478 EXPECT_TRUE(stream->Write(request));
479 EXPECT_TRUE(stream->Read(&response));
480 EXPECT_EQ(response.message(), request.message());
481
482 request.set_message(msg + "2");
483 EXPECT_TRUE(stream->Write(request));
484 EXPECT_TRUE(stream->Read(&response));
485 EXPECT_EQ(response.message(), request.message());
486
487 stream->WritesDone();
488 EXPECT_FALSE(stream->Read(&response));
489
Craig Tiller4d0fb5f2015-02-09 16:27:22 -0800490 Status s = stream->Finish();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700491 EXPECT_TRUE(s.ok());
yangg1456d152015-01-08 15:39:58 -0800492}
493
494// Talk to the two services with the same name but different package names.
495// The two stubs are created on the same channel.
496TEST_F(End2endTest, DiffPackageServices) {
yang-g8b25f2a2015-07-21 23:54:36 -0700497 ResetStub();
yangg1456d152015-01-08 15:39:58 -0800498 EchoRequest request;
499 EchoResponse response;
500 request.set_message("Hello");
501
yangg1456d152015-01-08 15:39:58 -0800502 ClientContext context;
yang-g8b25f2a2015-07-21 23:54:36 -0700503 Status s = stub_->Echo(&context, request, &response);
yangg1456d152015-01-08 15:39:58 -0800504 EXPECT_EQ(response.message(), request.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700505 EXPECT_TRUE(s.ok());
yangg1456d152015-01-08 15:39:58 -0800506
507 std::unique_ptr<grpc::cpp::test::util::duplicate::TestService::Stub>
508 dup_pkg_stub(
yang-g8b25f2a2015-07-21 23:54:36 -0700509 grpc::cpp::test::util::duplicate::TestService::NewStub(channel_));
yangg1456d152015-01-08 15:39:58 -0800510 ClientContext context2;
511 s = dup_pkg_stub->Echo(&context2, request, &response);
512 EXPECT_EQ("no package", response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700513 EXPECT_TRUE(s.ok());
nnoble0c475f02014-12-05 15:37:39 -0800514}
515
yangg4105e2b2015-01-09 14:19:44 -0800516// rpc and stream should fail on bad credentials.
517TEST_F(End2endTest, BadCredentials) {
Yang Gaoa8938922015-05-14 11:51:07 -0700518 std::shared_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1);
Vijay Paic4af2242015-07-21 18:43:28 +0000519 EXPECT_EQ(static_cast<Credentials *>(nullptr), bad_creds.get());
yangg4105e2b2015-01-09 14:19:44 -0800520 std::shared_ptr<ChannelInterface> channel =
521 CreateChannel(server_address_.str(), bad_creds, ChannelArguments());
522 std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub(
523 grpc::cpp::test::util::TestService::NewStub(channel));
524 EchoRequest request;
525 EchoResponse response;
526 ClientContext context;
Yang Gao26a49122015-05-15 17:02:56 -0700527 request.set_message("Hello");
yangg4105e2b2015-01-09 14:19:44 -0800528
529 Status s = stub->Echo(&context, request, &response);
530 EXPECT_EQ("", response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700531 EXPECT_FALSE(s.ok());
532 EXPECT_EQ(StatusCode::UNKNOWN, s.error_code());
533 EXPECT_EQ("Rpc sent on a lame channel.", s.error_message());
yangg4105e2b2015-01-09 14:19:44 -0800534
535 ClientContext context2;
Craig Tillerfd1b49b2015-02-23 12:53:39 -0800536 auto stream = stub->BidiStream(&context2);
Craig Tiller4d0fb5f2015-02-09 16:27:22 -0800537 s = stream->Finish();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700538 EXPECT_FALSE(s.ok());
539 EXPECT_EQ(StatusCode::UNKNOWN, s.error_code());
540 EXPECT_EQ("Rpc sent on a lame channel.", s.error_message());
yangg4105e2b2015-01-09 14:19:44 -0800541}
542
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700543void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
Craig Tiller20b5fe92015-07-06 10:43:50 -0700544 gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
Craig Tiller677c50c2015-07-13 10:49:06 -0700545 gpr_time_from_micros(delay_us, GPR_TIMESPAN)));
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700546 while (!service->signal_client()) {
547 }
548 context->TryCancel();
549}
550
551// Client cancels rpc after 10ms
552TEST_F(End2endTest, ClientCancelsRpc) {
553 ResetStub();
554 EchoRequest request;
555 EchoResponse response;
556 request.set_message("Hello");
557 const int kCancelDelayUs = 10 * 1000;
558 request.mutable_param()->set_client_cancel_after_us(kCancelDelayUs);
559
560 ClientContext context;
561 std::thread cancel_thread(CancelRpc, &context, kCancelDelayUs, &service_);
562 Status s = stub_->Echo(&context, request, &response);
563 cancel_thread.join();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700564 EXPECT_EQ(StatusCode::CANCELLED, s.error_code());
565 EXPECT_EQ(s.error_message(), "Cancelled");
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700566}
567
568// Server cancels rpc after 1ms
569TEST_F(End2endTest, ServerCancelsRpc) {
570 ResetStub();
571 EchoRequest request;
572 EchoResponse response;
573 request.set_message("Hello");
574 request.mutable_param()->set_server_cancel_after_us(1000);
575
576 ClientContext context;
577 Status s = stub_->Echo(&context, request, &response);
Yang Gaoc1a2c312015-06-16 10:59:46 -0700578 EXPECT_EQ(StatusCode::CANCELLED, s.error_code());
579 EXPECT_TRUE(s.error_message().empty());
Yang Gao0c4b0dd2015-03-30 13:08:34 -0700580}
581
Abhishek Kumard774c5c2015-04-23 14:59:49 -0700582// Client cancels request stream after sending two messages
583TEST_F(End2endTest, ClientCancelsRequestStream) {
584 ResetStub();
585 EchoRequest request;
586 EchoResponse response;
587 ClientContext context;
588 request.set_message("hello");
589
590 auto stream = stub_->RequestStream(&context, &response);
591 EXPECT_TRUE(stream->Write(request));
592 EXPECT_TRUE(stream->Write(request));
Yang Gaoc71a9d22015-05-04 00:22:12 -0700593
Abhishek Kumard774c5c2015-04-23 14:59:49 -0700594 context.TryCancel();
595
596 Status s = stream->Finish();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700597 EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code());
Abhishek Kumard774c5c2015-04-23 14:59:49 -0700598
Yang Gaoc71a9d22015-05-04 00:22:12 -0700599 EXPECT_EQ(response.message(), "");
Abhishek Kumard774c5c2015-04-23 14:59:49 -0700600}
601
Abhishek Kumare41d0402015-04-17 14:12:33 -0700602// Client cancels server stream after sending some messages
Abhishek Kumara1d3a722015-04-23 10:24:04 -0700603TEST_F(End2endTest, ClientCancelsResponseStream) {
Abhishek Kumare41d0402015-04-17 14:12:33 -0700604 ResetStub();
605 EchoRequest request;
606 EchoResponse response;
607 ClientContext context;
608 request.set_message("hello");
609
610 auto stream = stub_->ResponseStream(&context, request);
611
612 EXPECT_TRUE(stream->Read(&response));
613 EXPECT_EQ(response.message(), request.message() + "0");
614 EXPECT_TRUE(stream->Read(&response));
615 EXPECT_EQ(response.message(), request.message() + "1");
616
617 context.TryCancel();
618
619 // The cancellation races with responses, so there might be zero or
620 // one responses pending, read till failure
621
622 if (stream->Read(&response)) {
623 EXPECT_EQ(response.message(), request.message() + "2");
624 // Since we have cancelled, we expect the next attempt to read to fail
625 EXPECT_FALSE(stream->Read(&response));
626 }
627
628 Status s = stream->Finish();
Abhishek Kumar18298a72015-04-17 15:00:25 -0700629 // The final status could be either of CANCELLED or OK depending on
630 // who won the race.
Yang Gaoc1a2c312015-06-16 10:59:46 -0700631 EXPECT_GE(grpc::StatusCode::CANCELLED, s.error_code());
Abhishek Kumare41d0402015-04-17 14:12:33 -0700632}
633
Abhishek Kumar82a83312015-04-17 13:30:51 -0700634// Client cancels bidi stream after sending some messages
635TEST_F(End2endTest, ClientCancelsBidi) {
636 ResetStub();
637 EchoRequest request;
638 EchoResponse response;
639 ClientContext context;
640 grpc::string msg("hello");
641
642 auto stream = stub_->BidiStream(&context);
643
644 request.set_message(msg + "0");
645 EXPECT_TRUE(stream->Write(request));
646 EXPECT_TRUE(stream->Read(&response));
647 EXPECT_EQ(response.message(), request.message());
648
649 request.set_message(msg + "1");
650 EXPECT_TRUE(stream->Write(request));
651
652 context.TryCancel();
653
654 // The cancellation races with responses, so there might be zero or
655 // one responses pending, read till failure
656
657 if (stream->Read(&response)) {
658 EXPECT_EQ(response.message(), request.message());
659 // Since we have cancelled, we expect the next attempt to read to fail
660 EXPECT_FALSE(stream->Read(&response));
661 }
662
663 Status s = stream->Finish();
Yang Gaoc1a2c312015-06-16 10:59:46 -0700664 EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code());
Abhishek Kumar82a83312015-04-17 13:30:51 -0700665}
666
Yang Gao3921c562015-04-30 16:07:06 -0700667TEST_F(End2endTest, RpcMaxMessageSize) {
668 ResetStub();
669 EchoRequest request;
670 EchoResponse response;
Yang Gaoc71a9d22015-05-04 00:22:12 -0700671 request.set_message(string(kMaxMessageSize_ * 2, 'a'));
Yang Gao3921c562015-04-30 16:07:06 -0700672
673 ClientContext context;
674 Status s = stub_->Echo(&context, request, &response);
Yang Gaoc1a2c312015-06-16 10:59:46 -0700675 EXPECT_FALSE(s.ok());
Yang Gao3921c562015-04-30 16:07:06 -0700676}
Abhishek Kumar82a83312015-04-17 13:30:51 -0700677
Yang Gao26a49122015-05-15 17:02:56 -0700678bool MetadataContains(const std::multimap<grpc::string, grpc::string>& metadata,
679 const grpc::string& key, const grpc::string& value) {
680 int count = 0;
681
682 for (std::multimap<grpc::string, grpc::string>::const_iterator iter =
683 metadata.begin();
684 iter != metadata.end(); ++iter) {
685 if ((*iter).first == key && (*iter).second == value) {
686 count++;
687 }
688 }
689 return count == 1;
690}
691
Yang Gaoa8938922015-05-14 11:51:07 -0700692TEST_F(End2endTest, SetPerCallCredentials) {
693 ResetStub();
694 EchoRequest request;
695 EchoResponse response;
696 ClientContext context;
697 std::shared_ptr<Credentials> creds =
698 IAMCredentials("fake_token", "fake_selector");
699 context.set_credentials(creds);
Yang Gao26a49122015-05-15 17:02:56 -0700700 request.set_message("Hello");
701 request.mutable_param()->set_echo_metadata(true);
Yang Gaoa8938922015-05-14 11:51:07 -0700702
703 Status s = stub_->Echo(&context, request, &response);
Yang Gaoa8938922015-05-14 11:51:07 -0700704 EXPECT_EQ(request.message(), response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700705 EXPECT_TRUE(s.ok());
Yang Gao26a49122015-05-15 17:02:56 -0700706 EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
707 GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
708 "fake_token"));
709 EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
710 GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
711 "fake_selector"));
Yang Gaoa8938922015-05-14 11:51:07 -0700712}
713
714TEST_F(End2endTest, InsecurePerCallCredentials) {
715 ResetStub();
716 EchoRequest request;
717 EchoResponse response;
718 ClientContext context;
719 std::shared_ptr<Credentials> creds = InsecureCredentials();
720 context.set_credentials(creds);
Yang Gao26a49122015-05-15 17:02:56 -0700721 request.set_message("Hello");
722 request.mutable_param()->set_echo_metadata(true);
Yang Gaoa8938922015-05-14 11:51:07 -0700723
724 Status s = stub_->Echo(&context, request, &response);
Yang Gaoc1a2c312015-06-16 10:59:46 -0700725 EXPECT_EQ(StatusCode::CANCELLED, s.error_code());
726 EXPECT_EQ("Failed to set credentials to rpc.", s.error_message());
Yang Gaoa8938922015-05-14 11:51:07 -0700727}
728
729TEST_F(End2endTest, OverridePerCallCredentials) {
730 ResetStub();
731 EchoRequest request;
732 EchoResponse response;
733 ClientContext context;
Yang Gao26a49122015-05-15 17:02:56 -0700734 std::shared_ptr<Credentials> creds1 =
735 IAMCredentials("fake_token1", "fake_selector1");
Yang Gaoa8938922015-05-14 11:51:07 -0700736 context.set_credentials(creds1);
737 std::shared_ptr<Credentials> creds2 =
Yang Gao26a49122015-05-15 17:02:56 -0700738 IAMCredentials("fake_token2", "fake_selector2");
Yang Gaoa8938922015-05-14 11:51:07 -0700739 context.set_credentials(creds2);
Yang Gao26a49122015-05-15 17:02:56 -0700740 request.set_message("Hello");
741 request.mutable_param()->set_echo_metadata(true);
Yang Gaoa8938922015-05-14 11:51:07 -0700742
743 Status s = stub_->Echo(&context, request, &response);
Yang Gao26a49122015-05-15 17:02:56 -0700744 EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
745 GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
746 "fake_token2"));
747 EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(),
748 GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
749 "fake_selector2"));
Yang Gaob57f72d2015-05-17 21:54:54 -0700750 EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(),
751 GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
752 "fake_token1"));
753 EXPECT_FALSE(MetadataContains(context.GetServerTrailingMetadata(),
754 GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
755 "fake_selector1"));
Yang Gaoa8938922015-05-14 11:51:07 -0700756 EXPECT_EQ(request.message(), response.message());
Yang Gaoc1a2c312015-06-16 10:59:46 -0700757 EXPECT_TRUE(s.ok());
Yang Gaoa8938922015-05-14 11:51:07 -0700758}
759
yang-g0b6ad7d2015-06-25 14:39:01 -0700760// Client sends 20 requests and the server returns CANCELLED status after
761// reading 10 requests.
762TEST_F(End2endTest, RequestStreamServerEarlyCancelTest) {
763 ResetStub();
764 EchoRequest request;
765 EchoResponse response;
766 ClientContext context;
767
768 context.AddMetadata(kServerCancelAfterReads, "10");
769 auto stream = stub_->RequestStream(&context, &response);
770 request.set_message("hello");
771 int send_messages = 20;
772 while (send_messages > 0) {
773 EXPECT_TRUE(stream->Write(request));
774 send_messages--;
775 }
776 stream->WritesDone();
777 Status s = stream->Finish();
778 EXPECT_EQ(s.error_code(), StatusCode::CANCELLED);
779}
780
yang-gc4eef2e2015-07-06 23:26:58 -0700781TEST_F(End2endTest, ClientAuthContext) {
782 ResetStub();
783 EchoRequest request;
784 EchoResponse response;
785 request.set_message("Hello");
786 request.mutable_param()->set_check_auth_context(true);
787
788 ClientContext context;
789 Status s = stub_->Echo(&context, request, &response);
790 EXPECT_EQ(response.message(), request.message());
791 EXPECT_TRUE(s.ok());
792
yang-g8b25f2a2015-07-21 23:54:36 -0700793 std::shared_ptr<const AuthContext> auth_ctx = context.auth_context();
794 std::vector<grpc::string> ssl =
795 auth_ctx->FindPropertyValues("transport_security_type");
796 EXPECT_EQ(1u, ssl.size());
797 EXPECT_EQ("ssl", ssl[0]);
798 EXPECT_EQ("x509_subject_alternative_name",
799 auth_ctx->GetPeerIdentityPropertyName());
800 EXPECT_EQ(3u, auth_ctx->GetPeerIdentity().size());
801 EXPECT_EQ("*.test.google.fr", auth_ctx->GetPeerIdentity()[0]);
802 EXPECT_EQ("waterzooi.test.google.be", auth_ctx->GetPeerIdentity()[1]);
803 EXPECT_EQ("*.test.youtube.com", auth_ctx->GetPeerIdentity()[2]);
yang-gc4eef2e2015-07-06 23:26:58 -0700804}
805
yang-g6f30dec2015-07-22 23:11:56 -0700806// Make the response larger than the flow control window.
807TEST_F(End2endTest, HugeResponse) {
808 ResetStub();
809 EchoRequest request;
810 EchoResponse response;
811 request.set_message("huge response");
812 const int kResponseSize = 1024 * (1024 + 10);
813 request.mutable_param()->set_response_message_length(kResponseSize);
814
815 ClientContext context;
816 Status s = stub_->Echo(&context, request, &response);
817 EXPECT_EQ(kResponseSize, response.message().size());
818 EXPECT_TRUE(s.ok());
819}
820
yangged5e7e02015-01-06 10:16:15 -0800821} // namespace testing
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800822} // namespace grpc
823
824int main(int argc, char** argv) {
Craig Tiller14e60e92015-01-13 17:26:46 -0800825 grpc_test_init(argc, argv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800826 ::testing::InitGoogleTest(&argc, argv);
Yang Gaoc4b6ffb2015-04-23 16:35:24 -0700827 return RUN_ALL_TESTS();
Craig Tiller190d3602015-02-18 09:23:38 -0800828}