Skip to content

Commit

Permalink
Rename to DelayStrategy (#35434)
Browse files Browse the repository at this point in the history
* Rename to DelayStrategy

* Rename
  • Loading branch information
JoshLove-msft committed Apr 7, 2023
1 parent af08a03 commit 0db2086
Show file tree
Hide file tree
Showing 42 changed files with 95 additions and 97 deletions.
2 changes: 1 addition & 1 deletion eng/Directory.Build.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<Compile Include="$(AzureCoreSharedSources)OperationInternal.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)OperationInternalBase.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)OperationInternalOfT.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)DelayStrategy.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)DelayStrategyInternal.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)ConstantDelayStrategy.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)ExponentialDelayStrategy.cs" LinkBase="Shared/Core" />
<Compile Include="$(AzureCoreSharedSources)RetryAfterDelayStrategy.cs" LinkBase="Shared/Core" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace Azure.Core
{
/// <summary>
/// Implementation of a <see cref="DelayStrategy"/> with 0 interval.
/// Implementation of a <see cref="DelayStrategyInternal"/> with 0 interval.
/// This is normally used for testing, like record playback.
/// </summary>
internal class ZeroPollingStrategy : DelayStrategy
internal class ZeroPollingStrategy : DelayStrategyInternal
{
public override TimeSpan GetNextDelay(Response response, TimeSpan? suggestedInterval) => TimeSpan.Zero;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected MockOperation()
string operationTypeName = null,
IEnumerable<KeyValuePair<string, string>> scopeAttributes = null,
int? callsToComplete = null,
DelayStrategy fallbackStrategy = null,
DelayStrategyInternal fallbackStrategy = null,
bool exceptionOnWait = false,
Exception customExceptionOnUpdate = null,
RequestFailedException originalExceptionOnUpdate = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class MockOperationInternal : OperationInternal, IMockOperationInternal
Func<MockResponse> responseFactory,
string operationTypeName,
IEnumerable<KeyValuePair<string, string>> scopeAttributes,
DelayStrategy pollingStrategy)
DelayStrategyInternal pollingStrategy)
: base(clientDiagnostics, operation, responseFactory(), operationTypeName, scopeAttributes, pollingStrategy)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class MockOperationInternal<TResult> : OperationInternal<TResult>, IMoc
Func<MockResponse> responseFactory,
string operationTypeName,
IEnumerable<KeyValuePair<string, string>> scopeAttributes,
DelayStrategy pollingStrategy)
DelayStrategyInternal pollingStrategy)
: base(clientDiagnostics, operation, responseFactory(), operationTypeName, scopeAttributes, pollingStrategy)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected MockOperation()
string operationTypeName = null,
IEnumerable<KeyValuePair<string, string>> scopeAttributes = null,
int? callsToComplete = null,
DelayStrategy fallbackStrategy = null,
DelayStrategyInternal fallbackStrategy = null,
bool exceptionOnWait = false,
Exception customExceptionOnUpdate = null,
RequestFailedException originalExceptionOnUpdate = null)
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Set the Activity status to `Error` on failed activity source activities.
- Mark the `Azure.Core.Http.Request` span as failed if the request fails with an exception thrown in the pipeline.
- Fixed equality comparison when comparing a `string` to a `ContentType` instance.
- Jitter is added when using a `RetryMode` of `Fixed`.

### Other Changes

