Skip to content

Commit 8abeaca

Browse files
authored
test(bigtable): exercise DataConnection in integration tests (#9110)
1 parent 39ef319 commit 8abeaca

File tree

3 files changed

+45
-27
lines changed

3 files changed

+45
-27
lines changed

google/cloud/bigtable/testing/table_integration_test.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void TableAdminTestEnvironment::TearDown() {
112112
}
113113

114114
void TableIntegrationTest::SetUp() {
115+
data_connection_ = bigtable_internal::MakeDataConnection();
115116
data_client_ = bigtable::MakeDataClient(TableTestEnvironment::project_id(),
116117
TableTestEnvironment::instance_id());
117118

@@ -153,7 +154,14 @@ void TableIntegrationTest::SetUp() {
153154
}
154155
}
155156

156-
bigtable::Table TableIntegrationTest::GetTable() {
157+
bigtable::Table TableIntegrationTest::GetTable(
158+
std::string const& implementation) {
159+
if (implementation == "with-data-connection") {
160+
return bigtable_internal::MakeTable(data_connection_,
161+
TableTestEnvironment::project_id(),
162+
TableTestEnvironment::instance_id(), "",
163+
TableTestEnvironment::table_id());
164+
}
157165
return bigtable::Table(data_client_, TableTestEnvironment::table_id());
158166
}
159167

google/cloud/bigtable/testing/table_integration_test.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class TableIntegrationTest
9696
void SetUp() override;
9797

9898
/// Gets a Table object for the current test.
99-
bigtable::Table GetTable();
99+
bigtable::Table GetTable(
100+
std::string const& implementation = "with-data-client");
100101

101102
/// Return all the cells in @p table that pass @p filter.
102103
static std::vector<bigtable::Cell> ReadRows(bigtable::Table& table,
@@ -179,6 +180,7 @@ class TableIntegrationTest
179180
}
180181

181182
std::shared_ptr<bigtable::DataClient> data_client_;
183+
std::shared_ptr<bigtable_internal::DataConnection> data_connection_;
182184
};
183185

184186
} // namespace testing

google/cloud/bigtable/tests/data_integration_test.cc

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ using ::std::chrono::milliseconds;
3434
using ::testing::Contains;
3535
using ::testing::HasSubstr;
3636

37-
using DataIntegrationTest =
37+
using DataIntegrationTestClientOnly =
3838
::google::cloud::bigtable::testing::TableIntegrationTest;
3939

