Deal with to_string, proper usage of nullptr, and lack of map::emplace

pull/6863/head
Vijay Pai 9 years ago
parent 12bf3801b8
commit a63271c77f
  1. 12
      include/grpc++/impl/codegen/config.h
  2. 4
      test/cpp/end2end/async_end2end_test.cc
  3. 12
      test/cpp/end2end/end2end_test.cc
  4. 3
      test/cpp/end2end/test_service_impl.cc
  5. 4
      test/cpp/end2end/thread_stress_test.cc
  6. 4
      test/cpp/util/metrics_server.cc
  7. 9
      test/cpp/util/test_credentials_provider.cc

@ -54,6 +54,7 @@
// nullptr was added in gcc 4.6 // nullptr was added in gcc 4.6
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 406) #if (__GNUC__ * 100 + __GNUC_MINOR__ < 406)
#define GRPC_CXX0X_NO_NULLPTR 1 #define GRPC_CXX0X_NO_NULLPTR 1
#define GRPC_CXX0X_LIMITED_TOSTRING 1
#endif #endif
// final and override were added in gcc 4.7 // final and override were added in gcc 4.7
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 407) #if (__GNUC__ * 100 + __GNUC_MINOR__ < 407)
@ -116,6 +117,17 @@ namespace grpc {
typedef GRPC_CUSTOM_STRING string; typedef GRPC_CUSTOM_STRING string;
#ifdef GRPC_CXX0X_LIMITED_TOSTRING
inline grpc::string to_string(const int x) {
return std::to_string(static_cast<const long long int>(x));
}
inline grpc::string to_string(const unsigned int x) {
return std::to_string(static_cast<const long long unsigned int>(x));
}
#else
using std::to_string;
#endif
} // namespace grpc } // namespace grpc
#endif // GRPCXX_IMPL_CODEGEN_CONFIG_H #endif // GRPCXX_IMPL_CODEGEN_CONFIG_H

@ -938,7 +938,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
// Client sends 3 messages (tags 3, 4 and 5) // Client sends 3 messages (tags 3, 4 and 5)
for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { 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)); cli_stream->Write(send_request, tag(tag_idx));
Verifier(GetParam().disable_blocking) Verifier(GetParam().disable_blocking)
.Expect(tag_idx, true) .Expect(tag_idx, true)
@ -1104,7 +1104,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
// Server sends three messages (tags 3, 4 and 5) // Server sends three messages (tags 3, 4 and 5)
// But if want_done tag is true, we might also see tag 11 // But if want_done tag is true, we might also see tag 11
for (int tag_idx = 3; tag_idx <= 5; tag_idx++) { 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)); srv_stream.Write(send_response, tag(tag_idx));
// Note that we'll add something to the verifier and verify that // 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 // something was seen, but it might be tag 11 and not what we

@ -329,7 +329,7 @@ class End2endServerTryCancelTest : public End2endTest {
// Send server_try_cancel value in the client metadata // Send server_try_cancel value in the client metadata
context.AddMetadata(kServerTryCancelRequest, context.AddMetadata(kServerTryCancelRequest,
std::to_string(server_try_cancel)); grpc::to_string(server_try_cancel));
auto stream = stub_->RequestStream(&context, &response); auto stream = stub_->RequestStream(&context, &response);
@ -402,7 +402,7 @@ class End2endServerTryCancelTest : public End2endTest {
// Send server_try_cancel in the client metadata // Send server_try_cancel in the client metadata
context.AddMetadata(kServerTryCancelRequest, context.AddMetadata(kServerTryCancelRequest,
std::to_string(server_try_cancel)); grpc::to_string(server_try_cancel));
request.set_message("hello"); request.set_message("hello");
auto stream = stub_->ResponseStream(&context, request); auto stream = stub_->ResponseStream(&context, request);
@ -413,7 +413,7 @@ class End2endServerTryCancelTest : public End2endTest {
break; break;
} }
EXPECT_EQ(response.message(), EXPECT_EQ(response.message(),
request.message() + std::to_string(num_msgs_read)); request.message() + grpc::to_string(num_msgs_read));
num_msgs_read++; num_msgs_read++;
} }
gpr_log(GPR_INFO, "Read %d messages", num_msgs_read); gpr_log(GPR_INFO, "Read %d messages", num_msgs_read);
@ -479,14 +479,14 @@ class End2endServerTryCancelTest : public End2endTest {
// Send server_try_cancel in the client metadata // Send server_try_cancel in the client metadata
context.AddMetadata(kServerTryCancelRequest, context.AddMetadata(kServerTryCancelRequest,
std::to_string(server_try_cancel)); grpc::to_string(server_try_cancel));
auto stream = stub_->BidiStream(&context); auto stream = stub_->BidiStream(&context);
int num_msgs_read = 0; int num_msgs_read = 0;
int num_msgs_sent = 0; int num_msgs_sent = 0;
while (num_msgs_sent < num_messages) { 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)) { if (!stream->Write(request)) {
break; break;
} }
@ -548,7 +548,7 @@ TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) {
ClientContext context; ClientContext context;
context.AddMetadata(kServerTryCancelRequest, context.AddMetadata(kServerTryCancelRequest,
std::to_string(CANCEL_BEFORE_PROCESSING)); grpc::to_string(CANCEL_BEFORE_PROCESSING));
Status s = stub_->Echo(&context, request, &response); Status s = stub_->Echo(&context, request, &response);
EXPECT_FALSE(s.ok()); EXPECT_FALSE(s.ok());
EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code());

