clang-format code

pull/4722/head
Craig Tiller 9 years ago
parent 6d32e873a6
commit 754bd26e28
  1. 2
      include/grpc++/support/byte_buffer.h
  2. 9
      src/cpp/util/byte_buffer.cc
  3. 34
      test/cpp/qps/client_async.cc
  4. 2
      test/cpp/qps/qps_driver.cc
  5. 32
      test/cpp/qps/server_async.cc

@ -57,7 +57,7 @@ class ByteBuffer GRPC_FINAL {
/// Constuct a byte buffer by referencing elements of existing buffer /// Constuct a byte buffer by referencing elements of existing buffer
/// \a buf. Wrapper of core function grpc_byte_buffer_copy /// \a buf. Wrapper of core function grpc_byte_buffer_copy
ByteBuffer(const ByteBuffer&buf); ByteBuffer(const ByteBuffer& buf);
~ByteBuffer(); ~ByteBuffer();

@ -79,13 +79,12 @@ size_t ByteBuffer::Length() const {
} }
} }
ByteBuffer::ByteBuffer(const ByteBuffer& buf): ByteBuffer::ByteBuffer(const ByteBuffer& buf)
buffer_(grpc_byte_buffer_copy(buf.buffer_)) { : buffer_(grpc_byte_buffer_copy(buf.buffer_)) {}
}
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
Clear(); // first remove existing data Clear(); // first remove existing data
buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy
return *this; return *this;
} }

@ -93,8 +93,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
std::function< std::function<
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>( std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&, BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)> CompletionQueue*)> start_req,
start_req,
std::function<void(grpc::Status, ResponseType*)> on_done) std::function<void(grpc::Status, ResponseType*)> on_done)
: ClientRpcContext(channel_id), : ClientRpcContext(channel_id),
context_(), context_(),
@ -140,8 +139,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
std::function<void(grpc::Status, ResponseType*)> callback_; std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>( std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&, BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)> CompletionQueue*)> start_req_;
start_req_;
grpc::Status status_; grpc::Status status_;
double start_; double start_;
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>> std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>
@ -160,12 +158,11 @@ class AsyncClient : public ClientImpl<StubType, RequestType> {
using Client::closed_loop_; using Client::closed_loop_;
using ClientImpl<StubType, RequestType>::channels_; using ClientImpl<StubType, RequestType>::channels_;
using ClientImpl<StubType, RequestType>::request_; using ClientImpl<StubType, RequestType>::request_;
AsyncClient( AsyncClient(const ClientConfig& config,
const ClientConfig& config, std::function<ClientRpcContext*(int, StubType*,
std::function<ClientRpcContext*(int, StubType*, const RequestType&)> const RequestType&)> setup_ctx,
setup_ctx, std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)>
std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)> create_stub)
create_stub)
: ClientImpl<StubType, RequestType>(config, create_stub), : ClientImpl<StubType, RequestType>(config, create_stub),
channel_lock_(new std::mutex[config.client_channels()]), channel_lock_(new std::mutex[config.client_channels()]),
contexts_(config.client_channels()), contexts_(config.client_channels()),
@ -394,8 +391,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
std::function<std::unique_ptr< std::function<std::unique_ptr<
grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>( grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*,
void*)> void*)> start_req,
start_req,
std::function<void(grpc::Status, ResponseType*)> on_done) std::function<void(grpc::Status, ResponseType*)> on_done)
: ClientRpcContext(channel_id), : ClientRpcContext(channel_id),
context_(), context_(),
@ -447,10 +443,10 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
ResponseType response_; ResponseType response_;
bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram*); bool (ClientRpcContextStreamingImpl::*next_state_)(bool, Histogram*);
std::function<void(grpc::Status, ResponseType*)> callback_; std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<std::unique_ptr< std::function<
grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>( std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, void*)> BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*,
start_req_; void*)> start_req_;
grpc::Status status_; grpc::Status status_;
double start_; double start_;
std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>> std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>
@ -494,8 +490,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
int channel_id, grpc::GenericStub* stub, const ByteBuffer& req, int channel_id, grpc::GenericStub* stub, const ByteBuffer& req,
std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>( std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
grpc::GenericStub*, grpc::ClientContext*, grpc::GenericStub*, grpc::ClientContext*,
const grpc::string& method_name, CompletionQueue*, void*)> const grpc::string& method_name, CompletionQueue*, void*)> start_req,
start_req,
std::function<void(grpc::Status, ByteBuffer*)> on_done) std::function<void(grpc::Status, ByteBuffer*)> on_done)
: ClientRpcContext(channel_id), : ClientRpcContext(channel_id),
context_(), context_(),
@ -552,8 +547,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
std::function<void(grpc::Status, ByteBuffer*)> callback_; std::function<void(grpc::Status, ByteBuffer*)> callback_;
std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>( std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
grpc::GenericStub*, grpc::ClientContext*, const grpc::string&, grpc::GenericStub*, grpc::ClientContext*, const grpc::string&,
CompletionQueue*, void*)> CompletionQueue*, void*)> start_req_;
start_req_;
grpc::Status status_; grpc::Status status_;
double start_; double start_;
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> stream_; std::unique_ptr<grpc::GenericClientAsyncReaderWriter> stream_;

