Rename anonymous to generic globally

pull/1003/head
Yang Gao 10 years ago
parent 2fe6ecebee
commit 005eb88c45
  1. 106
      Makefile
  2. 30
      build.json
  3. 14
      include/grpc++/generic_service.h
  4. 12
      include/grpc++/generic_stub.h
  5. 14
      include/grpc++/server.h
  6. 8
      include/grpc++/server_builder.h
  7. 10
      src/cpp/server/generic_service.cc
  8. 28
      src/cpp/server/server.cc
  9. 14
      src/cpp/server/server_builder.cc
  10. 32
      test/cpp/end2end/generic_end2end_test.cc
  11. 10
      tools/run_tests/tests.json

File diff suppressed because one or more lines are too long

@ -12,7 +12,6 @@
{
"name": "grpc++_base",
"public_headers": [
"include/grpc++/anonymous_service.h",
"include/grpc++/async_unary_call.h",
"include/grpc++/byte_buffer.h",
"include/grpc++/channel_arguments.h",
@ -22,6 +21,7 @@
"include/grpc++/config.h",
"include/grpc++/create_channel.h",
"include/grpc++/credentials.h",
"include/grpc++/generic_service.h",
"include/grpc++/impl/call.h",
"include/grpc++/impl/client_unary_call.h",
"include/grpc++/impl/internal_stub.h",
@ -57,7 +57,7 @@
"src/cpp/common/completion_queue.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc",
"src/cpp/server/anonymous_service.cc",
"src/cpp/server/generic_service.cc",
"src/cpp/server/insecure_server_credentials.cc",
"src/cpp/server/server.cc",
"src/cpp/server/server_builder.cc",
@ -1647,11 +1647,11 @@
]
},
{
"name": "anonymous_end2end_test",
"name": "async_end2end_test",
"build": "test",
"language": "c++",
"src": [
"test/cpp/end2end/anonymous_end2end_test.cc"
"test/cpp/end2end/async_end2end_test.cc"
],
"deps": [
"grpc++_test_util",
@ -1663,27 +1663,24 @@
]
},
{
"name": "async_end2end_test",
"name": "channel_arguments_test",
"build": "test",
"language": "c++",
"src": [
"test/cpp/end2end/async_end2end_test.cc"
"test/cpp/client/channel_arguments_test.cc"
],
"deps": [
"grpc++_test_util",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr"
]
},
{
"name": "channel_arguments_test",
"name": "credentials_test",
"build": "test",
"language": "c++",
"src": [
"test/cpp/client/channel_arguments_test.cc"
"test/cpp/client/credentials_test.cc"
],
"deps": [
"grpc++",
@ -1692,24 +1689,27 @@
]
},
{
"name": "credentials_test",
"name": "end2end_test",
"build": "test",
"language": "c++",
"src": [
"test/cpp/client/credentials_test.cc"
"test/cpp/end2end/end2end_test.cc"
],
"deps": [
"grpc++_test_util",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr"
]
},
{
"name": "end2end_test",
"name": "generic_end2end_test",
"build": "test",
"language": "c++",
"src": [
"test/cpp/end2end/end2end_test.cc"
"test/cpp/end2end/generic_end2end_test.cc"
],
"deps": [
"grpc++_test_util",

@ -31,8 +31,8 @@
*
*/
#ifndef GRPCXX_ANONYMOUS_SERVICE_H
#define GRPCXX_ANONYMOUS_SERVICE_H
#ifndef GRPCXX_GENERIC_SERVICE_H
#define GRPCXX_GENERIC_SERVICE_H
#include <grpc++/byte_buffer.h>
#include <grpc++/stream.h>
@ -43,7 +43,7 @@ namespace grpc {
typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> GenericServerReaderWriter;
class AnonymousServerContext : public ServerContext {
class GenericServerContext : public ServerContext {
public:
const grpc::string& method() const { return method_; }
const grpc::string& host() const { return host_; }
@ -55,13 +55,13 @@ class AnonymousServerContext : public ServerContext {
grpc::string host_;
};
class AnonymousService {
class GenericService {
public:
// TODO(yangg) Once we can add multiple completion queues to the server
// in c core, add a CompletionQueue* argument to the ctor here.
AnonymousService() : server_(nullptr) {}
GenericService() : server_(nullptr) {}
void RequestCall(AnonymousServerContext* ctx,
void RequestCall(GenericServerContext* ctx,
GenericServerReaderWriter* reader_writer,
CompletionQueue* cq, void* tag);
@ -72,4 +72,4 @@ class AnonymousService {
} // namespace grpc
#endif // GRPCXX_ANONYMOUS_SERVICE_H
#endif // GRPCXX_GENERIC_SERVICE_H

@ -31,8 +31,8 @@
*
*/
#ifndef GRPCXX_ANONYMOUS_STUB_H
#define GRPCXX_ANONYMOUS_STUB_H
#ifndef GRPCXX_GENERIC_STUB_H
#define GRPCXX_GENERIC_STUB_H
#include <grpc++/byte_buffer.h>
#include <grpc++/stream.h>
@ -41,11 +41,11 @@ namespace grpc {
typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer> GenericClientReaderWriter;
// Anonymous stubs provide a type-unsafe interface to call gRPC methods
// Generic stubs provide a type-unsafe interface to call gRPC methods
// by name.
class AnonymousStub {
class GenericStub {
public:
explicit AnonymousStub(std::shared_ptr<ChannelInterface> channel) : channel_(channel) {}
explicit GenericStub(std::shared_ptr<ChannelInterface> channel) : channel_(channel) {}
// begin a call to a named method
std::unique_ptr<GenericClientReaderWriter> Call(ClientContext* context, const grpc::string& method);
@ -56,4 +56,4 @@ class AnonymousStub {
} // namespace grpc
#endif // GRPCXX_ANONYMOUS_STUB_H
#endif // GRPCXX_GENERIC_STUB_H

@ -48,9 +48,9 @@
struct grpc_server;
namespace grpc {
class AnonymousServerContext;
class AnonymousService;
class AsynchronousService;
class GenericServerContext;
class GenericService;
class RpcService;
class RpcServiceMethod;
class ServerCredentials;
@ -73,7 +73,7 @@ class Server GRPC_FINAL : private CallHook,
CompletionQueue* cq() { return &cq_; }
private:
friend class AnonymousService;
friend class GenericService;
friend class ServerBuilder;
class SyncRequest;
@ -86,7 +86,7 @@ class Server GRPC_FINAL : private CallHook,
// The service must exist for the lifetime of the Server instance.
bool RegisterService(RpcService* service);
bool RegisterAsyncService(AsynchronousService* service);
void RegisterAnonymousService(AnonymousService* service);
void RegisterGenericService(GenericService* service);
// Add a listening port. Can be called multiple times.
int AddPort(const grpc::string& addr, ServerCredentials* creds);
// Start the server.
@ -104,9 +104,9 @@ class Server GRPC_FINAL : private CallHook,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) GRPC_OVERRIDE;
void RequestAsyncAnonymousCall(AnonymousServerContext* context,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag);
void RequestGenericCall(GenericServerContext* context,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag);
// Completion queue.
CompletionQueue cq_;

@ -41,9 +41,9 @@
namespace grpc {
class AnonymousService;
class AsynchronousService;
class CompletionQueue;
class GenericService;
class RpcService;
class Server;
class ServerCredentials;
@ -65,8 +65,8 @@ class ServerBuilder {
// instance returned by BuildAndStart().
void RegisterAsyncService(AsynchronousService* service);
// Register an anonymous service.
void RegisterAnonymousService(AnonymousService* service);
// Register a generic service.
void RegisterGenericService(GenericService* service);
// Add a listening port. Can be called multiple times.
void AddPort(const grpc::string& addr,
@ -91,7 +91,7 @@ class ServerBuilder {
std::vector<AsynchronousService*> async_services_;
std::vector<Port> ports_;
std::shared_ptr<ServerCredentials> creds_;
AnonymousService* anonymous_service_;
GenericService* generic_service_;
ThreadPoolInterface* thread_pool_;
};

@ -31,16 +31,16 @@
*
*/
#include <grpc++/anonymous_service.h>
#include <grpc++/generic_service.h>
#include <grpc++/server.h>
namespace grpc {
void AnonymousService::RequestCall(AnonymousServerContext* ctx,
GenericServerReaderWriter* reader_writer,
CompletionQueue* cq, void* tag) {
server_->RequestAsyncAnonymousCall(ctx, reader_writer, cq, tag);
void GenericService::RequestCall(GenericServerContext* ctx,
GenericServerReaderWriter* reader_writer,
CompletionQueue* cq, void* tag) {
server_->RequestGenericCall(ctx, reader_writer, cq, tag);
}
} // namespace grpc

@ -37,8 +37,8 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include <grpc++/anonymous_service.h>
#include <grpc++/completion_queue.h>
#include <grpc++/generic_service.h>
#include <grpc++/impl/rpc_service_method.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/server_context.h>
@ -227,9 +227,9 @@ bool Server::RegisterAsyncService(AsynchronousService* service) {
return true;
}
void Server::RegisterAnonymousService(AnonymousService* service) {
void Server::RegisterGenericService(GenericService* service) {
GPR_ASSERT(service->server_ == nullptr &&
"Can only register an anonymous service against one server.");
"Can only register an generic service against one server.");
service->server_ = this;
}
@ -296,7 +296,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
stream_(stream),
cq_(cq),
ctx_(ctx),
anonymous_ctx_(nullptr),
generic_ctx_(nullptr),
server_(server),
call_(nullptr),
payload_(nullptr) {
@ -307,7 +307,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
&array_, request ? &payload_ : nullptr, cq->cq(), this);
}
AsyncRequest(Server* server, AnonymousServerContext* ctx,
AsyncRequest(Server* server, GenericServerContext* ctx,
ServerAsyncStreamingInterface* stream, CompletionQueue* cq,
void* tag)
: tag_(tag),
@ -315,7 +315,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
stream_(stream),
cq_(cq),
ctx_(nullptr),
anonymous_ctx_(ctx),
generic_ctx_(ctx),
server_(server),
call_(nullptr),
payload_(nullptr) {
@ -343,7 +343,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
*status = false;
}
}
ServerContext* ctx = ctx_ ? ctx_ : anonymous_ctx_;
ServerContext* ctx = ctx_ ? ctx_ : generic_ctx_;
GPR_ASSERT(ctx);
if (*status) {
ctx->deadline_ = Timespec2Timepoint(call_details_.deadline);
@ -354,9 +354,9 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
array_.metadata[i].value,
array_.metadata[i].value + array_.metadata[i].value_length)));
}
if (anonymous_ctx_) {
anonymous_ctx_->method_ = call_details_.method;
anonymous_ctx_->host_ = call_details_.host;
if (generic_ctx_) {
generic_ctx_->method_ = call_details_.method;
generic_ctx_->host_ = call_details_.host;
}
}
ctx->call_ = call_;
@ -376,7 +376,7 @@ class Server::AsyncRequest GRPC_FINAL : public CompletionQueueTag {
ServerAsyncStreamingInterface* const stream_;
CompletionQueue* const cq_;
ServerContext* const ctx_;
AnonymousServerContext* const anonymous_ctx_;
GenericServerContext* const generic_ctx_;
Server* const server_;
grpc_call* call_;
grpc_call_details call_details_;
@ -391,9 +391,9 @@ void Server::RequestAsyncCall(void* registered_method, ServerContext* context,
new AsyncRequest(this, registered_method, context, request, stream, cq, tag);
}
void Server::RequestAsyncAnonymousCall(AnonymousServerContext* context,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) {
void Server::RequestGenericCall(GenericServerContext* context,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) {
new AsyncRequest(this, context, stream, cq, tag);
}

@ -42,7 +42,7 @@
namespace grpc {
ServerBuilder::ServerBuilder()
: anonymous_service_(nullptr), thread_pool_(nullptr) {}
: generic_service_(nullptr), thread_pool_(nullptr) {}
void ServerBuilder::RegisterService(SynchronousService* service) {
services_.push_back(service->service());
@ -52,14 +52,14 @@ void ServerBuilder::RegisterAsyncService(AsynchronousService* service) {
async_services_.push_back(service);
}
void ServerBuilder::RegisterAnonymousService(AnonymousService* service) {
if (anonymous_service_) {
void ServerBuilder::RegisterGenericService(GenericService* service) {
if (generic_service_) {
gpr_log(GPR_ERROR,
"Adding multiple AnonymousService is unsupported for now. "
"Adding multiple GenericService is unsupported for now. "
"Dropping the service %p", service);
return;
}
anonymous_service_ = service;
generic_service_ = service;
}
void ServerBuilder::AddPort(const grpc::string& addr,
@ -95,8 +95,8 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
return nullptr;
}
}
if (anonymous_service_) {
server->RegisterAnonymousService(anonymous_service_);
if (generic_service_) {
server->RegisterGenericService(generic_service_);
}
for (auto& port : ports_) {
int r = server->AddPort(port.addr, port.creds.get());

@ -37,7 +37,7 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo.pb.h"
#include "src/cpp/util/time.h"
#include <grpc++/anonymous_service.h>
#include <grpc++/generic_service.h>
#include <grpc++/async_unary_call.h>
#include <grpc++/byte_buffer.h>
#include <grpc++/channel_arguments.h>
@ -77,9 +77,9 @@ void verify_ok(CompletionQueue* cq, int i, bool expect_ok) {
EXPECT_EQ(tag(i), got_tag);
}
class AnonymousEnd2endTest : public ::testing::Test {
class GenericEnd2endTest : public ::testing::Test {
protected:
AnonymousEnd2endTest() {}
GenericEnd2endTest() {}
void SetUp() GRPC_OVERRIDE {
int port = grpc_pick_unused_port_or_die();
@ -87,7 +87,7 @@ class AnonymousEnd2endTest : public ::testing::Test {
// Setup server
ServerBuilder builder;
builder.AddPort(server_address_.str(), InsecureServerCredentials());
builder.RegisterAnonymousService(&anonymous_service_);
builder.RegisterGenericService(&generic_service_);
server_ = builder.BuildAndStart();
}
@ -123,7 +123,7 @@ class AnonymousEnd2endTest : public ::testing::Test {
Status recv_status;
ClientContext cli_ctx;
AnonymousServerContext srv_ctx;
GenericServerContext srv_ctx;
GenericServerReaderWriter stream(&srv_ctx);
send_request.set_message("Hello");
@ -131,7 +131,7 @@ class AnonymousEnd2endTest : public ::testing::Test {
stub_->AsyncEcho(&cli_ctx, send_request, &cli_cq_, tag(1)));
client_ok(1);
anonymous_service_.RequestCall(&srv_ctx, &stream, &srv_cq_, tag(2));
generic_service_.RequestCall(&srv_ctx, &stream, &srv_cq_, tag(2));
verify_ok(server_->cq(), 2, true);
EXPECT_EQ(server_address_.str(), srv_ctx.host());
@ -171,22 +171,22 @@ class AnonymousEnd2endTest : public ::testing::Test {
CompletionQueue srv_cq_;
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
std::unique_ptr<Server> server_;
AnonymousService anonymous_service_;
GenericService generic_service_;
std::ostringstream server_address_;
};
TEST_F(AnonymousEnd2endTest, SimpleRpc) {
TEST_F(GenericEnd2endTest, SimpleRpc) {
ResetStub();
SendRpc(1);
}
TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
TEST_F(GenericEnd2endTest, SequentialRpcs) {
ResetStub();
SendRpc(10);
}
// // Two pings and a final pong.
// TEST_F(AnonymousEnd2endTest, SimpleClientStreaming) {
// TEST_F(GenericEnd2endTest, SimpleClientStreaming) {
// ResetStub();
//
// EchoRequest send_request;
@ -239,7 +239,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// }
//
// // One ping, two pongs.
// TEST_F(AnonymousEnd2endTest, SimpleServerStreaming) {
// TEST_F(GenericEnd2endTest, SimpleServerStreaming) {
// ResetStub();
//
// EchoRequest send_request;
@ -290,7 +290,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// }
//
// // One ping, one pong.
// TEST_F(AnonymousEnd2endTest, SimpleBidiStreaming) {
// TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
// ResetStub();
//
// EchoRequest send_request;
@ -342,7 +342,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// }
//
// // Metadata tests
// TEST_F(AnonymousEnd2endTest, ClientInitialMetadataRpc) {
// TEST_F(GenericEnd2endTest, ClientInitialMetadataRpc) {
// ResetStub();
//
// EchoRequest send_request;
@ -386,7 +386,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// EXPECT_TRUE(recv_status.IsOk());
// }
//
// TEST_F(AnonymousEnd2endTest, ServerInitialMetadataRpc) {
// TEST_F(GenericEnd2endTest, ServerInitialMetadataRpc) {
// ResetStub();
//
// EchoRequest send_request;
@ -434,7 +434,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// EXPECT_TRUE(recv_status.IsOk());
// }
//
// TEST_F(AnonymousEnd2endTest, ServerTrailingMetadataRpc) {
// TEST_F(GenericEnd2endTest, ServerTrailingMetadataRpc) {
// ResetStub();
//
// EchoRequest send_request;
@ -479,7 +479,7 @@ TEST_F(AnonymousEnd2endTest, SequentialRpcs) {
// EXPECT_EQ(static_cast<size_t>(2), server_trailing_metadata.size());
// }
//
// TEST_F(AnonymousEnd2endTest, MetadataRpc) {
// TEST_F(GenericEnd2endTest, MetadataRpc) {
// ResetStub();
//
// EchoRequest send_request;

@ -336,11 +336,6 @@
"language": "c",
"name": "transport_security_test"
},
{
"flaky": false,
"language": "c++",
"name": "anonymous_end2end_test"
},
{
"flaky": false,
"language": "c++",
@ -361,6 +356,11 @@
"language": "c++",
"name": "end2end_test"
},
{
"flaky": false,
"language": "c++",
"name": "generic_end2end_test"
},
{
"flaky": false,
"language": "c++",

Loading…
Cancel
Save