1414
1515#include " google/cloud/bigtable/row_reader.h"
1616#include " google/cloud/bigtable/table.h"
17+ #include " google/cloud/bigtable/testing/mock_policies.h"
1718#include " google/cloud/bigtable/testing/mock_read_rows_reader.h"
1819#include " google/cloud/bigtable/testing/table_test_fixture.h"
1920#include " google/cloud/internal/api_client_header.h"
@@ -35,14 +36,18 @@ namespace {
3536using ::google::bigtable::v2::ReadRowsRequest;
3637using ::google::bigtable::v2::ReadRowsResponse_CellChunk;
3738using ::google::cloud::bigtable::Row;
39+ using ::google::cloud::bigtable::testing::MockBackoffPolicy;
3840using ::google::cloud::bigtable::testing::MockReadRowsReader;
41+ using ::google::cloud::bigtable::testing::MockRetryPolicy;
3942using ::google::cloud::testing_util::IsContextMDValid;
4043using ::testing::_;
44+ using ::testing::An;
4145using ::testing::Contains;
4246using ::testing::DoAll;
4347using ::testing::Eq;
4448using ::testing::HasSubstr;
4549using ::testing::Matcher;
50+ using ::testing::NiceMock;
4651using ::testing::Not;
4752using ::testing::Property;
4853using ::testing::Return;
@@ -105,36 +110,6 @@ class ReadRowsParserMockFactory
105110 std::deque<ParserPtr> parsers_;
106111};
107112
108- class RetryPolicyMock : public bigtable ::RPCRetryPolicy {
109- public:
110- RetryPolicyMock () = default ;
111- std::unique_ptr<RPCRetryPolicy> clone () const override {
112- google::cloud::internal::ThrowRuntimeError (" Mocks cannot be copied." );
113- }
114-
115- MOCK_METHOD (void , Setup, (grpc::ClientContext&), (const , override ));
116- MOCK_METHOD (bool , OnFailure, (grpc::Status const & status), (override ));
117- bool OnFailure (google::cloud::Status const &) override { return true ; }
118- };
119-
120- class BackoffPolicyMock : public bigtable ::RPCBackoffPolicy {
121- public:
122- BackoffPolicyMock () = default ;
123- std::unique_ptr<RPCBackoffPolicy> clone () const override {
124- google::cloud::internal::ThrowRuntimeError (" Mocks cannot be copied." );
125- }
126- void Setup (grpc::ClientContext&) const override {}
127- MOCK_METHOD (std::chrono::milliseconds, OnCompletionHook,
128- (grpc::Status const & s));
129- std::chrono::milliseconds OnCompletion (grpc::Status const & s) override {
130- return OnCompletionHook (s);
131- }
132- std::chrono::milliseconds OnCompletion (
133- google::cloud::Status const &) override {
134- return std::chrono::milliseconds (0 );
135- }
136- };
137-
138113// Match the number of expected row keys in a request in EXPECT_CALL
139114Matcher<ReadRowsRequest const &> RequestWithRowKeysCount (int n) {
140115 return Property (
@@ -151,14 +126,14 @@ class RowReaderTest : public bigtable::testing::TableTestFixture {
151126 public:
152127 RowReaderTest ()
153128 : TableTestFixture(CompletionQueue{}),
154- retry_policy_ (new RetryPolicyMock ),
155- backoff_policy_ (new BackoffPolicyMock ),
129+ retry_policy_ (absl::make_unique<NiceMock<MockRetryPolicy>>() ),
130+ backoff_policy_ (absl::make_unique<NiceMock<MockBackoffPolicy>>() ),
156131 metadata_update_policy_ (kTableName ,
157132 bigtable::MetadataParamTypes::TABLE_NAME),
158133 parser_factory_ (new ReadRowsParserMockFactory) {}
159134
160- std::unique_ptr<RetryPolicyMock > retry_policy_;
161- std::unique_ptr<BackoffPolicyMock > backoff_policy_;
135+ std::unique_ptr<MockRetryPolicy > retry_policy_;
136+ std::unique_ptr<MockBackoffPolicy > backoff_policy_;
162137 bigtable::MetadataUpdatePolicy metadata_update_policy_;
163138 std::unique_ptr<ReadRowsParserMockFactory> parser_factory_;
164139};
@@ -316,8 +291,9 @@ TEST_F(RowReaderTest, FailedStreamIsRetried) {
316291 EXPECT_CALL (*stream, Finish ())
317292 .WillOnce (Return (grpc::Status (grpc::StatusCode::INTERNAL, " retry" )));
318293
319- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
320- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
294+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
295+ .WillOnce (Return (true ));
296+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
321297 .WillOnce (Return (std::chrono::milliseconds (0 )));
322298
323299 // the stub will free it
@@ -354,8 +330,10 @@ TEST_F(RowReaderTest, FailedStreamWithNoRetryThrowsNoExcept) {
354330 EXPECT_CALL (*stream, Finish ())
355331 .WillOnce (Return (grpc::Status (grpc::StatusCode::INTERNAL, " retry" )));
356332
357- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (false ));
358- EXPECT_CALL (*backoff_policy_, OnCompletionHook).Times (0 );
333+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
334+ .WillOnce (Return (false ));
335+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
336+ .Times (0 );
359337 }
360338
361339 parser_factory_->AddParser (std::move (parser));
@@ -386,8 +364,9 @@ TEST_F(RowReaderTest, FailedStreamRetriesSkipAlreadyReadRows) {
386364 EXPECT_CALL (*stream, Finish ())
387365 .WillOnce (Return (grpc::Status (grpc::StatusCode::INTERNAL, " retry" )));
388366
389- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
390- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
367+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
368+ .WillOnce (Return (true ));
369+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
391370 .WillOnce (Return (std::chrono::milliseconds (0 )));
392371
393372 // the stub will free it
@@ -429,8 +408,9 @@ TEST_F(RowReaderTest, FailedParseIsRetried) {
429408 .WillOnce (SetArgReferee<1 >(
430409 grpc::Status (grpc::StatusCode::INTERNAL, " parser exception" )));
431410
432- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
433- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
411+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
412+ .WillOnce (Return (true ));
413+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
434414 .WillOnce (Return (std::chrono::milliseconds (0 )));
435415
436416 // the stub will free it
@@ -475,8 +455,9 @@ TEST_F(RowReaderTest, FailedParseRetriesSkipAlreadyReadRows) {
475455 .WillOnce (SetArgReferee<0 >(
476456 grpc::Status (grpc::StatusCode::INTERNAL, " InternalError" )));
477457
478- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
479- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
458+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
459+ .WillOnce (Return (true ));
460+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
480461 .WillOnce (Return (std::chrono::milliseconds (0 )));
481462
482463 // the stub will free it
@@ -517,8 +498,10 @@ TEST_F(RowReaderTest, FailedParseWithNoRetryThrowsNoExcept) {
517498 EXPECT_CALL (*parser, HandleEndOfStreamHook)
518499 .WillOnce (SetArgReferee<0 >(
519500 grpc::Status (grpc::StatusCode::INTERNAL, " InternalError" )));
520- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (false ));
521- EXPECT_CALL (*backoff_policy_, OnCompletionHook).Times (0 );
501+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
502+ .WillOnce (Return (false ));
503+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
504+ .Times (0 );
522505 }
523506
524507 parser_factory_->AddParser (std::move (parser));
@@ -600,8 +583,9 @@ TEST_F(RowReaderTest, RowLimitIsDecreasedOnRetry) {
600583 EXPECT_CALL (*stream, Finish ())
601584 .WillOnce (Return (grpc::Status (grpc::StatusCode::INTERNAL, " retry" )));
602585
603- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
604- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
586+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
587+ .WillOnce (Return (true ));
588+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
605589 .WillOnce (Return (std::chrono::milliseconds (0 )));
606590
607591 // the stub will free it
@@ -757,8 +741,9 @@ TEST_F(RowReaderTest, FailedStreamRetryNewContext) {
757741 EXPECT_CALL (*stream, Finish ())
758742 .WillOnce (Return (grpc::Status (grpc::StatusCode::INTERNAL, " retry" )));
759743
760- EXPECT_CALL (*retry_policy_, OnFailure).WillOnce (Return (true ));
761- EXPECT_CALL (*backoff_policy_, OnCompletionHook)
744+ EXPECT_CALL (*retry_policy_, OnFailure (An<grpc::Status const &>()))
745+ .WillOnce (Return (true ));
746+ EXPECT_CALL (*backoff_policy_, OnCompletion (An<grpc::Status const &>()))
762747 .WillOnce (Return (std::chrono::milliseconds (0 )));
763748
764749 // the stub will free it
0 commit comments