Skip to content

Commit fe748ba

Browse files
authored
feat(bigtable): per-operation Options (pt. 1) (#9623)
1 parent 1ccda8e commit fe748ba

6 files changed

Lines changed: 352 additions & 76 deletions

File tree

google/cloud/bigtable/data_connection.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,23 @@
2525

2626
namespace google {
2727
namespace cloud {
28-
namespace bigtable {
28+
namespace bigtable_internal {
2929
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30-
namespace {
3130

32-
std::vector<FailedMutation> MakeUnimplementedFailedMutations(std::size_t n) {
33-
std::vector<FailedMutation> mutations;
31+
std::vector<bigtable::FailedMutation> MakeFailedMutations(Status const& status,
32+
std::size_t n) {
33+
std::vector<bigtable::FailedMutation> mutations;
3434
mutations.reserve(n);
3535
for (int i = 0; i != static_cast<int>(n); ++i) {
36-
mutations.emplace_back(FailedMutation(
37-
Status(StatusCode::kUnimplemented, "not implemented"), i));
36+
mutations.emplace_back(bigtable::FailedMutation(status, i));
3837
}
3938
return mutations;
4039
}
4140

42-
} // namespace
41+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
42+
} // namespace bigtable_internal
43+
namespace bigtable {
44+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
4345

4446
DataConnection::~DataConnection() = default;
4547

@@ -58,13 +60,15 @@ future<Status> DataConnection::AsyncApply(
5860
std::vector<FailedMutation> DataConnection::BulkApply(
5961
// NOLINTNEXTLINE(performance-unnecessary-value-param)
6062
std::string const&, BulkMutation mut) {
61-
return MakeUnimplementedFailedMutations(mut.size());
63+
return bigtable_internal::MakeFailedMutations(
64+
Status(StatusCode::kUnimplemented, "not-implemented"), mut.size());
6265
}
6366

6467
future<std::vector<FailedMutation>> DataConnection::AsyncBulkApply(
6568
// NOLINTNEXTLINE(performance-unnecessary-value-param)
6669
std::string const&, BulkMutation mut) {
67-
return make_ready_future(MakeUnimplementedFailedMutations(mut.size()));
70+
return make_ready_future(bigtable_internal::MakeFailedMutations(
71+
Status(StatusCode::kUnimplemented, "not-implemented"), mut.size()));
6872
}
6973

7074
RowReader DataConnection::ReadRows(

google/cloud/bigtable/data_connection.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
namespace google {
3434
namespace cloud {
35+
namespace bigtable_internal {
36+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
37+
38+
std::vector<bigtable::FailedMutation> MakeFailedMutations(Status const& status,
39+
std::size_t n);
40+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
41+
} // namespace bigtable_internal
3542
namespace bigtable {
3643
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3744

google/cloud/bigtable/legacy_table_test.cc

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ namespace {
2626

2727
namespace btproto = ::google::bigtable::v2;
2828
using ::google::cloud::testing_util::FakeCompletionQueueImpl;
29+
using ::google::cloud::testing_util::StatusIs;
2930
using ::testing::HasSubstr;
31+
using ::testing::MockFunction;
32+
33+
Options NonEmptyOptions() {
34+
struct TestOption {
35+
using Type = bool;
36+
};
37+
return Options{}.set<TestOption>(true);
38+
}
3039

3140
/// Define types and functions used in the tests.
32-
namespace {
3341
class TableTest : public ::google::cloud::bigtable::testing::TableTestFixture {
3442
public:
3543
TableTest() : TableTestFixture(CompletionQueue{}) {}
3644
};
37-
} // anonymous namespace
3845

3946
TEST_F(TableTest, ClientProjectId) {
4047
EXPECT_EQ(kProjectId, client_->project_id());
@@ -260,6 +267,127 @@ TEST_F(ValidContextMdAsyncTest, AsyncReadModifyWriteRow) {
260267
ReadModifyWriteRule::AppendValue("fam", "list", ";element")));
261268
}
262269

270+
TEST_F(TableTest, ApplyWithOptions) {
271+
Table table(client_, kTableId);
272+
auto status = table.Apply(SingleRowMutation("row"), NonEmptyOptions());
273+
EXPECT_THAT(status, StatusIs(StatusCode::kInvalidArgument));
274+
}
275+
276+
TEST_F(TableTest, AsyncApplyWithOptions) {
277+
Table table(client_, kTableId);
278+
auto status = table.AsyncApply(SingleRowMutation("row"), NonEmptyOptions());
279+
EXPECT_THAT(status.get(), StatusIs(StatusCode::kInvalidArgument));
280+
}
281+
282+
TEST_F(TableTest, BulkApplyWithOptions) {
283+
Table table(client_, kTableId);
284+
auto bulk = BulkMutation(SingleRowMutation("r1"), SingleRowMutation("r2"));
285+
auto failed = table.BulkApply(bulk, NonEmptyOptions());
286+
ASSERT_EQ(2, failed.size());
287+
EXPECT_EQ(0, failed[0].original_index());
288+
EXPECT_THAT(failed[0].status(), StatusIs(StatusCode::kInvalidArgument));
289+
EXPECT_EQ(1, failed[1].original_index());
290+
EXPECT_THAT(failed[1].status(), StatusIs(StatusCode::kInvalidArgument));
291+
}
292+
293+
TEST_F(TableTest, AsyncBulkApplyWithOptions) {
294+
Table table(client_, kTableId);
295+
auto bulk = BulkMutation(SingleRowMutation("r1"), SingleRowMutation("r2"));
296+
auto failed = table.AsyncBulkApply(bulk, NonEmptyOptions()).get();
297+
ASSERT_EQ(2, failed.size());
298+
EXPECT_EQ(0, failed[0].original_index());
299+
EXPECT_THAT(failed[0].status(), StatusIs(StatusCode::kInvalidArgument));
300+
EXPECT_EQ(1, failed[1].original_index());
301+
EXPECT_THAT(failed[1].status(), StatusIs(StatusCode::kInvalidArgument));
302+
}
303+
304+
TEST_F(TableTest, ReadRowsWithOptions) {
305+
Table table(client_, kTableId);
306+
auto reader =
307+
table.ReadRows(RowSet(), Filter::PassAllFilter(), NonEmptyOptions());
308+
auto it = reader.begin();
309+
EXPECT_NE(it, reader.end());
310+
EXPECT_THAT(*it, StatusIs(StatusCode::kInvalidArgument));
311+
EXPECT_EQ(++it, reader.end());
312+
}
313+
314+
TEST_F(TableTest, ReadRowsWithLimitWithOptions) {
315+
Table table(client_, kTableId);
316+
auto reader =
317+
table.ReadRows(RowSet(), 1, Filter::PassAllFilter(), NonEmptyOptions());
318+
auto it = reader.begin();
319+
EXPECT_NE(it, reader.end());
320+
EXPECT_THAT(*it, StatusIs(StatusCode::kInvalidArgument));
321+
EXPECT_EQ(++it, reader.end());
322+
}
323+
324+
TEST_F(TableTest, ReadRowWithOptions) {
325+
Table table(client_, kTableId);
326+
auto row = table.ReadRow("row", Filter::PassAllFilter(), NonEmptyOptions());
327+
EXPECT_THAT(row, StatusIs(StatusCode::kInvalidArgument));
328+
}
329+
330+
TEST_F(TableTest, AsyncReadRowWithOptions) {
331+
Table table(client_, kTableId);
332+
auto row =
333+
table.AsyncReadRow("row", Filter::PassAllFilter(), NonEmptyOptions());
334+
EXPECT_THAT(row.get(), StatusIs(StatusCode::kInvalidArgument));
335+
}
336+
337+
TEST_F(TableTest, CheckAndMutateRowWithOptions) {
338+
Table table(client_, kTableId);
339+
auto branch = table.CheckAndMutateRow("row", Filter::PassAllFilter(), {}, {},
340+
NonEmptyOptions());
341+
EXPECT_THAT(branch, StatusIs(StatusCode::kInvalidArgument));
342+
}
343+
344+
TEST_F(TableTest, AsyncCheckAndMutateRowWithOptions) {
345+
Table table(client_, kTableId);
346+
auto branch = table.AsyncCheckAndMutateRow("row", Filter::PassAllFilter(), {},
347+
{}, NonEmptyOptions());
348+
EXPECT_THAT(branch.get(), StatusIs(StatusCode::kInvalidArgument));
349+
}
350+
351+
TEST_F(TableTest, SampleRowsWithOptions) {
352+
Table table(client_, kTableId);
353+
auto rows = table.SampleRows(NonEmptyOptions());
354+
EXPECT_THAT(rows, StatusIs(StatusCode::kInvalidArgument));
355+
}
356+
357+
TEST_F(TableTest, AsyncSampleRowsWithOptions) {
358+
Table table(client_, kTableId);
359+
auto rows = table.AsyncSampleRows(NonEmptyOptions());
360+
EXPECT_THAT(rows.get(), StatusIs(StatusCode::kInvalidArgument));
361+
}
362+
363+
TEST_F(TableTest, AsyncReadRowsWithOptions) {
364+
MockFunction<future<bool>(bigtable::Row const&)> on_row;
365+
EXPECT_CALL(on_row, Call).Times(0);
366+
367+
MockFunction<void(Status)> on_finish;
368+
EXPECT_CALL(on_finish, Call).WillOnce([](Status const& status) {
369+
EXPECT_THAT(status, StatusIs(StatusCode::kInvalidArgument));
370+
});
371+
372+
Table table(client_, kTableId);
373+
table.AsyncReadRows(on_row.AsStdFunction(), on_finish.AsStdFunction(),
374+
RowSet(), Filter::PassAllFilter(), NonEmptyOptions());
375+
}
376+
377+
TEST_F(TableTest, AsyncReadRowsWithLimitWithOptions) {
378+
MockFunction<future<bool>(bigtable::Row const&)> on_row;
379+
EXPECT_CALL(on_row, Call).Times(0);
380+
381+
MockFunction<void(Status)> on_finish;
382+
EXPECT_CALL(on_finish, Call).WillOnce([](Status const& status) {
383+
EXPECT_THAT(status, StatusIs(StatusCode::kInvalidArgument));
384+
});
385+
386+
Table table(client_, kTableId);
387+
table.AsyncReadRows(on_row.AsStdFunction(), on_finish.AsStdFunction(),
388+
RowSet(), 1, Filter::PassAllFilter(), NonEmptyOptions());
389+
}
390+
263391
} // namespace
264392
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
265393
} // namespace bigtable

0 commit comments

Comments
 (0)