client_helper.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_CLIENT_HELPER_H
20 #define GRPC_TEST_CPP_INTEROP_CLIENT_HELPER_H
21 
22 #include <functional>
23 #include <memory>
24 #include <unordered_map>
25 
26 #include <grpcpp/channel.h>
27 #include <grpcpp/client_context.h>
28 
31 
32 namespace grpc {
33 namespace testing {
34 
36 
38 
39 void UpdateActions(
40  std::unordered_map<std::string, std::function<bool()>>* actions);
41 
42 std::shared_ptr<Channel> CreateChannelForTestCase(
43  const std::string& test_case,
44  std::vector<
45  std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
46  interceptor_creators = {});
47 
49  public:
51  : context_(context) {}
52 
53  // Inspector methods, able to peek inside ClientContext, follow.
56  }
57 
58  bool WasCompressed() const {
63  }
64 
65  private:
67 };
68 
70  public:
72  std::multimap<std::string, std::string> additional_metadata)
73  : additional_metadata_(std::move(additional_metadata)) {}
74 
76  if (methods->QueryInterceptionHookPoint(
78  std::multimap<std::string, std::string>* metadata =
79  methods->GetSendInitialMetadata();
80  for (const auto& entry : additional_metadata_) {
81  metadata->insert(entry);
82  }
83  }
84  methods->Proceed();
85  }
86 
87  private:
88  const std::multimap<std::string, std::string> additional_metadata_;
89 };
90 
93  public:
95  std::multimap<std::string, std::string> additional_metadata)
96  : additional_metadata_(std::move(additional_metadata)) {}
97 
99  experimental::ClientRpcInfo* /*info*/) override {
101  }
102 
103  const std::multimap<std::string, std::string> additional_metadata_;
104 };
105 
107  public:
109 
110  void Intercept(experimental::InterceptorBatchMethods* methods) override;
111 };
112 
115  public:
117 
119  experimental::ClientRpcInfo* /*info*/) override {
121  }
122 };
123 
124 } // namespace testing
125 } // namespace grpc
126 
127 #endif // GRPC_TEST_CPP_INTEROP_CLIENT_HELPER_H
grpc::testing::AdditionalMetadataInterceptorFactory::CreateClientInterceptor
experimental::Interceptor * CreateClientInterceptor(experimental::ClientRpcInfo *) override
Definition: client_helper.h:98
grpc::testing::AdditionalMetadataInterceptorFactory::AdditionalMetadataInterceptorFactory
AdditionalMetadataInterceptorFactory(std::multimap< std::string, std::string > additional_metadata)
Definition: client_helper.h:94
testing
Definition: aws_request_signer_test.cc:25
metadata
Definition: cq_verifier.cc:48
grpc::experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA
@ PRE_SEND_INITIAL_METADATA
The first three in this list are for clients and servers.
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::InteropClientContextInspector::context_
const grpc::ClientContext & context_
Definition: client_helper.h:66
grpc::testing::MetadataAndStatusLoggerInterceptorFactory::CreateClientInterceptor
experimental::Interceptor * CreateClientInterceptor(experimental::ClientRpcInfo *) override
Definition: client_helper.h:118
grpc_compression_algorithm
grpc_compression_algorithm
Definition: compression_types.h:60
call_test_only.h
grpc::experimental::ClientInterceptorFactoryInterface
Definition: impl/codegen/client_interceptor.h:48
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::AdditionalMetadataInterceptor::Intercept
void Intercept(experimental::InterceptorBatchMethods *methods) override
Definition: client_helper.h:75
grpc::testing::InteropClientContextInspector
Definition: client_helper.h:48
grpc::experimental::InterceptorBatchMethods::QueryInterceptionHookPoint
virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type)=0
grpc::testing::GetOauth2AccessToken
std::string GetOauth2AccessToken()
Definition: client_helper.cc:68
grpc::experimental::ClientRpcInfo
Definition: impl/codegen/client_interceptor.h:68
grpc::testing::InteropClientContextInspector::GetCallCompressionAlgorithm
grpc_compression_algorithm GetCallCompressionAlgorithm() const
Definition: client_helper.h:54
grpc::testing::UpdateActions
void UpdateActions(std::unordered_map< std::string, std::function< bool()>> *)
Definition: client_helper.cc:82
grpc::testing::AdditionalMetadataInterceptor::additional_metadata_
const std::multimap< std::string, std::string > additional_metadata_
Definition: client_helper.h:88
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_call_test_only_get_compression_algorithm
grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm(grpc_call *call)
Definition: call.cc:1810
grpc::testing::MetadataAndStatusLoggerInterceptorFactory::MetadataAndStatusLoggerInterceptorFactory
MetadataAndStatusLoggerInterceptorFactory()
Definition: client_helper.h:116
channel.h
grpc::testing::MetadataAndStatusLoggerInterceptor::MetadataAndStatusLoggerInterceptor
MetadataAndStatusLoggerInterceptor()
Definition: client_helper.h:108
grpc::testing::InteropClientContextInspector::InteropClientContextInspector
InteropClientContextInspector(const grpc::ClientContext &context)
Definition: client_helper.h:50
grpc::testing::GetServiceAccountJsonKey
std::string GetServiceAccountJsonKey()
Definition: client_helper.cc:57
grpc_call_test_only_get_message_flags
uint32_t grpc_call_test_only_get_message_flags(grpc_call *call)
Definition: call.cc:1815
grpc::testing::AdditionalMetadataInterceptorFactory::additional_metadata_
const std::multimap< std::string, std::string > additional_metadata_
Definition: client_helper.h:103
grpc::testing::InteropClientContextInspector::WasCompressed
bool WasCompressed() const
Definition: client_helper.h:58
grpc::experimental::InterceptorBatchMethods
Definition: impl/codegen/interceptor.h:98
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
grpc::testing::MetadataAndStatusLoggerInterceptor::Intercept
void Intercept(experimental::InterceptorBatchMethods *methods) override
Definition: client_helper.cc:159
grpc::experimental::InterceptorBatchMethods::GetSendInitialMetadata
virtual std::multimap< std::string, std::string > * GetSendInitialMetadata()=0
client_context.h
GRPC_WRITE_INTERNAL_COMPRESS
#define GRPC_WRITE_INTERNAL_COMPRESS
Definition: transport.h:75
grpc::ClientContext::call_
grpc_call * call_
Definition: grpcpp/impl/codegen/client_context.h:495
grpc::testing::MetadataAndStatusLoggerInterceptor
Definition: client_helper.h:106
GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED
#define GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED
Definition: transport.h:79
grpc::testing::CreateChannelForTestCase
std::shared_ptr< Channel > CreateChannelForTestCase(const std::string &test_case, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
Definition: client_helper.cc:85
grpc::testing::AdditionalMetadataInterceptor
Definition: client_helper.h:69
grpc::experimental::Interceptor
Definition: impl/codegen/interceptor.h:221
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
grpc::testing::AdditionalMetadataInterceptor::AdditionalMetadataInterceptor
AdditionalMetadataInterceptor(std::multimap< std::string, std::string > additional_metadata)
Definition: client_helper.h:71
transport.h
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
grpc::experimental::InterceptorBatchMethods::Proceed
virtual void Proceed()=0
grpc::testing::MetadataAndStatusLoggerInterceptorFactory
Definition: client_helper.h:113
grpc::testing::AdditionalMetadataInterceptorFactory
Definition: client_helper.h:91


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:47