aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar Noah Eisen <ncteisen@google.com>2017-04-25 17:01:08 -0700
committerGravatar Noah Eisen <ncteisen@google.com>2017-04-25 17:01:08 -0700
commitf725d7e6b6ac57641e67f363f3e3b585d074f0e2 (patch)
tree08d98309e9fe0993e6fb33e79662776fc7cc5b54 /test/cpp
parentad8d36d4dcd4deeec2d05644b78eb78ae0918f06 (diff)
parentb864e7c41c6d0363e23093fb090625f260994962 (diff)
Merge branch 'master' of https://github.com/grpc/grpc into client-auth-filter-fuzz
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/codegen/BUILD2
-rw-r--r--test/cpp/codegen/compiler_test_golden144
-rw-r--r--test/cpp/codegen/compiler_test_mock_golden34
-rw-r--r--test/cpp/codegen/golden_file_test.cc31
-rw-r--r--test/cpp/end2end/BUILD1
-rw-r--r--test/cpp/end2end/async_end2end_test.cc28
-rw-r--r--test/cpp/end2end/mock_test.cc278
-rw-r--r--test/cpp/microbenchmarks/fullstack_fixtures.h26
8 files changed, 415 insertions, 129 deletions
diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD
index 14d5733da2..43d133fc34 100644
--- a/test/cpp/codegen/BUILD
+++ b/test/cpp/codegen/BUILD
@@ -62,7 +62,7 @@ cc_test(
cc_test(
name = "golden_file_test",
srcs = ["golden_file_test.cc"],
- args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/compiler_test.grpc.pb.h"],
+ args = ["--generated_file_path=$(GENDIR)/src/proto/grpc/testing/"],
data = [
":compiler_test_golden",
"//src/proto/grpc/testing:_compiler_test_proto_grpc_codegen",
diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden
index fd26a17ac1..8e3ae32a49 100644
--- a/test/cpp/codegen/compiler_test_golden
+++ b/test/cpp/codegen/compiler_test_golden
@@ -89,10 +89,30 @@ class ServiceA final {
return std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag));
}
// MethodA2 trailing comment 1
+ // Method A3 leading comment 1
+ std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) {
+ return std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>>(MethodA3Raw(context, request));
+ }
+ std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag));
+ }
+ // Method A3 trailing comment 1
+ // Method A4 leading comment 1
+ std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) {
+ return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context));
+ }
+ std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag));
+ }
+ // Method A4 trailing comment 1
private:
virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientWriterInterface< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) = 0;
virtual ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) = 0;
+ virtual ::grpc::ClientReaderInterface< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) = 0;
+ virtual ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) = 0;
+ virtual ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) = 0;
+ virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0;
};
class Stub final : public StubInterface {
public:
@@ -107,14 +127,32 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>> AsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) {
+ return std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>>(MethodA3Raw(context, request));
+ }
+ std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) {
+ return std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag));
+ }
+ std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) {
+ return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context));
+ }
+ std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag));
+ }
private:
std::shared_ptr< ::grpc::ChannelInterface> channel_;
::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
::grpc::ClientWriter< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) override;
::grpc::ClientAsyncWriter< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) override;
+ ::grpc::ClientReader< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) override;
+ ::grpc::ClientAsyncReader< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) override;
+ ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) override;
+ ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) override;
const ::grpc::RpcMethod rpcmethod_MethodA1_;
const ::grpc::RpcMethod rpcmethod_MethodA2_;
+ const ::grpc::RpcMethod rpcmethod_MethodA3_;
+ const ::grpc::RpcMethod rpcmethod_MethodA4_;
};
static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
@@ -131,6 +169,12 @@ class ServiceA final {
// Method A2 leading comment 2
virtual ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response);
// MethodA2 trailing comment 1
+ // Method A3 leading comment 1
+ virtual ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer);
+ // Method A3 trailing comment 1
+ // Method A4 leading comment 1
+ virtual ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream);
+ // Method A4 trailing comment 1
};
template <class BaseClass>
class WithAsyncMethod_MethodA1 : public BaseClass {
@@ -172,7 +216,47 @@ class ServiceA final {
::grpc::Service::RequestAsyncClientStreaming(1, context, reader, new_call_cq, notification_cq, tag);
}
};
- typedef WithAsyncMethod_MethodA1<WithAsyncMethod_MethodA2<Service > > AsyncService;
+ template <class BaseClass>
+ class WithAsyncMethod_MethodA3 : public BaseClass {
+ private:
+ void BaseClassMustBeDerivedFromService(const Service *service) {}
+ public:
+ WithAsyncMethod_MethodA3() {
+ ::grpc::Service::MarkMethodAsync(2);
+ }
+ ~WithAsyncMethod_MethodA3() override {
+ BaseClassMustBeDerivedFromService(this);
+ }
+ // disable synchronous version of this method
+ ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override {
+ abort();
+ return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+ }
+ void RequestMethodA3(::grpc::ServerContext* context, ::grpc::testing::Request* request, ::grpc::ServerAsyncWriter< ::grpc::testing::Response>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+ ::grpc::Service::RequestAsyncServerStreaming(2, context, request, writer, new_call_cq, notification_cq, tag);
+ }
+ };
+ template <class BaseClass>
+ class WithAsyncMethod_MethodA4 : public BaseClass {
+ private:
+ void BaseClassMustBeDerivedFromService(const Service *service) {}
+ public:
+ WithAsyncMethod_MethodA4() {
+ ::grpc::Service::MarkMethodAsync(3);
+ }
+ ~WithAsyncMethod_MethodA4() override {
+ BaseClassMustBeDerivedFromService(this);
+ }
+ // disable synchronous version of this method
+ ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override {
+ abort();
+ return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+ }
+ void RequestMethodA4(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
+ ::grpc::Service::RequestAsyncBidiStreaming(3, context, stream, new_call_cq, notification_cq, tag);
+ }
+ };
+ typedef WithAsyncMethod_MethodA1<WithAsyncMethod_MethodA2<WithAsyncMethod_MethodA3<WithAsyncMethod_MethodA4<Service > > > > AsyncService;
template <class BaseClass>
class WithGenericMethod_MethodA1 : public BaseClass {
private:
@@ -208,6 +292,40 @@ class ServiceA final {
}
};
template <class BaseClass>
+ class WithGenericMethod_MethodA3 : public BaseClass {
+ private:
+ void BaseClassMustBeDerivedFromService(const Service *service) {}
+ public:
+ WithGenericMethod_MethodA3() {
+ ::grpc::Service::MarkMethodGeneric(2);
+ }
+ ~WithGenericMethod_MethodA3() override {
+ BaseClassMustBeDerivedFromService(this);
+ }
+ // disable synchronous version of this method
+ ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override {
+ abort();
+ return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+ }
+ };
+ template <class BaseClass>
+ class WithGenericMethod_MethodA4 : public BaseClass {
+ private:
+ void BaseClassMustBeDerivedFromService(const Service *service) {}
+ public:
+ WithGenericMethod_MethodA4() {
+ ::grpc::Service::MarkMethodGeneric(3);
+ }
+ ~WithGenericMethod_MethodA4() override {
+ BaseClassMustBeDerivedFromService(this);
+ }
+ // disable synchronous version of this method
+ ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override {
+ abort();
+ return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+ }
+ };
+ template <class BaseClass>
class WithStreamedUnaryMethod_MethodA1 : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(const Service *service) {}
@@ -228,8 +346,28 @@ class ServiceA final {
virtual ::grpc::Status StreamedMethodA1(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_unary_streamer) = 0;
};
typedef WithStreamedUnaryMethod_MethodA1<Service > StreamedUnaryService;
- typedef Service SplitStreamedService;
- typedef WithStreamedUnaryMethod_MethodA1<Service > StreamedService;
+ template <class BaseClass>
+ class WithSplitStreamingMethod_MethodA3 : public BaseClass {
+ private:
+ void BaseClassMustBeDerivedFromService(const Service *service) {}
+ public:
+ WithSplitStreamingMethod_MethodA3() {
+ ::grpc::Service::MarkMethodStreamed(2,
+ new ::grpc::SplitServerStreamingHandler< ::grpc::testing::Request, ::grpc::testing::Response>(std::bind(&WithSplitStreamingMethod_MethodA3<BaseClass>::StreamedMethodA3, this, std::placeholders::_1, std::placeholders::_2)));
+ }
+ ~WithSplitStreamingMethod_MethodA3() override {
+ BaseClassMustBeDerivedFromService(this);
+ }
+ // disable regular version of this method
+ ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override {
+ abort();
+ return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
+ }
+ // replace default version of method with split streamed
+ virtual ::grpc::Status StreamedMethodA3(::grpc::ServerContext* context, ::grpc::ServerSplitStreamer< ::grpc::testing::Request,::grpc::testing::Response>* server_split_streamer) = 0;
+ };
+ typedef WithSplitStreamingMethod_MethodA3<Service > SplitStreamedService;
+ typedef WithStreamedUnaryMethod_MethodA1<WithSplitStreamingMethod_MethodA3<Service > > StreamedService;
};
// ServiceB leading comment 1
diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden
new file mode 100644
index 0000000000..8e4b4d5911
--- /dev/null
+++ b/test/cpp/codegen/compiler_test_mock_golden
@@ -0,0 +1,34 @@
+// Generated by the gRPC C++ plugin.
+// If you make any local change, they will be lost.
+// source: src/proto/grpc/testing/compiler_test.proto
+
+#include "src/proto/grpc/testing/compiler_test.pb.h"
+#include "src/proto/grpc/testing/compiler_test.grpc.pb.h"
+
+#include <grpc++/impl/codegen/async_stream.h>
+#include <grpc++/impl/codegen/sync_stream.h>
+#include <gmock/gmock.h>
+namespace grpc {
+namespace testing {
+
+class MockServiceAStub : public ServiceA::StubInterface {
+ public:
+ MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response));
+ MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
+ MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response));
+ MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag));
+ MOCK_METHOD2(MethodA3Raw, ::grpc::ClientReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request));
+ MOCK_METHOD4(AsyncMethodA3Raw, ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag));
+ MOCK_METHOD1(MethodA4Raw, ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context));
+ MOCK_METHOD3(AsyncMethodA4Raw, ::grpc::ClientAsyncReaderWriterInterface<::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag));
+};
+
+class MockServiceBStub : public ServiceB::StubInterface {
+ public:
+ MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response));
+ MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
+};
+
+} // namespace grpc
+} // namespace testing
+
diff --git a/test/cpp/codegen/golden_file_test.cc b/test/cpp/codegen/golden_file_test.cc
index 158a4d933c..7789ac738b 100644
--- a/test/cpp/codegen/golden_file_test.cc
+++ b/test/cpp/codegen/golden_file_test.cc
@@ -37,16 +37,18 @@
#include <gflags/gflags.h>
#include <gtest/gtest.h>
-DEFINE_string(generated_file_path, "",
- "path to the generated compiler_test.grpc.pb.h file");
+DEFINE_string(
+ generated_file_path, "",
+ "path to the directory containing generated files compiler_test.grpc.pb.h"
+ "and compiler_test_mock.grpc.pb.h");
const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden";
+const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden";
-TEST(GoldenFileTest, TestGeneratedFile) {
- ASSERT_FALSE(FLAGS_generated_file_path.empty());
-
- std::ifstream generated(FLAGS_generated_file_path);
- std::ifstream golden(kGoldenFilePath);
+void run_test(std::basic_string<char> generated_file,
+ std::basic_string<char> golden_file) {
+ std::ifstream generated(generated_file);
+ std::ifstream golden(golden_file);
ASSERT_TRUE(generated.good());
ASSERT_TRUE(golden.good());
@@ -61,8 +63,23 @@ TEST(GoldenFileTest, TestGeneratedFile) {
golden.close();
}
+TEST(GoldenFileTest, TestGeneratedFile) {
+ run_test(FLAGS_generated_file_path + "compiler_test.grpc.pb.h",
+ kGoldenFilePath);
+}
+
+TEST(GoldenMockFileTest, TestGeneratedMockFile) {
+ run_test(FLAGS_generated_file_path + "compiler_test_mock.grpc.pb.h",
+ kMockGoldenFilePath);
+}
+
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
::google::ParseCommandLineFlags(&argc, &argv, true);
+ if (FLAGS_generated_file_path.empty()) {
+ FLAGS_generated_file_path = "gens/src/proto/grpc/testing/";
+ }
+ if (FLAGS_generated_file_path.back() != '/')
+ FLAGS_generated_file_path.append("/");
return RUN_ALL_TESTS();
}
diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD
index 0bf7948fcf..f1212e15c7 100644
--- a/test/cpp/end2end/BUILD
+++ b/test/cpp/end2end/BUILD
@@ -51,6 +51,7 @@ cc_test(
"//src/proto/grpc/testing:echo_messages_proto",
"//src/proto/grpc/testing:echo_proto",
"//src/proto/grpc/testing/duplicate:echo_duplicate_proto",
+ "//src/proto/grpc/health/v1:health_proto",
"//test/core/util:gpr_test_util",
"//test/core/util:grpc_test_util",
"//test/cpp/util:test_util",
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 0b5215ef8e..cc3958bf13 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -38,6 +38,7 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
+#include <grpc++/ext/health_check_service_server_builder_option.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -49,6 +50,7 @@
#include <gtest/gtest.h>
#include "src/core/lib/iomgr/port.h"
+#include "src/proto/grpc/health/v1/health.grpc.pb.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"
@@ -224,13 +226,15 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption {
class TestScenario {
public:
- TestScenario(bool non_block, const grpc::string& creds_type,
+ TestScenario(bool non_block, const grpc::string& creds_type, bool hcs,
const grpc::string& content)
: disable_blocking(non_block),
+ health_check_service(hcs),
credentials_type(creds_type),
message_content(content) {}
void Log() const;
bool disable_blocking;
+ bool health_check_service;
// Although the below grpc::string's are logically const, we can't declare
// them const because of a limitation in the way old compilers (e.g., gcc-4.4)
// manage vector insertion using a copy constructor
@@ -243,6 +247,8 @@ static std::ostream& operator<<(std::ostream& out,
return out << "TestScenario{disable_blocking="
<< (scenario.disable_blocking ? "true" : "false")
<< ", credentials='" << scenario.credentials_type
+ << ", health_check_service="
+ << (scenario.health_check_service ? "true" : "false")
<< "', message_size=" << scenario.message_content.size() << "}";
}
@@ -252,6 +258,8 @@ void TestScenario::Log() const {
gpr_log(GPR_DEBUG, "%s", out.str().c_str());
}
+class HealthCheck : public health::v1::Health::Service {};
+
class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
protected:
AsyncEnd2endTest() { GetParam().Log(); }
@@ -268,6 +276,9 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
GetParam().credentials_type);
builder.AddListeningPort(server_address_.str(), server_creds);
builder.RegisterService(&service_);
+ if (GetParam().health_check_service) {
+ builder.RegisterService(&health_check_);
+ }
cq_ = builder.AddCompletionQueue();
// TODO(zyc): make a test option to choose wheather sync plugins should be
@@ -340,6 +351,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_;
std::unique_ptr<Server> server_;
grpc::testing::EchoTestService::AsyncService service_;
+ HealthCheck health_check_;
std::ostringstream server_address_;
int port_;
@@ -1754,12 +1766,14 @@ std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking,
messages.push_back(big_msg);
}
- for (auto cred = credentials_types.begin(); cred != credentials_types.end();
- ++cred) {
- for (auto msg = messages.begin(); msg != messages.end(); msg++) {
- scenarios.emplace_back(false, *cred, *msg);
- if (test_disable_blocking) {
- scenarios.emplace_back(true, *cred, *msg);
+ for (auto health_check_service : {false, true}) {
+ for (auto cred = credentials_types.begin(); cred != credentials_types.end();
+ ++cred) {
+ for (auto msg = messages.begin(); msg != messages.end(); msg++) {
+ scenarios.emplace_back(false, *cred, health_check_service, *msg);
+ if (test_disable_blocking) {
+ scenarios.emplace_back(true, *cred, health_check_service, *msg);
+ }
}
}
}
diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc
index fdb2732e50..7e330063ed 100644
--- a/test/cpp/end2end/mock_test.cc
+++ b/test/cpp/end2end/mock_test.cc
@@ -34,6 +34,7 @@
#include <climits>
#include <thread>
+#include <gmock/gmock.h>
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
@@ -46,120 +47,35 @@
#include <grpc/support/time.h>
#include <gtest/gtest.h>
+#include <grpc++/test/mock_stream.h>
+
#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
+#include "src/proto/grpc/testing/echo_mock.grpc.pb.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
+#include <iostream>
+
+using namespace std;
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
using grpc::testing::EchoTestService;
+using grpc::testing::MockClientReaderWriter;
using std::chrono::system_clock;
+using ::testing::AtLeast;
+using ::testing::SetArgPointee;
+using ::testing::SaveArg;
+using ::testing::_;
+using ::testing::Return;
+using ::testing::Invoke;
+using ::testing::WithArg;
+using ::testing::DoAll;
namespace grpc {
namespace testing {
namespace {
-template <class W, class R>
-class MockClientReaderWriter final : public ClientReaderWriterInterface<W, R> {
- public:
- void WaitForInitialMetadata() override {}
- bool NextMessageSize(uint32_t* sz) override {
- *sz = UINT_MAX;
- return true;
- }
- bool Read(R* msg) override { return true; }
- bool Write(const W& msg) override { return true; }
- bool WritesDone() override { return true; }
- Status Finish() override { return Status::OK; }
-};
-template <>
-class MockClientReaderWriter<EchoRequest, EchoResponse> final
- : public ClientReaderWriterInterface<EchoRequest, EchoResponse> {
- public:
- MockClientReaderWriter() : writes_done_(false) {}
- void WaitForInitialMetadata() override {}
- bool NextMessageSize(uint32_t* sz) override {
- *sz = UINT_MAX;
- return true;
- }
- bool Read(EchoResponse* msg) override {
- if (writes_done_) return false;
- msg->set_message(last_message_);
- return true;
- }
-
- bool Write(const EchoRequest& msg, WriteOptions options) override {
- gpr_log(GPR_INFO, "mock recv msg %s", msg.message().c_str());
- last_message_ = msg.message();
- return true;
- }
- bool WritesDone() override {
- writes_done_ = true;
- return true;
- }
- Status Finish() override { return Status::OK; }
-
- private:
- bool writes_done_;
- grpc::string last_message_;
-};
-
-// Mocked stub.
-class MockStub : public EchoTestService::StubInterface {
- public:
- MockStub() {}
- ~MockStub() {}
- Status Echo(ClientContext* context, const EchoRequest& request,
- EchoResponse* response) override {
- response->set_message(request.message());
- return Status::OK;
- }
- Status Unimplemented(ClientContext* context, const EchoRequest& request,
- EchoResponse* response) override {
- return Status::OK;
- }
-
- private:
- ClientAsyncResponseReaderInterface<EchoResponse>* AsyncEchoRaw(
- ClientContext* context, const EchoRequest& request,
- CompletionQueue* cq) override {
- return nullptr;
- }
- ClientWriterInterface<EchoRequest>* RequestStreamRaw(
- ClientContext* context, EchoResponse* response) override {
- return nullptr;
- }
- ClientAsyncWriterInterface<EchoRequest>* AsyncRequestStreamRaw(
- ClientContext* context, EchoResponse* response, CompletionQueue* cq,
- void* tag) override {
- return nullptr;
- }
- ClientReaderInterface<EchoResponse>* ResponseStreamRaw(
- ClientContext* context, const EchoRequest& request) override {
- return nullptr;
- }
- ClientAsyncReaderInterface<EchoResponse>* AsyncResponseStreamRaw(
- ClientContext* context, const EchoRequest& request, CompletionQueue* cq,
- void* tag) override {
- return nullptr;
- }
- ClientReaderWriterInterface<EchoRequest, EchoResponse>* BidiStreamRaw(
- ClientContext* context) override {
- return new MockClientReaderWriter<EchoRequest, EchoResponse>();
- }
- ClientAsyncReaderWriterInterface<EchoRequest, EchoResponse>*
- AsyncBidiStreamRaw(ClientContext* context, CompletionQueue* cq,
- void* tag) override {
- return nullptr;
- }
- ClientAsyncResponseReaderInterface<EchoResponse>* AsyncUnimplementedRaw(
- ClientContext* context, const EchoRequest& request,
- CompletionQueue* cq) override {
- return nullptr;
- }
-};
-
class FakeClient {
public:
explicit FakeClient(EchoTestService::StubInterface* stub) : stub_(stub) {}
@@ -174,6 +90,55 @@ class FakeClient {
EXPECT_TRUE(s.ok());
}
+ void DoRequestStream() {
+ EchoRequest request;
+ EchoResponse response;
+
+ ClientContext context;
+ grpc::string msg("hello");
+ grpc::string exp(msg);
+
+ std::unique_ptr<ClientWriterInterface<EchoRequest>> cstream =
+ stub_->RequestStream(&context, &response);
+
+ request.set_message(msg);
+ EXPECT_TRUE(cstream->Write(request));
+
+ msg = ", world";
+ request.set_message(msg);
+ exp.append(msg);
+ EXPECT_TRUE(cstream->Write(request));
+
+ cstream->WritesDone();
+ Status s = cstream->Finish();
+
+ EXPECT_EQ(exp, response.message());
+ EXPECT_TRUE(s.ok());
+ }
+
+ void DoResponseStream() {
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("hello world");
+
+ ClientContext context;
+ std::unique_ptr<ClientReaderInterface<EchoResponse>> cstream =
+ stub_->ResponseStream(&context, request);
+
+ grpc::string exp = "";
+ EXPECT_TRUE(cstream->Read(&response));
+ exp.append(response.message() + " ");
+
+ EXPECT_TRUE(cstream->Read(&response));
+ exp.append(response.message());
+
+ EXPECT_FALSE(cstream->Read(&response));
+ EXPECT_EQ(request.message(), exp);
+
+ Status s = cstream->Finish();
+ EXPECT_TRUE(s.ok());
+ }
+
void DoBidiStream() {
EchoRequest request;
EchoResponse response;
@@ -219,6 +184,30 @@ class TestServiceImpl : public EchoTestService::Service {
return Status::OK;
}
+ Status RequestStream(ServerContext* context,
+ ServerReader<EchoRequest>* reader,
+ EchoResponse* response) override {
+ EchoRequest request;
+ grpc::string resp("");
+ while (reader->Read(&request)) {
+ gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
+ resp.append(request.message());
+ }
+ response->set_message(resp);
+ return Status::OK;
+ }
+
+ Status ResponseStream(ServerContext* context, const EchoRequest* request,
+ ServerWriter<EchoResponse>* writer) override {
+ EchoResponse response;
+ vector<grpc::string> tokens = split(request->message());
+ for (grpc::string token : tokens) {
+ response.set_message(token);
+ writer->Write(response);
+ }
+ return Status::OK;
+ }
+
Status BidiStream(
ServerContext* context,
ServerReaderWriter<EchoResponse, EchoRequest>* stream) override {
@@ -231,6 +220,25 @@ class TestServiceImpl : public EchoTestService::Service {
}
return Status::OK;
}
+
+ private:
+ const vector<grpc::string> split(const grpc::string& input) {
+ grpc::string buff("");
+ vector<grpc::string> result;
+
+ for (auto n : input) {
+ if (n != ' ') {
+ buff += n;
+ continue;
+ }
+ if (buff == "") continue;
+ result.push_back(buff);
+ buff = "";
+ }
+ if (buff != "") result.push_back(buff);
+
+ return result;
+ }
};
class MockTest : public ::testing::Test {
@@ -267,16 +275,82 @@ TEST_F(MockTest, SimpleRpc) {
ResetStub();
FakeClient client(stub_.get());
client.DoEcho();
- MockStub stub;
+ MockEchoTestServiceStub stub;
+ EchoResponse resp;
+ resp.set_message("hello world");
+ EXPECT_CALL(stub, Echo(_, _, _))
+ .Times(AtLeast(1))
+ .WillOnce(DoAll(SetArgPointee<2>(resp), Return(Status::OK)));
client.ResetStub(&stub);
client.DoEcho();
}
+TEST_F(MockTest, ClientStream) {
+ ResetStub();
+ FakeClient client(stub_.get());
+ client.DoRequestStream();
+
+ MockEchoTestServiceStub stub;
+ auto w = new MockClientWriter<EchoRequest>();
+ EchoResponse resp;
+ resp.set_message("hello, world");
+
+ EXPECT_CALL(*w, Write(_, _)).Times(2).WillRepeatedly(Return(true));
+ EXPECT_CALL(*w, WritesDone());
+ EXPECT_CALL(*w, Finish()).WillOnce(Return(Status::OK));
+
+ EXPECT_CALL(stub, RequestStreamRaw(_, _))
+ .WillOnce(DoAll(SetArgPointee<1>(resp), Return(w)));
+ client.ResetStub(&stub);
+ client.DoRequestStream();
+}
+
+TEST_F(MockTest, ServerStream) {
+ ResetStub();
+ FakeClient client(stub_.get());
+ client.DoResponseStream();
+
+ MockEchoTestServiceStub stub;
+ auto r = new MockClientReader<EchoResponse>();
+ EchoResponse resp1;
+ resp1.set_message("hello");
+ EchoResponse resp2;
+ resp2.set_message("world");
+
+ EXPECT_CALL(*r, Read(_))
+ .WillOnce(DoAll(SetArgPointee<0>(resp1), Return(true)))
+ .WillOnce(DoAll(SetArgPointee<0>(resp2), Return(true)))
+ .WillOnce(Return(false));
+ EXPECT_CALL(*r, Finish()).WillOnce(Return(Status::OK));
+
+ EXPECT_CALL(stub, ResponseStreamRaw(_, _)).WillOnce(Return(r));
+
+ client.ResetStub(&stub);
+ client.DoResponseStream();
+}
+
+ACTION_P(copy, msg) { arg0->set_message(msg->message()); }
+
TEST_F(MockTest, BidiStream) {
ResetStub();
FakeClient client(stub_.get());
client.DoBidiStream();
- MockStub stub;
+ MockEchoTestServiceStub stub;
+ auto rw = new MockClientReaderWriter<EchoRequest, EchoResponse>();
+ EchoRequest msg;
+
+ EXPECT_CALL(*rw, Write(_, _))
+ .Times(3)
+ .WillRepeatedly(DoAll(SaveArg<0>(&msg), Return(true)));
+ EXPECT_CALL(*rw, Read(_))
+ .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true)))
+ .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true)))
+ .WillOnce(DoAll(WithArg<0>(copy(&msg)), Return(true)))
+ .WillOnce(Return(false));
+ EXPECT_CALL(*rw, WritesDone());
+ EXPECT_CALL(*rw, Finish()).WillOnce(Return(Status::OK));
+
+ EXPECT_CALL(stub, BidiStreamRaw(_)).WillOnce(Return(rw));
client.ResetStub(&stub);
client.DoBidiStream();
}
diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h
index f129ede26a..98aca1c346 100644
--- a/test/cpp/microbenchmarks/fullstack_fixtures.h
+++ b/test/cpp/microbenchmarks/fullstack_fixtures.h
@@ -113,13 +113,17 @@ class TCP : public FullstackFixture {
public:
TCP(Service* service, const FixtureConfiguration& fixture_configuration =
FixtureConfiguration())
- : FullstackFixture(service, fixture_configuration, MakeAddress()) {}
+ : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {}
+
+ ~TCP() { grpc_recycle_unused_port(port_); }
private:
- static grpc::string MakeAddress() {
- int port = grpc_pick_unused_port_or_die();
+ int port_;
+
+ static grpc::string MakeAddress(int* port) {
+ *port = grpc_pick_unused_port_or_die();
std::stringstream addr;
- addr << "localhost:" << port;
+ addr << "localhost:" << *port;
return addr.str();
}
};
@@ -128,14 +132,18 @@ class UDS : public FullstackFixture {
public:
UDS(Service* service, const FixtureConfiguration& fixture_configuration =
FixtureConfiguration())
- : FullstackFixture(service, fixture_configuration, MakeAddress()) {}
+ : FullstackFixture(service, fixture_configuration, MakeAddress(&port_)) {}
+
+ ~UDS() { grpc_recycle_unused_port(port_); }
private:
- static grpc::string MakeAddress() {
- int port = grpc_pick_unused_port_or_die(); // just for a unique id - not a
- // real port
+ int port_;
+
+ static grpc::string MakeAddress(int* port) {
+ *port = grpc_pick_unused_port_or_die(); // just for a unique id - not a
+ // real port
std::stringstream addr;
- addr << "unix:/tmp/bm_fullstack." << port;
+ addr << "unix:/tmp/bm_fullstack." << *port;
return addr.str();
}
};