Skip to content

Commit

Permalink
feat(bigtable): add AppProfileIdOption (#9382)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Jun 29, 2022
1 parent dce75df commit 8b167c8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 26 deletions.
23 changes: 23 additions & 0 deletions google/cloud/bigtable/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ namespace cloud {
namespace bigtable {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/**
* The application profile id.
*
* An application profile, or app profile, stores settings that tell your Cloud
* Bigtable instance how to handle incoming requests from an application. When
* an applications connects to a Bigtable instance, it can specify an app
* profile, and Bigtable uses that app profile for requests that the application
* sends over that connection.
*
* This option is always used in conjunction with a `bigtable::Table`. The app
* profile belongs to the table's instance, with an id given by the value of
* this option.
*
* @see https://cloud.google.com/bigtable/docs/app-profiles for an overview of
* app profiles.
*
* @see https://cloud.google.com/bigtable/docs/replication-overview#app-profiles
* for how app profiles are used to achieve replication.
*/
struct AppProfileIdOption {
using Type = std::string;
};

/**
* The endpoint for data operations.
*
Expand Down
21 changes: 10 additions & 11 deletions google/cloud/bigtable/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "google/cloud/bigtable/internal/legacy_async_row_reader.h"
#include "google/cloud/bigtable/mutation_branch.h"
#include "google/cloud/bigtable/mutations.h"
#include "google/cloud/bigtable/options.h"
#include "google/cloud/bigtable/read_modify_write_rule.h"
#include "google/cloud/bigtable/resource_names.h"
#include "google/cloud/bigtable/row_key_sample.h"
Expand All @@ -34,6 +35,7 @@
#include "google/cloud/bigtable/version.h"
#include "google/cloud/future.h"
#include "google/cloud/grpc_error_delegate.h"
#include "google/cloud/options.h"
#include "google/cloud/status.h"
#include "google/cloud/status_or.h"
#include "absl/meta/type_traits.h"
Expand All @@ -53,8 +55,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
// public.
bigtable::Table MakeTable(std::shared_ptr<bigtable::DataConnection> conn,
std::string project_id, std::string instance_id,
std::string app_profile_id, std::string table_id,
Options options = {});
std::string table_id, Options options = {});

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_internal
Expand Down Expand Up @@ -953,12 +954,11 @@ class Table {
private:
friend Table bigtable_internal::MakeTable(
std::shared_ptr<bigtable::DataConnection>, std::string, std::string,
std::string, std::string, Options);
std::string, Options);
explicit Table(std::shared_ptr<bigtable::DataConnection> conn,
std::string project_id, std::string instance_id,
std::string app_profile_id, std::string table_id,
Options options = {})
: app_profile_id_(std::move(app_profile_id)),
std::string table_id, Options options = {})
: app_profile_id_(options.get<AppProfileIdOption>()),
project_id_(std::move(project_id)),
instance_id_(std::move(instance_id)),
table_name_(TableName(project_id_, instance_id_, table_id)),
Expand Down Expand Up @@ -1051,12 +1051,11 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

inline bigtable::Table MakeTable(std::shared_ptr<bigtable::DataConnection> conn,
std::string project_id,
std::string instance_id,
std::string app_profile_id,
std::string table_id, Options options) {
std::string instance_id, std::string table_id,
Options options) {
return bigtable::Table(std::move(conn), std::move(project_id),
std::move(instance_id), std::move(app_profile_id),
std::move(table_id), std::move(options));
std::move(instance_id), std::move(table_id),
std::move(options));
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down
24 changes: 19 additions & 5 deletions google/cloud/bigtable/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ struct TestOption {
using Type = bool;
};

Options TableOptions() { return Options{}.set<TestOption>(true); }
Options TableOptions() {
return Options{}.set<AppProfileIdOption>(kAppProfileId).set<TestOption>(true);
}

Table TestTable(std::shared_ptr<MockDataConnection> mock) {
EXPECT_CALL(*mock, options).WillOnce(Return(Options{}));
EXPECT_CALL(*mock, options).WillRepeatedly(Return(Options{}));
return bigtable_internal::MakeTable(std::move(mock), kProjectId, kInstanceId,
kAppProfileId, kTableId, TableOptions());
kTableId, TableOptions());
}

void CheckCurrentOptions() {
Expand All @@ -131,14 +133,26 @@ void CheckCurrentOptions() {

TEST(TableTest, ConnectionConstructor) {
auto conn = std::make_shared<MockDataConnection>();
auto table = TestTable(std::move(conn));
EXPECT_EQ(kAppProfileId, table.app_profile_id());
auto table = bigtable_internal::MakeTable(std::move(conn), kProjectId,
kInstanceId, kTableId);
EXPECT_EQ(kProjectId, table.project_id());
EXPECT_EQ(kInstanceId, table.instance_id());
EXPECT_EQ(kTableId, table.table_id());
EXPECT_EQ(kTableName, table.table_name());
}

TEST(TableTest, AppProfileId) {
auto conn = std::make_shared<MockDataConnection>();
auto table =
bigtable_internal::MakeTable(conn, kProjectId, kInstanceId, kTableId);
EXPECT_EQ("", table.app_profile_id());

table = bigtable_internal::MakeTable(
conn, kProjectId, kInstanceId, kTableId,
Options{}.set<AppProfileIdOption>(kAppProfileId));
EXPECT_EQ(kAppProfileId, table.app_profile_id());
}

TEST(TableTest, Apply) {
auto mock = std::make_shared<MockDataConnection>();
EXPECT_CALL(*mock, Apply)
Expand Down
7 changes: 3 additions & 4 deletions google/cloud/bigtable/testing/table_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ void TableIntegrationTest::SetUp() {
bigtable::Table TableIntegrationTest::GetTable(
std::string const& implementation) {
if (implementation == "with-data-connection") {
return bigtable_internal::MakeTable(data_connection_,
TableTestEnvironment::project_id(),
TableTestEnvironment::instance_id(), "",
TableTestEnvironment::table_id());
return bigtable_internal::MakeTable(
data_connection_, TableTestEnvironment::project_id(),
TableTestEnvironment::instance_id(), TableTestEnvironment::table_id());
}
return bigtable::Table(data_client_, TableTestEnvironment::table_id());
}
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigtable/tests/data_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ TEST_P(DataIntegrationTest, TableApplyWithLogging) {
if (GetParam() == "with-data-connection") {
auto conn = MakeDataConnection(options);
return bigtable_internal::MakeTable(std::move(conn), project_id(),
instance_id(), "", table_id);
instance_id(), table_id);
}
auto data_client = MakeDataClient(project_id(), instance_id(), options);
return Table(std::move(data_client), table_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SampleRowsIntegrationTest
auto table = bigtable_internal::MakeTable(
MakeDataConnection(Options{}.set<TracingComponentsOption>({"rpc"})),
TableTestEnvironment::project_id(), TableTestEnvironment::instance_id(),
"", TableTestEnvironment::table_id());
TableTestEnvironment::table_id());

int constexpr kBatchCount = 10;
int constexpr kBatchSize = 5000;
Expand Down Expand Up @@ -107,16 +107,14 @@ class SampleRowsIntegrationTest
TEST_F(SampleRowsIntegrationTest, SyncWithDataConnection) {
auto table = bigtable_internal::MakeTable(
MakeDataConnection(), TableTestEnvironment::project_id(),
TableTestEnvironment::instance_id(), "",
TableTestEnvironment::table_id());
TableTestEnvironment::instance_id(), TableTestEnvironment::table_id());
VerifySamples(table.SampleRows());
};

TEST_F(SampleRowsIntegrationTest, AsyncWithDataConnection) {
auto table = bigtable_internal::MakeTable(
MakeDataConnection(), TableTestEnvironment::project_id(),
TableTestEnvironment::instance_id(), "",
TableTestEnvironment::table_id());
TableTestEnvironment::instance_id(), TableTestEnvironment::table_id());
auto fut = table.AsyncSampleRows();
VerifySamples(fut.get());
};
Expand Down

0 comments on commit 8b167c8

Please sign in to comment.