Provide a way to run C++ interop server with custom ServerBuilderOptions

pull/15270/head
Alexander Polcyn 7 years ago
parent 2d894a8c3b
commit 11c1739a10
  1. 22
      test/cpp/interop/interop_server.cc
  2. 24
      test/cpp/interop/server_helper.h

@ -318,12 +318,27 @@ class TestServiceImpl : public TestService::Service {
void grpc::testing::interop::RunServer(
std::shared_ptr<ServerCredentials> creds) {
RunServer(creds, FLAGS_port, nullptr);
RunServer(creds, FLAGS_port, nullptr, nullptr);
}
void grpc::testing::interop::RunServer(
std::shared_ptr<ServerCredentials> creds,
std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
server_options) {
RunServer(creds, FLAGS_port, nullptr, std::move(server_options));
}
void grpc::testing::interop::RunServer(
std::shared_ptr<ServerCredentials> creds, const int port,
ServerStartedCondition* server_started_condition) {
RunServer(creds, FLAGS_port, server_started_condition, nullptr);
}
void grpc::testing::interop::RunServer(
std::shared_ptr<ServerCredentials> creds, const int port,
ServerStartedCondition* server_started_condition,
std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
server_options) {
GPR_ASSERT(port != 0);
std::ostringstream server_address;
server_address << "0.0.0.0:" << port;
@ -335,6 +350,11 @@ void grpc::testing::interop::RunServer(
ServerBuilder builder;
builder.RegisterService(&service);
builder.AddListeningPort(server_address.str(), creds);
if (server_options != nullptr) {
for (size_t i = 0; i < server_options->size(); i++) {
builder.SetOption(std::move((*server_options)[i]));
}
}
if (FLAGS_max_send_message_size >= 0) {
builder.SetMaxSendMessageSize(FLAGS_max_send_message_size);
}

@ -26,6 +26,8 @@
#include <grpc/impl/codegen/atm.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>
namespace grpc {
@ -72,6 +74,28 @@ void RunServer(std::shared_ptr<ServerCredentials> creds);
void RunServer(std::shared_ptr<ServerCredentials> creds, int port,
ServerStartedCondition* server_started_condition);
/// Run gRPC interop server.
///
/// \param creds The credentials associated with the server.
/// \param server_options List of options to set when building the server.
void RunServer(
std::shared_ptr<ServerCredentials> creds,
std::unique_ptr<std::vector<std::unique_ptr<ServerBuilderOption>>>
server_options);
/// Run gRPC interop server.
///
/// \param creds The credentials associated with the server.
/// \param port Port to use for the server.
/// \param server_options List of options to set when building the server.
/// \param server_started_condition (optional) Struct holding mutex, condition
// variable, and condition used to notify when the server has started.
void RunServer(
std::shared_ptr<ServerCredentials> creds, const int port,
ServerStartedCondition* server_started_condition,
std::unique_ptr<std::vector<std::unique_ptr<grpc::ServerBuilderOption>>>
server_options);
} // namespace interop
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save