diff --git a/README.md b/README.md index 8fa9fa4956e..fa60b83d162 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/grpc/grpc.svg?branch=master)](https://travis-ci.org/grpc/grpc) + [gRPC - An RPC library and framework](http://github.com/grpc/grpc) =================================== diff --git a/build.json b/build.json index 3af186ca890..922e9159d16 100644 --- a/build.json +++ b/build.json @@ -1777,7 +1777,6 @@ ], "deps": [ "pubsub_client_lib", - "grpc++_test_util", "grpc_test_util", "grpc++", "grpc", diff --git a/examples/pubsub/main.cc b/examples/pubsub/main.cc index 39fb8aea15c..ce22cfa1560 100644 --- a/examples/pubsub/main.cc +++ b/examples/pubsub/main.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -48,17 +49,11 @@ #include "examples/pubsub/publisher.h" #include "examples/pubsub/subscriber.h" -#include "test/cpp/util/create_test_channel.h" DEFINE_int32(server_port, 443, "Server port."); DEFINE_string(server_host, "pubsub-staging.googleapis.com", "Server host to connect to"); DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); -DEFINE_string(service_account_key_file, "", - "Path to service account json key file."); -DEFINE_string(oauth_scope, - "https://www.googleapis.com/auth/cloud-platform", - "Scope for OAuth tokens."); // In some distros, gflags is in the namespace google, and in some others, // in gflags. This hack is enabling us to find both. @@ -75,17 +70,6 @@ const char kMessageData[] = "Test Data"; } // namespace -grpc::string GetServiceAccountJsonKey() { - grpc::string json_key; - if (json_key.empty()) { - std::ifstream json_key_file(FLAGS_service_account_key_file); - std::stringstream key_stream; - key_stream << json_key_file.rdbuf(); - json_key = key_stream.str(); - } - return json_key; -} - int main(int argc, char** argv) { grpc_init(); ParseCommandLineFlags(&argc, &argv, true); @@ -93,23 +77,12 @@ int main(int argc, char** argv) { std::ostringstream ss; - std::unique_ptr creds; - if (FLAGS_service_account_key_file != "") { - grpc::string json_key = GetServiceAccountJsonKey(); - creds = grpc::CredentialsFactory::ServiceAccountCredentials( - json_key, FLAGS_oauth_scope, std::chrono::hours(1)); - } else { - creds = grpc::CredentialsFactory::ComputeEngineCredentials(); - } - ss << FLAGS_server_host << ":" << FLAGS_server_port; - std::shared_ptr channel( - grpc::CreateTestChannel( - ss.str(), - FLAGS_server_host, - true, // enable SSL - true, // use prod roots - creds)); + + std::unique_ptr creds = + grpc::CredentialsFactory::GoogleDefaultCredentials(); + std::shared_ptr channel = + grpc::CreateChannel(ss.str(), creds, grpc::ChannelArguments()); grpc::examples::pubsub::Publisher publisher(channel); grpc::examples::pubsub::Subscriber subscriber(channel); @@ -129,6 +102,7 @@ int main(int argc, char** argv) { subscription_name, &subscription_topic).IsOk()) { subscriber.DeleteSubscription(subscription_name); } + if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); grpc::Status s = publisher.CreateTopic(topic); diff --git a/include/grpc++/async_unary_call.h b/include/grpc++/async_unary_call.h index 71b7d3ff858..f86a1ea5185 100644 --- a/include/grpc++/async_unary_call.h +++ b/include/grpc++/async_unary_call.h @@ -49,7 +49,7 @@ class ClientAsyncResponseReader GRPC_FINAL { public: ClientAsyncResponseReader(ChannelInterface* channel, CompletionQueue* cq, const RpcMethod& method, ClientContext* context, - const google::protobuf::Message& request, void* tag) + const grpc::protobuf::Message& request, void* tag) : context_(context), call_(channel->CreateCall(method, context, cq)) { init_buf_.Reset(tag); @@ -77,7 +77,6 @@ class ClientAsyncResponseReader GRPC_FINAL { call_.PerformOps(&finish_buf_); } - private: ClientContext* context_; Call call_; diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h index 77d13636184..51260aed3d7 100644 --- a/include/grpc++/channel_interface.h +++ b/include/grpc++/channel_interface.h @@ -37,12 +37,6 @@ #include #include -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google - struct grpc_call; namespace grpc { diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 87e5e9ad6c4..c55d7c2d586 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -47,12 +47,6 @@ using std::chrono::system_clock; struct grpc_call; struct grpc_completion_queue; -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google - namespace grpc { class CallOpBuffer; diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index 0ca12604038..f741e3c36bb 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -106,8 +106,8 @@ class CompletionQueue { friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result); + const grpc::protobuf::Message &request, + grpc::protobuf::Message *result); // Wraps grpc_completion_queue_pluck. // Cannot be mixed with calls to Next(). diff --git a/include/grpc++/config.h b/include/grpc++/config.h index cfa8d3be9f1..327ed7a549a 100644 --- a/include/grpc++/config.h +++ b/include/grpc++/config.h @@ -34,8 +34,6 @@ #ifndef GRPCXX_CONFIG_H #define GRPCXX_CONFIG_H -#include - #ifdef GRPC_OLD_CXX #define GRPC_FINAL #define GRPC_OVERRIDE @@ -44,9 +42,23 @@ #define GRPC_OVERRIDE override #endif +#ifndef GRPC_CUSTOM_STRING +#include +#define GRPC_CUSTOM_STRING std::string +#endif + +#ifndef GRPC_CUSTOM_MESSAGE +#include +#define GRPC_CUSTOM_MESSAGE ::google::protobuf::Message +#endif + namespace grpc { -typedef std::string string; +typedef GRPC_CUSTOM_STRING string; + +namespace protobuf { +typedef GRPC_CUSTOM_MESSAGE Message; +} // namespace protobuf } // namespace grpc diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 3e199e3eaef..5de56629735 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -42,12 +42,6 @@ #include #include -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google - struct grpc_call; struct grpc_op; @@ -67,8 +61,8 @@ class CallOpBuffer : public CompletionQueueTag { std::multimap *metadata); void AddSendInitialMetadata(ClientContext *ctx); void AddRecvInitialMetadata(ClientContext *ctx); - void AddSendMessage(const google::protobuf::Message &message); - void AddRecvMessage(google::protobuf::Message *message); + void AddSendMessage(const grpc::protobuf::Message &message); + void AddRecvMessage(grpc::protobuf::Message *message); void AddClientSendClose(); void AddClientRecvStatus(ClientContext *ctx, Status *status); void AddServerSendStatus(std::multimap *metadata, @@ -95,10 +89,10 @@ class CallOpBuffer : public CompletionQueueTag { std::multimap *recv_initial_metadata_; grpc_metadata_array recv_initial_metadata_arr_; // Send message - const google::protobuf::Message *send_message_; + const grpc::protobuf::Message *send_message_; grpc_byte_buffer *send_message_buf_; // Recv message - google::protobuf::Message *recv_message_; + grpc::protobuf::Message *recv_message_; grpc_byte_buffer *recv_message_buf_; // Client send close bool client_send_close_; diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h index d8703264e60..fd9715da504 100644 --- a/include/grpc++/impl/client_unary_call.h +++ b/include/grpc++/impl/client_unary_call.h @@ -34,11 +34,7 @@ #ifndef GRPCXX_IMPL_CLIENT_UNARY_CALL_H #define GRPCXX_IMPL_CLIENT_UNARY_CALL_H -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google +#include namespace grpc { @@ -51,8 +47,8 @@ class Status; // Wrapper that performs a blocking unary call Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result); + const grpc::protobuf::Message &request, + grpc::protobuf::Message *result); } // namespace grpc diff --git a/include/grpc++/impl/rpc_method.h b/include/grpc++/impl/rpc_method.h index ab407f5c468..e8909ac1846 100644 --- a/include/grpc++/impl/rpc_method.h +++ b/include/grpc++/impl/rpc_method.h @@ -34,12 +34,6 @@ #ifndef GRPCXX_IMPL_RPC_METHOD_H #define GRPCXX_IMPL_RPC_METHOD_H -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google - namespace grpc { class RpcMethod { diff --git a/include/grpc++/impl/rpc_service_method.h b/include/grpc++/impl/rpc_service_method.h index ff94c7e6c00..325c8812caf 100644 --- a/include/grpc++/impl/rpc_service_method.h +++ b/include/grpc++/impl/rpc_service_method.h @@ -56,13 +56,13 @@ class MethodHandler { virtual ~MethodHandler() {} struct HandlerParameter { HandlerParameter(Call* c, ServerContext* context, - const google::protobuf::Message* req, - google::protobuf::Message* resp) + const grpc::protobuf::Message* req, + grpc::protobuf::Message* resp) : call(c), server_context(context), request(req), response(resp) {} Call* call; ServerContext* server_context; - const google::protobuf::Message* request; - google::protobuf::Message* response; + const grpc::protobuf::Message* request; + grpc::protobuf::Message* response; }; virtual Status RunHandler(const HandlerParameter& param) = 0; }; @@ -165,8 +165,8 @@ class RpcServiceMethod : public RpcMethod { // Takes ownership of the handler and two prototype objects. RpcServiceMethod(const char* name, RpcMethod::RpcType type, MethodHandler* handler, - google::protobuf::Message* request_prototype, - google::protobuf::Message* response_prototype) + grpc::protobuf::Message* request_prototype, + grpc::protobuf::Message* response_prototype) : RpcMethod(name, type), handler_(handler), request_prototype_(request_prototype), @@ -174,17 +174,17 @@ class RpcServiceMethod : public RpcMethod { MethodHandler* handler() { return handler_.get(); } - google::protobuf::Message* AllocateRequestProto() { + grpc::protobuf::Message* AllocateRequestProto() { return request_prototype_->New(); } - google::protobuf::Message* AllocateResponseProto() { + grpc::protobuf::Message* AllocateResponseProto() { return response_prototype_->New(); } private: std::unique_ptr handler_; - std::unique_ptr request_prototype_; - std::unique_ptr response_prototype_; + std::unique_ptr request_prototype_; + std::unique_ptr response_prototype_; }; // This class contains all the method information for an rpc service. It is diff --git a/include/grpc++/impl/service_type.h b/include/grpc++/impl/service_type.h index 7481d64d6af..7cd3ddad6b7 100644 --- a/include/grpc++/impl/service_type.h +++ b/include/grpc++/impl/service_type.h @@ -34,11 +34,7 @@ #ifndef GRPCXX_IMPL_SERVICE_TYPE_H #define GRPCXX_IMPL_SERVICE_TYPE_H -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google +#include namespace grpc { @@ -72,7 +68,7 @@ class AsynchronousService { public: virtual void RequestAsyncCall(void* registered_method, ServerContext* context, - ::google::protobuf::Message* request, + ::grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag) = 0; }; @@ -91,7 +87,7 @@ class AsynchronousService { protected: void RequestAsyncUnary(int index, ServerContext* context, - ::google::protobuf::Message* request, + grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag) { dispatch_impl_->RequestAsyncCall(request_args_[index], context, request, @@ -104,7 +100,7 @@ class AsynchronousService { stream, cq, tag); } void RequestServerStreaming(int index, ServerContext* context, - ::google::protobuf::Message* request, + grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag) { dispatch_impl_->RequestAsyncCall(request_args_[index], context, request, diff --git a/include/grpc++/server.h b/include/grpc++/server.h index 3282b82d04e..e3ba93e4877 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -47,12 +47,6 @@ struct grpc_server; -namespace google { -namespace protobuf { -class Message; -} // namespace protobuf -} // namespace google - namespace grpc { class AsynchronousService; class RpcService; @@ -101,7 +95,7 @@ class Server GRPC_FINAL : private CallHook, // DispatchImpl void RequestAsyncCall(void* registered_method, ServerContext* context, - ::google::protobuf::Message* request, + grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag); diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index d95a379757e..7625bcc38d3 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -88,7 +88,7 @@ class ClientReader GRPC_FINAL : public ClientStreamingInterface, public: // Blocking create a stream and write the first request out. ClientReader(ChannelInterface* channel, const RpcMethod& method, - ClientContext* context, const google::protobuf::Message& request) + ClientContext* context, const grpc::protobuf::Message& request) : context_(context), call_(channel->CreateCall(method, context, &cq_)) { CallOpBuffer buf; buf.AddSendInitialMetadata(&context->send_initial_metadata_); @@ -142,7 +142,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface, public: // Blocking create a stream. ClientWriter(ChannelInterface* channel, const RpcMethod& method, - ClientContext* context, google::protobuf::Message* response) + ClientContext* context, grpc::protobuf::Message* response) : context_(context), response_(response), call_(channel->CreateCall(method, context, &cq_)) { @@ -179,7 +179,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface, private: ClientContext* context_; - google::protobuf::Message* const response_; + grpc::protobuf::Message* const response_; CompletionQueue cq_; Call call_; }; @@ -386,7 +386,7 @@ class ClientAsyncReader GRPC_FINAL : public ClientAsyncStreamingInterface, // Create a stream and write the first request out. ClientAsyncReader(ChannelInterface* channel, CompletionQueue* cq, const RpcMethod& method, ClientContext* context, - const google::protobuf::Message& request, void* tag) + const grpc::protobuf::Message& request, void* tag) : context_(context), call_(channel->CreateCall(method, context, cq)) { init_buf_.Reset(tag); init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_); @@ -436,7 +436,7 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncStreamingInterface, public: ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq, const RpcMethod& method, ClientContext* context, - google::protobuf::Message* response, void* tag) + grpc::protobuf::Message* response, void* tag) : context_(context), response_(response), call_(channel->CreateCall(method, context, cq)) { @@ -477,7 +477,7 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncStreamingInterface, private: ClientContext* context_; - google::protobuf::Message* const response_; + grpc::protobuf::Message* const response_; Call call_; CallOpBuffer init_buf_; CallOpBuffer meta_buf_; diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index f0a8453fd77..0151550a818 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -267,7 +267,6 @@ static void unary_poll_do_promote(void *args, int success) { * and we don't have any mechanism to unbecome multipoller. */ pollset->in_flight_cbs--; if (pollset->shutting_down) { - gpr_log(GPR_INFO, "Shutting down"); /* We don't care about this pollset anymore. */ if (pollset->in_flight_cbs == 0) { do_shutdown_cb = 1; @@ -275,7 +274,6 @@ static void unary_poll_do_promote(void *args, int success) { } else if (grpc_fd_is_orphaned(fd)) { /* Don't try to add it to anything, we'll drop our ref on it below */ } else if (pollset->vtable != original_vtable) { - gpr_log(GPR_INFO, "Not original vtable"); pollset->vtable->add_fd(pollset, fd); } else if (fd != pollset->data.ptr) { grpc_fd *fds[2]; diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 7cf3c0e4fd6..b2033f3dc0e 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -140,6 +140,8 @@ struct grpc_call { gpr_uint8 have_alarm; /* are we currently performing a send operation */ gpr_uint8 sending; + /* are we currently completing requests */ + gpr_uint8 completing; /* pairs with completed_requests */ gpr_uint8 num_completed_requests; /* flag that we need to request more data */ @@ -357,7 +359,7 @@ static void lock(grpc_call *call) { gpr_mu_lock(&call->mu); } static void unlock(grpc_call *call) { send_action sa = SEND_NOTHING; completed_request completed_requests[GRPC_IOREQ_OP_COUNT]; - int num_completed_requests = call->num_completed_requests; + int completing_requests = 0; int need_more_data = call->need_more_data && (call->write_state >= WRITE_STATE_STARTED || !call->is_client); @@ -367,10 +369,12 @@ static void unlock(grpc_call *call) { call->need_more_data = 0; } - if (num_completed_requests != 0) { + if (!call->completing && call->num_completed_requests != 0) { + completing_requests = call->num_completed_requests; memcpy(completed_requests, call->completed_requests, sizeof(completed_requests)); call->num_completed_requests = 0; + call->completing = 1; } if (!call->sending) { @@ -391,9 +395,14 @@ static void unlock(grpc_call *call) { enact_send_action(call, sa); } - for (i = 0; i < num_completed_requests; i++) { - completed_requests[i].on_complete(call, completed_requests[i].status, - completed_requests[i].user_data); + if (completing_requests > 0) { + for (i = 0; i < completing_requests; i++) { + completed_requests[i].on_complete(call, completed_requests[i].status, + completed_requests[i].user_data); + } + lock(call); + call->completing = 0; + unlock(call); } } diff --git a/src/cpp/client/client_unary_call.cc b/src/cpp/client/client_unary_call.cc index 684b3cbadb4..5c179de9d8f 100644 --- a/src/cpp/client/client_unary_call.cc +++ b/src/cpp/client/client_unary_call.cc @@ -44,8 +44,8 @@ namespace grpc { // Wrapper that performs a blocking unary call Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result) { + const grpc::protobuf::Message &request, + grpc::protobuf::Message *result) { CompletionQueue cq; Call call(channel->CreateCall(method, context, &cq)); CallOpBuffer buf; diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc index a140f551e0d..eff0892810b 100644 --- a/src/cpp/client/credentials.cc +++ b/src/cpp/client/credentials.cc @@ -47,7 +47,8 @@ grpc_credentials *Credentials::GetRawCreds() { return creds_; } std::unique_ptr CredentialsFactory::GoogleDefaultCredentials() { grpc_credentials *c_creds = grpc_google_default_credentials_create(); - std::unique_ptr cpp_creds(new Credentials(c_creds)); + std::unique_ptr cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); return cpp_creds; } diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index f3a691114d2..b2b6c627857 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -163,11 +163,11 @@ void CallOpBuffer::AddSendInitialMetadata(ClientContext* ctx) { AddSendInitialMetadata(&ctx->send_initial_metadata_); } -void CallOpBuffer::AddSendMessage(const google::protobuf::Message& message) { +void CallOpBuffer::AddSendMessage(const grpc::protobuf::Message& message) { send_message_ = &message; } -void CallOpBuffer::AddRecvMessage(google::protobuf::Message* message) { +void CallOpBuffer::AddRecvMessage(grpc::protobuf::Message* message) { recv_message_ = message; recv_message_->Clear(); } diff --git a/src/cpp/proto/proto_utils.cc b/src/cpp/proto/proto_utils.cc index 69a6bb080e0..e6badd5d6e7 100644 --- a/src/cpp/proto/proto_utils.cc +++ b/src/cpp/proto/proto_utils.cc @@ -40,7 +40,7 @@ namespace grpc { -bool SerializeProto(const google::protobuf::Message &msg, +bool SerializeProto(const grpc::protobuf::Message &msg, grpc_byte_buffer **bp) { grpc::string msg_str; bool success = msg.SerializeToString(&msg_str); @@ -54,7 +54,7 @@ bool SerializeProto(const google::protobuf::Message &msg, } bool DeserializeProto(grpc_byte_buffer *buffer, - google::protobuf::Message *msg) { + grpc::protobuf::Message *msg) { grpc::string msg_string; grpc_byte_buffer_reader *reader = grpc_byte_buffer_reader_create(buffer); gpr_slice slice; diff --git a/src/cpp/proto/proto_utils.h b/src/cpp/proto/proto_utils.h index a0af4d6465d..7a1b1f8b7cb 100644 --- a/src/cpp/proto/proto_utils.h +++ b/src/cpp/proto/proto_utils.h @@ -34,23 +34,20 @@ #ifndef GRPC_INTERNAL_CPP_PROTO_PROTO_UTILS_H #define GRPC_INTERNAL_CPP_PROTO_PROTO_UTILS_H +#include + struct grpc_byte_buffer; -namespace google { -namespace protobuf { -class Message; -} -} namespace grpc { // Serialize the msg into a buffer created inside the function. The caller // should destroy the returned buffer when done with it. If serialization fails, // false is returned and buffer is left unchanged. -bool SerializeProto(const google::protobuf::Message &msg, +bool SerializeProto(const grpc::protobuf::Message &msg, grpc_byte_buffer **buffer); // The caller keeps ownership of buffer and msg. -bool DeserializeProto(grpc_byte_buffer *buffer, google::protobuf::Message *msg); +bool DeserializeProto(grpc_byte_buffer *buffer, grpc::protobuf::Message *msg); } // namespace grpc diff --git a/src/cpp/server/async_server_context.cc b/src/cpp/server/async_server_context.cc index 5f8c2ba10f4..bee75497b8c 100644 --- a/src/cpp/server/async_server_context.cc +++ b/src/cpp/server/async_server_context.cc @@ -58,14 +58,14 @@ void AsyncServerContext::Accept(grpc_completion_queue *cq) { call_, GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK); } -bool AsyncServerContext::StartRead(google::protobuf::Message *request) { +bool AsyncServerContext::StartRead(grpc::protobuf::Message *request) { GPR_ASSERT(request); request_ = request; grpc_call_error err = grpc_call_start_read_old(call_, this); return err == GRPC_CALL_OK; } -bool AsyncServerContext::StartWrite(const google::protobuf::Message &response, +bool AsyncServerContext::StartWrite(const grpc::protobuf::Message &response, int flags) { grpc_byte_buffer *buffer = nullptr; if (!SerializeProto(response, &buffer)) { diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 97bf0f1a6ea..2a5a7fe5ebd 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -117,8 +117,8 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { } void Run() { - std::unique_ptr req; - std::unique_ptr res; + std::unique_ptr req; + std::unique_ptr res; if (has_request_payload_) { req.reset(method_->AllocateRequestProto()); if (!DeserializeProto(request_payload_, req.get())) { @@ -298,7 +298,7 @@ void Server::PerformOpsOnCall(CallOpBuffer* buf, Call* call) { class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { public: AsyncRequest(Server* server, void* registered_method, ServerContext* ctx, - ::google::protobuf::Message* request, + grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag) : tag_(tag), @@ -324,6 +324,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE { *tag = tag_; + bool orig_status = *status; if (*status && request_) { if (payload_) { *status = DeserializeProto(payload_, request_); @@ -343,7 +344,9 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { } ctx_->call_ = call_; Call call(call_, server_, cq_); - ctx_->BeginCompletionOp(&call); + if (orig_status && call_) { + ctx_->BeginCompletionOp(&call); + } // just the pointers inside call are copied here stream_->BindCall(&call); delete this; @@ -352,7 +355,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { private: void* const tag_; - ::google::protobuf::Message* const request_; + grpc::protobuf::Message* const request_; ServerAsyncStreamingInterface* const stream_; CompletionQueue* const cq_; ServerContext* const ctx_; @@ -364,7 +367,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag { }; void Server::RequestAsyncCall(void* registered_method, ServerContext* context, - ::google::protobuf::Message* request, + grpc::protobuf::Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* cq, void* tag) { new AsyncRequest(this, registered_method, context, request, stream, cq, tag); diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index c797d8af963..c006262fc34 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -143,21 +143,24 @@ class AsyncQpsServerTest { delete contexts_.front(); contexts_.pop_front(); } + for (auto& thr: threads_) { + thr.join(); + } } void ServeRpcs(int num_threads) { - std::vector threads; for (int i = 0; i < num_threads; i++) { - threads.push_back(std::thread([=]() { + threads_.push_back(std::thread([=]() { // Wait until work is available or we are shutting down bool ok; void *got_tag; while (srv_cq_.Next(&got_tag, &ok)) { - EXPECT_EQ(ok, true); - ServerRpcContext *ctx = detag(got_tag); - // The tag is a pointer to an RPC context to invoke - if (ctx->RunNextState() == false) { - // this RPC context is done, so refresh it - ctx->Reset(); + if (ok) { + ServerRpcContext *ctx = detag(got_tag); + // The tag is a pointer to an RPC context to invoke + if (ctx->RunNextState() == false) { + // this RPC context is done, so refresh it + ctx->Reset(); + } } } return; @@ -260,6 +263,7 @@ class AsyncQpsServerTest { } CompletionQueue srv_cq_; TestService::AsyncService async_service_; + std::vector threads_; std::unique_ptr server_; std::function *, void *)> diff --git a/tools/dockerfile/grpc_csharp_mono/Dockerfile b/tools/dockerfile/grpc_csharp_mono/Dockerfile index d0e2d2be7e4..8f863665606 100644 --- a/tools/dockerfile/grpc_csharp_mono/Dockerfile +++ b/tools/dockerfile/grpc_csharp_mono/Dockerfile @@ -38,12 +38,8 @@ RUN cd /var/local/git/grpc \ # Install the gRPC C# extension library RUN make install_grpc_csharp_ext -j12 -C /var/local/git/grpc -# TODO: download NuGet from web. The problem is there seems to be no direct link -# we could use :-) -ADD NuGet.exe NuGet.exe - # Restore the NuGet dependencies -RUN cd /var/local/git/grpc/src/csharp && mono /NuGet.exe restore Grpc.sln +RUN cd /var/local/git/grpc/src/csharp && mono /var/local/NuGet.exe restore Grpc.sln # Build gRPC solution RUN cd /var/local/git/grpc/src/csharp && xbuild Grpc.sln diff --git a/tools/dockerfile/grpc_csharp_mono_base/Dockerfile b/tools/dockerfile/grpc_csharp_mono_base/Dockerfile index 74919a7fdb5..88766a4545a 100644 --- a/tools/dockerfile/grpc_csharp_mono_base/Dockerfile +++ b/tools/dockerfile/grpc_csharp_mono_base/Dockerfile @@ -43,6 +43,9 @@ RUN apt-get update && apt-get install -y \ nunit-console \ monodevelop +# Download NuGet +RUN cd /var/local && wget www.nuget.org/NuGet.exe + # Get the source from GitHub RUN git clone git@github.com:grpc/grpc.git /var/local/git/grpc RUN cd /var/local/git/grpc && \ diff --git a/tools/dockerfile/grpc_go/Dockerfile b/tools/dockerfile/grpc_go/Dockerfile index ada2208097d..06bb3e2d5e7 100644 --- a/tools/dockerfile/grpc_go/Dockerfile +++ b/tools/dockerfile/grpc_go/Dockerfile @@ -37,8 +37,8 @@ RUN go get google.golang.org/grpc ADD service_account service_account # Build the interop client and server -RUN go install google.golang.org/grpc/interop/client -RUN go install google.golang.org/grpc/interop/server +RUN cd src/google.golang.org/grpc/interop/client && go install +RUN cd src/google.golang.org/grpc/interop/server && go install # Specify the default command such that the interop server runs on its known testing port -CMD ["server", "--use_tls=true", "--port=8020"] +CMD ["/bin/bash", "-c", "cd src/google.golang.org/grpc/interop/server && go run server.go --use_tls=true --port=8020"] diff --git a/tools/dockerfile/grpc_python/Dockerfile b/tools/dockerfile/grpc_python/Dockerfile index 2e72752cdd7..58a3d8c14f1 100644 --- a/tools/dockerfile/grpc_python/Dockerfile +++ b/tools/dockerfile/grpc_python/Dockerfile @@ -44,21 +44,21 @@ RUN cd /var/local/git/grpc \ && pip install src/python/interop # Run Python GRPC's tests +# TODO(nathaniel): It would be nice for these to be auto-discoverable? RUN cd /var/local/git/grpc \ - # TODO(nathaniel): It would be nice for these to be auto-discoverable? - && python2.7 -B -m grpc._adapter._blocking_invocation_inline_service_test - && python2.7 -B -m grpc._adapter._c_test - && python2.7 -B -m grpc._adapter._event_invocation_synchronous_event_service_test - && python2.7 -B -m grpc._adapter._future_invocation_asynchronous_event_service_test - && python2.7 -B -m grpc._adapter._links_test - && python2.7 -B -m grpc._adapter._lonely_rear_link_test - && python2.7 -B -m grpc._adapter._low_test - && python2.7 -B -m grpc.framework.assembly.implementations_test - && python2.7 -B -m grpc.framework.base.packets.implementations_test - && python2.7 -B -m grpc.framework.face.blocking_invocation_inline_service_test - && python2.7 -B -m grpc.framework.face.event_invocation_synchronous_event_service_test - && python2.7 -B -m grpc.framework.face.future_invocation_asynchronous_event_service_test - && python2.7 -B -m grpc.framework.foundation._later_test + && python2.7 -B -m grpc._adapter._blocking_invocation_inline_service_test \ + && python2.7 -B -m grpc._adapter._c_test \ + && python2.7 -B -m grpc._adapter._event_invocation_synchronous_event_service_test \ + && python2.7 -B -m grpc._adapter._future_invocation_asynchronous_event_service_test \ + && python2.7 -B -m grpc._adapter._links_test \ + && python2.7 -B -m grpc._adapter._lonely_rear_link_test \ + && python2.7 -B -m grpc._adapter._low_test \ + && python2.7 -B -m grpc.framework.assembly.implementations_test \ + && python2.7 -B -m grpc.framework.base.packets.implementations_test \ + && python2.7 -B -m grpc.framework.face.blocking_invocation_inline_service_test \ + && python2.7 -B -m grpc.framework.face.event_invocation_synchronous_event_service_test \ + && python2.7 -B -m grpc.framework.face.future_invocation_asynchronous_event_service_test \ + && python2.7 -B -m grpc.framework.foundation._later_test \ && python2.7 -B -m grpc.framework.foundation._logging_pool_test # Add a cacerts directory containing the Google root pem file, allowing the interop client to access the production test instance diff --git a/tools/gce_setup/build_images.sh b/tools/gce_setup/build_images.sh new file mode 100755 index 00000000000..ea58a98608c --- /dev/null +++ b/tools/gce_setup/build_images.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +main() { + # rebuild images on all languages on existing builder vm. + source grpc_docker.sh + cd ../../ + + # build images for all languages + languages=(cxx java go ruby node python) + for lan in "${languages[@]}" + do + grpc_update_image $lan + done +} + +set -x +main "$@" diff --git a/tools/gce_setup/cloud_prod_runner.sh b/tools/gce_setup/cloud_prod_runner.sh index e11185c226b..3760ae49795 100755 --- a/tools/gce_setup/cloud_prod_runner.sh +++ b/tools/gce_setup/cloud_prod_runner.sh @@ -31,7 +31,8 @@ main() { source grpc_docker.sh - test_cases=(large_unary empty_unary ping_pong client_streaming server_streaming cancel_after_begin cancel_after_first_response) + # temporarily remove ping_pong and cancel_after_first_response while investigating timeout + test_cases=(large_unary empty_unary client_streaming server_streaming cancel_after_begin) auth_test_cases=(service_account_creds compute_engine_creds) clients=(cxx java go ruby node) for test_case in "${test_cases[@]}"