1515#include " google/cloud/bigtable/internal/data_connection_impl.h"
1616#include " google/cloud/bigtable/data_connection.h"
1717#include " google/cloud/bigtable/internal/defaults.h"
18+ #include " google/cloud/bigtable/options.h"
1819#include " google/cloud/bigtable/testing/mock_bigtable_stub.h"
1920#include " google/cloud/bigtable/testing/mock_policies.h"
2021#include " google/cloud/common_options.h"
@@ -40,6 +41,7 @@ using ::google::cloud::bigtable::DataBackoffPolicyOption;
4041using ::google::cloud::bigtable::DataLimitedErrorCountRetryPolicy;
4142using ::google::cloud::bigtable::DataRetryPolicyOption;
4243using ::google::cloud::bigtable::IdempotentMutationPolicyOption;
44+ using ::google::cloud::bigtable::ReverseScanOption;
4345using ::google::cloud::bigtable::testing::MockAsyncReadRowsStream;
4446using ::google::cloud::bigtable::testing::MockBigtableStub;
4547using ::google::cloud::bigtable::testing::MockIdempotentMutationPolicy;
@@ -705,6 +707,23 @@ TEST(DataConnectionTest, ReadRows) {
705707 EXPECT_EQ (reader.begin (), reader.end ());
706708}
707709
710+ TEST (DataConnectionTest, ReadRowsReverseScan) {
711+ auto mock = std::make_shared<MockBigtableStub>();
712+ EXPECT_CALL (*mock, ReadRows)
713+ .WillOnce ([](auto , google::bigtable::v2::ReadRowsRequest const & request) {
714+ EXPECT_TRUE (request.reversed ());
715+
716+ auto stream = std::make_unique<MockReadRowsStream>();
717+ EXPECT_CALL (*stream, Read).WillOnce (Return (Status ()));
718+ return stream;
719+ });
720+
721+ auto conn = TestConnection (std::move (mock));
722+ internal::OptionsSpan span (CallOptions ().set <ReverseScanOption>(true ));
723+ auto reader = conn->ReadRows (kTableName , TestRowSet (), 42 , TestFilter ());
724+ EXPECT_EQ (reader.begin (), reader.end ());
725+ }
726+
708727// The DefaultRowReader is tested extensively in `default_row_reader_test.cc`.
709728// In this test, we just verify that the configuration is passed along.
710729TEST (DataConnectionTest, ReadRowsFull) {
@@ -716,7 +735,7 @@ TEST(DataConnectionTest, ReadRowsFull) {
716735 EXPECT_EQ (42 , request.rows_limit ());
717736 EXPECT_THAT (request, HasTestRowSet ());
718737 EXPECT_THAT (request.filter (), IsTestFilter ());
719- EXPECT_FALSE (request.reversed ());
738+ EXPECT_TRUE (request.reversed ());
720739
721740 auto stream = std::make_unique<MockReadRowsStream>();
722741 EXPECT_CALL (*stream, Read).WillOnce (Return (Status ()));
@@ -726,7 +745,7 @@ TEST(DataConnectionTest, ReadRowsFull) {
726745 auto conn = TestConnection (std::move (mock));
727746 internal::OptionsSpan span (CallOptions ());
728747 auto reader = conn->ReadRowsFull (bigtable::ReadRowsParams{
729- kTableName , kAppProfile , TestRowSet (), 42 , TestFilter ()});
748+ kTableName , kAppProfile , TestRowSet (), 42 , TestFilter (), true });
730749 EXPECT_EQ (reader.begin (), reader.end ());
731750}
732751
@@ -1478,6 +1497,32 @@ TEST(DataConnectionTest, AsyncReadRows) {
14781497 TestFilter ());
14791498}
14801499
1500+ TEST (DataConnectionTest, AsyncReadRowsReverseScan) {
1501+ auto mock = std::make_shared<MockBigtableStub>();
1502+ EXPECT_CALL (*mock, AsyncReadRows)
1503+ .WillOnce (
1504+ [](CompletionQueue const &, auto , v2::ReadRowsRequest const & request) {
1505+ EXPECT_TRUE (request.reversed ());
1506+ using ErrorStream =
1507+ internal::AsyncStreamingReadRpcError<v2::ReadRowsResponse>;
1508+ return std::make_unique<ErrorStream>(PermanentError ());
1509+ });
1510+
1511+ MockFunction<future<bool >(bigtable::Row const &)> on_row;
1512+ EXPECT_CALL (on_row, Call).Times (0 );
1513+
1514+ MockFunction<void (Status)> on_finish;
1515+ EXPECT_CALL (on_finish, Call).WillOnce ([](Status const & status) {
1516+ EXPECT_THAT (status, StatusIs (StatusCode::kPermissionDenied ));
1517+ });
1518+
1519+ auto conn = TestConnection (std::move (mock));
1520+ internal::OptionsSpan span (CallOptions ().set <ReverseScanOption>(true ));
1521+ conn->AsyncReadRows (kTableName , on_row.AsStdFunction (),
1522+ on_finish.AsStdFunction (), TestRowSet (), 42 ,
1523+ TestFilter ());
1524+ }
1525+
14811526TEST (DataConnectionTest, AsyncReadRowEmpty) {
14821527 auto mock = std::make_shared<MockBigtableStub>();
14831528 EXPECT_CALL (*mock, AsyncReadRows)
0 commit comments