From 8d9f83016863a4d1b27e21fc372f7df02dbc6537 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 13 Jul 2015 16:18:19 -0700 Subject: [PATCH 1/3] Introduced InteropContextInspector to be able to peek into server contexts during interop testing. --- include/grpc++/server_context.h | 5 +++++ test/cpp/interop/server_helper.cc | 4 ++++ test/cpp/interop/server_helper.h | 11 +++++++++++ 3 files changed, 20 insertions(+) diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index a4ee986df17..e6440c7fd81 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -76,6 +76,10 @@ class CallOpBuffer; class CompletionQueue; class Server; +namespace testing { +class InteropContextInspector; +} // namespace testing + // Interface of server side rpc context. class ServerContext { public: @@ -104,6 +108,7 @@ class ServerContext { } private: + friend class ::grpc::testing::InteropContextInspector; friend class ::grpc::Server; template friend class ::grpc::ServerAsyncReader; diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index c2e750dcf77..0f8b89ced2f 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -58,5 +58,9 @@ std::shared_ptr CreateInteropServerCredentials() { } } +InteropContextInspector::InteropContextInspector( + const ::grpc::ServerContext& context) + : context_(context) {} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index f98e67bb673..52332bf6336 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -36,6 +36,7 @@ #include +#include #include namespace grpc { @@ -43,6 +44,16 @@ namespace testing { std::shared_ptr CreateInteropServerCredentials(); +class InteropContextInspector { + public: + InteropContextInspector (const ::grpc::ServerContext& context); + + // Inspector methods, able to peek inside ServerContext go here. + + private: + const ::grpc::ServerContext& context_; +}; + } // namespace testing } // namespace grpc From e4109866359b711bd618b2890c7696f59a2b813c Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 15 Jul 2015 14:10:48 -0700 Subject: [PATCH 2/3] clang-format'd. --- test/cpp/interop/server_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index 52332bf6336..d738d05038c 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -46,7 +46,7 @@ std::shared_ptr CreateInteropServerCredentials(); class InteropContextInspector { public: - InteropContextInspector (const ::grpc::ServerContext& context); + InteropContextInspector(const ::grpc::ServerContext& context); // Inspector methods, able to peek inside ServerContext go here. From 6dd49a5c8f64369ebc269fdc41a97c4a27f160f5 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 15 Jul 2015 14:58:32 -0700 Subject: [PATCH 3/3] Added some methods to context inspector. Also minor tweak to server context IsCancelled() method --- include/grpc++/server_context.h | 2 +- src/cpp/server/server_context.cc | 2 +- test/cpp/interop/server_helper.cc | 9 +++++++++ test/cpp/interop/server_helper.h | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index e6440c7fd81..830b6b0b6ff 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -97,7 +97,7 @@ class ServerContext { void AddInitialMetadata(const grpc::string& key, const grpc::string& value); void AddTrailingMetadata(const grpc::string& key, const grpc::string& value); - bool IsCancelled(); + bool IsCancelled() const; const std::multimap& client_metadata() { return client_metadata_; diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 1bb3a8bcc4c..908c065ae69 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -144,7 +144,7 @@ void ServerContext::AddTrailingMetadata(const grpc::string& key, trailing_metadata_.insert(std::make_pair(key, value)); } -bool ServerContext::IsCancelled() { +bool ServerContext::IsCancelled() const { return completion_op_ && completion_op_->CheckCancelled(cq_); } diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc index 0f8b89ced2f..30a78ffddf9 100644 --- a/test/cpp/interop/server_helper.cc +++ b/test/cpp/interop/server_helper.cc @@ -62,5 +62,14 @@ InteropContextInspector::InteropContextInspector( const ::grpc::ServerContext& context) : context_(context) {} +std::shared_ptr InteropContextInspector::GetAuthContext() + const { + return context_.auth_context(); +} + +bool InteropContextInspector::IsCancelled() const { + return context_.IsCancelled(); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h index d738d05038c..ce977b47058 100644 --- a/test/cpp/interop/server_helper.h +++ b/test/cpp/interop/server_helper.h @@ -48,7 +48,9 @@ class InteropContextInspector { public: InteropContextInspector(const ::grpc::ServerContext& context); - // Inspector methods, able to peek inside ServerContext go here. + // Inspector methods, able to peek inside ServerContext, follow. + std::shared_ptr GetAuthContext() const; + bool IsCancelled() const; private: const ::grpc::ServerContext& context_;