Skip to content

Commit 05cf595

Browse files
committed
partial table test updates
1 parent 87f4b35 commit 05cf595

2 files changed

Lines changed: 55 additions & 23 deletions

File tree

google/cloud/bigtable/testing/table_integration_test.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ class TableIntegrationTest
162162
return names;
163163
}
164164

165+
static StatusOr<std::vector<std::string>> TableNames(
166+
StreamRange<google::bigtable::admin::v2::Table>& tables) {
167+
std::vector<std::string> names;
168+
for (auto const& table : tables) {
169+
if (!table) return table.status();
170+
names.push_back(table->name());
171+
}
172+
return names;
173+
}
174+
165175
static std::vector<std::string> BackupNames(
166176
std::vector<google::bigtable::admin::v2::Backup> const& backups) {
167177
std::vector<std::string> names(backups.size());

google/cloud/bigtable/tests/admin_integration_test.cc

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
16+
#include "google/cloud/bigtable/table_config.h"
1617
#include "google/cloud/bigtable/testing/table_integration_test.h"
1718
#include "google/cloud/internal/getenv.h"
1819
#include "google/cloud/internal/random.h"
@@ -66,7 +67,7 @@ TEST_F(TableAdminIntegrationTest, TableListWithMultipleTables) {
6667
bigtable::TableName(project_id(), instance_id(), std::move(table_id)));
6768
}
6869
google::bigtable::admin::v2::ListTablesRequest list_request;
69-
list_request.set_parent(bigtable::InstanceName(project_id(), instance_id()));
70+
list_request.set_parent(instance_name);
7071
list_request.set_view(btadmin::Table::NAME_ONLY);
7172
auto tables = table_admin_->ListTables(list_request);
7273
std::vector<btadmin::Table> table_list;
@@ -93,7 +94,7 @@ TEST_F(TableAdminIntegrationTest, TableListWithMultipleTables) {
9394
EXPECT_THAT(names, Not(Contains(t)));
9495
}
9596
}
96-
#if 0
97+
9798
TEST_F(TableAdminIntegrationTest, DropRowsByPrefix) {
9899
auto table = GetTable();
99100

@@ -119,10 +120,11 @@ TEST_F(TableAdminIntegrationTest, DropRowsByPrefix) {
119120
// Create records
120121
CreateCells(table, created_cells);
121122
// Delete all the records for a row
122-
EXPECT_STATUS_OK(table_admin_->DropRowsByPrefix(
123-
bigtable::testing::TableTestEnvironment::table_id(), row_key1_prefix));
123+
google::bigtable::admin::v2::DropRowRangeRequest drop_rows_by_prefix;
124+
drop_rows_by_prefix.set_name(table.table_name());
125+
drop_rows_by_prefix.set_row_key_prefix(row_key1_prefix);
126+
EXPECT_STATUS_OK(table_admin_->DropRowRange(drop_rows_by_prefix));
124127
auto actual_cells = ReadRows(table, bigtable::Filter::PassAllFilter());
125-
126128
CheckEqualUnordered(expected_cells, actual_cells);
127129
}
128130

@@ -143,10 +145,11 @@ TEST_F(TableAdminIntegrationTest, DropAllRows) {
143145
// Create records
144146
CreateCells(table, created_cells);
145147
// Delete all the records from a table
146-
EXPECT_STATUS_OK(table_admin_->DropAllRows(
147-
bigtable::testing::TableTestEnvironment::table_id()));
148+
google::bigtable::admin::v2::DropRowRangeRequest drop_all_rows;
149+
drop_all_rows.set_name(table.table_name());
150+
drop_all_rows.set_delete_all_data_from_table(true);
151+
EXPECT_STATUS_OK(table_admin_->DropRowRange(drop_all_rows));
148152
auto actual_cells = ReadRows(table, bigtable::Filter::PassAllFilter());
149-
150153
ASSERT_TRUE(actual_cells.empty());
151154
}
152155

@@ -156,6 +159,7 @@ TEST_F(TableAdminIntegrationTest, CreateListGetDeleteTable) {
156159
auto const table_id = RandomTableId();
157160
auto const table_name =
158161
bigtable::TableName(project_id(), instance_id(), table_id);
162+
auto const instance_name = InstanceName(project_id(), instance_id());
159163

160164
// Create table config
161165
bigtable::TableConfig table_config(
@@ -164,17 +168,28 @@ TEST_F(TableAdminIntegrationTest, CreateListGetDeleteTable) {
164168
{"a1000", "a2000", "b3000", "m5000"});
165169

166170
// Create table
167-
ASSERT_STATUS_OK(table_admin_->CreateTable(table_id, table_config));
171+
google::bigtable::admin::v2::CreateTableRequest create_request =
172+
std::move(table_config).as_proto();
173+
create_request.set_parent(instance_name);
174+
create_request.set_table_id(table_id);
175+
ASSERT_STATUS_OK(table_admin_->CreateTable(create_request));
168176
bigtable::Table table(MakeDataConnection(),
169177
TableResource(project_id(), instance_id(), table_id));
170178

171179
// List tables
172-
auto tables = table_admin_->ListTables(btadmin::Table::NAME_ONLY);
173-
ASSERT_STATUS_OK(tables);
174-
EXPECT_THAT(TableNames(*tables), Contains(table_name));
180+
google::bigtable::admin::v2::ListTablesRequest list_request;
181+
list_request.set_parent(instance_name);
182+
list_request.set_view(btadmin::Table::NAME_ONLY);
183+
auto tables = table_admin_->ListTables(list_request);
184+
auto table_list = TableNames(tables);
185+
ASSERT_STATUS_OK(table_list);
186+
EXPECT_THAT(*table_list, Contains(table_name));
175187

176188
// Get table
177-
auto table_detailed = table_admin_->GetTable(table_id, btadmin::Table::FULL);
189+
google::bigtable::admin::v2::GetTableRequest get_request;
190+
get_request.set_name(table_name);
191+
get_request.set_view(btadmin::Table::FULL);
192+
auto table_detailed = table_admin_->GetTable(get_request);
178193
ASSERT_STATUS_OK(table_detailed);
179194

180195
// Verify new table was created
@@ -195,15 +210,20 @@ TEST_F(TableAdminIntegrationTest, CreateListGetDeleteTable) {
195210
EXPECT_EQ(1, count_matching_families(*table_detailed, "foo"));
196211

197212
// Update table
198-
std::vector<bigtable::ColumnFamilyModification> column_modification_list = {
199-
bigtable::ColumnFamilyModification::Create(
200-
"newfam", GC::Intersection(GC::MaxAge(std::chrono::hours(7 * 24)),
201-
GC::MaxNumVersions(1))),
202-
bigtable::ColumnFamilyModification::Update("fam", GC::MaxNumVersions(2)),
203-
bigtable::ColumnFamilyModification::Drop("foo")};
213+
std::vector<
214+
google::bigtable::admin::v2::ModifyColumnFamiliesRequest::Modification>
215+
column_modification_list = {
216+
bigtable::ColumnFamilyModification::Create(
217+
"newfam", GC::Intersection(GC::MaxAge(std::chrono::hours(7 * 24)),
218+
GC::MaxNumVersions(1)))
219+
.as_proto(),
220+
bigtable::ColumnFamilyModification::Update("fam",
221+
GC::MaxNumVersions(2))
222+
.as_proto(),
223+
bigtable::ColumnFamilyModification::Drop("foo").as_proto()};
204224

205225
auto table_modified =
206-
table_admin_->ModifyColumnFamilies(table_id, column_modification_list);
226+
table_admin_->ModifyColumnFamilies(table_name, column_modification_list);
207227
ASSERT_STATUS_OK(table_modified);
208228
EXPECT_EQ(1, count_matching_families(*table_modified, "fam"));
209229
EXPECT_EQ(0, count_matching_families(*table_modified, "foo"));
@@ -216,10 +236,12 @@ TEST_F(TableAdminIntegrationTest, CreateListGetDeleteTable) {
216236
EXPECT_STATUS_OK(table_admin_->DeleteTable(table_id));
217237

218238
// List to verify it is no longer there
219-
tables = table_admin_->ListTables(btadmin::Table::NAME_ONLY);
220-
ASSERT_STATUS_OK(tables);
221-
EXPECT_THAT(TableNames(*tables), Not(Contains(table_name)));
239+
tables = table_admin_->ListTables(list_request);
240+
table_list = TableNames(tables);
241+
ASSERT_STATUS_OK(table_list);
242+
EXPECT_THAT(*table_list, Not(Contains(table_name)));
222243
}
244+
#if 0
223245

224246
/// @test Verify that `bigtable::TableAdmin` WaitForConsistencyCheck works as
225247
/// expected.

0 commit comments

Comments
 (0)