Debian Codegraph @

test/cpp/interop/interop_client.h

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #ifndef GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H
20 #define GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H
21
22 #include <memory>
23
24 #include <grpc/grpc.h>
25 #include <grpcpp/channel.h>
26
27 #include "src/proto/grpc/testing/messages.pb.h"
28 #include "src/proto/grpc/testing/test.grpc.pb.h"
29
30 namespace grpc {
31 namespace testing {
32
33 // Function pointer for custom checks.
34 typedef std::function<void(const InteropClientContextInspector&,
35 const SimpleRequest*, const SimpleResponse*)>
36 CheckerFn;
37
38 typedef std::function<std::shared_ptr<Channel>(void)> ChannelCreationFunc;
39
40 class InteropClient {
41 public:
42 /// If new_stub_every_test_case is true, a new TestService::Stub object is
43 /// created for every test case
44 /// If do_not_abort_on_transient_failures is true, abort() is not called in
45 /// case of transient failures (like connection failures)
46 explicit InteropClient(ChannelCreationFunc channel_creation_func,
47 bool new_stub_every_test_case,
48 bool do_not_abort_on_transient_failures);
49 ~InteropClient() {}
50
51 void Reset(const std::shared_ptr<Channel>& channel);
52
53 bool DoEmpty();
54 bool DoLargeUnary();
55 bool DoServerCompressedUnary();
56 bool DoClientCompressedUnary();
57 bool DoPingPong();
58 bool DoHalfDuplex();
59 bool DoRequestStreaming();
60 bool DoResponseStreaming();
61 bool DoServerCompressedStreaming();
62 bool DoClientCompressedStreaming();
63 bool DoResponseStreamingWithSlowConsumer();
64 bool DoCancelAfterBegin();
65 bool DoCancelAfterFirstResponse();
66 bool DoTimeoutOnSleepingServer();
67 bool DoEmptyStream();
68 bool DoStatusWithMessage();
69 // Verifies Unicode and Whitespace is correctly processed in status message.
70 bool DoSpecialStatusMessage();
71 bool DoCustomMetadata();
72 bool DoUnimplementedMethod();
73 bool DoUnimplementedService();
74 // all requests are sent to one server despite multiple servers are resolved
75 bool DoPickFirstUnary();
76
77 // The following interop test are not yet part of the interop spec, and are
78 // not implemented cross-language. They are considered experimental for now,
79 // but at some point in the future, might be codified and implemented in all
80 // languages
81 bool DoChannelSoakTest(int32_t soak_iterations, int32_t max_failures,
82 int64_t max_acceptable_per_iteration_latency_ms,
83 int32_t soak_min_time_ms_between_rpcs,
84 int32_t overall_timeout_seconds);
85 bool DoRpcSoakTest(int32_t soak_iterations, int32_t max_failures,
86 int64_t max_acceptable_per_iteration_latency_ms,
87 int32_t soak_min_time_ms_between_rpcs,
88 int32_t overall_timeout_seconds);
89 bool DoLongLivedChannelTest(int32_t soak_iterations,
90 int32_t iteration_interval);
91
92 // Auth tests.
93 // username is a string containing the user email
94 bool DoJwtTokenCreds(const std::string& username);
95 bool DoComputeEngineCreds(const std::string& default_service_account,
96 const std::string& oauth_scope);
97 // username the GCE default service account email
98 bool DoOauth2AuthToken(const std::string& username,
99 const std::string& oauth_scope);
100 // username is a string containing the user email
101 bool DoPerRpcCreds(const std::string& json_key);
102 // default_service_account is the GCE default service account email
103 bool DoGoogleDefaultCredentials(const std::string& default_service_account);
104
105 private:
106 class ServiceStub {
107 public:
108 // If new_stub_every_call = true, pointer to a new instance of
109 // TestServce::Stub is returned by Get() everytime it is called
110 ServiceStub(ChannelCreationFunc channel_creation_func,
111 bool new_stub_every_call);
112
113 TestService::Stub* Get();
114 UnimplementedService::Stub* GetUnimplementedServiceStub();
115
116 // forces channel to be recreated.
117 void ResetChannel();
118
119 private:
120 ChannelCreationFunc channel_creation_func_;
121 std::unique_ptr<TestService::Stub> stub_;
122 std::unique_ptr<UnimplementedService::Stub> unimplemented_service_stub_;
123 std::shared_ptr<Channel> channel_;
124 bool new_stub_every_call_; // If true, a new stub is returned by every
125 // Get() call
126 };
127
128 bool PerformLargeUnary(SimpleRequest* request, SimpleResponse* response);
129
130 /// Run \a custom_check_fn as an additional check.
131 bool PerformLargeUnary(SimpleRequest* request, SimpleResponse* response,
132 const CheckerFn& custom_checks_fn);
133 bool AssertStatusOk(const Status& s,
134 const std::string& optional_debug_string);
135 bool AssertStatusCode(const Status& s, StatusCode expected_code,
136 const std::string& optional_debug_string);
137 bool TransientFailureOrAbort();
138
139 std::tuple<bool, int32_t, std::string, std::string>
140 PerformOneSoakTestIteration(
141 const bool reset_channel,
142 const int32_t max_acceptable_per_iteration_latency_ms);
143
144 void PerformSoakTest(const bool reset_channel_per_iteration,
145 const int32_t soak_iterations,
146 const int32_t max_failures,
147 const int32_t max_acceptable_per_iteration_latency_ms,
148 const int32_t min_time_ms_between_rpcs,
149 const int32_t overall_timeout_seconds);
150
151 ServiceStub serviceStub_;
152 /// If true, abort() is not called for transient failures
153 bool do_not_abort_on_transient_failures_;
154 };
155
156 } // namespace testing
157 } // namespace grpc
158
159 #endif // GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H