diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/support/log_test.c | 2 | ||||
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 21 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 21 | ||||
-rw-r--r-- | test/cpp/end2end/hybrid_end2end_test.cc | 171 | ||||
-rw-r--r-- | test/cpp/end2end/server_builder_plugin_test.cc | 34 | ||||
-rw-r--r-- | test/cpp/end2end/test_service_impl.cc | 3 | ||||
-rw-r--r-- | test/cpp/end2end/thread_stress_test.cc | 4 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.cc | 5 | ||||
-rw-r--r-- | test/cpp/interop/interop_client.h | 6 | ||||
-rw-r--r-- | test/cpp/qps/client_async.cc | 9 | ||||
-rw-r--r-- | test/cpp/qps/driver.cc | 1 | ||||
-rw-r--r-- | test/cpp/util/metrics_server.cc | 4 | ||||
-rw-r--r-- | test/cpp/util/proto_reflection_descriptor_database.cc | 2 | ||||
-rw-r--r-- | test/cpp/util/test_credentials_provider.cc | 59 |
14 files changed, 187 insertions, 155 deletions
diff --git a/test/core/support/log_test.c b/test/core/support/log_test.c index 0ae298aa4c..807a8175d7 100644 --- a/test/core/support/log_test.c +++ b/test/core/support/log_test.c @@ -78,11 +78,13 @@ int main(int argc, char **argv) { gpr_set_log_function(test_callback); gpr_log_message(GPR_INFO, "hello 1 2 3"); gpr_log(GPR_INFO, "hello %d %d %d", 1, 2, 3); + gpr_set_log_function(NULL); /* gpr_log_verbosity_init() will be effective only once, and only before * gpr_set_log_verbosity() is called */ gpr_setenv("GRPC_VERBOSITY", "ERROR"); gpr_log_verbosity_init(); + test_log_function_reached(GPR_ERROR); test_log_function_unreached(GPR_INFO); test_log_function_unreached(GPR_DEBUG); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 8229bda6bf..6c7eae53a4 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -31,6 +31,7 @@ * */ +#include <cinttypes> #include <memory> #include <thread> @@ -207,12 +208,11 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption { public: void UpdateArguments(ChannelArguments* arg) GRPC_OVERRIDE {} - void UpdatePlugins( - std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>>* plugins) + void UpdatePlugins(std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) GRPC_OVERRIDE { auto plugin = plugins->begin(); while (plugin != plugins->end()) { - if ((*plugin).second->has_sync_methods()) { + if ((*plugin)->has_sync_methods()) { plugins->erase(plugin++); } else { plugin++; @@ -235,8 +235,11 @@ class TestScenario { disable_blocking, credentials_type.c_str(), message_content.size()); } bool disable_blocking; - const grpc::string credentials_type; - const grpc::string message_content; + // Although the below grpc::string's are logically const, we can't declare + // them const because of a limitation in the way old compilers (e.g., gcc-4.4) + // manage vector insertion using a copy constructor + grpc::string credentials_type; + grpc::string message_content; }; class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> { @@ -940,7 +943,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { // Client sends 3 messages (tags 3, 4 and 5) for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { - send_request.set_message("Ping " + std::to_string(tag_idx)); + send_request.set_message("Ping " + grpc::to_string(tag_idx)); cli_stream->Write(send_request, tag(tag_idx)); Verifier(GetParam().disable_blocking) .Expect(tag_idx, true) @@ -1106,7 +1109,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { // Server sends three messages (tags 3, 4 and 5) // But if want_done tag is true, we might also see tag 11 for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { - send_response.set_message("Pong " + std::to_string(tag_idx)); + send_response.set_message("Pong " + grpc::to_string(tag_idx)); srv_stream.Write(send_response, tag(tag_idx)); // Note that we'll add something to the verifier and verify that // something was seen, but it might be tag 11 and not what we @@ -1397,9 +1400,9 @@ std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking, for (auto cred = credentials_types.begin(); cred != credentials_types.end(); ++cred) { for (auto msg = messages.begin(); msg != messages.end(); msg++) { - scenarios.push_back(TestScenario(false, *cred, *msg)); + scenarios.emplace_back(false, *cred, *msg); if (test_disable_blocking) { - scenarios.push_back(TestScenario(true, *cred, *msg)); + scenarios.emplace_back(true, *cred, *msg); } } } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index e3667cf26b..8de9d339f6 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -199,7 +199,10 @@ class TestScenario { credentials_type.c_str()); } bool use_proxy; - const grpc::string credentials_type; + // Although the below grpc::string is logically const, we can't declare + // them const because of a limitation in the way old compilers (e.g., gcc-4.4) + // manage vector insertion using a copy constructor + grpc::string credentials_type; }; class End2endTest : public ::testing::TestWithParam<TestScenario> { @@ -329,7 +332,7 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel value in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); auto stream = stub_->RequestStream(&context, &response); @@ -402,7 +405,7 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); request.set_message("hello"); auto stream = stub_->ResponseStream(&context, request); @@ -413,7 +416,7 @@ class End2endServerTryCancelTest : public End2endTest { break; } EXPECT_EQ(response.message(), - request.message() + std::to_string(num_msgs_read)); + request.message() + grpc::to_string(num_msgs_read)); num_msgs_read++; } gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); @@ -479,14 +482,14 @@ class End2endServerTryCancelTest : public End2endTest { // Send server_try_cancel in the client metadata context.AddMetadata(kServerTryCancelRequest, - std::to_string(server_try_cancel)); + grpc::to_string(server_try_cancel)); auto stream = stub_->BidiStream(&context); int num_msgs_read = 0; int num_msgs_sent = 0; while (num_msgs_sent < num_messages) { - request.set_message("hello " + std::to_string(num_msgs_sent)); + request.set_message("hello " + grpc::to_string(num_msgs_sent)); if (!stream->Write(request)) { break; } @@ -548,7 +551,7 @@ TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) { ClientContext context; context.AddMetadata(kServerTryCancelRequest, - std::to_string(CANCEL_BEFORE_PROCESSING)); + grpc::to_string(CANCEL_BEFORE_PROCESSING)); Status s = stub_->Echo(&context, request, &response); EXPECT_FALSE(s.ok()); EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); @@ -1431,9 +1434,9 @@ std::vector<TestScenario> CreateTestScenarios(bool use_proxy, } for (auto it = credentials_types.begin(); it != credentials_types.end(); ++it) { - scenarios.push_back(TestScenario(false, *it)); + scenarios.emplace_back(false, *it); if (use_proxy) { - scenarios.push_back(TestScenario(true, *it)); + scenarios.emplace_back(true, *it); } } return scenarios; diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 2c05db345b..7e0c0e8a7c 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -347,47 +347,50 @@ class HybridEnd2endTest : public ::testing::Test { } grpc::testing::UnimplementedService::Service unimplemented_service_; - std::vector<std::unique_ptr<ServerCompletionQueue> > cqs_; + std::vector<std::unique_ptr<ServerCompletionQueue>> cqs_; std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; std::unique_ptr<Server> server_; std::ostringstream server_address_; }; TEST_F(HybridEnd2endTest, AsyncEcho) { - EchoTestService::WithAsyncMethod_Echo<TestServiceImpl> service; + typedef EchoTestService::WithAsyncMethod_Echo<TestServiceImpl> SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread echo_handler_thread( - [this, &service] { HandleEcho(&service, cqs_[0].get(), false); }); + std::thread echo_handler_thread(HandleEcho<SType>, &service, cqs_[0].get(), + false); TestAllMethods(); echo_handler_thread.join(); } TEST_F(HybridEnd2endTest, AsyncEchoRequestStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_Echo<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_Echo<TestServiceImpl>> + SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread echo_handler_thread( - [this, &service] { HandleEcho(&service, cqs_[0].get(), false); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread echo_handler_thread(HandleEcho<SType>, &service, cqs_[0].get(), + false); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); TestAllMethods(); echo_handler_thread.join(); request_stream_handler_thread.join(); } TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> + SType; + SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + 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(); response_stream_handler_thread.join(); request_stream_handler_thread.join(); @@ -395,16 +398,17 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream) { // Add a second service with one sync method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> + SType; + SType service; TestServiceImplDupPkg dup_service; SetUpServer(&service, &dup_service, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + 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(); @@ -413,18 +417,20 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { // Add a second service with one async method. TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> + SType; + SType service; duplicate::EchoTestService::AsyncService dup_service; SetUpServer(&service, &dup_service, nullptr); ResetStub(); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[0].get()); }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread response_stream_handler_thread(HandleServerStreaming<SType>, + &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); std::thread echo_handler_thread( - [this, &dup_service] { HandleEcho(&dup_service, cqs_[2].get(), true); }); + HandleEcho<duplicate::EchoTestService::AsyncService>, &dup_service, + cqs_[2].get(), true); TestAllMethods(); SendEchoToDupService(); response_stream_handler_thread.join(); @@ -437,25 +443,24 @@ TEST_F(HybridEnd2endTest, GenericEcho) { AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); TestAllMethods(); generic_handler_thread.join(); } TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo<TestServiceImpl>> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); TestAllMethods(); generic_handler_thread.join(); request_stream_handler_thread.join(); @@ -463,18 +468,18 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { // Add a second service with one sync method. TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_SyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo<TestServiceImpl>> + SType; + SType service; AsyncGenericService generic_service; TestServiceImplDupPkg dup_service; SetUpServer(&service, &dup_service, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); TestAllMethods(); SendEchoToDupService(); generic_handler_thread.join(); @@ -483,20 +488,21 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_SyncDupService) { // Add a second service with one async method. TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_AsyncDupService) { - EchoTestService::WithAsyncMethod_RequestStream< - EchoTestService::WithGenericMethod_Echo<TestServiceImpl> > - service; + typedef EchoTestService::WithAsyncMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo<TestServiceImpl>> + SType; + SType service; AsyncGenericService generic_service; duplicate::EchoTestService::AsyncService dup_service; SetUpServer(&service, &dup_service, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); std::thread echo_handler_thread( - [this, &dup_service] { HandleEcho(&dup_service, cqs_[2].get(), true); }); + HandleEcho<duplicate::EchoTestService::AsyncService>, &dup_service, + cqs_[2].get(), true); TestAllMethods(); SendEchoToDupService(); generic_handler_thread.join(); @@ -505,20 +511,20 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_AsyncDupService) { } TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { - EchoTestService::WithAsyncMethod_RequestStream< + typedef EchoTestService::WithAsyncMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > > - service; + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread request_stream_handler_thread( - [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread(HandleClientStreaming<SType>, + &service, cqs_[1].get()); + std::thread response_stream_handler_thread(HandleServerStreaming<SType>, + &service, cqs_[2].get()); TestAllMethods(); generic_handler_thread.join(); request_stream_handler_thread.join(); @@ -526,21 +532,20 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { } TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { - EchoTestService::WithGenericMethod_RequestStream< + typedef EchoTestService::WithGenericMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > > - service; + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>> + SType; + SType service; AsyncGenericService generic_service; SetUpServer(&service, nullptr, &generic_service); ResetStub(); - std::thread generic_handler_thread([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[0].get()); - }); - std::thread generic_handler_thread2([this, &generic_service] { - HandleGenericCall(&generic_service, cqs_[1].get()); - }); - std::thread response_stream_handler_thread( - [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread generic_handler_thread2(HandleGenericCall, &generic_service, + cqs_[1].get()); + std::thread response_stream_handler_thread(HandleServerStreaming<SType>, + &service, cqs_[2].get()); TestAllMethods(); generic_handler_thread.join(); generic_handler_thread2.join(); @@ -552,7 +557,7 @@ TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { TEST_F(HybridEnd2endTest, GenericMethodWithoutGenericService) { EchoTestService::WithGenericMethod_RequestStream< EchoTestService::WithGenericMethod_Echo< - EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > > + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>> service; SetUpServer(&service, nullptr, nullptr); EXPECT_EQ(nullptr, server_.get()); diff --git a/test/cpp/end2end/server_builder_plugin_test.cc b/test/cpp/end2end/server_builder_plugin_test.cc index 1c1095087a..75f23b64a7 100644 --- a/test/cpp/end2end/server_builder_plugin_test.cc +++ b/test/cpp/end2end/server_builder_plugin_test.cc @@ -113,15 +113,14 @@ class InsertPluginServerBuilderOption : public ServerBuilderOption { void UpdateArguments(ChannelArguments* arg) GRPC_OVERRIDE {} - void UpdatePlugins( - std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>>* plugins) + void UpdatePlugins(std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) GRPC_OVERRIDE { plugins->clear(); std::unique_ptr<TestServerBuilderPlugin> plugin( new TestServerBuilderPlugin()); if (register_service_) plugin->SetRegisterService(); - (*plugins)[plugin->name()] = std::move(plugin); + plugins->emplace_back(std::move(plugin)); } void SetRegisterService() { register_service_ = true; } @@ -162,7 +161,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { void InsertPlugin() { if (GetParam()) { // Add ServerBuilder plugin in static initialization - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); + CheckPresent(); } else { // Add ServerBuilder plugin using ServerBuilder::SetOption() builder_->SetOption(std::unique_ptr<ServerBuilderOption>( @@ -173,10 +172,8 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { void InsertPluginWithTestService() { if (GetParam()) { // Add ServerBuilder plugin in static initialization - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); - auto plugin = static_cast<TestServerBuilderPlugin*>( - builder_->plugins_[PLUGIN_NAME].get()); - EXPECT_TRUE(plugin != nullptr); + auto plugin = CheckPresent(); + EXPECT_TRUE(plugin); plugin->SetRegisterService(); } else { // Add ServerBuilder plugin using ServerBuilder::SetOption() @@ -192,7 +189,7 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { builder_->AddListeningPort(server_address, InsecureServerCredentials()); cq_ = builder_->AddCompletionQueue(); server_ = builder_->BuildAndStart(); - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); + EXPECT_TRUE(CheckPresent()); } void ResetStub() { @@ -202,10 +199,8 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { } void TearDown() GRPC_OVERRIDE { - EXPECT_TRUE(builder_->plugins_[PLUGIN_NAME] != nullptr); - auto plugin = static_cast<TestServerBuilderPlugin*>( - builder_->plugins_[PLUGIN_NAME].get()); - EXPECT_TRUE(plugin != nullptr); + auto plugin = CheckPresent(); + EXPECT_TRUE(plugin); EXPECT_TRUE(plugin->init_server_is_called()); EXPECT_TRUE(plugin->finish_is_called()); server_->Shutdown(); @@ -230,6 +225,19 @@ class ServerBuilderPluginTest : public ::testing::TestWithParam<bool> { std::unique_ptr<Server> server_; TestServiceImpl service_; int port_; + + private: + TestServerBuilderPlugin* CheckPresent() { + auto it = builder_->plugins_.begin(); + for (; it != builder_->plugins_.end(); it++) { + if ((*it)->name() == PLUGIN_NAME) break; + } + if (it != builder_->plugins_.end()) { + return static_cast<TestServerBuilderPlugin*>(it->get()); + } else { + return nullptr; + } + } }; TEST_P(ServerBuilderPluginTest, PluginWithoutServiceTest) { diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc index cbaee92228..52abd80d69 100644 --- a/test/cpp/end2end/test_service_impl.cc +++ b/test/cpp/end2end/test_service_impl.cc @@ -33,6 +33,7 @@ #include "test/cpp/end2end/test_service_impl.h" +#include <string> #include <thread> #include <grpc++/security/credentials.h> @@ -253,7 +254,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context, } for (int i = 0; i < kNumResponseStreamsMsgs; i++) { - response.set_message(request->message() + std::to_string(i)); + response.set_message(request->message() + grpc::to_string(i)); writer->Write(response); } diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 94541f9a45..b021b34523 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -230,7 +230,7 @@ class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> { }; class CommonStressTestAsyncServer - : public CommonStressTest<::grpc::testing::EchoTestService::AsyncService> { + : public CommonStressTest<grpc::testing::EchoTestService::AsyncService> { public: void SetUp() GRPC_OVERRIDE { shutting_down_ = false; @@ -394,7 +394,7 @@ class AsyncClientEnd2endTest : public ::testing::Test { for (int i = 0; i < num_rpcs; ++i) { AsyncClientCall* call = new AsyncClientCall; EchoRequest request; - request.set_message("Hello: " + std::to_string(i)); + request.set_message("Hello: " + grpc::to_string(i)); call->response_reader = common_.GetStub()->AsyncEcho(&call->context, request, &cq_); call->response_reader->Finish(&call->response, &call->status, diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index 0bf1fd6f73..608f902d6f 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -31,10 +31,8 @@ * */ -#include "test/cpp/interop/interop_client.h" - #include <unistd.h> - +#include <cinttypes> #include <fstream> #include <memory> @@ -51,6 +49,7 @@ #include "src/proto/grpc/testing/messages.grpc.pb.h" #include "src/proto/grpc/testing/test.grpc.pb.h" #include "test/cpp/interop/client_helper.h" +#include "test/cpp/interop/interop_client.h" namespace grpc { namespace testing { diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index ae75762bb8..c8d6810c12 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -45,9 +45,9 @@ namespace grpc { namespace testing { // Function pointer for custom checks. -using CheckerFn = - std::function<void(const InteropClientContextInspector&, - const SimpleRequest*, const SimpleResponse*)>; +typedef std::function<void(const InteropClientContextInspector&, + const SimpleRequest*, const SimpleResponse*)> + CheckerFn; class InteropClient { public: diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 6ad4c320b5..3d98ab0939 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -249,7 +249,8 @@ class AsyncUnaryClient GRPC_FINAL : public AsyncClient<BenchmarkService::Stub, SimpleRequest> { public: explicit AsyncUnaryClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, BenchmarkStubCreator) { + : AsyncClient<BenchmarkService::Stub, SimpleRequest>( + config, SetupCtx, BenchmarkStubCreator) { StartThreads(num_async_threads_); } ~AsyncUnaryClient() GRPC_OVERRIDE { EndThreads(); } @@ -376,7 +377,8 @@ class AsyncStreamingClient GRPC_FINAL : public AsyncClient<BenchmarkService::Stub, SimpleRequest> { public: explicit AsyncStreamingClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, BenchmarkStubCreator) { + : AsyncClient<BenchmarkService::Stub, SimpleRequest>( + config, SetupCtx, BenchmarkStubCreator) { StartThreads(num_async_threads_); } @@ -511,7 +513,8 @@ class GenericAsyncStreamingClient GRPC_FINAL : public AsyncClient<grpc::GenericStub, ByteBuffer> { public: explicit GenericAsyncStreamingClient(const ClientConfig& config) - : AsyncClient(config, SetupCtx, GenericStubCreator) { + : AsyncClient<grpc::GenericStub, ByteBuffer>(config, SetupCtx, + GenericStubCreator) { StartThreads(num_async_threads_); } diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 83dbdc3e59..08bf045883 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -31,6 +31,7 @@ * */ +#include <cinttypes> #include <deque> #include <list> #include <thread> diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc index cc6b39b753..1c7cd6382a 100644 --- a/test/cpp/util/metrics_server.cc +++ b/test/cpp/util/metrics_server.cc @@ -99,7 +99,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge( std::lock_guard<std::mutex> lock(mu_); std::shared_ptr<QpsGauge> qps_gauge(new QpsGauge()); - const auto p = qps_gauges_.emplace(name, qps_gauge); + const auto p = qps_gauges_.insert(std::make_pair(name, qps_gauge)); // p.first is an iterator pointing to <name, shared_ptr<QpsGauge>> pair. // p.second is a boolean which is set to 'true' if the QpsGauge is @@ -114,7 +114,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge( std::unique_ptr<grpc::Server> MetricsServiceImpl::StartServer(int port) { gpr_log(GPR_INFO, "Building metrics server.."); - const grpc::string address = "0.0.0.0:" + std::to_string(port); + const grpc::string address = "0.0.0.0:" + grpc::to_string(port); ServerBuilder builder; builder.AddListeningPort(address, grpc::InsecureServerCredentials()); diff --git a/test/cpp/util/proto_reflection_descriptor_database.cc b/test/cpp/util/proto_reflection_descriptor_database.cc index 6907d97bd5..25b720aee0 100644 --- a/test/cpp/util/proto_reflection_descriptor_database.cc +++ b/test/cpp/util/proto_reflection_descriptor_database.cc @@ -298,7 +298,7 @@ void ProtoReflectionDescriptorDatabase::AddFileFromResponse( const std::shared_ptr<ProtoReflectionDescriptorDatabase::ClientStream> ProtoReflectionDescriptorDatabase::GetStream() { - if (stream_ == nullptr) { + if (!stream_) { stream_ = stub_->ServerReflectionInfo(&ctx_); } return stream_; diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 9c09a73115..6e68f59e6a 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -41,15 +41,9 @@ #include "test/core/end2end/data/ssl_test_data.h" +namespace grpc { namespace { -using grpc::ChannelArguments; -using grpc::ChannelCredentials; -using grpc::InsecureChannelCredentials; -using grpc::InsecureServerCredentials; -using grpc::ServerCredentials; -using grpc::SslCredentialsOptions; -using grpc::SslServerCredentialsOptions; using grpc::testing::CredentialTypeProvider; // Provide test credentials. Thread-safe. @@ -69,19 +63,27 @@ class CredentialsProvider { class DefaultCredentialsProvider : public CredentialsProvider { public: - ~DefaultCredentialsProvider() override {} + ~DefaultCredentialsProvider() GRPC_OVERRIDE {} - void AddSecureType( - const grpc::string& type, - std::unique_ptr<CredentialTypeProvider> type_provider) override { + void AddSecureType(const grpc::string& type, + std::unique_ptr<CredentialTypeProvider> type_provider) + GRPC_OVERRIDE { // This clobbers any existing entry for type, except the defaults, which // can't be clobbered. grpc::unique_lock<grpc::mutex> lock(mu_); - added_secure_types_[type] = std::move(type_provider); + auto it = std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type); + if (it == added_secure_type_names_.end()) { + added_secure_type_names_.push_back(type); + added_secure_type_providers_.push_back(std::move(type_provider)); + } else { + added_secure_type_providers_[it - added_secure_type_names_.begin()] = + std::move(type_provider); + } } std::shared_ptr<ChannelCredentials> GetChannelCredentials( - const grpc::string& type, ChannelArguments* args) override { + const grpc::string& type, ChannelArguments* args) GRPC_OVERRIDE { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureChannelCredentials(); } else if (type == grpc::testing::kTlsCredentialsType) { @@ -90,17 +92,19 @@ class DefaultCredentialsProvider : public CredentialsProvider { return SslCredentials(ssl_opts); } else { grpc::unique_lock<grpc::mutex> lock(mu_); - auto it(added_secure_types_.find(type)); - if (it == added_secure_types_.end()) { + auto it(std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type)); + if (it == added_secure_type_names_.end()) { gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); return nullptr; } - return it->second->GetChannelCredentials(args); + return added_secure_type_providers_[it - added_secure_type_names_.begin()] + ->GetChannelCredentials(args); } } std::shared_ptr<ServerCredentials> GetServerCredentials( - const grpc::string& type) override { + const grpc::string& type) GRPC_OVERRIDE { if (type == grpc::testing::kInsecureCredentialsType) { return InsecureServerCredentials(); } else if (type == grpc::testing::kTlsCredentialsType) { @@ -112,28 +116,32 @@ class DefaultCredentialsProvider : public CredentialsProvider { return SslServerCredentials(ssl_opts); } else { grpc::unique_lock<grpc::mutex> lock(mu_); - auto it(added_secure_types_.find(type)); - if (it == added_secure_types_.end()) { + auto it(std::find(added_secure_type_names_.begin(), + added_secure_type_names_.end(), type)); + if (it == added_secure_type_names_.end()) { gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); return nullptr; } - return it->second->GetServerCredentials(); + return added_secure_type_providers_[it - added_secure_type_names_.begin()] + ->GetServerCredentials(); } } - std::vector<grpc::string> GetSecureCredentialsTypeList() override { + std::vector<grpc::string> GetSecureCredentialsTypeList() GRPC_OVERRIDE { std::vector<grpc::string> types; types.push_back(grpc::testing::kTlsCredentialsType); grpc::unique_lock<grpc::mutex> lock(mu_); - for (const auto& type_pair : added_secure_types_) { - types.push_back(type_pair.first); + for (auto it = added_secure_type_names_.begin(); + it != added_secure_type_names_.end(); it++) { + types.push_back(*it); } return types; } private: grpc::mutex mu_; - std::unordered_map<grpc::string, std::unique_ptr<CredentialTypeProvider> > - added_secure_types_; + std::vector<grpc::string> added_secure_type_names_; + std::vector<std::unique_ptr<CredentialTypeProvider>> + added_secure_type_providers_; }; gpr_once g_once_init_provider = GPR_ONCE_INIT; @@ -148,7 +156,6 @@ CredentialsProvider* GetProvider() { } // namespace -namespace grpc { namespace testing { void AddSecureType(const grpc::string& type, |