Skip to content

Commit 187395b

Browse files
More shared source updates (Azure#35642)
* More shared source updates * add temp backcompat * Add translation between old and new strategy types * fix maps * Update ZeroPollingStrategy * Fix tests
1 parent 15314c3 commit 187395b

File tree

13 files changed

+164
-184
lines changed

13 files changed

+164
-184
lines changed

sdk/core/Azure.Core.TestFramework/src/Instrumentation/ZeroPollingStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
namespace Azure.Core
99
{
1010
/// <summary>
11-
/// Implementation of a <see cref="DelayStrategyInternal"/> with 0 interval.
11+
/// Implementation of a delay strategy with 0 interval.
1212
/// This is normally used for testing, like record playback.
1313
/// </summary>
14-
internal class ZeroPollingStrategy : DelayStrategyInternal
14+
internal class ZeroPollingStrategy : DelayStrategy
1515
{
16-
public override TimeSpan GetNextDelay(Response response, TimeSpan? suggestedInterval) => TimeSpan.Zero;
16+
protected override TimeSpan GetNextDelayCore(Response? response, int retryNumber) => TimeSpan.Zero;
1717
}
1818
}

sdk/core/Azure.Core/src/Shared/OperationInternal.cs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,50 @@ internal class OperationInternal : OperationInternalBase
6363
/// <summary>
6464
/// Initializes a new instance of the <see cref="OperationInternal"/> class.
6565
/// </summary>
66-
/// <param name="clientDiagnostics">Used for diagnostic scope and exception creation. This is expected to be the instance created during the construction of your main client.</param>
6766
/// <param name="operation">The long-running operation making use of this class. Passing "<c>this</c>" is expected.</param>
67+
/// <param name="clientDiagnostics">Used for diagnostic scope and exception creation. This is expected to be the instance created during the construction of your main client.</param>
6868
/// <param name="rawResponse">
69-
/// The initial value of <see cref="OperationInternalBase.RawResponse"/>. Usually, long-running operation objects can be instantiated in two ways:
70-
/// <list type="bullet">
71-
/// <item>
72-
/// When calling a client's "<c>Start&lt;OperationName&gt;</c>" method, a service call is made to start the operation, and an <see cref="Operation"/> instance is returned.
73-
/// In this case, the response received from this service call can be passed here.
74-
/// </item>
75-
/// <item>
76-
/// When a user instantiates an <see cref="Operation"/> directly using a public constructor, there's no previous service call. In this case, passing <c>null</c> is expected.
77-
/// </item>
78-
/// </list>
69+
/// The initial value of <see cref="OperationInternalBase.RawResponse"/>. Usually, long-running operation objects can be instantiated in two ways:
70+
/// <list type="bullet">
71+
/// <item>
72+
/// When calling a client's "<c>Start&lt;OperationName&gt;</c>" method, a service call is made to start the operation, and an <see cref="Operation"/> instance is returned.
73+
/// In this case, the response received from this service call can be passed here.
74+
/// </item>
75+
/// <item>
76+
/// When a user instantiates an <see cref="Operation"/> directly using a public constructor, there's no previous service call. In this case, passing <c>null</c> is expected.
77+
/// </item>
78+
/// </list>
7979
/// </param>
8080
/// <param name="operationTypeName">
81-
/// The type name of the long-running operation making use of this class. Used when creating diagnostic scopes. If left <c>null</c>, the type name will be inferred based on the
82-
/// parameter <paramref name="operation"/>.
81+
/// The type name of the long-running operation making use of this class. Used when creating diagnostic scopes. If left <c>null</c>, the type name will be inferred based on the
82+
/// parameter <paramref name="operation"/>.
8383
/// </param>
8484
/// <param name="scopeAttributes">The attributes to use during diagnostic scope creation.</param>
85-
/// <param name="fallbackStrategy">The fallback delay strategy when Retry-After header is not present. When it is present, the longer of the two delays will be used. Default is <see cref="ConstantDelayStrategy"/>.</param>
85+
/// <param name="fallbackStrategy"> The delay strategy to use. Default is <see cref="FixedDelayWithNoJitterStrategy"/>.</param>
86+
public OperationInternal(IOperation operation,
87+
ClientDiagnostics clientDiagnostics,
88+
Response rawResponse,
89+
string? operationTypeName = null,
90+
IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null,
91+
DelayStrategy? fallbackStrategy = null)
92+
:base(clientDiagnostics, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy)
93+
{
94+
_internalOperation = new OperationInternal<VoidValue>(new OperationToOperationOfTProxy(operation), clientDiagnostics, rawResponse, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy);
95+
}
96+
97+
// TEMP backcompat with AutoRest
8698
public OperationInternal(
8799
ClientDiagnostics clientDiagnostics,
88100
IOperation operation,
89101
Response rawResponse,
90102
string? operationTypeName = null,
91103
IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null,
92104
DelayStrategyInternal? fallbackStrategy = null)
93-
:base(clientDiagnostics, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy)
105+
: base(
106+
clientDiagnostics,
107+
operationTypeName ?? operation.GetType().Name,
108+
scopeAttributes,
109+
fallbackStrategy is ExponentialDelayStrategy ? new SequentialDelayStrategy() : (fallbackStrategy is ConstantDelayStrategy) ? new FixedDelayWithNoJitterStrategy() : null)
94110
{
95111
_internalOperation = new OperationInternal<VoidValue>(clientDiagnostics, new OperationToOperationOfTProxy(operation), rawResponse, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy);
96112
}

sdk/core/Azure.Core/src/Shared/OperationInternalBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal abstract class OperationInternalBase
1616
{
1717
private readonly ClientDiagnostics _diagnostics;
1818
private readonly IReadOnlyDictionary<string, string>? _scopeAttributes;
19-
private readonly DelayStrategyInternal? _fallbackStrategy;
19+
private readonly DelayStrategy? _fallbackStrategy;
2020
private readonly AsyncLockWithValue<Response> _responseLock;
2121

2222
private readonly string _waitForCompletionResponseScopeName;
@@ -34,7 +34,7 @@ protected OperationInternalBase(Response rawResponse)
3434
_responseLock = new AsyncLockWithValue<Response>(rawResponse);
3535
}
3636

37-
protected OperationInternalBase(ClientDiagnostics clientDiagnostics, string operationTypeName, IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null, DelayStrategyInternal? fallbackStrategy = null)
37+
protected OperationInternalBase(ClientDiagnostics clientDiagnostics, string operationTypeName, IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null, DelayStrategy? fallbackStrategy = null)
3838
{
3939
_diagnostics = clientDiagnostics;
4040
_updateStatusScopeName = $"{operationTypeName}.{nameof(UpdateStatus)}";
@@ -107,7 +107,7 @@ public Response UpdateStatus(CancellationToken cancellationToken) =>
107107
/// <summary>
108108
/// Periodically calls <see cref="UpdateStatusAsync(CancellationToken)"/> until the long-running operation completes.
109109
/// After each service call, a retry-after header may be returned to communicate that there is no reason to poll
110-
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback <see cref="DelayStrategyInternal"/>
110+
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback strategy
111111
/// is then used as the wait interval.
112112
/// Headers supported are: "Retry-After", "retry-after-ms", and "x-ms-retry-after-ms",
113113
/// <example>Usage example:
@@ -147,7 +147,7 @@ public async ValueTask<Response> WaitForCompletionResponseAsync(TimeSpan polling
147147
/// <summary>
148148
/// Periodically calls <see cref="UpdateStatus(CancellationToken)"/> until the long-running operation completes.
149149
/// After each service call, a retry-after header may be returned to communicate that there is no reason to poll
150-
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback <see cref="DelayStrategyInternal"/>
150+
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback strategy
151151
/// is then used as the wait interval.
152152
/// Headers supported are: "Retry-After", "retry-after-ms", and "x-ms-retry-after-ms",
153153
/// and "x-ms-retry-after-ms".

sdk/core/Azure.Core/src/Shared/OperationInternalOfT.cs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,59 @@ internal class OperationInternal<T> : OperationInternalBase
7272
/// <summary>
7373
/// Initializes a new instance of the <see cref="OperationInternal{T}"/> class.
7474
/// </summary>
75-
/// <param name="clientDiagnostics">Used for diagnostic scope and exception creation. This is expected to be the instance created during the construction of your main client.</param>
7675
/// <param name="operation">The long-running operation making use of this class. Passing "<c>this</c>" is expected.</param>
76+
/// <param name="clientDiagnostics">Used for diagnostic scope and exception creation. This is expected to be the instance created during the construction of your main client.</param>
7777
/// <param name="rawResponse">
78-
/// The initial value of <see cref="OperationInternalBase.RawResponse"/>. Usually, long-running operation objects can be instantiated in two ways:
79-
/// <list type="bullet">
80-
/// <item>
81-
/// When calling a client's "<c>Start&lt;OperationName&gt;</c>" method, a service call is made to start the operation, and an <see cref="Operation{T}"/> instance is returned.
82-
/// In this case, the response received from this service call can be passed here.
83-
/// </item>
84-
/// <item>
85-
/// When a user instantiates an <see cref="Operation{T}"/> directly using a public constructor, there's no previous service call. In this case, passing <c>null</c> is expected.
86-
/// </item>
87-
/// </list>
78+
/// The initial value of <see cref="OperationInternalBase.RawResponse"/>. Usually, long-running operation objects can be instantiated in two ways:
79+
/// <list type="bullet">
80+
/// <item>
81+
/// When calling a client's "<c>Start&lt;OperationName&gt;</c>" method, a service call is made to start the operation, and an <see cref="Operation{T}"/> instance is returned.
82+
/// In this case, the response received from this service call can be passed here.
83+
/// </item>
84+
/// <item>
85+
/// When a user instantiates an <see cref="Operation{T}"/> directly using a public constructor, there's no previous service call. In this case, passing <c>null</c> is expected.
86+
/// </item>
87+
/// </list>
8888
/// </param>
8989
/// <param name="operationTypeName">
90-
/// The type name of the long-running operation making use of this class. Used when creating diagnostic scopes. If left <c>null</c>, the type name will be inferred based on the
91-
/// parameter <paramref name="operation"/>.
90+
/// The type name of the long-running operation making use of this class. Used when creating diagnostic scopes. If left <c>null</c>, the type name will be inferred based on the
91+
/// parameter <paramref name="operation"/>.
9292
/// </param>
9393
/// <param name="scopeAttributes">The attributes to use during diagnostic scope creation.</param>
94-
/// <param name="fallbackStrategy">The fallback delay strategy when Retry-After header is not present. When it is present, the longer of the two delays will be used. Default is <see cref="ConstantDelayStrategy"/>.</param>
94+
/// <param name="fallbackStrategy">The delay strategy when Retry-After header is not present. When it is present, the longer of the two delays will be used.
95+
/// Default is <see cref="FixedDelayWithNoJitterStrategy"/>.</param>
96+
public OperationInternal(IOperation<T> operation,
97+
ClientDiagnostics clientDiagnostics,
98+
Response rawResponse,
99+
string? operationTypeName = null,
100+
IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null,
101+
DelayStrategy? fallbackStrategy = null)
102+
: base(clientDiagnostics, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy)
103+
{
104+
_operation = operation;
105+
_rawResponse = rawResponse;
106+
_stateLock = new AsyncLockWithValue<OperationState<T>>();
107+
}
108+
109+
//TEMP for backcompat with AutoRest
95110
public OperationInternal(
96111
ClientDiagnostics clientDiagnostics,
97112
IOperation<T> operation,
98113
Response rawResponse,
99114
string? operationTypeName = null,
100115
IEnumerable<KeyValuePair<string, string>>? scopeAttributes = null,
101116
DelayStrategyInternal? fallbackStrategy = null)
102-
: base(clientDiagnostics, operationTypeName ?? operation.GetType().Name, scopeAttributes, fallbackStrategy)
117+
: base(
118+
clientDiagnostics,
119+
operationTypeName ?? operation.GetType().Name,
120+
scopeAttributes,
121+
fallbackStrategy is ExponentialDelayStrategy ? new SequentialDelayStrategy() : (fallbackStrategy is ConstantDelayStrategy) ? new FixedDelayWithNoJitterStrategy() : null)
103122
{
104123
_operation = operation;
105124
_rawResponse = rawResponse;
106125
_stateLock = new AsyncLockWithValue<OperationState<T>>();
107126
}
127+
//end TEMP for backcompat with AutoRest
108128

109129
private OperationInternal(OperationState<T> finalState)
110130
: base(finalState.RawResponse)
@@ -160,8 +180,7 @@ public T Value
160180
/// <summary>
161181
/// Periodically calls <see cref="OperationInternalBase.UpdateStatusAsync(CancellationToken)"/> until the long-running operation completes.
162182
/// After each service call, a retry-after header may be returned to communicate that there is no reason to poll
163-
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback <see cref="DelayStrategyInternal"/>
164-
/// is then used as the wait interval.
183+
/// for status change until the specified time has passed.
165184
/// Headers supported are: "Retry-After", "retry-after-ms", and "x-ms-retry-after-ms",
166185
/// <example>Usage example:
167186
/// <code>
@@ -200,8 +219,7 @@ public async ValueTask<Response<T>> WaitForCompletionAsync(TimeSpan pollingInter
200219
/// <summary>
201220
/// Periodically calls <see cref="OperationInternalBase.UpdateStatus(CancellationToken)"/> until the long-running operation completes.
202221
/// After each service call, a retry-after header may be returned to communicate that there is no reason to poll
203-
/// for status change until the specified time has passed. The maximum of the retry after value and the fallback <see cref="DelayStrategyInternal"/>
204-
/// is then use as the wait interval.
222+
/// for status change until the specified time has passed.
205223
/// Headers supported are: "Retry-After", "retry-after-ms", and "x-ms-retry-after-ms",
206224
/// <example>Usage example:
207225
/// <code>
@@ -218,11 +236,8 @@ public Response<T> WaitForCompletion(CancellationToken cancellationToken)
218236

219237
/// <summary>
220238
/// Periodically calls <see cref="OperationInternalBase.UpdateStatus(CancellationToken)"/> until the long-running operation completes. The interval
221-
/// between calls is defined by the property <see cref="ConstantDelayStrategy.DefaultPollingInterval"/>, but it can change based on information returned
222-
/// from the server. After each service call, a retry-after header may be returned to communicate that there is no reason to poll
223-
/// for status change until the specified time has passed. In this case, the maximum value between the <see cref="ConstantDelayStrategy.DefaultPollingInterval"/>
224-
/// property and the retry-after header is chosen as the wait interval. Headers supported are: "Retry-After", "retry-after-ms",
225-
/// and "x-ms-retry-after-ms".
239+
/// between calls is defined by the <see cref="FixedDelayWithNoJitterStrategy"/>, which takes into account any retry-after header that is returned
240+
/// from the server.
226241
/// <example>Usage example:
227242
/// <code>
228243
/// public async ValueTask&lt;Response&lt;T&gt;&gt; WaitForCompletionAsync(CancellationToken cancellationToken) =>

0 commit comments

Comments
 (0)