|
|
|
@ -28,6 +28,7 @@ |
|
|
|
|
#include <grpcpp/server_builder.h> |
|
|
|
|
#include <grpcpp/server_context.h> |
|
|
|
|
|
|
|
|
|
#include "src/core/lib/iomgr/iomgr.h" |
|
|
|
|
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" |
|
|
|
|
#include "src/proto/grpc/testing/echo.grpc.pb.h" |
|
|
|
|
#include "test/core/util/port.h" |
|
|
|
@ -39,7 +40,6 @@ |
|
|
|
|
|
|
|
|
|
namespace grpc { |
|
|
|
|
namespace testing { |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
void* tag(int i) { return (void*)static_cast<intptr_t>(i); } |
|
|
|
@ -225,13 +225,23 @@ class TestServiceImplDupPkg |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class HybridEnd2endTest : public ::testing::Test { |
|
|
|
|
class HybridEnd2endTest : public ::testing::TestWithParam<bool> { |
|
|
|
|
protected: |
|
|
|
|
HybridEnd2endTest() {} |
|
|
|
|
|
|
|
|
|
void SetUpServer(::grpc::Service* service1, ::grpc::Service* service2, |
|
|
|
|
AsyncGenericService* generic_service, |
|
|
|
|
int max_message_size = 0) { |
|
|
|
|
void SetUp() override { |
|
|
|
|
inproc_ = (::testing::UnitTest::GetInstance() |
|
|
|
|
->current_test_info() |
|
|
|
|
->value_param() != nullptr) |
|
|
|
|
? GetParam() |
|
|
|
|
: false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool SetUpServer( |
|
|
|
|
::grpc::Service* service1, ::grpc::Service* service2, |
|
|
|
|
AsyncGenericService* generic_service, |
|
|
|
|
experimental::CallbackGenericService* callback_generic_service, |
|
|
|
|
int max_message_size = 0) { |
|
|
|
|
int port = grpc_pick_unused_port_or_die(); |
|
|
|
|
server_address_ << "localhost:" << port; |
|
|
|
|
|
|
|
|
@ -249,6 +259,10 @@ class HybridEnd2endTest : public ::testing::Test { |
|
|
|
|
if (generic_service) { |
|
|
|
|
builder.RegisterAsyncGenericService(generic_service); |
|
|
|
|
} |
|
|
|
|
if (callback_generic_service) { |
|
|
|
|
builder.experimental().RegisterCallbackGenericService( |
|
|
|
|
callback_generic_service); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (max_message_size != 0) { |
|
|
|
|
builder.SetMaxMessageSize(max_message_size); |
|
|
|
@ -259,6 +273,11 @@ class HybridEnd2endTest : public ::testing::Test { |
|
|
|
|
cqs_.push_back(builder.AddCompletionQueue(false)); |
|
|
|
|
} |
|
|
|
|
server_ = builder.BuildAndStart(); |
|
|
|
|
|
|
|
|
|
// If there is a generic callback service, this setup is only successful if
|
|
|
|
|
// we have an iomgr that can run in the background or are inprocess
|
|
|
|
|
return !callback_generic_service || grpc_iomgr_run_in_background() || |
|
|
|
|
inproc_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TearDown() override { |
|
|
|
@ -276,7 +295,9 @@ class HybridEnd2endTest : public ::testing::Test { |
|
|
|
|
|
|
|
|
|
void ResetStub() { |
|
|
|
|
std::shared_ptr<Channel> channel = |
|
|
|
|
CreateChannel(server_address_.str(), InsecureChannelCredentials()); |
|
|
|
|
inproc_ ? server_->InProcessChannel(ChannelArguments()) |
|
|
|
|
: CreateChannel(server_address_.str(), |
|
|
|
|
InsecureChannelCredentials()); |
|
|
|
|
stub_ = grpc::testing::EchoTestService::NewStub(channel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -411,12 +432,13 @@ class HybridEnd2endTest : public ::testing::Test { |
|
|
|
|
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; |
|
|
|
|
std::unique_ptr<Server> server_; |
|
|
|
|
std::ostringstream server_address_; |
|
|
|
|
bool inproc_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
TEST_F(HybridEnd2endTest, AsyncEcho) { |
|
|
|
|
typedef EchoTestService::WithAsyncMethod_Echo<TestServiceImpl> SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread echo_handler_thread(HandleEcho<SType>, &service, cqs_[0].get(), |
|
|
|
|
false); |
|
|
|
@ -427,7 +449,7 @@ TEST_F(HybridEnd2endTest, AsyncEcho) { |
|
|
|
|
TEST_F(HybridEnd2endTest, RawEcho) { |
|
|
|
|
typedef EchoTestService::WithRawMethod_Echo<TestServiceImpl> SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread echo_handler_thread(HandleRawEcho<SType>, &service, cqs_[0].get(), |
|
|
|
|
false); |
|
|
|
@ -438,7 +460,7 @@ TEST_F(HybridEnd2endTest, RawEcho) { |
|
|
|
|
TEST_F(HybridEnd2endTest, RawRequestStream) { |
|
|
|
|
typedef EchoTestService::WithRawMethod_RequestStream<TestServiceImpl> SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread request_stream_handler_thread(HandleRawClientStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -451,7 +473,7 @@ TEST_F(HybridEnd2endTest, AsyncEchoRawRequestStream) { |
|
|
|
|
EchoTestService::WithAsyncMethod_Echo<TestServiceImpl>> |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread echo_handler_thread(HandleEcho<SType>, &service, cqs_[0].get(), |
|
|
|
|
false); |
|
|
|
@ -468,7 +490,7 @@ TEST_F(HybridEnd2endTest, GenericEchoRawRequestStream) { |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service); |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -484,7 +506,7 @@ TEST_F(HybridEnd2endTest, AsyncEchoRequestStream) { |
|
|
|
|
EchoTestService::WithAsyncMethod_Echo<TestServiceImpl>> |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread echo_handler_thread(HandleEcho<SType>, &service, cqs_[0].get(), |
|
|
|
|
false); |
|
|
|
@ -500,7 +522,7 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream) { |
|
|
|
|
EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>> |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -518,7 +540,7 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_SyncDupService) { |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
TestServiceImplDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -557,7 +579,7 @@ TEST_F(HybridEnd2endTest, |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
StreamedUnaryDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, 8192); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr, 8192); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -595,7 +617,7 @@ TEST_F(HybridEnd2endTest, |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
FullyStreamedUnaryDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, 8192); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr, 8192); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -636,7 +658,7 @@ TEST_F(HybridEnd2endTest, |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
SplitResponseStreamDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, 8192); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr, 8192); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -676,7 +698,7 @@ TEST_F(HybridEnd2endTest, |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
FullySplitStreamedDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, 8192); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr, 8192); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -728,7 +750,7 @@ TEST_F(HybridEnd2endTest, |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
FullyStreamedDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, 8192); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr, 8192); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -748,7 +770,7 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
duplicate::EchoTestService::AsyncService dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr); |
|
|
|
|
SetUpServer(&service, &dup_service, nullptr, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread response_stream_handler_thread(HandleServerStreaming<SType>, |
|
|
|
|
&service, cqs_[0].get()); |
|
|
|
@ -767,7 +789,7 @@ TEST_F(HybridEnd2endTest, AsyncRequestStreamResponseStream_AsyncDupService) { |
|
|
|
|
TEST_F(HybridEnd2endTest, GenericEcho) { |
|
|
|
|
EchoTestService::WithGenericMethod_Echo<TestServiceImpl> service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service); |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -775,13 +797,56 @@ TEST_F(HybridEnd2endTest, GenericEcho) { |
|
|
|
|
generic_handler_thread.join(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_P(HybridEnd2endTest, CallbackGenericEcho) { |
|
|
|
|
EchoTestService::WithGenericMethod_Echo<TestServiceImpl> service; |
|
|
|
|
class GenericEchoService : public experimental::CallbackGenericService { |
|
|
|
|
private: |
|
|
|
|
experimental::ServerGenericBidiReactor* CreateReactor() override { |
|
|
|
|
class Reactor : public experimental::ServerGenericBidiReactor { |
|
|
|
|
private: |
|
|
|
|
void OnStarted(GenericServerContext* ctx) override { |
|
|
|
|
ctx_ = ctx; |
|
|
|
|
EXPECT_EQ(ctx->method(), "/grpc.testing.EchoTestService/Echo"); |
|
|
|
|
StartRead(&request_); |
|
|
|
|
} |
|
|
|
|
void OnDone() override { delete this; } |
|
|
|
|
void OnReadDone(bool ok) override { |
|
|
|
|
if (!ok) { |
|
|
|
|
EXPECT_EQ(reads_complete_, 1); |
|
|
|
|
} else { |
|
|
|
|
EXPECT_EQ(reads_complete_++, 0); |
|
|
|
|
response_ = request_; |
|
|
|
|
StartWrite(&response_); |
|
|
|
|
StartRead(&request_); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
void OnWriteDone(bool ok) override { |
|
|
|
|
Finish(ok ? Status::OK |
|
|
|
|
: Status(StatusCode::UNKNOWN, "Unexpected failure")); |
|
|
|
|
} |
|
|
|
|
GenericServerContext* ctx_; |
|
|
|
|
ByteBuffer request_; |
|
|
|
|
ByteBuffer response_; |
|
|
|
|
std::atomic_int reads_complete_{0}; |
|
|
|
|
}; |
|
|
|
|
return new Reactor; |
|
|
|
|
} |
|
|
|
|
} generic_service; |
|
|
|
|
|
|
|
|
|
if (!SetUpServer(&service, nullptr, nullptr, &generic_service)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
ResetStub(); |
|
|
|
|
TestAllMethods(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream) { |
|
|
|
|
typedef EchoTestService::WithAsyncMethod_RequestStream< |
|
|
|
|
EchoTestService::WithGenericMethod_Echo<TestServiceImpl>> |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service); |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -800,7 +865,7 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_SyncDupService) { |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
TestServiceImplDupPkg dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, &generic_service); |
|
|
|
|
SetUpServer(&service, &dup_service, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -820,7 +885,7 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStream_AsyncDupService) { |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
duplicate::EchoTestService::AsyncService dup_service; |
|
|
|
|
SetUpServer(&service, &dup_service, &generic_service); |
|
|
|
|
SetUpServer(&service, &dup_service, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -843,7 +908,7 @@ TEST_F(HybridEnd2endTest, GenericEchoAsyncRequestStreamResponseStream) { |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service); |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -864,7 +929,7 @@ TEST_F(HybridEnd2endTest, GenericEchoRequestStreamAsyncResponseStream) { |
|
|
|
|
SType; |
|
|
|
|
SType service; |
|
|
|
|
AsyncGenericService generic_service; |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service); |
|
|
|
|
SetUpServer(&service, nullptr, &generic_service, nullptr); |
|
|
|
|
ResetStub(); |
|
|
|
|
std::thread generic_handler_thread(HandleGenericCall, &generic_service, |
|
|
|
|
cqs_[0].get()); |
|
|
|
@ -885,10 +950,13 @@ TEST_F(HybridEnd2endTest, GenericMethodWithoutGenericService) { |
|
|
|
|
EchoTestService::WithGenericMethod_Echo< |
|
|
|
|
EchoTestService::WithAsyncMethod_ResponseStream<TestServiceImpl>>> |
|
|
|
|
service; |
|
|
|
|
SetUpServer(&service, nullptr, nullptr); |
|
|
|
|
SetUpServer(&service, nullptr, nullptr, nullptr); |
|
|
|
|
EXPECT_EQ(nullptr, server_.get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(HybridEnd2endTest, HybridEnd2endTest, |
|
|
|
|
::testing::Bool()); |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace testing
|
|
|
|
|
} // namespace grpc
|
|
|
|
|