Skip to content

Commit f70e8fa

Browse files
committed
update tests and examples
1 parent 0235fe7 commit f70e8fa

17 files changed

Lines changed: 151 additions & 53 deletions

google/cloud/bigtable/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ int main(int argc, char* argv[]) try {
3838
namespace cbt = ::google::cloud::bigtable;
3939

4040
cbt::Table table(
41-
cbt::MakeDataConnection(),
41+
cbt::MakeDataConnection({
42+
cbt::InstanceResource(google::cloud::Project(project_id),
43+
instance_id),
44+
}),
4245
cbt::TableResource(project_id, instance_id, table_id),
4346
google::cloud::Options{}.set<cbt::AppProfileIdOption>(app_profile_id));
4447

google/cloud/bigtable/benchmarks/benchmark.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ void Benchmark::DeleteTable() {
130130
Table Benchmark::MakeTable(Options connection_opts) const {
131131
auto connection_options = MergeOptions(std::move(connection_opts), opts_);
132132
auto table_opts = Options{}.set<AppProfileIdOption>(options_.app_profile_id);
133-
return Table(MakeDataConnection(std::move(connection_options)),
134-
TableResource(options_.project_id, options_.instance_id,
135-
options_.table_id),
136-
std::move(table_opts));
133+
return Table(
134+
MakeDataConnection({InstanceResource(Project(options_.project_id),
135+
options_.instance_id)},
136+
std::move(connection_options)),
137+
TableResource(options_.project_id, options_.instance_id,
138+
options_.table_id),
139+
std::move(table_opts));
137140
}
138141

139142
google::cloud::StatusOr<BenchmarkResult> Benchmark::PopulateTable() {

google/cloud/bigtable/benchmarks/embedded_server_test.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ TEST(EmbeddedServer, TableApply) {
7676
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
7777
.set<EndpointOption>(server->address());
7878

79-
Table table(MakeDataConnection(options),
79+
Table table(MakeDataConnection(
80+
{InstanceResource(Project("fake-project"), "fake-instance")},
81+
std::move(options)),
8082
TableResource("fake-project", "fake-instance", "fake-table"));
8183

8284
SingleRowMutation mutation("row1",
@@ -101,7 +103,9 @@ TEST(EmbeddedServer, TableBulkApply) {
101103
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
102104
.set<EndpointOption>(server->address());
103105

104-
Table table(MakeDataConnection(options),
106+
Table table(MakeDataConnection(
107+
{InstanceResource(Project("fake-project"), "fake-instance")},
108+
std::move(options)),
105109
TableResource("fake-project", "fake-instance", "fake-table"));
106110

107111
BulkMutation bulk;
@@ -128,7 +132,9 @@ TEST(EmbeddedServer, ReadRows1) {
128132
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
129133
.set<EndpointOption>(server->address());
130134

131-
Table table(MakeDataConnection(options),
135+
Table table(MakeDataConnection(
136+
{InstanceResource(Project("fake-project"), "fake-instance")},
137+
std::move(options)),
132138
TableResource("fake-project", "fake-instance", "fake-table"));
133139

134140
EXPECT_EQ(0, server->read_rows_count());
@@ -150,7 +156,9 @@ TEST(EmbeddedServer, ReadRows100) {
150156
.set<GrpcCredentialOption>(grpc::InsecureChannelCredentials())
151157
.set<EndpointOption>(server->address());
152158

153-
Table table(MakeDataConnection(options),
159+
Table table(MakeDataConnection(
160+
{InstanceResource(Project("fake-project"), "fake-instance")},
161+
std::move(options)),
154162
TableResource("fake-project", "fake-instance", "fake-table"));
155163

156164
EXPECT_EQ(0, server->read_rows_count());

google/cloud/bigtable/benchmarks/mutation_batcher_throughput_benchmark.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ int main(int argc, char* argv[]) {
201201

202202
auto table = cbt::Table(
203203
cbt::MakeDataConnection(
204+
{cbt::InstanceResource(google::cloud::Project(options->project_id),
205+
options->instance_id)},
204206
Options{}.set<google::cloud::GrpcBackgroundThreadPoolSizeOption>(
205207
options->max_batches)),
206208
cbt::TableResource(options->project_id, options->instance_id, *table_id));

google/cloud/bigtable/examples/bigtable_examples_common.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "google/cloud/internal/disable_deprecation_warnings.inc"
1516
#include "google/cloud/bigtable/examples/bigtable_examples_common.h"
1617
#include "google/cloud/internal/getenv.h"
1718
#include "absl/strings/str_join.h"
@@ -53,7 +54,9 @@ Commands::value_type MakeCommandEntry(std::string const& name,
5354
throw Usage{std::move(os).str()};
5455
}
5556
google::cloud::bigtable::Table table(
56-
google::cloud::bigtable::MakeDataConnection(),
57+
google::cloud::bigtable::MakeDataConnection(
58+
{google::cloud::bigtable::InstanceResource(
59+
google::cloud::Project(argv[0]), argv[1])}),
5760
google::cloud::bigtable::TableResource(argv[0], argv[1], argv[2]));
5861
argv.erase(argv.begin(), argv.begin() + 3);
5962
function(table, argv);
@@ -118,7 +121,9 @@ Commands::value_type MakeCommandEntry(std::string const& name,
118121
throw Usage{std::move(os).str()};
119122
}
120123
google::cloud::bigtable::Table table(
121-
google::cloud::bigtable::MakeDataConnection(),
124+
google::cloud::bigtable::MakeDataConnection(
125+
{google::cloud::bigtable::InstanceResource(
126+
google::cloud::Project(argv[0]), argv[1])}),
122127
google::cloud::bigtable::TableResource(argv[0], argv[1], argv[2]));
123128
google::cloud::CompletionQueue cq;
124129
std::thread t([&cq] { cq.Run(); });

google/cloud/bigtable/examples/bigtable_hello_app_profile.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ void HelloWorldAppProfile(std::vector<std::string> const& argv) {
4343
std::string const& profile_id = argv[3];
4444

4545
// Create an object to access the Cloud Bigtable Data API.
46-
auto connection = cbt::MakeDataConnection();
46+
auto connection = cbt::MakeDataConnection(
47+
{cbt::InstanceResource(google::cloud::Project(project_id), instance_id)});
4748

4849
// Use the default profile to write some data.
4950
cbt::Table write(connection,

google/cloud/bigtable/examples/bigtable_hello_world.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ void BigtableHelloWorld(std::vector<std::string> const& argv) {
5252

5353
//! [connect data]
5454
// Create an object to access the Cloud Bigtable Data API.
55-
cbt::Table table(cbt::MakeDataConnection(),
55+
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
56+
google::cloud::Project(project_id), instance_id)}),
5657
cbt::TableResource(project_id, instance_id, table_id));
5758
//! [connect data]
5859
//! [connect admin] [END bigtable_hw_connect]

google/cloud/bigtable/examples/client_samples.cc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ void TableSetEndpoint(std::vector<std::string> const& argv) {
4040
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
4141
"private.googleapis.com");
4242
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
43-
return bigtable::Table(bigtable::MakeDataConnection(options), resource);
43+
return bigtable::Table(
44+
bigtable::MakeDataConnection(
45+
{bigtable::InstanceResource(google::cloud::Project(project_id),
46+
instance_id)},
47+
std::move(options)),
48+
resource);
4449
}
4550
//! [table-set-endpoint]
4651
(argv.at(0), argv.at(1), argv.at(2));
@@ -66,7 +71,10 @@ void SetRetryPolicy(std::vector<std::string> const& argv) {
6671
/*maximum_delay=*/std::chrono::seconds(45),
6772
/*scaling=*/2.0)
6873
.clone());
69-
auto connection = cbt::MakeDataConnection(options);
74+
auto connection = cbt::MakeDataConnection(
75+
{cbt::InstanceResource(google::cloud::Project(project_id),
76+
instance_id)},
77+
std::move(options));
7078

7179
auto const table_name =
7280
cbt::TableResource(project_id, instance_id, table_id);
@@ -111,7 +119,12 @@ void TableWithServiceAccount(std::vector<std::string> const& argv) {
111119
google::cloud::Options{}.set<google::cloud::UnifiedCredentialsOption>(
112120
google::cloud::MakeServiceAccountCredentials(contents));
113121
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
114-
return bigtable::Table(bigtable::MakeDataConnection(options), resource);
122+
return bigtable::Table(
123+
bigtable::MakeDataConnection(
124+
{bigtable::InstanceResource(google::cloud::Project(project_id),
125+
instance_id)},
126+
std::move(options)),
127+
resource);
115128
}
116129
//! [table-with-service-account]
117130
(argv.at(0), argv.at(1), argv.at(2), argv.at(3));
@@ -137,7 +150,12 @@ void TableSetUniverseDomain(std::vector<std::string> const& argv) {
137150

138151
if (!ud_options.ok()) throw std::move(ud_options).status();
139152
auto resource = bigtable::TableResource(project_id, instance_id, table_id);
140-
return bigtable::Table(bigtable::MakeDataConnection(*ud_options), resource);
153+
return bigtable::Table(
154+
bigtable::MakeDataConnection(
155+
{bigtable::InstanceResource(google::cloud::Project(project_id),
156+
instance_id)},
157+
*std::move(ud_options)),
158+
resource);
141159
}
142160
//! [table-set-universe-domain]
143161
(argv.at(0), argv.at(1), argv.at(2));

google/cloud/bigtable/examples/data_async_snippets.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ void RunAll(std::vector<std::string> const& argv) {
350350
if (!schema) throw std::move(schema).status();
351351

352352
using ::google::cloud::Options;
353-
cbt::Table table(cbt::MakeDataConnection(),
353+
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
354+
google::cloud::Project(project_id), instance_id)}),
354355
cbt::TableResource(project_id, instance_id, table_id),
355356
Options{}.set<cbt::IdempotentMutationPolicyOption>(
356357
cbt::AlwaysRetryMutationPolicy().clone()));

google/cloud/bigtable/examples/data_filter_snippets.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ void RunAll(std::vector<std::string> const& argv) {
579579
table_id, std::move(t));
580580
if (!schema) throw std::move(schema).status();
581581

582-
cbt::Table table(cbt::MakeDataConnection(),
582+
cbt::Table table(cbt::MakeDataConnection({cbt::InstanceResource(
583+
google::cloud::Project(project_id), instance_id)}),
583584
cbt::TableResource(project_id, instance_id, table_id));
584585

585586
std::cout << "\nPreparing data for multiple examples" << std::endl;

0 commit comments

Comments
 (0)