-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impl(bigquery): Project options and policies (#11617)
- Loading branch information
Showing
10 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy.h" | ||
#include <memory> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
ProjectIdempotencyPolicy::~ProjectIdempotencyPolicy() = default; | ||
|
||
std::unique_ptr<ProjectIdempotencyPolicy> ProjectIdempotencyPolicy::clone() | ||
const { | ||
return std::make_unique<ProjectIdempotencyPolicy>(*this); | ||
} | ||
|
||
Idempotency ProjectIdempotencyPolicy::ListProjects(ListProjectsRequest const&) { | ||
return ::google::cloud::Idempotency::kIdempotent; | ||
} | ||
|
||
std::unique_ptr<ProjectIdempotencyPolicy> | ||
MakeDefaultProjectIdempotencyPolicy() { | ||
return std::make_unique<ProjectIdempotencyPolicy>(); | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google |
45 changes: 45 additions & 0 deletions
45
google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_IDEMPOTENCY_POLICY_H | ||
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_IDEMPOTENCY_POLICY_H | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_request.h" | ||
#include "google/cloud/idempotency.h" | ||
#include "google/cloud/version.h" | ||
#include <memory> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
class ProjectIdempotencyPolicy { | ||
public: | ||
virtual ~ProjectIdempotencyPolicy(); | ||
|
||
virtual std::unique_ptr<ProjectIdempotencyPolicy> clone() const; | ||
|
||
virtual google::cloud::Idempotency ListProjects( | ||
ListProjectsRequest const& request); | ||
}; | ||
|
||
std::unique_ptr<ProjectIdempotencyPolicy> MakeDefaultProjectIdempotencyPolicy(); | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google | ||
|
||
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_IDEMPOTENCY_POLICY_H |
34 changes: 34 additions & 0 deletions
34
google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy.h" | ||
#include <gmock/gmock.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
TEST(ProjectIdempotencyPolicytTest, ListProjects) { | ||
auto actual = MakeDefaultProjectIdempotencyPolicy(); | ||
auto expected = Idempotency::kIdempotent; | ||
|
||
ListProjectsRequest request; | ||
EXPECT_EQ(actual->ListProjects(request), expected); | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google |
56 changes: 56 additions & 0 deletions
56
google/cloud/bigquery/v2/minimal/internal/project_options.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_options.h" | ||
#include "google/cloud/bigquery/v2/minimal/internal/common_options.h" | ||
#include "google/cloud/internal/populate_common_options.h" | ||
#include <chrono> | ||
#include <memory> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
Options ProjectDefaultOptions(Options options) { | ||
options = google::cloud::internal::PopulateCommonOptions( | ||
std::move(options), "GOOGLE_CLOUD_CPP_BIGQUERY_V2_PROJECT_ENDPOINT", "", | ||
"GOOGLE_CLOUD_CPP_BIGQUERY_V2_PROJECT_AUTHORITY", | ||
"bigquery.googleapis.com"); | ||
|
||
if (!options.has<ProjectRetryPolicyOption>()) { | ||
options.set<ProjectRetryPolicyOption>( | ||
ProjectLimitedTimeRetryPolicy(std::chrono::minutes(30)).clone()); | ||
} | ||
if (!options.has<ProjectBackoffPolicyOption>()) { | ||
options.set<ProjectBackoffPolicyOption>( | ||
ExponentialBackoffPolicy(std::chrono::seconds(1), | ||
std::chrono::minutes(5), kBackoffScaling) | ||
.clone()); | ||
} | ||
if (!options.has<ProjectIdempotencyPolicyOption>()) { | ||
options.set<ProjectIdempotencyPolicyOption>( | ||
MakeDefaultProjectIdempotencyPolicy()); | ||
} | ||
if (!options.has<ProjectConnectionPoolSizeOption>()) { | ||
options.set<ProjectConnectionPoolSizeOption>(DefaultConnectionPoolSize()); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google |
76 changes: 76 additions & 0 deletions
76
google/cloud/bigquery/v2/minimal/internal/project_options.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_OPTIONS_H | ||
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_OPTIONS_H | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_idempotency_policy.h" | ||
#include "google/cloud/bigquery/v2/minimal/internal/project_retry_policy.h" | ||
#include "google/cloud/backoff_policy.h" | ||
#include "google/cloud/options.h" | ||
#include "google/cloud/version.h" | ||
#include <memory> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
/** | ||
* Use with `google::cloud::Options` to configure the retry policy. | ||
*/ | ||
struct ProjectRetryPolicyOption { | ||
using Type = std::shared_ptr<ProjectRetryPolicy>; | ||
}; | ||
|
||
/** | ||
* Use with `google::cloud::Options` to configure the backoff policy. | ||
*/ | ||
struct ProjectBackoffPolicyOption { | ||
using Type = std::shared_ptr<BackoffPolicy>; | ||
}; | ||
|
||
/** | ||
* Use with `google::cloud::Options` to configure which operations are retried. | ||
*/ | ||
struct ProjectIdempotencyPolicyOption { | ||
using Type = std::shared_ptr<ProjectIdempotencyPolicy>; | ||
}; | ||
|
||
/** | ||
* Use with `google::cloud::Options` to configure the connection pool size for | ||
* rest client. | ||
*/ | ||
struct ProjectConnectionPoolSizeOption { | ||
using Type = std::size_t; | ||
}; | ||
|
||
/** | ||
* The options applicable to Project. | ||
*/ | ||
using ProjectPolicyOptionList = | ||
OptionList<ProjectRetryPolicyOption, ProjectBackoffPolicyOption, | ||
ProjectIdempotencyPolicyOption, ProjectConnectionPoolSizeOption>; | ||
|
||
/** | ||
* Default options for Project. | ||
*/ | ||
Options ProjectDefaultOptions(Options options); | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google | ||
|
||
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_V2_MINIMAL_INTERNAL_PROJECT_OPTIONS_H |
58 changes: 58 additions & 0 deletions
58
google/cloud/bigquery/v2/minimal/internal/project_options_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2023 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/bigquery/v2/minimal/internal/project_options.h" | ||
#include "google/cloud/common_options.h" | ||
#include "google/cloud/testing_util/status_matchers.h" | ||
#include <gmock/gmock.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace bigquery_v2_minimal_internal { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
TEST(ProjectOptionsTest, DefaultOptions) { | ||
Options opts; | ||
auto actual = ProjectDefaultOptions(std::move(opts)); | ||
auto expected_retry = | ||
ProjectLimitedTimeRetryPolicy(std::chrono::minutes(30)).clone(); | ||
auto expected_backoff = ExponentialBackoffPolicy( | ||
std::chrono::seconds(1), std::chrono::minutes(5), 2.0); | ||
auto expected_idempotency = Idempotency::kIdempotent; | ||
auto const* default_endpoint = "bigquery.googleapis.com"; | ||
|
||
EXPECT_TRUE(actual.has<EndpointOption>()); | ||
EXPECT_EQ(actual.get<EndpointOption>(), default_endpoint); | ||
|
||
EXPECT_TRUE(actual.has<AuthorityOption>()); | ||
EXPECT_EQ(actual.get<AuthorityOption>(), default_endpoint); | ||
|
||
ListProjectsRequest request; | ||
EXPECT_TRUE(actual.has<ProjectIdempotencyPolicyOption>()); | ||
EXPECT_EQ(actual.get<ProjectIdempotencyPolicyOption>()->ListProjects(request), | ||
expected_idempotency); | ||
|
||
EXPECT_TRUE(actual.has<ProjectRetryPolicyOption>()); | ||
EXPECT_EQ(actual.get<ProjectRetryPolicyOption>()->IsExhausted(), | ||
expected_retry->IsExhausted()); | ||
|
||
EXPECT_TRUE(actual.has<ProjectBackoffPolicyOption>()); | ||
|
||
EXPECT_GT(actual.get<ProjectConnectionPoolSizeOption>(), 0); | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace bigquery_v2_minimal_internal | ||
} // namespace cloud | ||
} // namespace google |
Oops, something went wrong.