Expand Down
10 changes: 5 additions & 5 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ public abstract partial class ClientOptions
public static bool operator !=(Azure.Core.ContentType left, Azure.Core.ContentType right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class Delay
public abstract partial class DelayStrategy
{
protected Delay(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.Delay CreateExponentialDelay(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.Delay CreateFixedDelay(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
protected DelayStrategy(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.DelayStrategy CreateExponentialDelayStrategy(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.DelayStrategy CreateFixedDelayStrategy(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
public System.TimeSpan GetNextDelay(Azure.Response? response, int retryNumber) { throw null; }
protected abstract System.TimeSpan GetNextDelayCore(Azure.Response? response, int retryNumber);
protected static System.TimeSpan Max(System.TimeSpan val1, System.TimeSpan val2) { throw null; }
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public sealed partial class RedirectPolicy : Azure.Core.Pipeline.HttpPipelinePol
}
public partial class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
public RetryPolicy(int maxRetries = 3, Azure.Core.Delay? delay = null) { }
public RetryPolicy(int maxRetries = 3, Azure.Core.DelayStrategy? delayStrategy = null) { }
protected internal virtual void OnRequestSent(Azure.Core.HttpMessage message) { }
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync(Azure.Core.HttpMessage message) { throw null; }
protected internal virtual void OnSendingRequest(Azure.Core.HttpMessage message) { }
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ public abstract partial class ClientOptions
public static bool operator !=(Azure.Core.ContentType left, Azure.Core.ContentType right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class Delay
public abstract partial class DelayStrategy
{
protected Delay(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.Delay CreateExponentialDelay(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.Delay CreateFixedDelay(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
protected DelayStrategy(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.DelayStrategy CreateExponentialDelayStrategy(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.DelayStrategy CreateFixedDelayStrategy(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
public System.TimeSpan GetNextDelay(Azure.Response? response, int retryNumber) { throw null; }
protected abstract System.TimeSpan GetNextDelayCore(Azure.Response? response, int retryNumber);
protected static System.TimeSpan Max(System.TimeSpan val1, System.TimeSpan val2) { throw null; }
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public sealed partial class RedirectPolicy : Azure.Core.Pipeline.HttpPipelinePol
}
public partial class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
public RetryPolicy(int maxRetries = 3, Azure.Core.Delay? delay = null) { }
public RetryPolicy(int maxRetries = 3, Azure.Core.DelayStrategy? delayStrategy = null) { }
protected internal virtual void OnRequestSent(Azure.Core.HttpMessage message) { }
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync(Azure.Core.HttpMessage message) { throw null; }
protected internal virtual void OnSendingRequest(Azure.Core.HttpMessage message) { }
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ public abstract partial class ClientOptions
public static bool operator !=(Azure.Core.ContentType left, Azure.Core.ContentType right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class Delay
public abstract partial class DelayStrategy
{
protected Delay(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.Delay CreateExponentialDelay(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.Delay CreateFixedDelay(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
protected DelayStrategy(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.DelayStrategy CreateExponentialDelayStrategy(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.DelayStrategy CreateFixedDelayStrategy(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
public System.TimeSpan GetNextDelay(Azure.Response? response, int retryNumber) { throw null; }
protected abstract System.TimeSpan GetNextDelayCore(Azure.Response? response, int retryNumber);
protected static System.TimeSpan Max(System.TimeSpan val1, System.TimeSpan val2) { throw null; }
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public sealed partial class RedirectPolicy : Azure.Core.Pipeline.HttpPipelinePol
}
public partial class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
public RetryPolicy(int maxRetries = 3, Azure.Core.Delay? delay = null) { }
public RetryPolicy(int maxRetries = 3, Azure.Core.DelayStrategy? delayStrategy = null) { }
protected internal virtual void OnRequestSent(Azure.Core.HttpMessage message) { }
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync(Azure.Core.HttpMessage message) { throw null; }
protected internal virtual void OnSendingRequest(Azure.Core.HttpMessage message) { }
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ public abstract partial class ClientOptions
public static bool operator !=(Azure.Core.ContentType left, Azure.Core.ContentType right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class Delay
public abstract partial class DelayStrategy
{
protected Delay(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.Delay CreateExponentialDelay(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.Delay CreateFixedDelay(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
protected DelayStrategy(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.DelayStrategy CreateExponentialDelayStrategy(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.DelayStrategy CreateFixedDelayStrategy(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
public System.TimeSpan GetNextDelay(Azure.Response? response, int retryNumber) { throw null; }
protected abstract System.TimeSpan GetNextDelayCore(Azure.Response? response, int retryNumber);
protected static System.TimeSpan Max(System.TimeSpan val1, System.TimeSpan val2) { throw null; }
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public sealed partial class RedirectPolicy : Azure.Core.Pipeline.HttpPipelinePol
}
public partial class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
public RetryPolicy(int maxRetries = 3, Azure.Core.Delay? delay = null) { }
public RetryPolicy(int maxRetries = 3, Azure.Core.DelayStrategy? delayStrategy = null) { }
protected internal virtual void OnRequestSent(Azure.Core.HttpMessage message) { }
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync(Azure.Core.HttpMessage message) { throw null; }
protected internal virtual void OnSendingRequest(Azure.Core.HttpMessage message) { }
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,11 @@ public abstract partial class ClientOptions
public static bool operator !=(Azure.Core.ContentType left, Azure.Core.ContentType right) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class Delay
public abstract partial class DelayStrategy
{
protected Delay(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.Delay CreateExponentialDelay(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.Delay CreateFixedDelay(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
protected DelayStrategy(System.TimeSpan? maxDelay = default(System.TimeSpan?), double jitterFactor = 0.2) { }
public static Azure.Core.DelayStrategy CreateExponentialDelayStrategy(System.TimeSpan? initialDelay = default(System.TimeSpan?), System.TimeSpan? maxDelay = default(System.TimeSpan?)) { throw null; }
public static Azure.Core.DelayStrategy CreateFixedDelayStrategy(System.TimeSpan? delay = default(System.TimeSpan?)) { throw null; }
public System.TimeSpan GetNextDelay(Azure.Response? response, int retryNumber) { throw null; }
protected abstract System.TimeSpan GetNextDelayCore(Azure.Response? response, int retryNumber);
protected static System.TimeSpan Max(System.TimeSpan val1, System.TimeSpan val2) { throw null; }
Expand Down Expand Up @@ -1035,7 +1035,7 @@ public sealed partial class RedirectPolicy : Azure.Core.Pipeline.HttpPipelinePol
}
public partial class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy
{
public RetryPolicy(int maxRetries = 3, Azure.Core.Delay? delay = null) { }
public RetryPolicy(int maxRetries = 3, Azure.Core.DelayStrategy? delayStrategy = null) { }
protected internal virtual void OnRequestSent(Azure.Core.HttpMessage message) { }
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync(Azure.Core.HttpMessage message) { throw null; }
protected internal virtual void OnSendingRequest(Azure.Core.HttpMessage message) { }
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/Azure.Core/samples/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class GlobalTimeoutRetryPolicy : RetryPolicy
{
private readonly TimeSpan _timeout;

public GlobalTimeoutRetryPolicy(int maxRetries, Delay delay, TimeSpan timeout) : base(maxRetries, delay)
public GlobalTimeoutRetryPolicy(int maxRetries, DelayStrategy delayStrategy, TimeSpan timeout) : base(maxRetries, delayStrategy)
{
_timeout = timeout;
}
Expand Down Expand Up @@ -61,10 +61,10 @@ internal class GlobalTimeoutRetryPolicy : RetryPolicy
Here is how we would configure the client to use the policy we just created.

```C# Snippet:SetGlobalTimeoutRetryPolicy
var delay = Delay.CreateFixedDelay(TimeSpan.FromSeconds(2));
var delay = DelayStrategy.CreateFixedDelayStrategy(TimeSpan.FromSeconds(2));
SecretClientOptions options = new SecretClientOptions()
{
RetryPolicy = new GlobalTimeoutRetryPolicy(maxRetries: 4, delay: delay, timeout: TimeSpan.FromSeconds(30))
RetryPolicy = new GlobalTimeoutRetryPolicy(maxRetries: 4, delayStrategy: delay, timeout: TimeSpan.FromSeconds(30))
};
```

Expand All @@ -74,7 +74,7 @@ In the below example, we create a customized exponential delay strategy that use
```C# Snippet:CustomizeExponentialDelay
SecretClientOptions options = new SecretClientOptions()
{
RetryPolicy = new RetryPolicy(delay: new MyCustomDelay())
RetryPolicy = new RetryPolicy(delayStrategy: new MyCustomDelayStrategy())
};
```

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/Azure.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Compile Include="Shared\TaskExtensions.cs" />
<Compile Include="Shared\CancellationHelper.cs" />
<Compile Include="Shared\OperationPoller.cs" />
<Compile Include="Shared\DelayStrategy.cs" />
<Compile Include="Shared\DelayStrategyInternal.cs" />
<Compile Include="Shared\TypeReferenceTypeAttribute.cs" />
<Compile Include="Shared\GeoRedundantFallbackPolicy.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Azure.Core
/// An abstraction to control delay behavior.
/// </summary>
#pragma warning disable AZC0012 // Avoid single word type names
public abstract class Delay
public abstract class DelayStrategy
#pragma warning restore AZC0012 // Avoid single word type names
{
private readonly Random _random = new ThreadSafeRandom();
Expand All @@ -23,12 +23,12 @@ public abstract class Delay
private readonly TimeSpan _maxDelay;

/// <summary>
/// Constructs a new instance of <see cref="Delay"/>.
/// Constructs a new instance of <see cref="DelayStrategy"/>.
/// </summary>
/// <param name="maxDelay">The max delay value to apply on an individual delay.</param>
/// <param name="jitterFactor">The jitter factor to apply to each delay. For example, if the delay is 1 second with a jitterFactor of 0.2, the actual
/// delay used will be a random double between 0.8 and 1.2. If set to 0, no jitter will be applied.</param>
protected Delay(TimeSpan? maxDelay = default, double jitterFactor = 0.2)
protected DelayStrategy(TimeSpan? maxDelay = default, double jitterFactor = 0.2)
{
// use same defaults as RetryOptions
_minJitterFactor = 1 - jitterFactor;
Expand All @@ -41,23 +41,23 @@ protected Delay(TimeSpan? maxDelay = default, double jitterFactor = 0.2)
/// </summary>
/// <param name="initialDelay">The initial delay to use.</param>
/// <param name="maxDelay">The maximum delay to use.</param>
/// <returns>The <see cref="Delay"/> instance.</returns>
public static Delay CreateExponentialDelay(
/// <returns>The <see cref="DelayStrategy"/> instance.</returns>
public static DelayStrategy CreateExponentialDelayStrategy(
TimeSpan? initialDelay = default,
TimeSpan? maxDelay = default)
{
return new ExponentialDelay(initialDelay ?? TimeSpan.FromSeconds(0.8), maxDelay ?? TimeSpan.FromMinutes(1));
return new ExponentialDelayStrategyInternal(initialDelay ?? TimeSpan.FromSeconds(0.8), maxDelay ?? TimeSpan.FromMinutes(1));
}

/// <summary>
/// Create a fixed delay with jitter.
/// </summary>
/// <param name="delay">The delay to use.</param>
/// <returns>The <see cref="Delay"/> instance.</returns>
public static Delay CreateFixedDelay(
/// <returns>The <see cref="DelayStrategy"/> instance.</returns>
public static DelayStrategy CreateFixedDelayStrategy(
TimeSpan? delay = default)
{
return new FixedDelay(delay ?? TimeSpan.FromSeconds(0.8));
return new FixedDelayStrategy(delay ?? TimeSpan.FromSeconds(0.8));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace Azure.Core
{
internal class ExponentialDelay : Delay
internal class ExponentialDelayStrategyInternal : DelayStrategy
{
private readonly TimeSpan _delay;

public ExponentialDelay(
public ExponentialDelayStrategyInternal(
TimeSpan delay,
TimeSpan maxDelay) : base(maxDelay)
{
Expand Down

0 comments on commit 0db2086

Please sign in to comment.