From 68d615737b5bf968d3fa4bee37125bd81fc4fa1a Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Fri, 24 Apr 2015 14:42:42 -0700 Subject: [PATCH 1/4] Add two scenarios in interop test --- test/cpp/interop/client.cc | 9 ++++++ test/cpp/interop/interop_client.cc | 44 ++++++++++++++++++++++++++++++ test/cpp/interop/interop_client.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 42d16f2f85e..fc59907e754 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -62,6 +62,8 @@ DEFINE_string(test_case, "large_unary", " streaming with slow client consumer; " "half_duplex : half-duplex streaming; " "ping_pong : full-duplex streaming; " + "cancel_after_begin : cancel stream after starting it; " + "cancel_after_first_response: cancel on first response; " "service_account_creds : large_unary with service_account auth; " "compute_engine_creds: large_unary with compute engine auth; " "jwt_token_creds: large_unary with JWT token auth; " @@ -97,6 +99,10 @@ int main(int argc, char** argv) { client.DoHalfDuplex(); } else if (FLAGS_test_case == "ping_pong") { client.DoPingPong(); + } else if (FLAGS_test_case == "cancel_after_begin") { + client.DoCancelAfterBegin(); + } else if (FLAGS_test_case == "cancel_after_first_response") { + client.DoCancelAfterFirstResponse(); } else if (FLAGS_test_case == "service_account_creds") { grpc::string json_key = GetServiceAccountJsonKey(); client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope); @@ -113,6 +119,8 @@ int main(int argc, char** argv) { client.DoResponseStreaming(); client.DoHalfDuplex(); client.DoPingPong(); + client.DoCancelAfterBegin(); + client.DoCancelAfterFirstResponse(); // service_account_creds and jwt_token_creds can only run with ssl. if (FLAGS_enable_ssl) { grpc::string json_key = GetServiceAccountJsonKey(); @@ -125,6 +133,7 @@ int main(int argc, char** argv) { GPR_ERROR, "Unsupported test case %s. Valid options are all|empty_unary|" "large_unary|client_streaming|server_streaming|half_duplex|ping_pong|" + "cancel_after_begin|cancel_after_first_response|" "service_account_creds|compute_engine_creds|jwt_token_creds", FLAGS_test_case.c_str()); ret = 1; diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 7f5757d2ba8..874510e54f7 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -307,5 +307,49 @@ void InteropClient::DoPingPong() { gpr_log(GPR_INFO, "Ping pong streaming done."); } +void InteropClient::DoCancelAfterBegin() { + gpr_log(GPR_INFO, "Sending request steaming rpc ..."); + std::unique_ptr stub(TestService::NewStub(channel_)); + + ClientContext context; + StreamingInputCallRequest request; + StreamingInputCallResponse response; + + std::unique_ptr> stream( + stub->StreamingInputCall(&context, &response)); + + gpr_log(GPR_INFO, "Trying to cancel..."); + context.TryCancel(); + Status s = stream->Finish(); + GPR_ASSERT(s.code() == StatusCode::CANCELLED); + gpr_log(GPR_INFO, "Canceling streaming done."); +} + +void InteropClient::DoCancelAfterFirstResponse() { + gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc ..."); + std::unique_ptr stub(TestService::NewStub(channel_)); + + ClientContext context; + std::unique_ptr> + stream(stub->FullDuplexCall(&context)); + + StreamingOutputCallRequest request; + request.set_response_type(PayloadType::COMPRESSABLE); + ResponseParameters* response_parameter = request.add_response_parameters(); + response_parameter->set_size(31415); + request.mutable_payload()->set_body(grpc::string(27182, '\0')); + StreamingOutputCallResponse response; + GPR_ASSERT(stream->Write(request)); + GPR_ASSERT(stream->Read(&response)); + GPR_ASSERT(response.payload().has_body()); + GPR_ASSERT(response.payload().body() == grpc::string(31415, '\0')); + gpr_log(GPR_INFO, "Trying to cancel..."); + context.TryCancel(); + + Status s = stream->Finish(); + gpr_log(GPR_INFO, "Canceling pingpong streaming done."); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 3161f7f8756..d9c895dfd92 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -57,6 +57,8 @@ class InteropClient { void DoRequestStreaming(); void DoResponseStreaming(); void DoResponseStreamingWithSlowConsumer(); + void DoCancelAfterBegin(); + void DoCancelAfterFirstResponse(); // Auth tests. // username is a string containing the user email void DoJwtTokenCreds(const grpc::string& username); From b11728b90d5c4bbc3cae105b82b10bbf501f323f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 27 Apr 2015 18:27:04 -0700 Subject: [PATCH 2/4] Mac C++ compile fix --- include/grpc++/channel_interface.h | 6 +++++- src/cpp/client/channel.h | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h index 4d48974e691..e86a83bc45b 100644 --- a/include/grpc++/channel_interface.h +++ b/include/grpc++/channel_interface.h @@ -34,6 +34,8 @@ #ifndef GRPCXX_CHANNEL_INTERFACE_H #define GRPCXX_CHANNEL_INTERFACE_H +#include + #include #include @@ -47,7 +49,9 @@ class CompletionQueue; class RpcMethod; class CallInterface; -class ChannelInterface : public CallHook { +class ChannelInterface + : public CallHook, + public std::enable_shared_from_this { public: virtual ~ChannelInterface() {} diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index 46009d20bad..cd239247c82 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -51,7 +51,6 @@ class Credentials; class StreamContextInterface; class Channel GRPC_FINAL : public GrpcLibrary, - public std::enable_shared_from_this, public ChannelInterface { public: Channel(const grpc::string& target, grpc_channel* c_channel); From 75d5d303eaa53f4f561439e9cc93338e849028fe Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 27 Apr 2015 18:29:09 -0700 Subject: [PATCH 3/4] Indentation fix --- include/grpc++/channel_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h index e86a83bc45b..bc738fb15a8 100644 --- a/include/grpc++/channel_interface.h +++ b/include/grpc++/channel_interface.h @@ -50,7 +50,7 @@ class RpcMethod; class CallInterface; class ChannelInterface - : public CallHook, + : public CallHook, public std::enable_shared_from_this { public: virtual ~ChannelInterface() {} From 3691c3322d09b9a7225745695650772981923028 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 28 Apr 2015 08:01:45 -0700 Subject: [PATCH 4/4] clang-format --- include/grpc++/channel_interface.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h index bc738fb15a8..10fb9538bcd 100644 --- a/include/grpc++/channel_interface.h +++ b/include/grpc++/channel_interface.h @@ -49,13 +49,12 @@ class CompletionQueue; class RpcMethod; class CallInterface; -class ChannelInterface - : public CallHook, - public std::enable_shared_from_this { +class ChannelInterface : public CallHook, + public std::enable_shared_from_this { public: virtual ~ChannelInterface() {} - virtual void *RegisterMethod(const char *method_name) = 0; + virtual void* RegisterMethod(const char* method_name) = 0; virtual Call CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) = 0; };