@ -113,7 +113,7 @@ static void QpsDriver() {
} }
} else if (FLAGS_bbuf_resp_size >= 0) { } else if (FLAGS_bbuf_resp_size >= 0) {
auto params = auto params =
client_config.mutable_payload_config()->mutable_bytebuf_params(); client_config.mutable_payload_config()->mutable_bytebuf_params();
params->set_resp_size(FLAGS_bbuf_resp_size); params->set_resp_size(FLAGS_bbuf_resp_size);
if (FLAGS_bbuf_req_size >= 0) { if (FLAGS_bbuf_req_size >= 0) {
params->set_req_size(FLAGS_bbuf_req_size); params->set_req_size(FLAGS_bbuf_req_size);

@ -72,8 +72,7 @@ class AsyncQpsServerTest : public Server {
CompletionQueue *, ServerCompletionQueue *, void *)> CompletionQueue *, ServerCompletionQueue *, void *)>
request_streaming_function, request_streaming_function,
std::function<grpc::Status(const PayloadConfig &, const RequestType *, std::function<grpc::Status(const PayloadConfig &, const RequestType *,
ResponseType *)> ResponseType *)> process_rpc)
process_rpc)
: Server(config) { : Server(config) {
char *server_address = NULL; char *server_address = NULL;
@ -94,8 +93,8 @@ class AsyncQpsServerTest : public Server {
using namespace std::placeholders; using namespace std::placeholders;
auto process_rpc_bound = std::bind(process_rpc, config.payload_config(), auto process_rpc_bound =
_1, _2); std::bind(process_rpc, config.payload_config(), _1, _2);
for (int i = 0; i < 10000 / config.async_server_threads(); i++) { for (int i = 0; i < 10000 / config.async_server_threads(); i++) {
for (int j = 0; j < config.async_server_threads(); j++) { for (int j = 0; j < config.async_server_threads(); j++) {
@ -185,8 +184,7 @@ class AsyncQpsServerTest : public Server {
ServerRpcContextUnaryImpl( ServerRpcContextUnaryImpl(
std::function<void(ServerContextType *, RequestType *, std::function<void(ServerContextType *, RequestType *,
grpc::ServerAsyncResponseWriter<ResponseType> *, grpc::ServerAsyncResponseWriter<ResponseType> *,
void *)> void *)> request_method,
request_method,
std::function<grpc::Status(const RequestType *, ResponseType *)> std::function<grpc::Status(const RequestType *, ResponseType *)>
invoke_method) invoke_method)
: srv_ctx_(new ServerContextType), : srv_ctx_(new ServerContextType),
@ -359,8 +357,7 @@ static void RegisterGenericService(ServerBuilder *builder,
builder->RegisterAsyncGenericService(service); builder->RegisterAsyncGenericService(service);
} }
static Status ProcessSimpleRPC(const PayloadConfig &,
static Status ProcessSimpleRPC(const PayloadConfig&,
const SimpleRequest *request, const SimpleRequest *request,
SimpleResponse *response) { SimpleResponse *response) {
if (request->response_size() > 0) { if (request->response_size() > 0) {
@ -372,7 +369,7 @@ static Status ProcessSimpleRPC(const PayloadConfig&,
return Status::OK; return Status::OK;
} }
static Status ProcessGenericRPC(const PayloadConfig& payload_config, static Status ProcessGenericRPC(const PayloadConfig &payload_config,
const ByteBuffer *request, const ByteBuffer *request,
ByteBuffer *response) { ByteBuffer *response) {
int resp_size = payload_config.bytebuf_params().resp_size(); int resp_size = payload_config.bytebuf_params().resp_size();
@ -384,22 +381,19 @@ static Status ProcessGenericRPC(const PayloadConfig& payload_config,
} }
std::unique_ptr<Server> CreateAsyncServer(const ServerConfig &config) { std::unique_ptr<Server> CreateAsyncServer(const ServerConfig &config) {
return std::unique_ptr<Server>( return std::unique_ptr<Server>(new AsyncQpsServerTest<
new AsyncQpsServerTest<SimpleRequest, SimpleResponse, SimpleRequest, SimpleResponse, BenchmarkService::AsyncService,
BenchmarkService::AsyncService, grpc::ServerContext>(
grpc::ServerContext>( config, RegisterBenchmarkService,
config, RegisterBenchmarkService, &BenchmarkService::AsyncService::RequestUnaryCall,
&BenchmarkService::AsyncService::RequestUnaryCall, &BenchmarkService::AsyncService::RequestStreamingCall, ProcessSimpleRPC));
&BenchmarkService::AsyncService::RequestStreamingCall,
ProcessSimpleRPC));
} }
std::unique_ptr<Server> CreateAsyncGenericServer(const ServerConfig &config) { std::unique_ptr<Server> CreateAsyncGenericServer(const ServerConfig &config) {
return std::unique_ptr<Server>( return std::unique_ptr<Server>(
new AsyncQpsServerTest<ByteBuffer, ByteBuffer, grpc::AsyncGenericService, new AsyncQpsServerTest<ByteBuffer, ByteBuffer, grpc::AsyncGenericService,
grpc::GenericServerContext>( grpc::GenericServerContext>(
config, RegisterGenericService, nullptr, config, RegisterGenericService, nullptr,
&grpc::AsyncGenericService::RequestCall, &grpc::AsyncGenericService::RequestCall, ProcessGenericRPC));
ProcessGenericRPC));
} }
} // namespace testing } // namespace testing

Loading…
Cancel
Save