Skip to content

Commit

Permalink
feat(generator): connection respects per call policies (#8013)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Jan 19, 2022
1 parent cdf0814 commit bc7f1c5
Show file tree
Hide file tree
Showing 72 changed files with 3,816 additions and 1,806 deletions.
3 changes: 2 additions & 1 deletion generator/integration_tests/golden/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ function (google_cloud_cpp_generator_define_golden_tests)
tests/golden_thing_admin_metadata_decorator_test.cc
tests/golden_thing_admin_option_defaults_test.cc
tests/golden_thing_admin_stub_factory_test.cc
tests/golden_thing_admin_stub_test.cc)
tests/golden_thing_admin_stub_test.cc
tests/plumbing_test.cc)

# Export the list of unit tests to a .bzl file so we do not need to maintain
# the list in two places.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
GenerateAccessToken(
google::test::admin::database::v1::GenerateAccessTokenRequest const& request) override {
return google::cloud::internal::RetryLoop(
retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
idempotency_policy_->GenerateAccessToken(request),
retry_policy(), backoff_policy(),
idempotency_policy()->GenerateAccessToken(request),
[this](grpc::ClientContext& context,
google::test::admin::database::v1::GenerateAccessTokenRequest const& request) {
return stub_->GenerateAccessToken(context, request);
Expand All @@ -131,8 +131,8 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
GenerateIdToken(
google::test::admin::database::v1::GenerateIdTokenRequest const& request) override {
return google::cloud::internal::RetryLoop(
retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
idempotency_policy_->GenerateIdToken(request),
retry_policy(), backoff_policy(),
idempotency_policy()->GenerateIdToken(request),
[this](grpc::ClientContext& context,
google::test::admin::database::v1::GenerateIdTokenRequest const& request) {
return stub_->GenerateIdToken(context, request);
Expand All @@ -144,8 +144,8 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
WriteLogEntries(
google::test::admin::database::v1::WriteLogEntriesRequest const& request) override {
return google::cloud::internal::RetryLoop(
retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
idempotency_policy_->WriteLogEntries(request),
retry_policy(), backoff_policy(),
idempotency_policy()->WriteLogEntries(request),
[this](grpc::ClientContext& context,
google::test::admin::database::v1::WriteLogEntriesRequest const& request) {
return stub_->WriteLogEntries(context, request);
Expand All @@ -158,10 +158,10 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
request.clear_page_token();
auto stub = stub_;
auto retry =
std::shared_ptr<GoldenKitchenSinkRetryPolicy const>(retry_policy_prototype_->clone());
std::shared_ptr<GoldenKitchenSinkRetryPolicy const>(retry_policy());
auto backoff = std::shared_ptr<BackoffPolicy const>(
backoff_policy_prototype_->clone());
auto idempotency = idempotency_policy_->ListLogs(request);
backoff_policy());
auto idempotency = idempotency_policy()->ListLogs(request);
char const* function_name = __func__;
return google::cloud::internal::MakePaginationRange<StreamRange<
std::string>>(
Expand All @@ -187,11 +187,11 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
StreamRange<google::test::admin::database::v1::TailLogEntriesResponse> TailLogEntries(
google::test::admin::database::v1::TailLogEntriesRequest const& request) override {
auto stub = stub_;
auto retry_policy =
auto retry =
std::shared_ptr<GoldenKitchenSinkRetryPolicy const>(
retry_policy_prototype_->clone());
auto backoff_policy = std::shared_ptr<BackoffPolicy const>(
backoff_policy_prototype_->clone());
retry_policy());
auto backoff = std::shared_ptr<BackoffPolicy const>(
backoff_policy());

auto factory = [stub](
google::test::admin::database::v1::TailLogEntriesRequest const& request) {
Expand All @@ -203,7 +203,7 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
internal::MakeResumableStreamingReadRpc<
google::test::admin::database::v1::TailLogEntriesResponse,
google::test::admin::database::v1::TailLogEntriesRequest>(
retry_policy->clone(), backoff_policy->clone(),
retry->clone(), backoff->clone(),
[](std::chrono::milliseconds) {}, factory,
GoldenKitchenSinkTailLogEntriesStreamingUpdater,
request);
Expand All @@ -217,8 +217,8 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
ListServiceAccountKeys(
google::test::admin::database::v1::ListServiceAccountKeysRequest const& request) override {
return google::cloud::internal::RetryLoop(
retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
idempotency_policy_->ListServiceAccountKeys(request),
retry_policy(), backoff_policy(),
idempotency_policy()->ListServiceAccountKeys(request),
[this](grpc::ClientContext& context,
google::test::admin::database::v1::ListServiceAccountKeysRequest const& request) {
return stub_->ListServiceAccountKeys(context, request);
Expand All @@ -230,8 +230,8 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
DoNothing(
google::protobuf::Empty const& request) override {
return google::cloud::internal::RetryLoop(
retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
idempotency_policy_->DoNothing(request),
retry_policy(), backoff_policy(),
idempotency_policy()->DoNothing(request),
[this](grpc::ClientContext& context,
google::protobuf::Empty const& request) {
return stub_->DoNothing(context, request);
Expand All @@ -248,6 +248,30 @@ class GoldenKitchenSinkConnectionImpl : public GoldenKitchenSinkConnection {
}

private:
std::unique_ptr<GoldenKitchenSinkRetryPolicy> retry_policy() {
auto const& options = internal::CurrentOptions();
if (options.has<GoldenKitchenSinkRetryPolicyOption>()) {
return options.get<GoldenKitchenSinkRetryPolicyOption>()->clone();
}
return retry_policy_prototype_->clone();
}

std::unique_ptr<BackoffPolicy> backoff_policy() {
auto const& options = internal::CurrentOptions();
if (options.has<GoldenKitchenSinkBackoffPolicyOption>()) {
return options.get<GoldenKitchenSinkBackoffPolicyOption>()->clone();
}
return backoff_policy_prototype_->clone();
}

std::unique_ptr<GoldenKitchenSinkConnectionIdempotencyPolicy> idempotency_policy() {
auto const& options = internal::CurrentOptions();
if (options.has<GoldenKitchenSinkConnectionIdempotencyPolicyOption>()) {
return options.get<GoldenKitchenSinkConnectionIdempotencyPolicyOption>()->clone();
}
return idempotency_policy_->clone();
}

std::unique_ptr<google::cloud::BackgroundThreads> background_;
std::shared_ptr<golden_internal::GoldenKitchenSinkStub> stub_;
std::unique_ptr<GoldenKitchenSinkRetryPolicy const> retry_policy_prototype_;
Expand Down
Loading

0 comments on commit bc7f1c5

Please sign in to comment.