interop_client.h
Go to the documentation of this file.
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*)>
37 
38 typedef std::function<std::shared_ptr<Channel>(void)> ChannelCreationFunc;
39 
41  public:
46  explicit InteropClient(ChannelCreationFunc channel_creation_func,
47  bool new_stub_every_test_case,
48  bool do_not_abort_on_transient_failures);
50 
51  void Reset(const std::shared_ptr<Channel>& channel);
52 
53  bool DoEmpty();
54  bool DoLargeUnary();
57  bool DoPingPong();
58  bool DoHalfDuplex();
59  bool DoRequestStreaming();
60  bool DoResponseStreaming();
64  bool DoCancelAfterBegin();
67  bool DoEmptyStream();
68  bool DoStatusWithMessage();
69  // Verifies Unicode and Whitespace is correctly processed in status message.
71  bool DoCustomMetadata();
72  bool DoUnimplementedMethod();
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:
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 
129 
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);
138 
139  std::tuple<bool, int32_t, std::string, std::string>
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 
154 };
155 
156 } // namespace testing
157 } // namespace grpc
158 
159 #endif // GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H
messages_pb2.SimpleRequest
SimpleRequest
Definition: messages_pb2.py:597
grpc::testing::InteropClient::Reset
void Reset(const std::shared_ptr< Channel > &channel)
testing
Definition: aws_request_signer_test.cc:25
grpc::testing::InteropClient::DoOauth2AuthToken
bool DoOauth2AuthToken(const std::string &username, const std::string &oauth_scope)
Definition: interop_client.cc:235
grpc::testing::InteropClient::DoEmpty
bool DoEmpty()
Definition: interop_client.cc:159
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::InteropClient::DoCancelAfterFirstResponse
bool DoCancelAfterFirstResponse()
Definition: interop_client.cc:758
grpc::testing::InteropClient::DoServerCompressedUnary
bool DoServerCompressedUnary()
Definition: interop_client.cc:379
grpc::testing::InteropClient::DoResponseStreamingWithSlowConsumer
bool DoResponseStreamingWithSlowConsumer()
Definition: interop_client.cc:601
grpc::testing::InteropClient::DoLongLivedChannelTest
bool DoLongLivedChannelTest(int32_t soak_iterations, int32_t iteration_interval)
Definition: interop_client.cc:1176
grpc::testing::InteropClient::DoUnimplementedMethod
bool DoUnimplementedMethod()
Definition: interop_client.cc:1224
grpc::testing::InteropClient::ServiceStub::stub_
std::unique_ptr< TestService::Stub > stub_
Definition: interop_client.h:121
benchmark.request
request
Definition: benchmark.py:77
grpc::testing::InteropClient::InteropClient
InteropClient(ChannelCreationFunc channel_creation_func, bool new_stub_every_test_case, bool do_not_abort_on_transient_failures)
Definition: interop_client.cc:119
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::InteropClient::DoUnimplementedService
bool DoUnimplementedService()
Definition: interop_client.cc:1204
grpc::testing::InteropClient::DoPingPong
bool DoPingPong()
Definition: interop_client.cc:691
grpc::testing::InteropClient::ServiceStub::new_stub_every_call_
bool new_stub_every_call_
Definition: interop_client.h:124
grpc::testing::InteropClient::DoClientCompressedUnary
bool DoClientCompressedUnary()
Definition: interop_client.cc:333
grpc::testing::InteropClient::do_not_abort_on_transient_failures_
bool do_not_abort_on_transient_failures_
If true, abort() is not called for transient failures.
Definition: interop_client.h:153
grpc::testing::InteropClient::ServiceStub::ResetChannel
void ResetChannel()
Definition: interop_client.cc:112
grpc::testing::InteropClient::DoEmptyStream
bool DoEmptyStream()
Definition: interop_client.cc:817
grpc::testing::InteropClient::ServiceStub::Get
TestService::Stub * Get()
Definition: interop_client.cc:96
grpc::testing::InteropClient::ServiceStub::channel_
std::shared_ptr< Channel > channel_
Definition: interop_client.h:123
grpc::testing::InteropClient::DoCustomMetadata
bool DoCustomMetadata()
Definition: interop_client.cc:933
grpc::testing::InteropClient::DoRpcSoakTest
bool DoRpcSoakTest(int32_t soak_iterations, int32_t max_failures, int64_t max_acceptable_per_iteration_latency_ms, int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds)
Definition: interop_client.cc:1149
grpc::testing::InteropClient::DoGoogleDefaultCredentials
bool DoGoogleDefaultCredentials(const std::string &default_service_account)
Definition: interop_client.cc:303
grpc::testing::InteropClient::TransientFailureOrAbort
bool TransientFailureOrAbort()
Definition: interop_client.cc:406
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
grpc::testing::InteropClient::ServiceStub::ServiceStub
ServiceStub(ChannelCreationFunc channel_creation_func, bool new_stub_every_call)
Definition: interop_client.cc:84
grpc::testing::InteropClient::AssertStatusCode
bool AssertStatusCode(const Status &s, StatusCode expected_code, const std::string &optional_debug_string)
Definition: interop_client.cc:138
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
grpc::testing::InteropClient::DoResponseStreaming
bool DoResponseStreaming()
Definition: interop_client.cc:445
grpc.StatusCode
Definition: src/python/grpcio/grpc/__init__.py:232
grpc::testing::InteropClient::DoLargeUnary
bool DoLargeUnary()
Definition: interop_client.cc:322
grpc::testing::InteropClient::DoHalfDuplex
bool DoHalfDuplex()
Definition: interop_client.cc:644
grpc::testing::InteropClient::DoPerRpcCreds
bool DoPerRpcCreds(const std::string &json_key)
Definition: interop_client.cc:261
grpc.h
grpc::testing::InteropClient::~InteropClient
~InteropClient()
Definition: interop_client.h:49
grpc::testing::InteropClient::ServiceStub::channel_creation_func_
ChannelCreationFunc channel_creation_func_
Definition: interop_client.h:120
grpc::testing::InteropClient::DoCancelAfterBegin
bool DoCancelAfterBegin()
Definition: interop_client.cc:735
channel.h
grpc::testing::InteropClient::ServiceStub::unimplemented_service_stub_
std::unique_ptr< UnimplementedService::Stub > unimplemented_service_stub_
Definition: interop_client.h:122
grpc::testing::InteropClient
Definition: interop_client.h:40
grpc::testing::InteropClient::PerformLargeUnary
bool PerformLargeUnary(SimpleRequest *request, SimpleResponse *response)
Definition: interop_client.cc:176
grpc::testing::InteropClient::DoSpecialStatusMessage
bool DoSpecialStatusMessage()
Definition: interop_client.cc:883
grpc::testing::InteropClient::ServiceStub
Definition: interop_client.h:106
grpc::testing::ChannelCreationFunc
std::function< std::shared_ptr< Channel >void)> ChannelCreationFunc
Definition: interop_client.h:38
grpc::testing::InteropClient::DoServerCompressedStreaming
bool DoServerCompressedStreaming()
Definition: interop_client.cc:544
grpc::testing::InteropClient::AssertStatusOk
bool AssertStatusOk(const Status &s, const std::string &optional_debug_string)
Definition: interop_client.cc:125
grpc::testing::InteropClient::DoRequestStreaming
bool DoRequestStreaming()
Definition: interop_client.cc:414
grpc::testing::InteropClient::PerformSoakTest
void PerformSoakTest(const bool reset_channel_per_iteration, const int32_t soak_iterations, const int32_t max_failures, const int32_t max_acceptable_per_iteration_latency_ms, const int32_t min_time_ms_between_rpcs, const int32_t overall_timeout_seconds)
Definition: interop_client.cc:1058
asyncio_get_stats.response
response
Definition: asyncio_get_stats.py:28
grpc::testing::InteropClient::DoJwtTokenCreds
bool DoJwtTokenCreds(const std::string &username)
Definition: interop_client.cc:286
grpc::testing::InteropClient::DoStatusWithMessage
bool DoStatusWithMessage()
Definition: interop_client.cc:837
grpc::Status
Definition: include/grpcpp/impl/codegen/status.h:35
grpc::testing::InteropClient::serviceStub_
ServiceStub serviceStub_
Definition: interop_client.h:151
grpc::testing::InteropClient::DoComputeEngineCreds
bool DoComputeEngineCreds(const std::string &default_service_account, const std::string &oauth_scope)
Definition: interop_client.cc:210
grpc::testing::InteropClient::DoTimeoutOnSleepingServer
bool DoTimeoutOnSleepingServer()
Definition: interop_client.cc:791
grpc::testing::InteropClient::DoChannelSoakTest
bool DoChannelSoakTest(int32_t soak_iterations, int32_t max_failures, int64_t max_acceptable_per_iteration_latency_ms, int32_t soak_min_time_ms_between_rpcs, int32_t overall_timeout_seconds)
Definition: interop_client.cc:1162
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
messages_pb2.SimpleResponse
SimpleResponse
Definition: messages_pb2.py:604
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
grpc::testing::InteropClient::DoPickFirstUnary
bool DoPickFirstUnary()
Definition: interop_client.cc:907
grpc::testing::InteropClient::PerformOneSoakTestIteration
std::tuple< bool, int32_t, std::string, std::string > PerformOneSoakTestIteration(const bool reset_channel, const int32_t max_acceptable_per_iteration_latency_ms)
Definition: interop_client.cc:1024
grpc::testing::InteropClient::ServiceStub::GetUnimplementedServiceStub
UnimplementedService::Stub * GetUnimplementedServiceStub()
Definition: interop_client.cc:105
grpc::testing::CheckerFn
std::function< void(const InteropClientContextInspector &, const SimpleRequest *, const SimpleResponse *)> CheckerFn
Definition: interop_client.h:36
grpc::testing::InteropClient::DoClientCompressedStreaming
bool DoClientCompressedStreaming()
Definition: interop_client.cc:484


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:21