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

Update the RetryPolicy for the GA release, keeping ShouldRetry extension point hidden. #5771

Merged
merged 5 commits into from
Jul 12, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Other Changes ### Other Changes


- Updated JSON library to 3.11.3. - Updated JSON library to 3.11.3.
- Hide methods on the `RetryPolicy` that are not intended for public use.


## 1.13.0-beta.1 (2024-06-06) ## 1.13.0-beta.1 (2024-06-06)


Expand Down
21 changes: 19 additions & 2 deletions sdk/core/azure-core/inc/azure/core/http/policies/policy.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
#include <utility> #include <utility>
#include <vector> #include <vector>


#if defined(_azure_TESTING_BUILD)
// Define the classes used from tests
namespace Azure { namespace Core { namespace Test {
class RetryPolicyTest;
class RetryLogic;
}}} // namespace Azure::Core::Test
#endif

/** /**
* A function that should be implemented and linked to the end-user application in order to override * A function that should be implemented and linked to the end-user application in order to override
* an HTTP transport implementation provided by Azure SDK with custom implementation. * an HTTP transport implementation provided by Azure SDK with custom implementation.
Expand Down Expand Up @@ -363,7 +371,16 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
/** /**
* @brief HTTP retry policy. * @brief HTTP retry policy.
*/ */
class RetryPolicy : public HttpPolicy { class RetryPolicy
#if !defined(_azure_TESTING_BUILD)
final
#endif
: public HttpPolicy {
#if defined(_azure_TESTING_BUILD)
// make tests classes friends
friend class Azure::Core::Test::RetryPolicyTest;
friend class Azure::Core::Test::RetryLogic;
#endif
private: private:
RetryOptions m_retryOptions; RetryOptions m_retryOptions;


Expand Down Expand Up @@ -398,7 +415,7 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
*/ */
static int32_t GetRetryCount(Context const& context); static int32_t GetRetryCount(Context const& context);


protected: private:
virtual bool ShouldRetryOnTransportFailure( virtual bool ShouldRetryOnTransportFailure(
RetryOptions const& retryOptions, RetryOptions const& retryOptions,
int32_t attempt, int32_t attempt,
Expand Down
21 changes: 14 additions & 7 deletions sdk/core/azure-core/test/ut/retry_policy_test.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace Azure::Core::Http;
using namespace Azure::Core::Http::Policies; using namespace Azure::Core::Http::Policies;
using namespace Azure::Core::Http::Policies::_internal; using namespace Azure::Core::Http::Policies::_internal;


namespace { namespace Azure { namespace Core { namespace Test {
class TestTransportPolicy final : public HttpPolicy { class TestTransportPolicy final : public HttpPolicy {
private: private:
std::function<std::unique_ptr<RawResponse>()> m_send; std::function<std::unique_ptr<RawResponse>()> m_send;
Expand Down Expand Up @@ -127,7 +127,9 @@ class RetryPolicyTest final : public RetryPolicy {


class RetryPolicyTest_CustomRetry_True final : public RetryPolicy { class RetryPolicyTest_CustomRetry_True final : public RetryPolicy {
public: public:
RetryPolicyTest_CustomRetry_True(RetryOptions const& retryOptions) : RetryPolicy(retryOptions) {} RetryPolicyTest_CustomRetry_True(RetryOptions const& retryOptions) : RetryPolicy(retryOptions)
{
}


std::unique_ptr<HttpPolicy> Clone() const override std::unique_ptr<HttpPolicy> Clone() const override
{ {
Expand All @@ -143,7 +145,9 @@ class RetryPolicyTest_CustomRetry_True final : public RetryPolicy {


class RetryPolicyTest_CustomRetry_Throw final : public RetryPolicy { class RetryPolicyTest_CustomRetry_Throw final : public RetryPolicy {
public: public:
RetryPolicyTest_CustomRetry_Throw(RetryOptions const& retryOptions) : RetryPolicy(retryOptions) {} RetryPolicyTest_CustomRetry_Throw(RetryOptions const& retryOptions) : RetryPolicy(retryOptions)
{
}


std::unique_ptr<HttpPolicy> Clone() const override std::unique_ptr<HttpPolicy> Clone() const override
{ {
Expand All @@ -170,7 +174,8 @@ class RetryPolicyTest_CustomRetry_CopySource final : public RetryPolicy {
} }


protected: protected:
bool ShouldRetry(std::unique_ptr<RawResponse> const& response, RetryOptions const&) const override bool ShouldRetry(std::unique_ptr<RawResponse> const& response, RetryOptions const&)
const override
{ {
if (response == nullptr) if (response == nullptr)
{ {
Expand Down Expand Up @@ -213,7 +218,9 @@ class RetryPolicyTest_CustomRetry_CopySource final : public RetryPolicy {
return false; return false;
} }
}; };
} // namespace }}} // namespace Azure::Core::Test

using namespace Azure::Core::Test;


TEST(RetryPolicy, ShouldRetry) TEST(RetryPolicy, ShouldRetry)
{ {
Expand Down Expand Up @@ -589,7 +596,7 @@ TEST(RetryPolicy, ShouldRetryOnTransportFailure)
EXPECT_EQ(jitterReceived, -1); EXPECT_EQ(jitterReceived, -1);
} }


namespace { namespace Azure { namespace Core { namespace Test {
class RetryLogic final : private RetryPolicy { class RetryLogic final : private RetryPolicy {
RetryLogic() : RetryPolicy(RetryOptions()) {} RetryLogic() : RetryPolicy(RetryOptions()) {}
~RetryLogic() {} ~RetryLogic() {}
Expand Down Expand Up @@ -620,7 +627,7 @@ class RetryLogic final : private RetryPolicy {
}; };


RetryLogic const RetryLogic::g_retryPolicy; RetryLogic const RetryLogic::g_retryPolicy;
} // namespace }}} // namespace Azure::Core::Test


TEST(RetryPolicy, Exponential) TEST(RetryPolicy, Exponential)
{ {
Expand Down