diff options
author | heretic <heretic@yandex-team.ru> | 2022-03-25 12:34:53 +0300 |
---|---|---|
committer | heretic <heretic@yandex-team.ru> | 2022-03-25 12:34:53 +0300 |
commit | a41f3739eed6fceb6f62056a7620d220958a47e7 (patch) | |
tree | 278103258b510cb4a96761ea79d6ccd397ca05a0 /contrib/libs/grpc/include/grpcpp/test | |
parent | 73d3613a82e5c217fcbe0ab8bbf8120c1ed1af55 (diff) | |
download | ydb-a41f3739eed6fceb6f62056a7620d220958a47e7.tar.gz |
Update grpc to 1.43.2 DTCC-864
ref:50a492c335cda70f458797cf945e49fe739c2715
Diffstat (limited to 'contrib/libs/grpc/include/grpcpp/test')
3 files changed, 118 insertions, 8 deletions
diff --git a/contrib/libs/grpc/include/grpcpp/test/client_context_test_peer.h b/contrib/libs/grpc/include/grpcpp/test/client_context_test_peer.h new file mode 100644 index 0000000000..0afc32c0e8 --- /dev/null +++ b/contrib/libs/grpc/include/grpcpp/test/client_context_test_peer.h @@ -0,0 +1,62 @@ +/* + * + * Copyright 2021 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H +#define GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H + +#include <map> + +#include <grpcpp/client_context.h> + +namespace grpc { +namespace testing { + +/// A test-only class to access private members and methods of ClientContext. +class ClientContextTestPeer { + public: + explicit ClientContextTestPeer(ClientContext* const ctx) : ctx_(ctx) {} + + /// Inject metadata to the ClientContext for the test. The test peer + /// must be alive when a ClientContext::GetServerInitialMetadata is called. + void AddServerInitialMetadata(const TString& key, + const TString& value) { + server_initial_metadata_storage_.insert( + std::pair<TString, TString>(key, value)); + ctx_->initial_metadata_received_ = true; + ctx_->recv_initial_metadata_.map()->clear(); + for (const auto& item : server_initial_metadata_storage_) { + ctx_->recv_initial_metadata_.map()->insert( + std::pair<grpc::string_ref, grpc::string_ref>( + item.first.c_str(), + grpc::string_ref(item.second.data(), item.second.size()))); + } + } + + std::multimap<TString, TString> GetSendInitialMetadata() const { + return ctx_->send_initial_metadata_; + } + + private: + ClientContext* const ctx_; // not owned + std::multimap<TString, TString> server_initial_metadata_storage_; +}; + +} // namespace testing +} // namespace grpc + +#endif // GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H diff --git a/contrib/libs/grpc/include/grpcpp/test/default_reactor_test_peer.h b/contrib/libs/grpc/include/grpcpp/test/default_reactor_test_peer.h index a792e6f94a..4d4ae5c39d 100644 --- a/contrib/libs/grpc/include/grpcpp/test/default_reactor_test_peer.h +++ b/contrib/libs/grpc/include/grpcpp/test/default_reactor_test_peer.h @@ -34,22 +34,21 @@ namespace testing { /// test mode rather than letting it follow the normal paths. class DefaultReactorTestPeer { public: - explicit DefaultReactorTestPeer(experimental::CallbackServerContext* ctx) - : DefaultReactorTestPeer(ctx, [](::grpc::Status) {}) {} - DefaultReactorTestPeer(experimental::CallbackServerContext* ctx, - std::function<void(::grpc::Status)> finish_func) + explicit DefaultReactorTestPeer(CallbackServerContext* ctx) + : DefaultReactorTestPeer(ctx, [](Status) {}) {} + DefaultReactorTestPeer(CallbackServerContext* ctx, + std::function<void(Status)> finish_func) : ctx_(ctx) { ctx->SetupTestDefaultReactor(std::move(finish_func)); } - ::grpc::experimental::ServerUnaryReactor* reactor() const { - return reinterpret_cast<experimental::ServerUnaryReactor*>( - &ctx_->default_reactor_); + ServerUnaryReactor* reactor() const { + return reinterpret_cast<ServerUnaryReactor*>(&ctx_->default_reactor_); } bool test_status_set() const { return ctx_->test_status_set(); } Status test_status() const { return ctx_->test_status(); } private: - experimental::CallbackServerContext* const ctx_; // not owned + CallbackServerContext* const ctx_; // not owned }; } // namespace testing diff --git a/contrib/libs/grpc/include/grpcpp/test/mock_stream.h b/contrib/libs/grpc/include/grpcpp/test/mock_stream.h index e33595d709..f210b41ac6 100644 --- a/contrib/libs/grpc/include/grpcpp/test/mock_stream.h +++ b/contrib/libs/grpc/include/grpcpp/test/mock_stream.h @@ -22,6 +22,7 @@ #include <stdint.h> #include <gmock/gmock.h> + #include <grpcpp/impl/codegen/call.h> #include <grpcpp/support/async_stream.h> #include <grpcpp/support/async_unary_call.h> @@ -90,6 +91,8 @@ class MockClientAsyncResponseReader public: MockClientAsyncResponseReader() = default; + /// ClientAsyncResponseReaderInterface + MOCK_METHOD0_T(StartCall, void()); MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); MOCK_METHOD3_T(Finish, void(R*, Status*, void*)); }; @@ -100,6 +103,7 @@ class MockClientAsyncReader : public ClientAsyncReaderInterface<R> { MockClientAsyncReader() = default; /// ClientAsyncStreamingInterface + MOCK_METHOD1_T(StartCall, void(void*)); MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); MOCK_METHOD2_T(Finish, void(Status*, void*)); @@ -113,11 +117,13 @@ class MockClientAsyncWriter : public ::grpc::ClientAsyncWriterInterface<W> { MockClientAsyncWriter() = default; /// ClientAsyncStreamingInterface + MOCK_METHOD1_T(StartCall, void(void*)); MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); MOCK_METHOD2_T(Finish, void(Status*, void*)); /// AsyncWriterInterface MOCK_METHOD2_T(Write, void(const W&, void*)); + MOCK_METHOD3_T(Write, void(const W&, ::grpc::WriteOptions, void*)); /// ClientAsyncWriterInterface MOCK_METHOD1_T(WritesDone, void(void*)); @@ -130,11 +136,13 @@ class MockClientAsyncReaderWriter MockClientAsyncReaderWriter() = default; /// ClientAsyncStreamingInterface + MOCK_METHOD1_T(StartCall, void(void*)); MOCK_METHOD1_T(ReadInitialMetadata, void(void*)); MOCK_METHOD2_T(Finish, void(Status*, void*)); /// AsyncWriterInterface MOCK_METHOD2_T(Write, void(const W&, void*)); + MOCK_METHOD3_T(Write, void(const W&, ::grpc::WriteOptions, void*)); /// AsyncReaderInterface MOCK_METHOD2_T(Read, void(R*, void*)); @@ -143,6 +151,47 @@ class MockClientAsyncReaderWriter MOCK_METHOD1_T(WritesDone, void(void*)); }; +template <class R> +class MockServerReader : public ::grpc::ServerReaderInterface<R> { + public: + MockServerReader() = default; + + /// ServerStreamingInterface + MOCK_METHOD0_T(SendInitialMetadata, void()); + + /// ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); +}; + +template <class W> +class MockServerWriter : public ::grpc::ServerWriterInterface<W> { + public: + MockServerWriter() = default; + + /// ServerStreamingInterface + MOCK_METHOD0_T(SendInitialMetadata, void()); + + /// WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); +}; + +template <class W, class R> +class MockServerReaderWriter : public grpc::ServerReaderWriterInterface<W, R> { + public: + MockServerReaderWriter() = default; + + /// ServerStreamingInterface + MOCK_METHOD0_T(SendInitialMetadata, void()); + + /// ReaderInterface + MOCK_METHOD1_T(NextMessageSize, bool(uint32_t*)); + MOCK_METHOD1_T(Read, bool(R*)); + + /// WriterInterface + MOCK_METHOD2_T(Write, bool(const W&, const WriteOptions)); +}; + } // namespace testing } // namespace grpc |