Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: compress RetryPolicy class hierarchy #14947

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/// The retry policy for `DeprecatedServiceConnection`.
class DeprecatedServiceRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<DeprecatedServiceRetryPolicy> clone() const = 0;
};
};

/**
* A retry policy for `DeprecatedServiceConnection` based on counting errors.
Expand Down Expand Up @@ -79,7 +76,7 @@ class DeprecatedServiceLimitedErrorCountRetryPolicy : public DeprecatedServiceRe
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<DeprecatedServiceRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<DeprecatedServiceLimitedErrorCountRetryPolicy>(
maximum_failures());
}
Expand Down Expand Up @@ -144,7 +141,7 @@ class DeprecatedServiceLimitedTimeRetryPolicy : public DeprecatedServiceRetryPol
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<DeprecatedServiceRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<DeprecatedServiceLimitedTimeRetryPolicy>(
maximum_duration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
* @ingroup generator-integration_tests-golden-options
*/
struct DeprecatedServiceRetryPolicyOption {
using Type = std::shared_ptr<DeprecatedServiceRetryPolicy>;
using Type = std::shared_ptr<RetryPolicy>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/// The retry policy for `GoldenKitchenSinkConnection`.
class GoldenKitchenSinkRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const = 0;
};
};

/**
* A retry policy for `GoldenKitchenSinkConnection` based on counting errors.
Expand Down Expand Up @@ -84,7 +81,7 @@ class GoldenKitchenSinkLimitedErrorCountRetryPolicy : public GoldenKitchenSinkRe
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenKitchenSinkLimitedErrorCountRetryPolicy>(
maximum_failures());
}
Expand Down Expand Up @@ -150,7 +147,7 @@ class GoldenKitchenSinkLimitedTimeRetryPolicy : public GoldenKitchenSinkRetryPol
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenKitchenSinkRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenKitchenSinkLimitedTimeRetryPolicy>(
maximum_duration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
* @ingroup generator-integration_tests-golden-options
*/
struct GoldenKitchenSinkRetryPolicyOption {
using Type = std::shared_ptr<GoldenKitchenSinkRetryPolicy>;
using Type = std::shared_ptr<RetryPolicy>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/// The retry policy for `GoldenRestOnlyConnection`.
class GoldenRestOnlyRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const = 0;
};
};

/**
* A retry policy for `GoldenRestOnlyConnection` based on counting errors.
Expand Down Expand Up @@ -79,7 +76,7 @@ class GoldenRestOnlyLimitedErrorCountRetryPolicy : public GoldenRestOnlyRetryPol
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenRestOnlyLimitedErrorCountRetryPolicy>(
maximum_failures());
}
Expand Down Expand Up @@ -144,7 +141,7 @@ class GoldenRestOnlyLimitedTimeRetryPolicy : public GoldenRestOnlyRetryPolicy {
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenRestOnlyRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenRestOnlyLimitedTimeRetryPolicy>(
maximum_duration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
* @ingroup generator-integration_tests-golden-options
*/
struct GoldenRestOnlyRetryPolicyOption {
using Type = std::shared_ptr<GoldenRestOnlyRetryPolicy>;
using Type = std::shared_ptr<RetryPolicy>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

/// The retry policy for `GoldenThingAdminConnection`.
class GoldenThingAdminRetryPolicy : public ::google::cloud::RetryPolicy {
public:
/// Creates a new instance of the policy, reset to the initial state.
virtual std::unique_ptr<GoldenThingAdminRetryPolicy> clone() const = 0;
};
};

