aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/end2end
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r--test/cpp/end2end/async_test_server.cc155
-rw-r--r--test/cpp/end2end/async_test_server.h75
-rw-r--r--test/cpp/end2end/end2end_test.cc125
-rw-r--r--test/cpp/end2end/sync_client_async_server_test.cc237
4 files changed, 592 insertions, 0 deletions
diff --git a/test/cpp/end2end/async_test_server.cc b/test/cpp/end2end/async_test_server.cc
new file mode 100644
index 0000000000..0a40dbbbd9
--- /dev/null
+++ b/test/cpp/end2end/async_test_server.cc
@@ -0,0 +1,155 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/cpp/end2end/async_test_server.h"
+
+#include <chrono>
+
+#include <grpc/support/log.h>
+#include "src/cpp/proto/proto_utils.h"
+#include "test/cpp/util/echo.pb.h"
+#include <grpc++/async_server.h>
+#include <grpc++/async_server_context.h>
+#include <grpc++/completion_queue.h>
+#include <grpc++/status.h>
+#include <gtest/gtest.h>
+
+using grpc::cpp::test::util::EchoRequest;
+using grpc::cpp::test::util::EchoResponse;
+
+using std::chrono::duration_cast;
+using std::chrono::microseconds;
+using std::chrono::seconds;
+using std::chrono::system_clock;
+
+namespace grpc {
+namespace testing {
+
+AsyncTestServer::AsyncTestServer() : server_(&cq_), cq_drained_(false) {}
+
+AsyncTestServer::~AsyncTestServer() {}
+
+void AsyncTestServer::AddPort(const grpc::string& addr) {
+ server_.AddPort(addr);
+}
+
+void AsyncTestServer::Start() { server_.Start(); }
+
+// Return true if deadline actual is within 0.5s from expected.
+bool DeadlineMatched(const system_clock::time_point& actual,
+ const system_clock::time_point& expected) {
+ microseconds diff_usecs = duration_cast<microseconds>(expected - actual);
+ gpr_log(GPR_INFO, "diff_usecs= %d", diff_usecs.count());
+ return diff_usecs.count() < 500000 && diff_usecs.count() > -500000;
+}
+
+void AsyncTestServer::RequestOneRpc() { server_.RequestOneRpc(); }
+
+void AsyncTestServer::MainLoop() {
+ EchoRequest request;
+ EchoResponse response;
+ void* tag = nullptr;
+
+ RequestOneRpc();
+
+ while (true) {
+ CompletionQueue::CompletionType t = cq_.Next(&tag);
+ AsyncServerContext* server_context = static_cast<AsyncServerContext*>(tag);
+ switch (t) {
+ case CompletionQueue::SERVER_RPC_NEW:
+ gpr_log(GPR_INFO, "SERVER_RPC_NEW %p", server_context);
+ if (server_context) {
+ EXPECT_EQ(server_context->method(), "/foo");
+ EXPECT_EQ(server_context->host(), "localhost");
+ // TODO(ctiller): verify deadline
+ server_context->Accept(cq_.cq());
+ // Handle only one rpc at a time.
+ RequestOneRpc();
+ server_context->StartRead(&request);
+ }
+ break;
+ case CompletionQueue::RPC_END:
+ gpr_log(GPR_INFO, "RPC_END %p", server_context);
+ delete server_context;
+ break;
+ case CompletionQueue::SERVER_READ_OK:
+ gpr_log(GPR_INFO, "SERVER_READ_OK %p", server_context);
+ response.set_message(request.message());
+ server_context->StartWrite(response, 0);
+ break;
+ case CompletionQueue::SERVER_READ_ERROR:
+ gpr_log(GPR_INFO, "SERVER_READ_ERROR %p", server_context);
+ server_context->StartWriteStatus(Status::OK);
+ break;
+ case CompletionQueue::HALFCLOSE_OK:
+ gpr_log(GPR_INFO, "HALFCLOSE_OK %p", server_context);
+ // Do nothing, just wait for RPC_END.
+ break;
+ case CompletionQueue::SERVER_WRITE_OK:
+ gpr_log(GPR_INFO, "SERVER_WRITE_OK %p", server_context);
+ server_context->StartRead(&request);
+ break;
+ case CompletionQueue::SERVER_WRITE_ERROR:
+ EXPECT_TRUE(0);
+ break;
+ case CompletionQueue::QUEUE_CLOSED: {
+ gpr_log(GPR_INFO, "QUEUE_CLOSED");
+ HandleQueueClosed();
+ return;
+ }
+ default:
+ EXPECT_TRUE(0);
+ break;
+ }
+ }
+}
+
+void AsyncTestServer::HandleQueueClosed() {
+ std::unique_lock<std::mutex> lock(cq_drained_mu_);
+ cq_drained_ = true;
+ cq_drained_cv_.notify_all();
+}
+
+void AsyncTestServer::Shutdown() {
+ // The server need to be shut down before cq_ as grpc_server flushes all
+ // pending requested calls to the completion queue at shutdown.
+ server_.Shutdown();
+ cq_.Shutdown();
+ std::unique_lock<std::mutex> lock(cq_drained_mu_);
+ while (!cq_drained_) {
+ cq_drained_cv_.wait(lock);
+ }
+}
+
+} // namespace testing
+} // namespace grpc
diff --git a/test/cpp/end2end/async_test_server.h b/test/cpp/end2end/async_test_server.h
new file mode 100644
index 0000000000..a277061ace
--- /dev/null
+++ b/test/cpp/end2end/async_test_server.h
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __GRPCPP_TEST_END2END_ASYNC_TEST_SERVER_H__
+#define __GRPCPP_TEST_END2END_ASYNC_TEST_SERVER_H__
+
+#include <condition_variable>
+#include <mutex>
+#include <string>
+
+#include <grpc++/async_server.h>
+#include <grpc++/completion_queue.h>
+
+namespace grpc {
+
+namespace testing {
+
+class AsyncTestServer {
+ public:
+ AsyncTestServer();
+ virtual ~AsyncTestServer();
+
+ void AddPort(const grpc::string& addr);
+ void Start();
+ void RequestOneRpc();
+ virtual void MainLoop();
+ void Shutdown();
+
+ CompletionQueue* completion_queue() { return &cq_; }
+
+ protected:
+ void HandleQueueClosed();
+
+ private:
+ CompletionQueue cq_;
+ AsyncServer server_;
+ bool cq_drained_;
+ std::mutex cq_drained_mu_;
+ std::condition_variable cq_drained_cv_;
+};
+
+} // namespace testing
+} // namespace grpc
+
+#endif // __GRPCPP_TEST_END2END_ASYNC_TEST_SERVER_H__
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
new file mode 100644
index 0000000000..255e29e409
--- /dev/null
+++ b/test/cpp/end2end/end2end_test.cc
@@ -0,0 +1,125 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <thread>
+#include "src/cpp/server/rpc_service_method.h"
+#include "test/cpp/util/echo.pb.h"
+#include "net/util/netutil.h"
+#include <grpc++/channel_interface.h>
+#include <grpc++/client_context.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include <grpc++/status.h>
+#include <gtest/gtest.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/thd.h>
+
+using grpc::cpp::test::util::EchoRequest;
+using grpc::cpp::test::util::EchoResponse;
+using grpc::cpp::test::util::TestService;
+
+namespace grpc {
+
+class TestServiceImpl : public TestService::Service {
+ public:
+ Status Echo(const EchoRequest* request, EchoResponse* response) {
+ response->set_message(request->message());
+ return Status::OK;
+ }
+};
+
+class End2endTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ int port = PickUnusedPortOrDie();
+ server_address_ << "localhost:" << port;
+ // Setup server
+ ServerBuilder builder;
+ builder.AddPort(server_address_.str());
+ builder.RegisterService(service.service());
+ server_ = builder.BuildAndStart();
+ }
+
+ void TearDown() override {
+ server_->Shutdown();
+ }
+
+ std::unique_ptr<Server> server_;
+ std::ostringstream server_address_;
+ TestServiceImpl service;
+};
+
+static void SendRpc(const grpc::string& server_address, int num_rpcs) {
+ std::shared_ptr<ChannelInterface> channel =
+ CreateChannel(server_address);
+ TestService::Stub* stub = TestService::NewStub(channel);
+ EchoRequest request;
+ EchoResponse response;
+ request.set_message("Hello");
+
+ for (int i = 0; i < num_rpcs; ++i) {
+ ClientContext context;
+ Status s = stub->Echo(&context, request, &response);
+ EXPECT_EQ(response.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+ }
+
+ delete stub;
+}
+
+TEST_F(End2endTest, SimpleRpc) {
+ SendRpc(server_address_.str(), 1);
+}
+
+TEST_F(End2endTest, MultipleRpcs) {
+ vector<std::thread*> threads;
+ for (int i = 0; i < 10; ++i) {
+ threads.push_back(new std::thread(SendRpc, server_address_.str(), 10));
+ }
+ for (int i = 0; i < 10; ++i) {
+ threads[i]->join();
+ delete threads[i];
+ }
+}
+
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ grpc_init();
+ ::testing::InitGoogleTest(&argc, argv);
+ int result = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return result;
+}
diff --git a/test/cpp/end2end/sync_client_async_server_test.cc b/test/cpp/end2end/sync_client_async_server_test.cc
new file mode 100644
index 0000000000..f9ac6f2ea5
--- /dev/null
+++ b/test/cpp/end2end/sync_client_async_server_test.cc
@@ -0,0 +1,237 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+#include <chrono>
+#include <memory>
+#include <sstream>
+#include <string>
+
+#include <grpc/grpc.h>
+#include <grpc/support/thd.h>
+#include "src/cpp/client/internal_stub.h"
+#include "src/cpp/rpc_method.h"
+#include "test/cpp/util/echo.pb.h"
+#include "net/util/netutil.h"
+#include <grpc++/channel_interface.h>
+#include <grpc++/client_context.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/status.h>
+#include <grpc++/stream.h>
+#include "test/cpp/end2end/async_test_server.h"
+#include <gtest/gtest.h>
+
+using grpc::cpp::test::util::EchoRequest;
+using grpc::cpp::test::util::EchoResponse;
+
+using std::chrono::duration_cast;
+using std::chrono::microseconds;
+using std::chrono::seconds;
+using std::chrono::system_clock;
+
+using grpc::testing::AsyncTestServer;
+
+namespace grpc {
+namespace {
+
+void ServerLoop(void* s) {
+ AsyncTestServer* server = static_cast<AsyncTestServer*>(s);
+ server->MainLoop();
+}
+
+class End2endTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ int port = PickUnusedPortOrDie();
+ // TODO(yangg) protobuf has a StringPrintf, maybe use that
+ std::ostringstream oss;
+ oss << "[::]:" << port;
+ // Setup server
+ server_.reset(new AsyncTestServer());
+ server_->AddPort(oss.str());
+ server_->Start();
+
+ RunServerThread();
+
+ // Setup client
+ oss.str("");
+ oss << "127.0.0.1:" << port;
+ std::shared_ptr<ChannelInterface> channel = CreateChannel(oss.str());
+ stub_.set_channel(channel);
+ }
+
+ void RunServerThread() {
+ gpr_thd_id id;
+ EXPECT_TRUE(gpr_thd_new(&id, ServerLoop, server_.get(), NULL));
+ }
+
+ void TearDown() override {
+ server_->Shutdown();
+ }
+
+ std::unique_ptr<AsyncTestServer> server_;
+ InternalStub stub_;
+};
+
+TEST_F(End2endTest, NoOpTest) { EXPECT_TRUE(stub_.channel() != nullptr); }
+
+TEST_F(End2endTest, SimpleRpc) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo");
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ Status s =
+ stub_.channel()->StartBlockingRpc(method, &context, request, &result);
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+}
+
+TEST_F(End2endTest, KSequentialSimpleRpcs) {
+ int k = 3;
+ for (int i = 0; i < k; i++) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo");
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ Status s =
+ stub_.channel()->StartBlockingRpc(method, &context, request, &result);
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+ }
+}
+
+TEST_F(End2endTest, OnePingpongBidiStream) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo", RpcMethod::RpcType::BIDI_STREAMING);
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ StreamContextInterface* stream_interface =
+ stub_.channel()->CreateStream(method, &context, nullptr, nullptr);
+ std::unique_ptr<ClientReaderWriter<EchoRequest, EchoResponse>> stream(
+ new ClientReaderWriter<EchoRequest, EchoResponse>(stream_interface));
+ EXPECT_TRUE(stream->Write(request));
+ EXPECT_TRUE(stream->Read(&result));
+ stream->WritesDone();
+ EXPECT_FALSE(stream->Read(&result));
+ Status s = stream->Wait();
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+}
+
+TEST_F(End2endTest, TwoPingpongBidiStream) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo", RpcMethod::RpcType::BIDI_STREAMING);
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ StreamContextInterface* stream_interface =
+ stub_.channel()->CreateStream(method, &context, nullptr, nullptr);
+ std::unique_ptr<ClientReaderWriter<EchoRequest, EchoResponse>> stream(
+ new ClientReaderWriter<EchoRequest, EchoResponse>(stream_interface));
+ EXPECT_TRUE(stream->Write(request));
+ EXPECT_TRUE(stream->Read(&result));
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(stream->Write(request));
+ EXPECT_TRUE(stream->Read(&result));
+ EXPECT_EQ(result.message(), request.message());
+ stream->WritesDone();
+ EXPECT_FALSE(stream->Read(&result));
+ Status s = stream->Wait();
+ EXPECT_TRUE(s.IsOk());
+}
+
+TEST_F(End2endTest, OnePingpongClientStream) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo", RpcMethod::RpcType::CLIENT_STREAMING);
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ StreamContextInterface* stream_interface =
+ stub_.channel()->CreateStream(method, &context, nullptr, &result);
+ std::unique_ptr<ClientWriter<EchoRequest>> stream(
+ new ClientWriter<EchoRequest>(stream_interface));
+ EXPECT_TRUE(stream->Write(request));
+ stream->WritesDone();
+ Status s = stream->Wait();
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+}
+
+TEST_F(End2endTest, OnePingpongServerStream) {
+ EchoRequest request;
+ request.set_message("hello");
+ EchoResponse result;
+ ClientContext context;
+ RpcMethod method("/foo", RpcMethod::RpcType::SERVER_STREAMING);
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::seconds(10);
+ context.set_absolute_deadline(deadline);
+ StreamContextInterface* stream_interface =
+ stub_.channel()->CreateStream(method, &context, &request, nullptr);
+ std::unique_ptr<ClientReader<EchoResponse>> stream(
+ new ClientReader<EchoResponse>(stream_interface));
+ EXPECT_TRUE(stream->Read(&result));
+ EXPECT_FALSE(stream->Read(nullptr));
+ Status s = stream->Wait();
+ EXPECT_EQ(result.message(), request.message());
+ EXPECT_TRUE(s.IsOk());
+}
+
+} // namespace
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ grpc_init();
+ ::testing::InitGoogleTest(&argc, argv);
+ int result = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return result;
+}