clang-format

pull/5997/head
Vijay Pai 9 years ago
parent bbbbf621e4
commit 40d1a2cb87
  1. 39
      test/cpp/end2end/thread_stress_test.cc

@ -187,8 +187,9 @@ class CommonStressTest {
stub_ = grpc::testing::EchoTestService::NewStub(channel); stub_ = grpc::testing::EchoTestService::NewStub(channel);
} }
grpc::testing::EchoTestService::Stub* GetStub() { return stub_.get(); } grpc::testing::EchoTestService::Stub* GetStub() { return stub_.get(); }
protected: protected:
void SetUpStart(ServerBuilder *builder, Service *service) { void SetUpStart(ServerBuilder* builder, Service* service) {
int port = grpc_pick_unused_port_or_die(); int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port; server_address_ << "localhost:" << port;
// Setup server // Setup server
@ -199,11 +200,10 @@ class CommonStressTest {
kMaxMessageSize_); // For testing max message size. kMaxMessageSize_); // For testing max message size.
builder->RegisterService(&dup_pkg_service_); builder->RegisterService(&dup_pkg_service_);
} }
void SetUpEnd(ServerBuilder *builder) { void SetUpEnd(ServerBuilder* builder) { server_ = builder->BuildAndStart(); }
server_ = builder->BuildAndStart();
}
void TearDownStart() { server_->Shutdown(); } void TearDownStart() { server_->Shutdown(); }
void TearDownEnd() { } void TearDownEnd() {}
private: private:
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
std::unique_ptr<Server> server_; std::unique_ptr<Server> server_;
@ -223,12 +223,13 @@ class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> {
TearDownStart(); TearDownStart();
TearDownEnd(); TearDownEnd();
} }
private: private:
TestServiceImpl service_; TestServiceImpl service_;
}; };
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;
@ -241,7 +242,8 @@ class CommonStressTestAsyncServer :
RefreshContext(i); RefreshContext(i);
} }
for (int i = 0; i < kNumAsyncServerThreads; i++) { for (int i = 0; i < kNumAsyncServerThreads; i++) {
server_threads_.push_back(new std::thread(&CommonStressTestAsyncServer::ProcessRpcs, this)); server_threads_.push_back(
new std::thread(&CommonStressTestAsyncServer::ProcessRpcs, this));
} }
} }
void TearDown() GRPC_OVERRIDE { void TearDown() GRPC_OVERRIDE {
@ -264,9 +266,10 @@ class CommonStressTestAsyncServer :
TearDownEnd(); TearDownEnd();
delete[] contexts_; delete[] contexts_;
} }
private: private:
void ProcessRpcs() { void ProcessRpcs() {
void *tag; void* tag;
bool ok; bool ok;
while (cq_->Next(&tag, &ok)) { while (cq_->Next(&tag, &ok)) {
if (ok) { if (ok) {
@ -276,7 +279,8 @@ class CommonStressTestAsyncServer :
contexts_[i].state = Context::DONE; contexts_[i].state = Context::DONE;
EchoResponse send_response; EchoResponse send_response;
send_response.set_message(contexts_[i].recv_request.message()); send_response.set_message(contexts_[i].recv_request.message());
contexts_[i].response_writer->Finish(send_response, Status::OK, tag); contexts_[i].response_writer->Finish(send_response, Status::OK,
tag);
break; break;
} }
case Context::DONE: case Context::DONE:
@ -291,8 +295,11 @@ class CommonStressTestAsyncServer :
if (!shutting_down_) { if (!shutting_down_) {
contexts_[i].state = Context::READY; contexts_[i].state = Context::READY;
contexts_[i].srv_ctx.reset(new ServerContext); contexts_[i].srv_ctx.reset(new ServerContext);
contexts_[i].response_writer.reset(new grpc::ServerAsyncResponseWriter<EchoResponse>(contexts_[i].srv_ctx.get())); contexts_[i].response_writer.reset(
service_.RequestEcho(contexts_[i].srv_ctx.get(), &contexts_[i].recv_request, new grpc::ServerAsyncResponseWriter<EchoResponse>(
contexts_[i].srv_ctx.get()));
service_.RequestEcho(contexts_[i].srv_ctx.get(),
&contexts_[i].recv_request,
contexts_[i].response_writer.get(), cq_.get(), contexts_[i].response_writer.get(), cq_.get(),
cq_.get(), (void*)(intptr_t)i); cq_.get(), (void*)(intptr_t)i);
} }
@ -300,15 +307,15 @@ class CommonStressTestAsyncServer :
struct Context { struct Context {
std::unique_ptr<ServerContext> srv_ctx; std::unique_ptr<ServerContext> srv_ctx;
std::unique_ptr<grpc::ServerAsyncResponseWriter<EchoResponse>> std::unique_ptr<grpc::ServerAsyncResponseWriter<EchoResponse>>
response_writer; response_writer;
EchoRequest recv_request; EchoRequest recv_request;
enum {READY, DONE} state; enum { READY, DONE } state;
} *contexts_; } * contexts_;
::grpc::testing::EchoTestService::AsyncService service_; ::grpc::testing::EchoTestService::AsyncService service_;
std::unique_ptr<ServerCompletionQueue> cq_; std::unique_ptr<ServerCompletionQueue> cq_;
bool shutting_down_; bool shutting_down_;
mutex mu_; mutex mu_;
std::vector<std::thread *> server_threads_; std::vector<std::thread*> server_threads_;
}; };
class End2endTest : public ::testing::Test { class End2endTest : public ::testing::Test {

Loading…
Cancel
Save