Making split streaming testable

pull/8365/head
Vijay Pai 8 years ago
parent 22fcbf9663
commit 61536a7371
  1. 3
      include/grpc++/impl/codegen/method_handler_impl.h
  2. 2
      src/compiler/cpp_generator.cc
  3. 1
      src/proto/grpc/testing/duplicate/echo_duplicate.proto
  4. 61
      test/cpp/end2end/hybrid_end2end_test.cc

@ -243,8 +243,7 @@ class SplitServerStreamingHandler
public:
explicit SplitServerStreamingHandler(
std::function<Status(ServerContext*,
SplitServerStreamingHandler<RequestType,
ResponseType>*)>
ServerSplitStreamer<RequestType, ResponseType>*)>
func)
: TemplatedBidiStreamingHandler<
ServerSplitStreamer<RequestType, ResponseType>, false>(func) {}

@ -691,7 +691,7 @@ void PrintHeaderServerMethodSplitStreaming(
"// disable regular version of this method\n"
"::grpc::Status $Method$("
"::grpc::ServerContext* context, const $Request$* request, "
"$Response$* response) GRPC_FINAL GRPC_OVERRIDE {\n"
"::grpc::ServerWriter< $Response$>* writer) GRPC_FINAL GRPC_OVERRIDE {\n"
" abort();\n"
" return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"
"}\n");

@ -38,4 +38,5 @@ package grpc.testing.duplicate;
service EchoTestService {
rpc Echo(grpc.testing.EchoRequest) returns (grpc.testing.EchoResponse);
rpc ResponseStream(EchoRequest) returns (stream EchoResponse);
}

@ -320,6 +320,26 @@ class HybridEnd2endTest : public ::testing::Test {
EXPECT_TRUE(s.ok());
}
void SendSimpleServerStreamingToDupService() {
EchoRequest request;
EchoResponse response;
ClientContext context;
context.set_wait_for_ready(true);
request.set_message("hello");
auto stream = stub_->ResponseStream(&context, request);
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message() + "0_dup");
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message() + "1_dup");
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message() + "2_dup");
EXPECT_FALSE(stream->Read(&response));
Status s = stream->Finish();
EXPECT_TRUE(s.ok());
}
void SendBidiStreaming() {
EchoRequest request;
EchoResponse response;
@ -498,6 +518,47 @@ TEST_F(HybridEnd2endTest,
request_stream_handler_thread.join();
}
// Add a second service with one sync split server streaming method.
class SplitResponseStreamDupPkg
: public duplicate::EchoTestService::WithSplitStreamingMethod_ResponseStream<
TestServiceImplDupPkg> {
public:
Status StreamedResponseStream(ServerContext* context,
ServerSplitStreamer<EchoRequest, EchoResponse>* stream)
GRPC_OVERRIDE {
EchoRequest req;
EchoResponse resp;
uint32_t next_msg_sz;
stream->NextMessageSize(&next_msg_sz);
gpr_log(GPR_INFO, "Split Streamed Next Message Size is %u", next_msg_sz);
GPR_ASSERT(stream->Read(&req));
for (int i = 0; i < kNumResponseStreamsMsgs; i++) {
resp.set_message(req.message() + grpc::to_string(i) + "_dup");
GPR_ASSERT(stream->Write(resp));
}
return Status::OK;
}
};
TEST_F(HybridEnd2endTest,
AsyncRequestStreamResponseStream_SyncSplitStreamedDupService) {
typedef EchoTestService::WithAsyncMethod_RequestStream<
EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>
SType;
SType service;
SplitResponseStreamDupPkg dup_service;
SetUpServer(&service, &dup_service, nullptr, 8192);
ResetStub();
std::thread response_stream_handler_thread(HandleServerStreaming<SType>,
&service, cqs_[0].get());
std::thread request_stream_handler_thread(HandleClientStreaming<SType>,
&service, cqs_[1].get());
TestAllMethods();
SendSimpleServerStreamingToDupService();
response_stream_handler_thread.join();
request_stream_handler_thread.join();
}
// Add a second service with one async method.
TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) {
typedef EchoTestService::WithAsyncMethod_RequestStream<

Loading…
Cancel
Save