diff options
author | yang-g <yangg@google.com> | 2016-01-15 13:07:15 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-01-15 13:11:37 -0800 |
commit | ad63510102fe6a2318f8893f7609cf0b46734ab1 (patch) | |
tree | 1fa9480fddb9a8cb0790d81d82d99b87d14dfcbf /test/cpp/end2end | |
parent | 9f17314a35c6266a32e343a6c2d7c44a65991f96 (diff) |
Add a test with two methods generic
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r-- | test/cpp/end2end/hybrid_end2end_test.cc | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 3ceaf829ed..ba0ed89b96 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -140,6 +140,28 @@ void HandleGenericEcho(GenericServerAsyncReaderWriter* stream, Verify(cq, 4, true); } +void HandleGenericRequestStream(GenericServerAsyncReaderWriter* stream, + CompletionQueue* cq) { + ByteBuffer recv_buffer; + EchoRequest recv_request; + EchoResponse send_response; + int i = 1; + while (true) { + i++; + stream->Read(&recv_buffer, tag(i)); + if (!VerifyReturnSuccess(cq, i)) { + break; + } + EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request)); + send_response.mutable_message()->append(recv_request.message()); + } + auto send_buffer = SerializeToByteBuffer(&send_response); + stream->Write(*send_buffer, tag(99)); + Verify(cq, 99, true); + stream->Finish(Status::OK, tag(100)); + Verify(cq, 100, true); +} + // Request and handle one generic call. void HandleGenericCall(AsyncGenericService* service, ServerCompletionQueue* cq) { @@ -149,6 +171,9 @@ void HandleGenericCall(AsyncGenericService* service, Verify(cq, 1, true); if (srv_ctx.method() == "/grpc.testing.EchoTestService/Echo") { HandleGenericEcho(&stream, cq); + } else if (srv_ctx.method() == + "/grpc.testing.EchoTestService/RequestStream") { + HandleGenericRequestStream(&stream, cq); } else { // other methods not handled yet. gpr_log(GPR_ERROR, "method: %s", srv_ctx.method().c_str()); GPR_ASSERT(0); @@ -331,11 +356,11 @@ TEST_F(HybridEnd2endTest, GenericEcho) { AsyncGenericService generic_service; SetUpServer(&service, &generic_service); ResetStub(); - std::thread echo_handler_thread([this, &generic_service] { + std::thread generic_handler_thread([this, &generic_service] { HandleGenericCall(&generic_service, cqs_[0].get()); }); TestAllMethods(); - echo_handler_thread.join(); + generic_handler_thread.join(); } TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { @@ -344,13 +369,13 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { AsyncGenericService generic_service; SetUpServer(&service, &generic_service); ResetStub(); - std::thread echo_handler_thread([this, &generic_service] { + std::thread generic_handler_thread([this, &generic_service] { HandleGenericCall(&generic_service, cqs_[0].get()); }); std::thread request_stream_handler_thread( [this, &service] { HandleClientStreaming(&service, cqs_[1].get()); }); TestAllMethods(); - echo_handler_thread.join(); + generic_handler_thread.join(); request_stream_handler_thread.join(); } @@ -362,7 +387,7 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { AsyncGenericService generic_service; SetUpServer(&service, &generic_service); ResetStub(); - std::thread echo_handler_thread([this, &generic_service] { + std::thread generic_handler_thread([this, &generic_service] { HandleGenericCall(&generic_service, cqs_[0].get()); }); std::thread request_stream_handler_thread( @@ -370,11 +395,33 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { std::thread response_stream_handler_thread( [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); TestAllMethods(); - echo_handler_thread.join(); + generic_handler_thread.join(); request_stream_handler_thread.join(); response_stream_handler_thread.join(); } +TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { + EchoTestService::WithGenericMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo< + EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl> > > + service; + AsyncGenericService generic_service; + SetUpServer(&service, &generic_service); + ResetStub(); + std::thread generic_handler_thread([this, &generic_service] { + HandleGenericCall(&generic_service, cqs_[0].get()); + }); + std::thread generic_handler_thread2([this, &generic_service] { + HandleGenericCall(&generic_service, cqs_[1].get()); + }); + std::thread response_stream_handler_thread( + [this, &service] { HandleServerStreaming(&service, cqs_[2].get()); }); + TestAllMethods(); + generic_handler_thread.join(); + generic_handler_thread2.join(); + response_stream_handler_thread.join(); +} + } // namespace } // namespace testing } // namespace grpc |