@ -33,6 +33,7 @@
#include "test/cpp/end2end/test_service_impl.h" #include "test/cpp/end2end/test_service_impl.h"
#include <string>
#include <thread> #include <thread>
#include <grpc++/security/credentials.h> #include <grpc++/security/credentials.h>
@ -253,7 +254,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context,
} }
for (int i = 0; i < kNumResponseStreamsMsgs; i++) { 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); writer->Write(response);
} }

@ -230,7 +230,7 @@ class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> {
}; };
class CommonStressTestAsyncServer class CommonStressTestAsyncServer
: public CommonStressTest<::grpc::testing::EchoTestService::AsyncService> { : public CommonStressTest< ::grpc::testing::EchoTestService::AsyncService> {
public: public:
void SetUp() GRPC_OVERRIDE { void SetUp() GRPC_OVERRIDE {
shutting_down_ = false; shutting_down_ = false;
@ -394,7 +394,7 @@ class AsyncClientEnd2endTest : public ::testing::Test {
for (int i = 0; i < num_rpcs; ++i) { for (int i = 0; i < num_rpcs; ++i) {
AsyncClientCall* call = new AsyncClientCall; AsyncClientCall* call = new AsyncClientCall;
EchoRequest request; EchoRequest request;
request.set_message("Hello: " + std::to_string(i)); request.set_message("Hello: " + grpc::to_string(i));
call->response_reader = call->response_reader =
common_.GetStub()->AsyncEcho(&call->context, request, &cq_); common_.GetStub()->AsyncEcho(&call->context, request, &cq_);
call->response_reader->Finish(&call->response, &call->status, call->response_reader->Finish(&call->response, &call->status,

@ -99,7 +99,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge(
std::lock_guard<std::mutex> lock(mu_); std::lock_guard<std::mutex> lock(mu_);
std::shared_ptr<QpsGauge> qps_gauge(new QpsGauge()); 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.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 // 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) { std::unique_ptr<grpc::Server> MetricsServiceImpl::StartServer(int port) {
gpr_log(GPR_INFO, "Building metrics server.."); 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; ServerBuilder builder;
builder.AddListeningPort(address, grpc::InsecureServerCredentials()); builder.AddListeningPort(address, grpc::InsecureServerCredentials());

@ -41,15 +41,9 @@
#include "test/core/end2end/data/ssl_test_data.h" #include "test/core/end2end/data/ssl_test_data.h"
namespace grpc {
namespace { 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; using grpc::testing::CredentialTypeProvider;
// Provide test credentials. Thread-safe. // Provide test credentials. Thread-safe.
@ -162,7 +156,6 @@ CredentialsProvider* GetProvider() {
} // namespace } // namespace
namespace grpc {
namespace testing { namespace testing {
void AddSecureType(const grpc::string& type, void AddSecureType(const grpc::string& type,

Loading…
Cancel
Save