diff options
author | Yuchen Zeng <zyc@google.com> | 2016-09-12 11:11:32 -0700 |
---|---|---|
committer | Yuchen Zeng <zyc@google.com> | 2016-09-12 11:11:32 -0700 |
commit | 3951f2e05b44643b5a55f25b3c9233b60c299e83 (patch) | |
tree | a9a1671edd82586f7e248e425e039cf3cfd47572 /test/cpp | |
parent | 75e3ce645c3fbe315a8384c2cc952467826623e0 (diff) | |
parent | ec5c93cabfbf535be2528df55ca8bb4500e6bc9b (diff) |
Merge remote-tracking branch 'upstream/master' into cli_list
Diffstat (limited to 'test/cpp')
-rw-r--r-- | test/cpp/codegen/compiler_test_golden | 43 | ||||
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 4 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 4 | ||||
-rw-r--r-- | test/cpp/end2end/hybrid_end2end_test.cc | 87 | ||||
-rw-r--r-- | test/cpp/end2end/mock_test.cc | 9 | ||||
-rw-r--r-- | test/cpp/grpclb/grpclb_test.cc | 22 | ||||
-rw-r--r-- | test/cpp/qps/driver.cc | 3 | ||||
-rw-r--r-- | test/cpp/util/grpc_tool.cc | 22 | ||||
-rw-r--r-- | test/cpp/util/grpc_tool.h | 2 | ||||
-rw-r--r-- | test/cpp/util/test_config_cc.cc (renamed from test/cpp/util/test_config.cc) | 0 |
10 files changed, 167 insertions, 29 deletions
diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index ef3d1aaa51..7b0fd6ce80 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -43,6 +43,7 @@ #include <grpc++/impl/codegen/async_stream.h> #include <grpc++/impl/codegen/async_unary_call.h> +#include <grpc++/impl/codegen/method_handler_impl.h> #include <grpc++/impl/codegen/proto_utils.h> #include <grpc++/impl/codegen/rpc_method.h> #include <grpc++/impl/codegen/service_type.h> @@ -206,6 +207,27 @@ class ServiceA GRPC_FINAL { return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } }; + template <class BaseClass> + class WithStreamedUnaryMethod_MethodA1 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithStreamedUnaryMethod_MethodA1() { + ::grpc::Service::MarkMethodStreamedUnary(0, + new ::grpc::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodA1<BaseClass>::StreamedMethodA1, this, std::placeholders::_1, std::placeholders::_2))); + } + ~WithStreamedUnaryMethod_MethodA1() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable regular version of this method + ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + // replace default version of method with streamed unary + virtual ::grpc::Status StreamedMethodA1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0; + }; + typedef WithStreamedUnaryMethod_MethodA1<Service > StreamedUnaryService; }; // ServiceB leading comment 1 @@ -284,6 +306,27 @@ class ServiceB GRPC_FINAL { return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } }; + template <class BaseClass> + class WithStreamedUnaryMethod_MethodB1 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithStreamedUnaryMethod_MethodB1() { + ::grpc::Service::MarkMethodStreamedUnary(0, + new ::grpc::StreamedUnaryHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithStreamedUnaryMethod_MethodB1<BaseClass>::StreamedMethodB1, this, std::placeholders::_1, std::placeholders::_2))); + } + ~WithStreamedUnaryMethod_MethodB1() GRPC_OVERRIDE { + BaseClassMustBeDerivedFromService(this); + } + // disable regular version of this method + ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) GRPC_FINAL GRPC_OVERRIDE { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + // replace default version of method with streamed unary + virtual ::grpc::Status StreamedMethodB1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0; + }; + typedef WithStreamedUnaryMethod_MethodB1<Service > StreamedUnaryService; }; // ServiceB trailing comment 1 diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index ac79fe8274..a9b7c8f8d3 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -897,8 +897,8 @@ TEST_P(AsyncEnd2endTest, UnimplementedRpc) { GetChannelCredentials(GetParam().credentials_type, &args); std::shared_ptr<Channel> channel = CreateCustomChannel(server_address_.str(), channel_creds, args); - std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub; - stub = grpc::testing::UnimplementedService::NewStub(channel); + std::unique_ptr<grpc::testing::UnimplementedEchoService::Stub> stub; + stub = grpc::testing::UnimplementedEchoService::NewStub(channel); EchoRequest send_request; EchoResponse recv_response; Status recv_status; diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 46a58d3ac3..55d045a298 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -967,8 +967,8 @@ TEST_P(End2endTest, ChannelStateTimeout) { // Talking to a non-existing service. TEST_P(End2endTest, NonExistingService) { ResetChannel(); - std::unique_ptr<grpc::testing::UnimplementedService::Stub> stub; - stub = grpc::testing::UnimplementedService::NewStub(channel_); + std::unique_ptr<grpc::testing::UnimplementedEchoService::Stub> stub; + stub = grpc::testing::UnimplementedEchoService::NewStub(channel_); EchoRequest request; EchoResponse response; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 7e0c0e8a7c..82361d0e90 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -199,7 +199,8 @@ class HybridEnd2endTest : public ::testing::Test { HybridEnd2endTest() {} void SetUpServer(::grpc::Service* service1, ::grpc::Service* service2, - AsyncGenericService* generic_service) { + AsyncGenericService* generic_service, + int max_message_size = 0) { int port = grpc_pick_unused_port_or_die(); server_address_ << "localhost:" << port; @@ -217,6 +218,11 @@ class HybridEnd2endTest : public ::testing::Test { if (generic_service) { builder.RegisterAsyncGenericService(generic_service); } + + if (max_message_size != 0) { + builder.SetMaxMessageSize(max_message_size); + } + // Create a separate cq for each potential handler. for (int i = 0; i < 5; i++) { cqs_.push_back(builder.AddCompletionQueue(false)); @@ -346,7 +352,7 @@ class HybridEnd2endTest : public ::testing::Test { EXPECT_TRUE(s.ok()); } - grpc::testing::UnimplementedService::Service unimplemented_service_; + grpc::testing::UnimplementedEchoService::Service unimplemented_service_; std::vector<std::unique_ptr<ServerCompletionQueue>> cqs_; std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; std::unique_ptr<Server> server_; @@ -415,6 +421,83 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { request_stream_handler_thread.join(); } +// Add a second service with one sync streamed unary method. +class StreamedUnaryDupPkg + : public duplicate::EchoTestService::WithStreamedUnaryMethod_Echo< + TestServiceImplDupPkg> { + public: + Status StreamedEcho(ServerContext* context, + ServerUnaryStreamer<EchoRequest, EchoResponse>* stream) + GRPC_OVERRIDE { + EchoRequest req; + EchoResponse resp; + uint32_t next_msg_sz; + stream->NextMessageSize(&next_msg_sz); + gpr_log(GPR_INFO, "Streamed Unary Next Message Size is %u", next_msg_sz); + GPR_ASSERT(stream->Read(&req)); + resp.set_message(req.message() + "_dup"); + GPR_ASSERT(stream->Write(resp)); + return Status::OK; + } +}; + +TEST_F(HybridEnd2endTest, + AsyncRequestStreamResponseStream_SyncStreamedUnaryDupService) { + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> + SType; + SType service; + StreamedUnaryDupPkg dup_service; + SetUpServer(&service, &dup_service, nullptr, 8192); + ResetStub(); + std::thread response_stream_handler_thread(HandleServerStreaming<SType>, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); + TestAllMethods(); + SendEchoToDupService(); + response_stream_handler_thread.join(); + request_stream_handler_thread.join(); +} + +// Add a second service that is fully Streamed Unary +class FullyStreamedUnaryDupPkg + : public duplicate::EchoTestService::StreamedUnaryService { + public: + Status StreamedEcho(ServerContext* context, + ServerUnaryStreamer<EchoRequest, EchoResponse>* stream) + GRPC_OVERRIDE { + EchoRequest req; + EchoResponse resp; + uint32_t next_msg_sz; + stream->NextMessageSize(&next_msg_sz); + gpr_log(GPR_INFO, "Streamed Unary Next Message Size is %u", next_msg_sz); + GPR_ASSERT(stream->Read(&req)); + resp.set_message(req.message() + "_dup"); + GPR_ASSERT(stream->Write(resp)); + return Status::OK; + } +}; + +TEST_F(HybridEnd2endTest, + AsyncRequestStreamResponseStream_SyncFullyStreamedUnaryDupService) { + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> + SType; + SType service; + FullyStreamedUnaryDupPkg dup_service; + SetUpServer(&service, &dup_service, nullptr, 8192); + ResetStub(); + std::thread response_stream_handler_thread(HandleServerStreaming<SType>, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); + TestAllMethods(); + SendEchoToDupService(); + response_stream_handler_thread.join(); + request_stream_handler_thread.join(); +} + // Add a second service with one async method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { typedef EchoTestService::WithAsyncMethod_RequestStream< diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 0ace5d9418..4052627122 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -31,6 +31,7 @@ * */ +#include <climits> #include <thread> #include <grpc++/channel.h> @@ -63,6 +64,10 @@ class MockClientReaderWriter GRPC_FINAL : public ClientReaderWriterInterface<W, R> { public: void WaitForInitialMetadata() GRPC_OVERRIDE {} + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + *sz = UINT_MAX; + return true; + } bool Read(R* msg) GRPC_OVERRIDE { return true; } bool Write(const W& msg) GRPC_OVERRIDE { return true; } bool WritesDone() GRPC_OVERRIDE { return true; } @@ -74,6 +79,10 @@ class MockClientReaderWriter<EchoRequest, EchoResponse> GRPC_FINAL public: MockClientReaderWriter() : writes_done_(false) {} void WaitForInitialMetadata() GRPC_OVERRIDE {} + bool NextMessageSize(uint32_t* sz) GRPC_OVERRIDE { + *sz = UINT_MAX; + return true; + } bool Read(EchoResponse* msg) GRPC_OVERRIDE { if (writes_done_) return false; msg->set_message(last_message_); diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index b2fdce2963..6f6fb83c23 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -37,7 +37,6 @@ #include <cstring> #include <string> -extern "C" { #include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/host_port.h> @@ -47,6 +46,7 @@ extern "C" { #include <grpc/support/thd.h> #include <grpc/support/time.h> +extern "C" { #include "src/core/ext/client_config/client_channel.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/support/string.h" @@ -177,7 +177,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, tag(200)); GPR_ASSERT(GRPC_CALL_OK == error); gpr_log(GPR_INFO, "LB Server[%s] up", sf->servers_hostport); - cq_expect_completion(cqv, tag(200), 1); + CQ_EXPECT_COMPLETION(cqv, tag(200), 1); cq_verify(cqv); gpr_log(GPR_INFO, "LB Server[%s] after tag 200", sf->servers_hostport); @@ -205,7 +205,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, op++; error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(202), NULL); GPR_ASSERT(GRPC_CALL_OK == error); - cq_expect_completion(cqv, tag(202), 1); + CQ_EXPECT_COMPLETION(cqv, tag(202), 1); cq_verify(cqv); gpr_log(GPR_INFO, "LB Server[%s] after RECV_MSG", sf->servers_hostport); // TODO(dgq): validate request. @@ -233,7 +233,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, op++; error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(203), NULL); GPR_ASSERT(GRPC_CALL_OK == error); - cq_expect_completion(cqv, tag(203), 1); + CQ_EXPECT_COMPLETION(cqv, tag(203), 1); cq_verify(cqv); gpr_log(GPR_INFO, "LB Server[%s] after SEND_MESSAGE, iter %d", sf->servers_hostport, i); @@ -254,8 +254,8 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(204), NULL); GPR_ASSERT(GRPC_CALL_OK == error); - cq_expect_completion(cqv, tag(201), 1); - cq_expect_completion(cqv, tag(204), 1); + CQ_EXPECT_COMPLETION(cqv, tag(201), 1); + CQ_EXPECT_COMPLETION(cqv, tag(204), 1); cq_verify(cqv); gpr_log(GPR_INFO, "LB Server[%s] after tag 204. All done. LB server out", sf->servers_hostport); @@ -394,8 +394,8 @@ static void start_backend_server(server_fixture *sf) { error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); GPR_ASSERT(GRPC_CALL_OK == error); - cq_expect_completion(cqv, tag(101), 1); - cq_expect_completion(cqv, tag(104), 1); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + CQ_EXPECT_COMPLETION(cqv, tag(104), 1); cq_verify(cqv); gpr_log(GPR_INFO, "Server[%s] DONE. After servicing %d calls", sf->servers_hostport, sf->num_calls_serviced); @@ -475,7 +475,7 @@ static void perform_request(client_fixture *cf) { GPR_ASSERT(GRPC_CALL_OK == error); peer = grpc_call_get_peer(c); - cq_expect_completion(cqv, tag(2), 1); + CQ_EXPECT_COMPLETION(cqv, tag(2), 1); cq_verify(cqv); gpr_free(peer); @@ -493,8 +493,8 @@ static void perform_request(client_fixture *cf) { error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); - cq_expect_completion(cqv, tag(1), 1); - cq_expect_completion(cqv, tag(3), 1); + CQ_EXPECT_COMPLETION(cqv, tag(1), 1); + CQ_EXPECT_COMPLETION(cqv, tag(3), 1); cq_verify(cqv); peer = grpc_call_get_peer(c); gpr_log(GPR_INFO, "Client DONE WITH SERVER %s ", peer); diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 93f9271553..f67f353c4d 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -186,6 +186,9 @@ std::unique_ptr<ScenarioResult> RunScenario( const ClientConfig& initial_client_config, size_t num_clients, const ServerConfig& initial_server_config, size_t num_servers, int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count) { + // Log everything from the driver + gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); + // ClientContext allocations (all are destroyed at scope exit) list<ClientContext> contexts; diff --git a/test/cpp/util/grpc_tool.cc b/test/cpp/util/grpc_tool.cc index 22155cb5ea..bc81f870d2 100644 --- a/test/cpp/util/grpc_tool.cc +++ b/test/cpp/util/grpc_tool.cc @@ -62,7 +62,7 @@ DEFINE_bool(remotedb, true, "Use server types to parse and format messages"); DEFINE_string(metadata, "", "Metadata to send to server, in the form of key1:val1:key2:val2"); DEFINE_string(proto_path, ".", "Path to look for the proto file."); -DEFINE_string(proto_file, "", "Name of the proto file."); +DEFINE_string(protofiles, "", "Name of the proto file."); DEFINE_bool(binary_input, false, "Input in binary format"); DEFINE_bool(binary_output, false, "Output in binary format"); DEFINE_string(infile, "", "Input file (default is stdin)"); @@ -74,9 +74,9 @@ class GrpcTool { explicit GrpcTool(); virtual ~GrpcTool() {} - bool Help(int argc, const char** argv, CliCredentials cred, + bool Help(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback); - bool CallMethod(int argc, const char** argv, CliCredentials cred, + bool CallMethod(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback); bool ListServices(int argc, const char** argv, CliCredentials cred, GrpcToolOutputCallback callback); @@ -104,7 +104,7 @@ class GrpcTool { }; template <typename T> -std::function<bool(GrpcTool*, int, const char**, const CliCredentials, +std::function<bool(GrpcTool*, int, const char**, const CliCredentials&, GrpcToolOutputCallback)> BindWith5Args(T&& func) { return std::bind(std::forward<T>(func), std::placeholders::_1, @@ -159,7 +159,7 @@ void PrintMetadata(const T& m, const grpc::string& message) { struct Command { const char* command; - std::function<bool(GrpcTool*, int, const char**, const CliCredentials, + std::function<bool(GrpcTool*, int, const char**, const CliCredentials&, GrpcToolOutputCallback)> function; int min_args; @@ -204,7 +204,7 @@ const Command* FindCommand(const grpc::string& name) { } } // namespace -int GrpcToolMainLib(int argc, const char** argv, const CliCredentials cred, +int GrpcToolMainLib(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback) { if (argc < 2) { Usage("No command specified"); @@ -241,7 +241,7 @@ void GrpcTool::CommandUsage(const grpc::string& usage) const { } } -bool GrpcTool::Help(int argc, const char** argv, const CliCredentials cred, +bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred, GrpcToolOutputCallback callback) { CommandUsage( "Print help\n" @@ -361,7 +361,7 @@ bool GrpcTool::ListServices(int argc, const char** argv, } bool GrpcTool::CallMethod(int argc, const char** argv, - const CliCredentials cred, + const CliCredentials& cred, GrpcToolOutputCallback callback) { CommandUsage( "Call method\n" @@ -370,10 +370,10 @@ bool GrpcTool::CallMethod(int argc, const char** argv, " <service> ; Exported service name\n" " <method> ; Method name\n" " <request> ; Text protobuffer (overrides infile)\n" - " --proto_file ; Comma separated proto files used as a" + " --protofiles ; Comma separated proto files used as a" " fallback when parsing request/response\n" " --proto_path ; The search path of proto files, valid" - " only when --proto_file is given\n" + " only when --protofiles is given\n" " --metadata ; The metadata to be sent to the server\n" " --infile ; Input filename (defaults to stdin)\n" " --outfile ; Output filename (defaults to stdout)\n" @@ -413,7 +413,7 @@ bool GrpcTool::CallMethod(int argc, const char** argv, if (!FLAGS_binary_input || !FLAGS_binary_output) { parser.reset( new grpc::testing::ProtoFileParser(FLAGS_remotedb ? channel : nullptr, - FLAGS_proto_path, FLAGS_proto_file)); + FLAGS_proto_path, FLAGS_protofiles)); if (parser->HasError()) { return false; } diff --git a/test/cpp/util/grpc_tool.h b/test/cpp/util/grpc_tool.h index 3da86937c2..df3680258b 100644 --- a/test/cpp/util/grpc_tool.h +++ b/test/cpp/util/grpc_tool.h @@ -45,7 +45,7 @@ namespace testing { typedef std::function<bool(const grpc::string &)> GrpcToolOutputCallback; -int GrpcToolMainLib(int argc, const char **argv, CliCredentials cred, +int GrpcToolMainLib(int argc, const char **argv, const CliCredentials &cred, GrpcToolOutputCallback callback); } // namespace testing diff --git a/test/cpp/util/test_config.cc b/test/cpp/util/test_config_cc.cc index 8711746129..8711746129 100644 --- a/test/cpp/util/test_config.cc +++ b/test/cpp/util/test_config_cc.cc |