Skip to content

Commit 4408ac9

Browse files
authored
cleanup(bigtable): AsyncReadRows accepts move-only types again (#9317)
1 parent ed4f43c commit 4408ac9

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

google/cloud/bigtable/table.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,19 +889,32 @@ class Table {
889889
future<bool>>::value,
890890
"RowFunctor should return a future<bool>.");
891891

892+
auto on_row_ptr = std::make_shared<RowFunctor>(std::move(on_row));
893+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
894+
auto on_row_fn = [on_row_ptr](Row row) {
895+
return (*on_row_ptr)(std::move(row));
896+
};
897+
898+
auto on_finish_ptr = std::make_shared<FinishFunctor>(std::move(on_finish));
899+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
900+
auto on_finish_fn = [on_finish_ptr](Status status) {
901+
return (*on_finish_ptr)(std::move(status));
902+
};
903+
892904
if (connection_) {
893905
google::cloud::internal::OptionsSpan span(options_);
894-
connection_->AsyncReadRows(
895-
app_profile_id_, table_name_, std::move(on_row), std::move(on_finish),
896-
std::move(row_set), rows_limit, std::move(filter));
906+
connection_->AsyncReadRows(app_profile_id_, table_name_,
907+
std::move(on_row_fn), std::move(on_finish_fn),
908+
std::move(row_set), rows_limit,
909+
std::move(filter));
897910
return;
898911
}
899912

900913
bigtable_internal::LegacyAsyncRowReader::Create(
901914
background_threads_->cq(), client_, app_profile_id_, table_name_,
902-
std::move(on_row), std::move(on_finish), std::move(row_set), rows_limit,
903-
std::move(filter), clone_rpc_retry_policy(), clone_rpc_backoff_policy(),
904-
metadata_update_policy_,
915+
std::move(on_row_fn), std::move(on_finish_fn), std::move(row_set),
916+
rows_limit, std::move(filter), clone_rpc_retry_policy(),
917+
clone_rpc_backoff_policy(), metadata_update_policy_,
905918
absl::make_unique<bigtable::internal::ReadRowsParserFactory>());
906919
}
907920

google/cloud/bigtable/table_test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using ::testing::Matcher;
3535
using ::testing::MockFunction;
3636
using ::testing::Property;
3737
using ::testing::Return;
38+
using ::testing::Unused;
3839

3940
auto const* const kProjectId = "test-project";
4041
auto const* const kInstanceId = "test-instance";
@@ -498,6 +499,40 @@ TEST(TableTest, AsyncReadRowsWithRowLimit) {
498499
TestRowSet(), 42, TestFilter());
499500
}
500501

502+
TEST(TableTest, AsyncReadRowsAcceptsMoveOnlyTypes) {
503+
auto mock = std::make_shared<MockDataConnection>();
504+
EXPECT_CALL(*mock, AsyncReadRows)
505+
.WillOnce([](Unused, Unused,
506+
std::function<future<bool>(bigtable::Row)> const& on_row,
507+
std::function<void(Status)> const& on_finish, Unused, Unused,
508+
Unused) {
509+
// Invoke the callbacks.
510+
EXPECT_TRUE(on_row(bigtable::Row("row", {})).get());
511+
on_finish(PermanentError());
512+
});
513+
514+
class MoveOnly {
515+
public:
516+
MoveOnly() = default;
517+
MoveOnly(MoveOnly&&) = default;
518+
MoveOnly& operator=(MoveOnly&&) = default;
519+
MoveOnly(const MoveOnly&) = delete;
520+
MoveOnly& operator=(const MoveOnly&) = delete;
521+
522+
future<bool> operator()(Row const& row) {
523+
EXPECT_EQ("row", row.row_key());
524+
return make_ready_future(true);
525+
}
526+
527+
void operator()(Status const& status) {
528+
EXPECT_THAT(status, StatusIs(StatusCode::kPermissionDenied));
529+
}
530+
};
531+
532+
auto table = TestTable(std::move(mock));
533+
table.AsyncReadRows(MoveOnly{}, MoveOnly{}, TestRowSet(), TestFilter());
534+
}
535+
501536
TEST(TableTest, AsyncReadRow) {
502537
auto mock = std::make_shared<MockDataConnection>();
503538
EXPECT_CALL(*mock, AsyncReadRow)

0 commit comments

Comments
 (0)