/**
* A retry policy for `GoldenThingAdminConnection` based on counting errors.
Expand Down Expand Up @@ -86,7 +83,7 @@ class GoldenThingAdminLimitedErrorCountRetryPolicy : public GoldenThingAdminRetr
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenThingAdminRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenThingAdminLimitedErrorCountRetryPolicy>(
maximum_failures());
}
Expand Down Expand Up @@ -152,7 +149,7 @@ class GoldenThingAdminLimitedTimeRetryPolicy : public GoldenThingAdminRetryPolic
bool IsPermanentFailure(Status const& status) const override {
return impl_.IsPermanentFailure(status);
}
std::unique_ptr<GoldenThingAdminRetryPolicy> clone() const override {
std::unique_ptr<RetryPolicy> clone() const override {
return std::make_unique<GoldenThingAdminLimitedTimeRetryPolicy>(
maximum_duration());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
* @ingroup generator-integration_tests-golden-options
*/
struct GoldenThingAdminRetryPolicyOption {
using Type = std::shared_ptr<GoldenThingAdminRetryPolicy>;
using Type = std::shared_ptr<RetryPolicy>;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace golden_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

std::unique_ptr<golden_v1::DeprecatedServiceRetryPolicy>
std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::DeprecatedServiceRetryPolicyOption>()->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DeprecatedServiceRestConnectionImpl
Noop(google::test::deprecated::v1::DeprecatedServiceRequest const& request) override;

private:
static std::unique_ptr<golden_v1::DeprecatedServiceRetryPolicy>
static std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::DeprecatedServiceRetryPolicyOption>()->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace golden_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

std::unique_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>
std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::GoldenKitchenSinkRetryPolicyOption>()->clone();
}
Expand Down Expand Up @@ -113,7 +113,7 @@ GoldenKitchenSinkConnectionImpl::ListLogs(google::test::admin::database::v1::Lis
return google::cloud::internal::MakePaginationRange<StreamRange<std::string>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListLogsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down Expand Up @@ -256,7 +256,7 @@ GoldenKitchenSinkConnectionImpl::ListOperations(google::longrunning::ListOperati
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::longrunning::ListOperationsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ GoldenKitchenSinkRestConnectionImpl::ListLogs(google::test::admin::database::v1:
return google::cloud::internal::MakePaginationRange<StreamRange<std::string>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListLogsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down Expand Up @@ -196,7 +196,7 @@ GoldenKitchenSinkRestConnectionImpl::ListOperations(google::longrunning::ListOpe
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::longrunning::ListOperationsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class GoldenKitchenSinkRestConnectionImpl
ListOperations(google::longrunning::ListOperationsRequest request) override;

private:
static std::unique_ptr<golden_v1::GoldenKitchenSinkRetryPolicy>
static std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::GoldenKitchenSinkRetryPolicyOption>()->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GoldenRestOnlyRestConnectionImpl
Noop(google::protobuf::Empty const& request) override;

private:
static std::unique_ptr<golden_v1::GoldenRestOnlyRetryPolicy>
static std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::GoldenRestOnlyRetryPolicyOption>()->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace golden_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

std::unique_ptr<golden_v1::GoldenThingAdminRetryPolicy>
std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::GoldenThingAdminRetryPolicyOption>()->clone();
}
Expand Down Expand Up @@ -73,7 +73,7 @@ GoldenThingAdminConnectionImpl::ListDatabases(google::test::admin::database::v1:
return google::cloud::internal::MakePaginationRange<StreamRange<google::test::admin::database::v1::Database>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListDatabasesRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down Expand Up @@ -455,7 +455,7 @@ GoldenThingAdminConnectionImpl::ListBackups(google::test::admin::database::v1::L
return google::cloud::internal::MakePaginationRange<StreamRange<google::test::admin::database::v1::Backup>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListBackupsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down Expand Up @@ -562,7 +562,7 @@ GoldenThingAdminConnectionImpl::ListDatabaseOperations(google::test::admin::data
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListDatabaseOperationsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down Expand Up @@ -590,7 +590,7 @@ GoldenThingAdminConnectionImpl::ListBackupOperations(google::test::admin::databa
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListBackupOperationsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down Expand Up @@ -710,7 +710,7 @@ GoldenThingAdminConnectionImpl::ListOperations(google::longrunning::ListOperatio
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::longrunning::ListOperationsRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ GoldenThingAdminRestConnectionImpl::ListDatabases(google::test::admin::database:
return google::cloud::internal::MakePaginationRange<StreamRange<google::test::admin::database::v1::Database>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListDatabasesRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down Expand Up @@ -423,7 +423,7 @@ GoldenThingAdminRestConnectionImpl::ListBackups(google::test::admin::database::v
return google::cloud::internal::MakePaginationRange<StreamRange<google::test::admin::database::v1::Backup>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListBackupsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down Expand Up @@ -527,7 +527,7 @@ GoldenThingAdminRestConnectionImpl::ListDatabaseOperations(google::test::admin::
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListDatabaseOperationsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down Expand Up @@ -556,7 +556,7 @@ GoldenThingAdminRestConnectionImpl::ListBackupOperations(google::test::admin::da
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::admin::database::v1::ListBackupOperationsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down Expand Up @@ -598,7 +598,7 @@ GoldenThingAdminRestConnectionImpl::ListOperations(google::longrunning::ListOper
return google::cloud::internal::MakePaginationRange<StreamRange<google::longrunning::Operation>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::GoldenThingAdminRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::longrunning::ListOperationsRequest const& r) {
return google::cloud::rest_internal::RestRetryLoop(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class GoldenThingAdminRestConnectionImpl
AsyncDropDatabase(google::test::admin::database::v1::DropDatabaseRequest const& request) override;

private:
static std::unique_ptr<golden_v1::GoldenThingAdminRetryPolicy>
static std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::GoldenThingAdminRetryPolicyOption>()->clone();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace golden_v1_internal {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

std::unique_ptr<golden_v1::RequestIdServiceRetryPolicy>
std::unique_ptr<RetryPolicy>
retry_policy(Options const& options) {
return options.get<golden_v1::RequestIdServiceRetryPolicyOption>()->clone();
}
Expand Down Expand Up @@ -172,7 +172,7 @@ RequestIdServiceConnectionImpl::ListFoos(google::test::requestid::v1::ListFoosRe
return google::cloud::internal::MakePaginationRange<StreamRange<google::test::requestid::v1::Foo>>(
current, std::move(request),
[idempotency, function_name, stub = stub_,
retry = std::shared_ptr<golden_v1::RequestIdServiceRetryPolicy>(retry_policy(*current)),
retry = std::shared_ptr<RetryPolicy>(retry_policy(*current)),
backoff = std::shared_ptr<BackoffPolicy>(backoff_policy(*current))](
Options const& options, google::test::requestid::v1::ListFoosRequest const& r) {
return google::cloud::internal::RetryLoop(
Expand Down
Loading
Loading