Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/grpc/test/cpp/interop/reconnect_interop_client.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
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
34 #include <memory>
35 #include <sstream>
36
37 #include <grpc/grpc.h>
38 #include <grpc/support/log.h>
39 #include <gflags/gflags.h>
40 #include <grpc++/channel.h>
41 #include <grpc++/client_context.h>
42 #include "test/cpp/util/create_test_channel.h"
43 #include "test/cpp/util/test_config.h"
44 #include "src/proto/grpc/testing/test.grpc.pb.h"
45 #include "src/proto/grpc/testing/empty.grpc.pb.h"
46 #include "src/proto/grpc/testing/messages.grpc.pb.h"
47
48 DEFINE_int32(server_control_port, 0, "Server port for control rpcs.");
49 DEFINE_int32(server_retry_port, 0, "Server port for testing reconnection.");
50 DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
51
52 using grpc::Channel;
53 using grpc::ClientContext;
54 using grpc::CreateTestChannel;
55 using grpc::Status;
56 using grpc::testing::Empty;
57 using grpc::testing::ReconnectInfo;
58 using grpc::testing::ReconnectService;
59
60 int main(int argc, char** argv) {
61 grpc::testing::InitTest(&argc, &argv, true);
62 GPR_ASSERT(FLAGS_server_control_port);
63 GPR_ASSERT(FLAGS_server_retry_port);
64
65 std::ostringstream server_address;
66 server_address << FLAGS_server_host << ':' << FLAGS_server_control_port;
67 std::unique_ptr<ReconnectService::Stub> control_stub(
68 ReconnectService::NewStub(
69 CreateTestChannel(server_address.str(), false)));
70 ClientContext start_context;
71 Empty empty_request;
72 Empty empty_response;
73 Status start_status =
74 control_stub->Start(&start_context, empty_request, &empty_response);
75 GPR_ASSERT(start_status.ok());
76
77 gpr_log(GPR_INFO, "Starting connections with retries.");
78 server_address.str("");
79 server_address << FLAGS_server_host << ':' << FLAGS_server_retry_port;
80 std::shared_ptr<Channel> retry_channel =
81 CreateTestChannel(server_address.str(), true);
82 // About 13 retries.
83 const int kDeadlineSeconds = 540;
84 // Use any rpc to test retry.
85 std::unique_ptr<ReconnectService::Stub> retry_stub(
86 ReconnectService::NewStub(retry_channel));
87 ClientContext retry_context;
88 retry_context.set_deadline(std::chrono::system_clock::now() +
89 std::chrono::seconds(kDeadlineSeconds));
90 Status retry_status =
91 retry_stub->Start(&retry_context, empty_request, &empty_response);
92 GPR_ASSERT(retry_status.error_code() == grpc::StatusCode::DEADLINE_EXCEEDED);
93 gpr_log(GPR_INFO, "Done retrying, getting final data from server");
94
95 ClientContext stop_context;
96 ReconnectInfo response;
97 Status stop_status =
98 control_stub->Stop(&stop_context, empty_request, &response);
99 GPR_ASSERT(stop_status.ok());
100 GPR_ASSERT(response.passed() == true);
101 return 0;
102 }
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/interop/metrics_client.cc ('k') | third_party/grpc/test/cpp/interop/reconnect_interop_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698