40+
class DataIntegrationTest : public DataIntegrationTestClientOnly,
41+
public ::testing::WithParamInterface<std::string> {
42+
};
43+
44+
INSTANTIATE_TEST_SUITE_P(, DataIntegrationTest,
45+
::testing::Values("with-data-connection",
46+
"with-data-client"));
47+
4048
/// Use Table::Apply() to insert a single row.
4149
void Apply(Table& table, std::string const& row_key,
4250
std::vector<Cell> const& cells) {
@@ -76,7 +84,7 @@ std::string const kFamily2 = "family2";
7684
std::string const kFamily3 = "family3";
7785
std::string const kFamily4 = "family4";
7886

79-
TEST_F(DataIntegrationTest, TableApply) {
87+
TEST_F(DataIntegrationTestClientOnly, TableApply) {
8088
auto table = GetTable();
8189

8290
std::string const row_key = "row-key-1";
@@ -90,7 +98,7 @@ TEST_F(DataIntegrationTest, TableApply) {
9098
CheckEqualUnordered(expected, actual);
9199
}
92100

93-
TEST_F(DataIntegrationTest, TableBulkApply) {
101+
TEST_F(DataIntegrationTestClientOnly, TableBulkApply) {
94102
auto table = GetTable();
95103

96104
std::vector<Cell> created{{"row-key-1", kFamily4, "c0", 1000, "v1000"},
@@ -115,7 +123,7 @@ TEST_F(DataIntegrationTest, TableBulkApply) {
115123
CheckEqualUnordered(expected, actual);
116124
}
117125

118-
TEST_F(DataIntegrationTest, TableSingleRow) {
126+
TEST_F(DataIntegrationTestClientOnly, TableSingleRow) {
119127
std::string const row_key = "row-key-1";
120128
auto table = GetTable();
121129

@@ -132,7 +140,7 @@ TEST_F(DataIntegrationTest, TableSingleRow) {
132140
CheckEqualUnordered(expected, actual);
133141
}
134142

135-
TEST_F(DataIntegrationTest, TableReadRowTest) {
143+
TEST_F(DataIntegrationTestClientOnly, TableReadRowTest) {
136144
auto table = GetTable();
137145
std::string const row_key1 = "row-key-1";
138146
std::string const row_key2 = "row-key-2";
@@ -149,7 +157,7 @@ TEST_F(DataIntegrationTest, TableReadRowTest) {
149157
CheckEqualUnordered(expected, actual);
150158
}
151159

152-
TEST_F(DataIntegrationTest, TableReadRowNotExistTest) {
160+
TEST_F(DataIntegrationTestClientOnly, TableReadRowNotExistTest) {
153161
auto table = GetTable();
154162
std::string const row_key1 = "row-key-1";
155163
std::string const row_key2 = "row-key-2";
@@ -162,7 +170,7 @@ TEST_F(DataIntegrationTest, TableReadRowNotExistTest) {
162170
EXPECT_FALSE(row_cell->first);
163171
}
164172

165-
TEST_F(DataIntegrationTest, TableReadRowsAllRows) {
173+
TEST_F(DataIntegrationTestClientOnly, TableReadRowsAllRows) {
166174
auto table = GetTable();
167175
std::string const row_key1 = "row-key-1";
168176
std::string const row_key2 = "row-key-2";
@@ -194,7 +202,7 @@ TEST_F(DataIntegrationTest, TableReadRowsAllRows) {
194202
CheckEqualUnordered(created, MoveCellsFromReader(read4));
195203
}
196204

197-
TEST_F(DataIntegrationTest, TableReadRowsPartialRows) {
205+
TEST_F(DataIntegrationTestClientOnly, TableReadRowsPartialRows) {
198206
auto table = GetTable();
199207
std::string const row_key1 = "row-key-1";
200208
std::string const row_key2 = "row-key-2";
@@ -236,7 +244,7 @@ TEST_F(DataIntegrationTest, TableReadRowsPartialRows) {
236244
}
237245
}
238246

239-
TEST_F(DataIntegrationTest, TableReadRowsNoRows) {
247+
TEST_F(DataIntegrationTestClientOnly, TableReadRowsNoRows) {
240248
auto table = GetTable();
241249
std::string const row_key1 = "row-key-1";
242250
std::string const row_key2 = "row-key-2";
@@ -262,22 +270,21 @@ TEST_F(DataIntegrationTest, TableReadRowsNoRows) {
262270
CheckEqualUnordered(expected, MoveCellsFromReader(read3));
263271
}
264272

265-
TEST_F(DataIntegrationTest, TableReadRowsWrongTable) {
266-
std::string const table_id = RandomTableId();
267-
268-
Table table(data_client_, table_id);
273+
TEST_P(DataIntegrationTest, TableReadRowsWrongTable) {
274+
auto table = GetTable(GetParam());
275+
auto other_table = table.WithNewTarget(table.project_id(),
276+
table.instance_id(), RandomTableId());
269277

270-
auto read1 = table.ReadRows(RowSet(RowRange::InfiniteRange()),
271-
Filter::PassAllFilter());
278+
auto read1 = other_table.ReadRows(RowSet(RowRange::InfiniteRange()),
279+
Filter::PassAllFilter());
272280

273281
auto it = read1.begin();
274282
ASSERT_NE(read1.end(), it);
275-
EXPECT_FALSE(*it);
276-
++it;
283+
EXPECT_FALSE(*it++);
277284
EXPECT_EQ(read1.end(), it);
278285
}
279286

280-
TEST_F(DataIntegrationTest, TableCheckAndMutateRowPass) {
287+
TEST_F(DataIntegrationTestClientOnly, TableCheckAndMutateRowPass) {
281288
auto table = GetTable();
282289
std::string const key = "row-key";
283290

@@ -295,7 +302,7 @@ TEST_F(DataIntegrationTest, TableCheckAndMutateRowPass) {
295302
CheckEqualUnordered(expected, actual);
296303
}
297304

298-
TEST_F(DataIntegrationTest, TableCheckAndMutateRowFail) {
305+
TEST_F(DataIntegrationTestClientOnly, TableCheckAndMutateRowFail) {
299306
auto table = GetTable();
300307
std::string const key = "row-key";
301308

@@ -313,7 +320,7 @@ TEST_F(DataIntegrationTest, TableCheckAndMutateRowFail) {
313320
CheckEqualUnordered(expected, actual);
314321
}
315322

316-
TEST_F(DataIntegrationTest, TableReadModifyWriteAppendValueTest) {
323+
TEST_F(DataIntegrationTestClientOnly, TableReadModifyWriteAppendValueTest) {
317324
auto table = GetTable();
318325
std::string const row_key1 = "row-key-1";
319326
std::string const row_key2 = "row-key-2";
@@ -349,7 +356,8 @@ TEST_F(DataIntegrationTest, TableReadModifyWriteAppendValueTest) {
349356
actual_cells_ignore_timestamp);
350357
}
351358

352-
TEST_F(DataIntegrationTest, TableReadModifyWriteRowIncrementAmountTest) {
359+
TEST_F(DataIntegrationTestClientOnly,
360+
TableReadModifyWriteRowIncrementAmountTest) {
353361
auto table = GetTable();
354362
std::string const key = "row-key";
355363

@@ -376,7 +384,7 @@ TEST_F(DataIntegrationTest, TableReadModifyWriteRowIncrementAmountTest) {
376384
CheckEqualUnordered(expected_ignore_timestamp, actual_ignore_timestamp);
377385
}
378386

379-
TEST_F(DataIntegrationTest, TableReadModifyWriteRowMultipleTest) {
387+
TEST_F(DataIntegrationTestClientOnly, TableReadModifyWriteRowMultipleTest) {
380388
auto table = GetTable();
381389
std::string const key = "row-key";
382390

@@ -420,7 +428,7 @@ TEST_F(DataIntegrationTest, TableReadModifyWriteRowMultipleTest) {
420428
CheckEqualUnordered(expected_ignore_timestamp, actual_ignore_timestamp);
421429
}
422430

423-
TEST_F(DataIntegrationTest, TableCellValueInt64Test) {
431+
TEST_F(DataIntegrationTestClientOnly, TableCellValueInt64Test) {
424432
auto table = GetTable();
425433
std::string const key = "row-key";
426434

@@ -455,7 +463,7 @@ TEST_F(DataIntegrationTest, TableCellValueInt64Test) {
455463
CheckEqualUnordered(expected_ignore_timestamp, actual_ignore_timestamp);
456464
}
457465

458-
TEST_F(DataIntegrationTest, TableReadMultipleCellsBigValue) {
466+
TEST_F(DataIntegrationTestClientOnly, TableReadMultipleCellsBigValue) {
459467
auto table = GetTable();
460468

461469
std::string const row_key = "row-key-1";
@@ -507,7 +515,7 @@ TEST_F(DataIntegrationTest, TableReadMultipleCellsBigValue) {
507515
CheckEqualUnordered(expected_ignore_timestamp, actual_ignore_timestamp);
508516
}
509517

510-
TEST_F(DataIntegrationTest, TableApplyWithLogging) {
518+
TEST_F(DataIntegrationTestClientOnly, TableApplyWithLogging) {
511519
// In our ci builds, we set GOOGLE_CLOUD_CPP_ENABLE_TRACING to log our tests,
512520
// by default. We should unset this variable and create a fresh client in
513521
// order to have a conclusive test.

0 commit comments

Comments
 (0)