diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerPredicateArguments.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerPredicateArguments.cs index d09ca8d8692..4c72c2fa44e 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerPredicateArguments.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerPredicateArguments.cs @@ -6,4 +6,6 @@ namespace Polly.CircuitBreaker; /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct CircuitBreakerPredicateArguments(); +public readonly struct CircuitBreakerPredicateArguments +{ +} diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategy.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategy.cs index 90327f7d725..90eebbba01a 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategy.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategy.cs @@ -32,7 +32,7 @@ protected override async ValueTask> ExecuteCallbackAsync(Func outcome = await ExecuteCallbackSafeAsync(callback, context, state).ConfigureAwait(context.ContinueOnCapturedContext); - var args = new OutcomeArguments(context, outcome, new CircuitBreakerPredicateArguments()); + var args = new OutcomeArguments(context, outcome, default); if (await _handler(args).ConfigureAwait(context.ContinueOnCapturedContext)) { await _controller.OnActionFailureAsync(outcome, context).ConfigureAwait(context.ContinueOnCapturedContext); diff --git a/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs b/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs index 1c595c3929f..f0ac469682b 100644 --- a/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs +++ b/src/Polly.Core/CircuitBreaker/Controller/CircuitStateController.cs @@ -128,7 +128,7 @@ public ValueTask CloseCircuitAsync(ResilienceContext context) if (_circuitState == CircuitState.Open && PermitHalfOpenCircuitTest_NeedsLock()) { _circuitState = CircuitState.HalfOpen; - _telemetry.Report(new(ResilienceEventSeverity.Warning, CircuitBreakerConstants.OnHalfOpenEvent), context, new OnCircuitHalfOpenedArguments()); + _telemetry.Report(new(ResilienceEventSeverity.Warning, CircuitBreakerConstants.OnHalfOpenEvent), context, new OnCircuitHalfOpenedArguments(context)); isHalfOpen = true; } @@ -142,7 +142,7 @@ public ValueTask CloseCircuitAsync(ResilienceContext context) if (isHalfOpen && _onHalfOpen is not null) { - _executor.ScheduleTask(() => _onHalfOpen(new OnCircuitHalfOpenedArguments()).AsTask(), context, out task); + _executor.ScheduleTask(() => _onHalfOpen(new OnCircuitHalfOpenedArguments(context)).AsTask(), context, out task); } } diff --git a/src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs b/src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs index 5cb632c3dfe..42d33d9c1ac 100644 --- a/src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs +++ b/src/Polly.Core/CircuitBreaker/OnCircuitClosedArguments.cs @@ -3,5 +3,16 @@ namespace Polly.CircuitBreaker; /// /// Arguments used by event. /// -/// Indicates whether the circuit was closed manually by using . -public record OnCircuitClosedArguments(bool IsManual); +public sealed class OnCircuitClosedArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// Indicates whether the circuit was closed manually by using . + public OnCircuitClosedArguments(bool isManual) => IsManual = isManual; + + /// + /// Gets a value indicating whether the circuit was closed manually by using . + /// + public bool IsManual { get; } +} diff --git a/src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs b/src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs index 97444487f39..1dbc56a1e5d 100644 --- a/src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs +++ b/src/Polly.Core/CircuitBreaker/OnCircuitHalfOpenedArguments.cs @@ -3,4 +3,16 @@ namespace Polly.CircuitBreaker; /// /// Arguments used by event. /// -public record OnCircuitHalfOpenedArguments(); +public sealed class OnCircuitHalfOpenedArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The context instance. + public OnCircuitHalfOpenedArguments(ResilienceContext context) => Context = context; + + /// + /// Gets the context associated with the execution of a user-provided callback. + /// + public ResilienceContext Context { get; } +} diff --git a/src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs b/src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs index 261f18e53cb..3f4b7f89efe 100644 --- a/src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs +++ b/src/Polly.Core/CircuitBreaker/OnCircuitOpenedArguments.cs @@ -3,6 +3,26 @@ namespace Polly.CircuitBreaker; /// /// Arguments used by event. /// -/// The duration of break. -/// Indicates whether the circuit was opened manually by using . -public record OnCircuitOpenedArguments(TimeSpan BreakDuration, bool IsManual); +public sealed class OnCircuitOpenedArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The duration of break. + /// Indicates whether the circuit was opened manually by using . + public OnCircuitOpenedArguments(TimeSpan breakDuration, bool isManual) + { + BreakDuration = breakDuration; + IsManual = isManual; + } + + /// + /// Gets the duration of break. + /// + public TimeSpan BreakDuration { get; } + + /// + /// Gets a value indicating whether the circuit was opened manually by using . + /// + public bool IsManual { get; } +} diff --git a/src/Polly.Core/Fallback/FallbackPredicateArguments.cs b/src/Polly.Core/Fallback/FallbackPredicateArguments.cs index fb575d72ee9..1a7218e4b81 100644 --- a/src/Polly.Core/Fallback/FallbackPredicateArguments.cs +++ b/src/Polly.Core/Fallback/FallbackPredicateArguments.cs @@ -6,4 +6,6 @@ namespace Polly.Fallback; /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct FallbackPredicateArguments(); +public readonly struct FallbackPredicateArguments +{ +} diff --git a/src/Polly.Core/Fallback/FallbackResilienceStrategy.cs b/src/Polly.Core/Fallback/FallbackResilienceStrategy.cs index f0939511d0d..fa8a298c05d 100644 --- a/src/Polly.Core/Fallback/FallbackResilienceStrategy.cs +++ b/src/Polly.Core/Fallback/FallbackResilienceStrategy.cs @@ -21,7 +21,7 @@ public FallbackResilienceStrategy(FallbackHandler handler, Func> ExecuteCallbackAsync(Func>> callback, ResilienceContext context, TState state) { var outcome = await ExecuteCallbackSafeAsync(callback, context, state).ConfigureAwait(context.ContinueOnCapturedContext); - var handleFallbackArgs = new OutcomeArguments(context, outcome, new FallbackPredicateArguments()); + var handleFallbackArgs = new OutcomeArguments(context, outcome, default); if (!await _handler.ShouldHandle(handleFallbackArgs).ConfigureAwait(context.ContinueOnCapturedContext)) { return outcome; diff --git a/src/Polly.Core/Fallback/OnFallbackArguments.cs b/src/Polly.Core/Fallback/OnFallbackArguments.cs index 628aaa85718..c3452616a0c 100644 --- a/src/Polly.Core/Fallback/OnFallbackArguments.cs +++ b/src/Polly.Core/Fallback/OnFallbackArguments.cs @@ -3,4 +3,6 @@ namespace Polly.Fallback; /// /// Represents arguments used in fallback handling scenarios. /// -public record OnFallbackArguments(); +public sealed class OnFallbackArguments +{ +} diff --git a/src/Polly.Core/Hedging/Controller/TaskExecution.cs b/src/Polly.Core/Hedging/Controller/TaskExecution.cs index 9b44e76bf5e..d91f32c6060 100644 --- a/src/Polly.Core/Hedging/Controller/TaskExecution.cs +++ b/src/Polly.Core/Hedging/Controller/TaskExecution.cs @@ -224,7 +224,7 @@ private async Task ExecutePrimaryActionAsync(Func outcome) { - var args = new OutcomeArguments(Context, outcome, new HedgingPredicateArguments()); + var args = new OutcomeArguments(Context, outcome, default); Outcome = outcome.AsOutcome(); IsHandled = await _handler.ShouldHandle(args).ConfigureAwait(Context.ContinueOnCapturedContext); TelemetryUtil.ReportExecutionAttempt(_telemetry, Context, outcome, Attempt, ExecutionTime, IsHandled); diff --git a/src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs b/src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs index de2626fd0bb..9de0b577210 100644 --- a/src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs +++ b/src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs @@ -1,20 +1,57 @@ namespace Polly.Hedging; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Represents arguments used in the hedging resilience strategy. /// /// The type of the result. -/// The primary resilience context. -/// -/// The context that will be passed to action generated by . -/// This context is cloned from . -/// The zero-based hedging attempt number. -/// The callback passed to hedging strategy. /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct HedgingActionGeneratorArguments( - ResilienceContext PrimaryContext, - ResilienceContext ActionContext, - int Attempt, - Func>> Callback); +public readonly struct HedgingActionGeneratorArguments +{ + /// + /// Initializes a new instance of the struct. + /// + /// The primary resilience context. + /// + /// The context that will be passed to action generated by . + /// . + /// The zero-based hedging attempt number. + /// The callback passed to hedging strategy. + public HedgingActionGeneratorArguments( + ResilienceContext primaryContext, + ResilienceContext actionContext, + int attempt, + Func>> callback) + { + PrimaryContext = primaryContext; + ActionContext = actionContext; + Attempt = attempt; + Callback = callback; + } + + /// + /// Gets the primary resilience context. + /// + public ResilienceContext PrimaryContext { get; } + + /// + /// Gets the context that will be passed to action generated by . + /// + /// + /// This context is cloned from . + /// + public ResilienceContext ActionContext { get; } + + /// + /// Gets the zero-based hedging attempt number. + /// + public int Attempt { get; } + + /// + /// Gets the callback passed to hedging strategy. + /// + public Func>> Callback { get; } +} diff --git a/src/Polly.Core/Hedging/HedgingDelayArguments.cs b/src/Polly.Core/Hedging/HedgingDelayArguments.cs index a30006ac1bc..9f0fa9f201c 100644 --- a/src/Polly.Core/Hedging/HedgingDelayArguments.cs +++ b/src/Polly.Core/Hedging/HedgingDelayArguments.cs @@ -1,11 +1,33 @@ namespace Polly.Hedging; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Arguments used by hedging delay generator. /// -/// The context associated with the execution of a user-provided callback. -/// The zero-based hedging attempt number. /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct HedgingDelayArguments(ResilienceContext Context, int Attempt); +public readonly struct HedgingDelayArguments +{ + /// + /// Initializes a new instance of the struct. + /// + /// The context associated with the execution of a user-provided callback. + /// The zero-based hedging attempt number. + public HedgingDelayArguments(ResilienceContext context, int attempt) + { + Context = context; + Attempt = attempt; + } + + /// + /// Gets the context associated with the execution of a user-provided callback. + /// + public ResilienceContext Context { get; } + + /// + /// Gets the zero-based hedging attempt number. + /// + public int Attempt { get; } +} diff --git a/src/Polly.Core/Hedging/HedgingPredicateArguments.cs b/src/Polly.Core/Hedging/HedgingPredicateArguments.cs index 1a423192fc9..a3bf7a46105 100644 --- a/src/Polly.Core/Hedging/HedgingPredicateArguments.cs +++ b/src/Polly.Core/Hedging/HedgingPredicateArguments.cs @@ -6,4 +6,6 @@ namespace Polly.Hedging; /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct HedgingPredicateArguments(); +public readonly struct HedgingPredicateArguments +{ +} diff --git a/src/Polly.Core/Hedging/HedgingResilienceStrategy.cs b/src/Polly.Core/Hedging/HedgingResilienceStrategy.cs index 1034031ae64..930c12fc0ff 100644 --- a/src/Polly.Core/Hedging/HedgingResilienceStrategy.cs +++ b/src/Polly.Core/Hedging/HedgingResilienceStrategy.cs @@ -99,7 +99,7 @@ private async ValueTask> ExecuteCoreAsync( await HandleOnHedgingAsync( context, Outcome.FromResult(default), - new OnHedgingArguments(attempt, HasOutcome: false, ExecutionTime: delay)).ConfigureAwait(context.ContinueOnCapturedContext); + new OnHedgingArguments(attempt, hasOutcome: false, executionTime: delay)).ConfigureAwait(context.ContinueOnCapturedContext); continue; } @@ -115,7 +115,7 @@ await HandleOnHedgingAsync( await HandleOnHedgingAsync( context, outcome, - new OnHedgingArguments(attempt, HasOutcome: true, executionTime)).ConfigureAwait(context.ContinueOnCapturedContext); + new OnHedgingArguments(attempt, hasOutcome: true, executionTime)).ConfigureAwait(context.ContinueOnCapturedContext); } } diff --git a/src/Polly.Core/Hedging/OnHedgingArguments.cs b/src/Polly.Core/Hedging/OnHedgingArguments.cs index 4c963bd4985..1ea70e674e1 100644 --- a/src/Polly.Core/Hedging/OnHedgingArguments.cs +++ b/src/Polly.Core/Hedging/OnHedgingArguments.cs @@ -3,13 +3,36 @@ namespace Polly.Hedging; /// /// Represents arguments used by the on-hedging event. /// -/// The zero-based hedging attempt number. -/// -/// Determines whether the outcome is available before loading the next hedged task. -/// No outcome indicates that the previous action did not finish within the hedging delay. -/// -/// -/// The execution time of hedging attempt or the hedging delay -/// in case the attempt was not finished in time. -/// -public record OnHedgingArguments(int Attempt, bool HasOutcome, TimeSpan ExecutionTime); +public sealed class OnHedgingArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The zero-based hedging attempt number. + /// Indicates whether outcome is available. + /// The execution time of hedging attempt or the hedging delay in case the attempt was not finished in time. + public OnHedgingArguments(int attempt, bool hasOutcome, TimeSpan executionTime) + { + Attempt = attempt; + HasOutcome = hasOutcome; + ExecutionTime = executionTime; + } + + /// + /// Gets the zero-based hedging attempt number. + /// + public int Attempt { get; } + + /// + /// Gets a value indicating whether the outcome is available before loading the next hedged task. + /// + /// + /// No outcome indicates that the previous action did not finish within the hedging delay. + /// + public bool HasOutcome { get; } + + /// + /// Gets the execution time of hedging attempt or the hedging delay in case the attempt was not finished in time. + /// + public TimeSpan ExecutionTime { get; } +} diff --git a/src/Polly.Core/PublicAPI.Unshipped.txt b/src/Polly.Core/PublicAPI.Unshipped.txt index 19dd6d0c5b3..60c134d212d 100644 --- a/src/Polly.Core/PublicAPI.Unshipped.txt +++ b/src/Polly.Core/PublicAPI.Unshipped.txt @@ -68,16 +68,14 @@ Polly.CircuitBreaker.IsolatedCircuitException.IsolatedCircuitException(string! m Polly.CircuitBreaker.IsolatedCircuitException.IsolatedCircuitException(string! message, System.Exception! innerException) -> void Polly.CircuitBreaker.OnCircuitClosedArguments Polly.CircuitBreaker.OnCircuitClosedArguments.IsManual.get -> bool -Polly.CircuitBreaker.OnCircuitClosedArguments.IsManual.init -> void -Polly.CircuitBreaker.OnCircuitClosedArguments.OnCircuitClosedArguments(bool IsManual) -> void +Polly.CircuitBreaker.OnCircuitClosedArguments.OnCircuitClosedArguments(bool isManual) -> void Polly.CircuitBreaker.OnCircuitHalfOpenedArguments -Polly.CircuitBreaker.OnCircuitHalfOpenedArguments.OnCircuitHalfOpenedArguments() -> void +Polly.CircuitBreaker.OnCircuitHalfOpenedArguments.Context.get -> Polly.ResilienceContext! +Polly.CircuitBreaker.OnCircuitHalfOpenedArguments.OnCircuitHalfOpenedArguments(Polly.ResilienceContext! context) -> void Polly.CircuitBreaker.OnCircuitOpenedArguments Polly.CircuitBreaker.OnCircuitOpenedArguments.BreakDuration.get -> System.TimeSpan -Polly.CircuitBreaker.OnCircuitOpenedArguments.BreakDuration.init -> void Polly.CircuitBreaker.OnCircuitOpenedArguments.IsManual.get -> bool -Polly.CircuitBreaker.OnCircuitOpenedArguments.IsManual.init -> void -Polly.CircuitBreaker.OnCircuitOpenedArguments.OnCircuitOpenedArguments(System.TimeSpan BreakDuration, bool IsManual) -> void +Polly.CircuitBreaker.OnCircuitOpenedArguments.OnCircuitOpenedArguments(System.TimeSpan breakDuration, bool isManual) -> void Polly.CircuitBreaker.SimpleCircuitBreakerStrategyOptions Polly.CircuitBreaker.SimpleCircuitBreakerStrategyOptions.SimpleCircuitBreakerStrategyOptions() -> void Polly.CircuitBreaker.SimpleCircuitBreakerStrategyOptions @@ -104,22 +102,16 @@ Polly.Fallback.OnFallbackArguments.OnFallbackArguments() -> void Polly.FallbackResilienceStrategyBuilderExtensions Polly.Hedging.HedgingActionGeneratorArguments Polly.Hedging.HedgingActionGeneratorArguments.ActionContext.get -> Polly.ResilienceContext! -Polly.Hedging.HedgingActionGeneratorArguments.ActionContext.init -> void Polly.Hedging.HedgingActionGeneratorArguments.Attempt.get -> int -Polly.Hedging.HedgingActionGeneratorArguments.Attempt.init -> void Polly.Hedging.HedgingActionGeneratorArguments.Callback.get -> System.Func>>! -Polly.Hedging.HedgingActionGeneratorArguments.Callback.init -> void Polly.Hedging.HedgingActionGeneratorArguments.HedgingActionGeneratorArguments() -> void -Polly.Hedging.HedgingActionGeneratorArguments.HedgingActionGeneratorArguments(Polly.ResilienceContext! PrimaryContext, Polly.ResilienceContext! ActionContext, int Attempt, System.Func>>! Callback) -> void +Polly.Hedging.HedgingActionGeneratorArguments.HedgingActionGeneratorArguments(Polly.ResilienceContext! primaryContext, Polly.ResilienceContext! actionContext, int attempt, System.Func>>! callback) -> void Polly.Hedging.HedgingActionGeneratorArguments.PrimaryContext.get -> Polly.ResilienceContext! -Polly.Hedging.HedgingActionGeneratorArguments.PrimaryContext.init -> void Polly.Hedging.HedgingDelayArguments Polly.Hedging.HedgingDelayArguments.Attempt.get -> int -Polly.Hedging.HedgingDelayArguments.Attempt.init -> void Polly.Hedging.HedgingDelayArguments.Context.get -> Polly.ResilienceContext! -Polly.Hedging.HedgingDelayArguments.Context.init -> void Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments() -> void -Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments(Polly.ResilienceContext! Context, int Attempt) -> void +Polly.Hedging.HedgingDelayArguments.HedgingDelayArguments(Polly.ResilienceContext! context, int attempt) -> void Polly.Hedging.HedgingPredicateArguments Polly.Hedging.HedgingPredicateArguments.HedgingPredicateArguments() -> void Polly.Hedging.HedgingStrategyOptions @@ -138,12 +130,9 @@ Polly.Hedging.HedgingStrategyOptions.ShouldHandle.get -> System.Func.ShouldHandle.set -> void Polly.Hedging.OnHedgingArguments Polly.Hedging.OnHedgingArguments.Attempt.get -> int -Polly.Hedging.OnHedgingArguments.Attempt.init -> void Polly.Hedging.OnHedgingArguments.ExecutionTime.get -> System.TimeSpan -Polly.Hedging.OnHedgingArguments.ExecutionTime.init -> void Polly.Hedging.OnHedgingArguments.HasOutcome.get -> bool -Polly.Hedging.OnHedgingArguments.HasOutcome.init -> void -Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int Attempt, bool HasOutcome, System.TimeSpan ExecutionTime) -> void +Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int attempt, bool hasOutcome, System.TimeSpan executionTime) -> void Polly.HedgingResilienceStrategyBuilderExtensions Polly.NullResilienceStrategy Polly.NullResilienceStrategy @@ -307,12 +296,9 @@ Polly.ResilienceValidationContext.PrimaryMessage.get -> string! Polly.ResilienceValidationContext.ResilienceValidationContext(object! instance, string! primaryMessage) -> void Polly.Retry.OnRetryArguments Polly.Retry.OnRetryArguments.Attempt.get -> int -Polly.Retry.OnRetryArguments.Attempt.init -> void Polly.Retry.OnRetryArguments.ExecutionTime.get -> System.TimeSpan -Polly.Retry.OnRetryArguments.ExecutionTime.init -> void -Polly.Retry.OnRetryArguments.OnRetryArguments(int Attempt, System.TimeSpan RetryDelay, System.TimeSpan ExecutionTime) -> void +Polly.Retry.OnRetryArguments.OnRetryArguments(int attempt, System.TimeSpan retryDelay, System.TimeSpan executionTime) -> void Polly.Retry.OnRetryArguments.RetryDelay.get -> System.TimeSpan -Polly.Retry.OnRetryArguments.RetryDelay.init -> void Polly.Retry.RetryBackoffType Polly.Retry.RetryBackoffType.Constant = 0 -> Polly.Retry.RetryBackoffType Polly.Retry.RetryBackoffType.Exponential = 2 -> Polly.Retry.RetryBackoffType @@ -320,16 +306,13 @@ Polly.Retry.RetryBackoffType.ExponentialWithJitter = 3 -> Polly.Retry.RetryBacko Polly.Retry.RetryBackoffType.Linear = 1 -> Polly.Retry.RetryBackoffType Polly.Retry.RetryDelayArguments Polly.Retry.RetryDelayArguments.Attempt.get -> int -Polly.Retry.RetryDelayArguments.Attempt.init -> void Polly.Retry.RetryDelayArguments.DelayHint.get -> System.TimeSpan -Polly.Retry.RetryDelayArguments.DelayHint.init -> void Polly.Retry.RetryDelayArguments.RetryDelayArguments() -> void -Polly.Retry.RetryDelayArguments.RetryDelayArguments(int Attempt, System.TimeSpan DelayHint) -> void +Polly.Retry.RetryDelayArguments.RetryDelayArguments(int attempt, System.TimeSpan delayHint) -> void Polly.Retry.RetryPredicateArguments Polly.Retry.RetryPredicateArguments.Attempt.get -> int -Polly.Retry.RetryPredicateArguments.Attempt.init -> void Polly.Retry.RetryPredicateArguments.RetryPredicateArguments() -> void -Polly.Retry.RetryPredicateArguments.RetryPredicateArguments(int Attempt) -> void +Polly.Retry.RetryPredicateArguments.RetryPredicateArguments(int attempt) -> void Polly.Retry.RetryStrategyOptions Polly.Retry.RetryStrategyOptions.RetryStrategyOptions() -> void Polly.Retry.RetryStrategyOptions @@ -354,11 +337,9 @@ Polly.Telemetry.ExecutionAttemptArguments.ExecutionTime.get -> System.TimeSpan Polly.Telemetry.ExecutionAttemptArguments.Handled.get -> bool Polly.Telemetry.ResilienceEvent Polly.Telemetry.ResilienceEvent.EventName.get -> string! -Polly.Telemetry.ResilienceEvent.EventName.init -> void Polly.Telemetry.ResilienceEvent.ResilienceEvent() -> void -Polly.Telemetry.ResilienceEvent.ResilienceEvent(Polly.Telemetry.ResilienceEventSeverity Severity, string! EventName) -> void +Polly.Telemetry.ResilienceEvent.ResilienceEvent(Polly.Telemetry.ResilienceEventSeverity severity, string! eventName) -> void Polly.Telemetry.ResilienceEvent.Severity.get -> Polly.Telemetry.ResilienceEventSeverity -Polly.Telemetry.ResilienceEvent.Severity.init -> void Polly.Telemetry.ResilienceEventSeverity Polly.Telemetry.ResilienceEventSeverity.Critical = 5 -> Polly.Telemetry.ResilienceEventSeverity Polly.Telemetry.ResilienceEventSeverity.Debug = 1 -> Polly.Telemetry.ResilienceEventSeverity @@ -372,14 +353,10 @@ Polly.Telemetry.ResilienceStrategyTelemetry.Report(Polly.Telemet Polly.Telemetry.ResilienceStrategyTelemetry.Report(Polly.Telemetry.ResilienceEvent resilienceEvent, Polly.ResilienceContext! context, TArgs args) -> void Polly.Telemetry.ResilienceTelemetrySource Polly.Telemetry.ResilienceTelemetrySource.BuilderInstanceName.get -> string? -Polly.Telemetry.ResilienceTelemetrySource.BuilderInstanceName.init -> void Polly.Telemetry.ResilienceTelemetrySource.BuilderName.get -> string? -Polly.Telemetry.ResilienceTelemetrySource.BuilderName.init -> void Polly.Telemetry.ResilienceTelemetrySource.BuilderProperties.get -> Polly.ResilienceProperties! -Polly.Telemetry.ResilienceTelemetrySource.BuilderProperties.init -> void -Polly.Telemetry.ResilienceTelemetrySource.ResilienceTelemetrySource(string? BuilderName, string? BuilderInstanceName, Polly.ResilienceProperties! BuilderProperties, string? StrategyName) -> void +Polly.Telemetry.ResilienceTelemetrySource.ResilienceTelemetrySource(string? builderName, string? builderInstanceName, Polly.ResilienceProperties! builderProperties, string? strategyName) -> void Polly.Telemetry.ResilienceTelemetrySource.StrategyName.get -> string? -Polly.Telemetry.ResilienceTelemetrySource.StrategyName.init -> void Polly.Telemetry.TelemetryEventArguments Polly.Telemetry.TelemetryEventArguments.Arguments.get -> object! Polly.Telemetry.TelemetryEventArguments.Context.get -> Polly.ResilienceContext! @@ -388,17 +365,13 @@ Polly.Telemetry.TelemetryEventArguments.Outcome.get -> Polly.Outcome? Polly.Telemetry.TelemetryEventArguments.Source.get -> Polly.Telemetry.ResilienceTelemetrySource! Polly.Timeout.OnTimeoutArguments Polly.Timeout.OnTimeoutArguments.Context.get -> Polly.ResilienceContext! -Polly.Timeout.OnTimeoutArguments.Context.init -> void Polly.Timeout.OnTimeoutArguments.Exception.get -> System.Exception! -Polly.Timeout.OnTimeoutArguments.Exception.init -> void -Polly.Timeout.OnTimeoutArguments.OnTimeoutArguments(Polly.ResilienceContext! Context, System.Exception! Exception, System.TimeSpan Timeout) -> void +Polly.Timeout.OnTimeoutArguments.OnTimeoutArguments(Polly.ResilienceContext! context, System.Exception! exception, System.TimeSpan timeout) -> void Polly.Timeout.OnTimeoutArguments.Timeout.get -> System.TimeSpan -Polly.Timeout.OnTimeoutArguments.Timeout.init -> void Polly.Timeout.TimeoutGeneratorArguments Polly.Timeout.TimeoutGeneratorArguments.Context.get -> Polly.ResilienceContext! -Polly.Timeout.TimeoutGeneratorArguments.Context.init -> void Polly.Timeout.TimeoutGeneratorArguments.TimeoutGeneratorArguments() -> void -Polly.Timeout.TimeoutGeneratorArguments.TimeoutGeneratorArguments(Polly.ResilienceContext! Context) -> void +Polly.Timeout.TimeoutGeneratorArguments.TimeoutGeneratorArguments(Polly.ResilienceContext! context) -> void Polly.Timeout.TimeoutRejectedException Polly.Timeout.TimeoutRejectedException.Timeout.get -> System.TimeSpan Polly.Timeout.TimeoutRejectedException.TimeoutRejectedException() -> void diff --git a/src/Polly.Core/Retry/OnRetryArguments.cs b/src/Polly.Core/Retry/OnRetryArguments.cs index 70e5e1926c9..34bc2bbb399 100644 --- a/src/Polly.Core/Retry/OnRetryArguments.cs +++ b/src/Polly.Core/Retry/OnRetryArguments.cs @@ -3,7 +3,33 @@ namespace Polly.Retry; /// /// Represents the arguments used by for handling the retry event. /// -/// The zero-based attempt number. The first attempt is 0, the second attempt is 1, and so on. -/// The delay before the next retry. -/// The execution time of this attempt. -public record OnRetryArguments(int Attempt, TimeSpan RetryDelay, TimeSpan ExecutionTime); +public sealed class OnRetryArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The zero-based attempt number. + /// The delay before the next retry. + /// The execution time of this attempt. + public OnRetryArguments(int attempt, TimeSpan retryDelay, TimeSpan executionTime) + { + Attempt = attempt; + RetryDelay = retryDelay; + ExecutionTime = executionTime; + } + + /// + /// Gets the zero-based attempt number. + /// + public int Attempt { get; } + + /// + /// Gets the delay before the next retry. + /// + public TimeSpan RetryDelay { get; } + + /// + /// Gets the execution time of this attempt. + /// + public TimeSpan ExecutionTime { get; } +} diff --git a/src/Polly.Core/Retry/RetryDelayArguments.cs b/src/Polly.Core/Retry/RetryDelayArguments.cs index 0ea3b1c2251..854c8b3212a 100644 --- a/src/Polly.Core/Retry/RetryDelayArguments.cs +++ b/src/Polly.Core/Retry/RetryDelayArguments.cs @@ -1,11 +1,33 @@ namespace Polly.Retry; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Represents the arguments used by for generating the next retry delay. /// -/// The zero-based attempt number. The first attempt is 0, the second attempt is 1, and so on. -/// The delay suggested by the retry strategy. /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct RetryDelayArguments(int Attempt, TimeSpan DelayHint); +public readonly struct RetryDelayArguments +{ + /// + /// Initializes a new instance of the struct. + /// + /// The zero-based attempt number. + /// The delay suggested by the retry strategy. + public RetryDelayArguments(int attempt, TimeSpan delayHint) + { + Attempt = attempt; + DelayHint = delayHint; + } + + /// + /// Gets The zero-based attempt number. + /// + public int Attempt { get; } + + /// + /// Gets the delay suggested by the retry strategy. + /// + public TimeSpan DelayHint { get; } +} diff --git a/src/Polly.Core/Retry/RetryPredicateArguments.cs b/src/Polly.Core/Retry/RetryPredicateArguments.cs index 7a82ff19277..cb13a97733d 100644 --- a/src/Polly.Core/Retry/RetryPredicateArguments.cs +++ b/src/Polly.Core/Retry/RetryPredicateArguments.cs @@ -1,10 +1,23 @@ namespace Polly.Retry; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Represents the arguments used by for determining whether a retry should be performed. /// -/// The zero-based attempt number. The first attempt is 0, the second attempt is 1, and so on. /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct RetryPredicateArguments(int Attempt); +public readonly struct RetryPredicateArguments +{ + /// + /// Initializes a new instance of the struct. + /// + /// The zero-based attempt number. + public RetryPredicateArguments(int attempt) => Attempt = attempt; + + /// + /// Gets the zero-based attempt number. + /// + public int Attempt { get; } +} diff --git a/src/Polly.Core/Telemetry/ResilienceEvent.cs b/src/Polly.Core/Telemetry/ResilienceEvent.cs index fdc4710bc43..003ce816932 100644 --- a/src/Polly.Core/Telemetry/ResilienceEvent.cs +++ b/src/Polly.Core/Telemetry/ResilienceEvent.cs @@ -1,15 +1,36 @@ namespace Polly.Telemetry; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Represents a resilience event that has been reported. /// -/// The severity of the event. -/// The event name. /// /// Always use the constructor when creating this struct, otherwise we do not guarantee binary compatibility. /// -public readonly record struct ResilienceEvent(ResilienceEventSeverity Severity, string EventName) +public readonly struct ResilienceEvent { + /// + /// Initializes a new instance of the struct. + /// + /// The severity of the event. + /// The event name. + public ResilienceEvent(ResilienceEventSeverity severity, string eventName) + { + Severity = severity; + EventName = eventName; + } + + /// + /// Gets the severity of the event. + /// + public ResilienceEventSeverity Severity { get; } + + /// + /// Gets the event name. + /// + public string EventName { get; } + /// /// Returns an . /// diff --git a/src/Polly.Core/Telemetry/ResilienceTelemetrySource.cs b/src/Polly.Core/Telemetry/ResilienceTelemetrySource.cs index df58d5d47f3..96b134fd002 100644 --- a/src/Polly.Core/Telemetry/ResilienceTelemetrySource.cs +++ b/src/Polly.Core/Telemetry/ResilienceTelemetrySource.cs @@ -3,16 +3,48 @@ namespace Polly.Telemetry; /// /// The source of resilience telemetry events. /// -/// The builder name. -/// The builder instance name. -/// The builder properties. -/// The strategy name. /// /// This class is used by the telemetry infrastructure and should not be used directly by user code. /// -public sealed record class ResilienceTelemetrySource( - string? BuilderName, - string? BuilderInstanceName, - ResilienceProperties BuilderProperties, - string? StrategyName); +public sealed class ResilienceTelemetrySource +{ + /// + /// Initializes a new instance of the class. + /// + /// The builder name. + /// The builder instance name. + /// The builder properties. + /// The strategy name. + public ResilienceTelemetrySource( + string? builderName, + string? builderInstanceName, + ResilienceProperties builderProperties, + string? strategyName) + { + BuilderName = builderName; + BuilderInstanceName = builderInstanceName; + BuilderProperties = builderProperties; + StrategyName = strategyName; + } + + /// + /// Gets the builder name. + /// + public string? BuilderName { get; } + + /// + /// Gets the builder instance name. + /// + public string? BuilderInstanceName { get; } + + /// + /// Gets the builder properties. + /// + public ResilienceProperties BuilderProperties { get; } + + /// + /// Gets the strategy name. + /// + public string? StrategyName { get; } +} diff --git a/src/Polly.Core/Telemetry/TelemetryEventArguments.Pool.cs b/src/Polly.Core/Telemetry/TelemetryEventArguments.Pool.cs index d115c9468ca..02b70b9143d 100644 --- a/src/Polly.Core/Telemetry/TelemetryEventArguments.Pool.cs +++ b/src/Polly.Core/Telemetry/TelemetryEventArguments.Pool.cs @@ -1,6 +1,6 @@ namespace Polly.Telemetry; -public sealed partial record class TelemetryEventArguments +public sealed partial class TelemetryEventArguments { private static readonly ObjectPool Pool = new(() => new TelemetryEventArguments(), args => { diff --git a/src/Polly.Core/Telemetry/TelemetryEventArguments.cs b/src/Polly.Core/Telemetry/TelemetryEventArguments.cs index f8c592dd7ed..c450b13f6e2 100644 --- a/src/Polly.Core/Telemetry/TelemetryEventArguments.cs +++ b/src/Polly.Core/Telemetry/TelemetryEventArguments.cs @@ -3,7 +3,7 @@ namespace Polly.Telemetry; /// /// The arguments of the telemetry event. /// -public sealed partial record class TelemetryEventArguments +public sealed partial class TelemetryEventArguments { private TelemetryEventArguments() { diff --git a/src/Polly.Core/Timeout/OnTimeoutArguments.cs b/src/Polly.Core/Timeout/OnTimeoutArguments.cs index ab481e10e58..c78eb02f676 100644 --- a/src/Polly.Core/Timeout/OnTimeoutArguments.cs +++ b/src/Polly.Core/Timeout/OnTimeoutArguments.cs @@ -3,7 +3,33 @@ namespace Polly.Timeout; /// /// Arguments used by the timeout strategy to notify that a timeout occurred. /// -/// The context associated with the execution of a user-provided callback. -/// The original exception that caused the timeout. -/// The timeout value assigned. -public record OnTimeoutArguments(ResilienceContext Context, Exception Exception, TimeSpan Timeout); +public sealed class OnTimeoutArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The context associated with the execution of a user-provided callback. + /// The original exception that caused the timeout. + /// The timeout value assigned. + public OnTimeoutArguments(ResilienceContext context, Exception exception, TimeSpan timeout) + { + Context = context; + Exception = exception; + Timeout = timeout; + } + + /// + /// Gets the context associated with the execution of a user-provided callback. + /// + public ResilienceContext Context { get; } + + /// + /// Gets hte original exception that caused the timeout. + /// + public Exception Exception { get; } + + /// + /// Gets the timeout value assigned. + /// + public TimeSpan Timeout { get; } +} diff --git a/src/Polly.Core/Timeout/TimeoutGeneratorArguments.cs b/src/Polly.Core/Timeout/TimeoutGeneratorArguments.cs index feb3ef8561d..1b1868f87ec 100644 --- a/src/Polly.Core/Timeout/TimeoutGeneratorArguments.cs +++ b/src/Polly.Core/Timeout/TimeoutGeneratorArguments.cs @@ -1,7 +1,21 @@ namespace Polly.Timeout; +#pragma warning disable CA1815 // Override equals and operator equals on value types + /// /// Arguments used by the timeout strategy to retrieve a timeout for current execution. /// -/// The context associated with the execution of a user-provided callback. -public readonly record struct TimeoutGeneratorArguments(ResilienceContext Context); +public readonly struct TimeoutGeneratorArguments +{ + /// + /// Initializes a new instance of the struct. + /// + /// The context associated with the execution of a user-provided callback. + public TimeoutGeneratorArguments(ResilienceContext context) => Context = context; + + /// + /// Gets the context associated with the execution of a user-provided callback. + /// + public ResilienceContext Context { get; } +} + diff --git a/src/Polly.RateLimiting/OnRateLimiterRejectedArguments.cs b/src/Polly.RateLimiting/OnRateLimiterRejectedArguments.cs index 8771070fa93..b81ff2bdb31 100644 --- a/src/Polly.RateLimiting/OnRateLimiterRejectedArguments.cs +++ b/src/Polly.RateLimiting/OnRateLimiterRejectedArguments.cs @@ -5,7 +5,36 @@ namespace Polly.RateLimiting; /// /// The arguments used by the . /// -/// The context associated with the execution of a user-provided callback. -/// The lease that has no permits and was rejected by the rate limiter. -/// The amount of time to wait before retrying again. This value is retrieved from the by reading the . -public record OnRateLimiterRejectedArguments(ResilienceContext Context, RateLimitLease Lease, TimeSpan? RetryAfter); +public sealed class OnRateLimiterRejectedArguments +{ + /// + /// Initializes a new instance of the class. + /// + /// The context associated with the execution of a user-provided callback. + /// The lease that has no permits and was rejected by the rate limiter. + /// The amount of time to wait before retrying again. + public OnRateLimiterRejectedArguments(ResilienceContext context, RateLimitLease lease, TimeSpan? retryAfter) + { + Context = context; + Lease = lease; + RetryAfter = retryAfter; + } + + /// + /// Gets the context associated with the execution of a user-provided callback. + /// + public ResilienceContext Context { get; } + + /// + /// Gets the lease that has no permits and was rejected by the rate limiter. + /// + public RateLimitLease Lease { get; } + + /// + /// Gets the amount of time to wait before retrying again. + /// + /// + /// This value is retrieved from the by reading the . + /// + public TimeSpan? RetryAfter { get; } +} diff --git a/src/Polly.RateLimiting/PublicAPI.Unshipped.txt b/src/Polly.RateLimiting/PublicAPI.Unshipped.txt index e6dfdee2b6a..39fd5fb4303 100644 --- a/src/Polly.RateLimiting/PublicAPI.Unshipped.txt +++ b/src/Polly.RateLimiting/PublicAPI.Unshipped.txt @@ -2,12 +2,9 @@ Polly.RateLimiterResilienceStrategyBuilderExtensions Polly.RateLimiting.OnRateLimiterRejectedArguments Polly.RateLimiting.OnRateLimiterRejectedArguments.Context.get -> Polly.ResilienceContext! -Polly.RateLimiting.OnRateLimiterRejectedArguments.Context.init -> void Polly.RateLimiting.OnRateLimiterRejectedArguments.Lease.get -> System.Threading.RateLimiting.RateLimitLease! -Polly.RateLimiting.OnRateLimiterRejectedArguments.Lease.init -> void -Polly.RateLimiting.OnRateLimiterRejectedArguments.OnRateLimiterRejectedArguments(Polly.ResilienceContext! Context, System.Threading.RateLimiting.RateLimitLease! Lease, System.TimeSpan? RetryAfter) -> void +Polly.RateLimiting.OnRateLimiterRejectedArguments.OnRateLimiterRejectedArguments(Polly.ResilienceContext! context, System.Threading.RateLimiting.RateLimitLease! lease, System.TimeSpan? retryAfter) -> void Polly.RateLimiting.OnRateLimiterRejectedArguments.RetryAfter.get -> System.TimeSpan? -Polly.RateLimiting.OnRateLimiterRejectedArguments.RetryAfter.init -> void Polly.RateLimiting.RateLimiterRejectedException Polly.RateLimiting.RateLimiterRejectedException.RateLimiterRejectedException() -> void Polly.RateLimiting.RateLimiterRejectedException.RateLimiterRejectedException(string! message) -> void diff --git a/src/Polly.Testing/InnerStrategiesDescriptor.cs b/src/Polly.Testing/InnerStrategiesDescriptor.cs index 14f171a73a1..d2b80dc6c37 100644 --- a/src/Polly.Testing/InnerStrategiesDescriptor.cs +++ b/src/Polly.Testing/InnerStrategiesDescriptor.cs @@ -3,7 +3,33 @@ /// /// Describes the pipeline of a resilience strategy. /// -/// The strategies the pipeline is composed of. -/// Gets a value indicating whether the pipeline has telemetry enabled. -/// Gets a value indicating whether the resilience strategy is reloadable. -public record class InnerStrategiesDescriptor(IReadOnlyList Strategies, bool HasTelemetry, bool IsReloadable); +public sealed class InnerStrategiesDescriptor +{ + /// + /// Initializes a new instance of the class. + /// + /// The strategies the pipeline is composed of. + /// Determines whether the pipeline has telemetry enabled. + /// Determines whether the resilience strategy is reloadable. + public InnerStrategiesDescriptor(IReadOnlyList strategies, bool hasTelemetry, bool isReloadable) + { + Strategies = strategies; + HasTelemetry = hasTelemetry; + IsReloadable = isReloadable; + } + + /// + /// Gets the strategies the pipeline is composed of. + /// + public IReadOnlyList Strategies { get; } + + /// + /// Gets a value indicating whether the pipeline has telemetry enabled. + /// + public bool HasTelemetry { get; } + + /// + /// Gets a value indicating whether the resilience strategy is reloadable. + /// + public bool IsReloadable { get; } +} diff --git a/src/Polly.Testing/PublicAPI.Unshipped.txt b/src/Polly.Testing/PublicAPI.Unshipped.txt index d07931b733e..932466695a8 100644 --- a/src/Polly.Testing/PublicAPI.Unshipped.txt +++ b/src/Polly.Testing/PublicAPI.Unshipped.txt @@ -1,18 +1,13 @@ #nullable enable Polly.Testing.InnerStrategiesDescriptor Polly.Testing.InnerStrategiesDescriptor.HasTelemetry.get -> bool -Polly.Testing.InnerStrategiesDescriptor.HasTelemetry.init -> void -Polly.Testing.InnerStrategiesDescriptor.InnerStrategiesDescriptor(System.Collections.Generic.IReadOnlyList! Strategies, bool HasTelemetry, bool IsReloadable) -> void +Polly.Testing.InnerStrategiesDescriptor.InnerStrategiesDescriptor(System.Collections.Generic.IReadOnlyList! strategies, bool hasTelemetry, bool isReloadable) -> void Polly.Testing.InnerStrategiesDescriptor.IsReloadable.get -> bool -Polly.Testing.InnerStrategiesDescriptor.IsReloadable.init -> void Polly.Testing.InnerStrategiesDescriptor.Strategies.get -> System.Collections.Generic.IReadOnlyList! -Polly.Testing.InnerStrategiesDescriptor.Strategies.init -> void Polly.Testing.ResilienceStrategyDescriptor Polly.Testing.ResilienceStrategyDescriptor.Options.get -> Polly.ResilienceStrategyOptions? -Polly.Testing.ResilienceStrategyDescriptor.Options.init -> void -Polly.Testing.ResilienceStrategyDescriptor.ResilienceStrategyDescriptor(Polly.ResilienceStrategyOptions? Options, System.Type! StrategyType) -> void +Polly.Testing.ResilienceStrategyDescriptor.ResilienceStrategyDescriptor(Polly.ResilienceStrategyOptions? options, System.Type! strategyType) -> void Polly.Testing.ResilienceStrategyDescriptor.StrategyType.get -> System.Type! -Polly.Testing.ResilienceStrategyDescriptor.StrategyType.init -> void Polly.Testing.ResilienceStrategyExtensions static Polly.Testing.ResilienceStrategyExtensions.GetInnerStrategies(this Polly.ResilienceStrategy! strategy) -> Polly.Testing.InnerStrategiesDescriptor! static Polly.Testing.ResilienceStrategyExtensions.GetInnerStrategies(this Polly.ResilienceStrategy! strategy) -> Polly.Testing.InnerStrategiesDescriptor! diff --git a/src/Polly.Testing/ResilienceStrategyDescriptor.cs b/src/Polly.Testing/ResilienceStrategyDescriptor.cs index 04005d3249e..dbba00cfeeb 100644 --- a/src/Polly.Testing/ResilienceStrategyDescriptor.cs +++ b/src/Polly.Testing/ResilienceStrategyDescriptor.cs @@ -3,8 +3,26 @@ /// /// This class provides additional information about a . /// -/// The options used by the resilience strategy, if any. -/// The type of the strategy. -public record ResilienceStrategyDescriptor(ResilienceStrategyOptions? Options, Type StrategyType) +public sealed class ResilienceStrategyDescriptor { + /// + /// Initializes a new instance of the class. + /// + /// The options used by the resilience strategy, if any. + /// The type of the strategy. + public ResilienceStrategyDescriptor(ResilienceStrategyOptions? options, Type strategyType) + { + Options = options; + StrategyType = strategyType; + } + + /// + /// Gets the options used by the resilience strategy, if any. + /// + public ResilienceStrategyOptions? Options { get; } + + /// + /// Gets the type of the strategy. + /// + public Type StrategyType { get; } } diff --git a/src/Polly.Testing/ResilienceStrategyExtensions.cs b/src/Polly.Testing/ResilienceStrategyExtensions.cs index bf8ca6a1c8d..3f787e7a249 100644 --- a/src/Polly.Testing/ResilienceStrategyExtensions.cs +++ b/src/Polly.Testing/ResilienceStrategyExtensions.cs @@ -40,8 +40,8 @@ public static InnerStrategiesDescriptor GetInnerStrategies(this ResilienceStrate return new InnerStrategiesDescriptor( innerStrategies.Where(s => !ShouldSkip(s.StrategyType)).ToList().AsReadOnly(), - HasTelemetry: innerStrategies.Exists(s => s.StrategyType.FullName == TelemetryResilienceStrategy), - IsReloadable: innerStrategies.Exists(s => s.StrategyType == typeof(ReloadableResilienceStrategy))); + hasTelemetry: innerStrategies.Exists(s => s.StrategyType.FullName == TelemetryResilienceStrategy), + isReloadable: innerStrategies.Exists(s => s.StrategyType == typeof(ReloadableResilienceStrategy))); } private static bool ShouldSkip(Type type) => type == typeof(ReloadableResilienceStrategy) || type.FullName == TelemetryResilienceStrategy; diff --git a/test/Polly.Core.Tests/CircuitBreaker/AdvancedCircuitBreakerOptionsTests.cs b/test/Polly.Core.Tests/CircuitBreaker/AdvancedCircuitBreakerOptionsTests.cs index f0c9e6ba05e..73babb13273 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/AdvancedCircuitBreakerOptionsTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/AdvancedCircuitBreakerOptionsTests.cs @@ -33,7 +33,7 @@ public void Ctor_Defaults() public async Task ShouldHandle_EnsureDefaults() { var options = new AdvancedCircuitBreakerStrategyOptions(); - var args = new CircuitBreakerPredicateArguments(); + var args = default(CircuitBreakerPredicateArguments); var context = ResilienceContextPool.Shared.Get(); (await options.ShouldHandle(new(context, Outcome.FromResult("dummy"), args))).Should().Be(false); diff --git a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerPredicateArgumentsTests.cs b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerPredicateArgumentsTests.cs index 780f9d1fcfe..f5079538c36 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerPredicateArgumentsTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerPredicateArgumentsTests.cs @@ -7,6 +7,6 @@ public class CircuitBreakerPredicateArgumentsTests [Fact] public void Ctor_Ok() { - this.Invoking(_ => new CircuitBreakerPredicateArguments()).Should().NotThrow(); + this.Invoking(_ => default(CircuitBreakerPredicateArguments)).Should().NotThrow(); } } diff --git a/test/Polly.Core.Tests/CircuitBreaker/OnCircuitHalfOpenedArgumentsTests.cs b/test/Polly.Core.Tests/CircuitBreaker/OnCircuitHalfOpenedArgumentsTests.cs index 49046096470..81103a6618d 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/OnCircuitHalfOpenedArgumentsTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/OnCircuitHalfOpenedArgumentsTests.cs @@ -1,3 +1,4 @@ +using FluentAssertions; using Polly.CircuitBreaker; namespace Polly.Core.Tests.CircuitBreaker; @@ -7,6 +8,6 @@ public class OnCircuitHalfOpenedArgumentsTests [Fact] public void Ctor_Ok() { - this.Invoking(_ => new OnCircuitHalfOpenedArguments()).Should().NotThrow(); + new OnCircuitHalfOpenedArguments(ResilienceContextPool.Shared.Get()).Context.Should().NotBeNull(); } } diff --git a/test/Polly.Core.Tests/CircuitBreaker/SimpleCircuitBreakerOptionsTests.cs b/test/Polly.Core.Tests/CircuitBreaker/SimpleCircuitBreakerOptionsTests.cs index 7d3512e2a51..303a19503a5 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/SimpleCircuitBreakerOptionsTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/SimpleCircuitBreakerOptionsTests.cs @@ -30,7 +30,7 @@ public void Ctor_Defaults() public async Task ShouldHandle_EnsureDefaults() { var options = new SimpleCircuitBreakerStrategyOptions(); - var args = new CircuitBreakerPredicateArguments(); + var args = default(CircuitBreakerPredicateArguments); var context = ResilienceContextPool.Shared.Get(); (await options.ShouldHandle(new(context, Outcome.FromResult(""), args))).Should().Be(false); diff --git a/test/Polly.Core.Tests/Fallback/FallbackHandlerTests.cs b/test/Polly.Core.Tests/Fallback/FallbackHandlerTests.cs index 70866d1b1e2..fbf0451c37c 100644 --- a/test/Polly.Core.Tests/Fallback/FallbackHandlerTests.cs +++ b/test/Polly.Core.Tests/Fallback/FallbackHandlerTests.cs @@ -8,7 +8,7 @@ public async Task GenerateAction_Generic_Ok() { var handler = FallbackHelper.CreateHandler(_ => true, () => Outcome.FromResult("secondary"), true); var context = ResilienceContextPool.Shared.Get(); - var outcome = await handler.GetFallbackOutcomeAsync(new OutcomeArguments(context, Outcome.FromResult("primary"), new FallbackPredicateArguments()))!; + var outcome = await handler.GetFallbackOutcomeAsync(new OutcomeArguments(context, Outcome.FromResult("primary"), default))!; outcome.Result.Should().Be("secondary"); } @@ -18,7 +18,7 @@ public async Task GenerateAction_NonGeneric_Ok() { var handler = FallbackHelper.CreateHandler(_ => true, () => Outcome.FromResult((object)"secondary"), false); var context = ResilienceContextPool.Shared.Get(); - var outcome = await handler.GetFallbackOutcomeAsync(new OutcomeArguments(context, Outcome.FromResult("primary"), new FallbackPredicateArguments()))!; + var outcome = await handler.GetFallbackOutcomeAsync(new OutcomeArguments(context, Outcome.FromResult("primary"), default))!; outcome.Result.Should().Be("secondary"); } diff --git a/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs b/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs index 1d65fbbf2ef..430e03abce9 100644 --- a/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Fallback/FallbackStrategyOptionsTests.cs @@ -20,7 +20,7 @@ public void Ctor_EnsureDefaults() public async Task ShouldHandle_EnsureDefaults() { var options = new FallbackStrategyOptions(); - var args = new FallbackPredicateArguments(); + var args = default(FallbackPredicateArguments); var context = ResilienceContextPool.Shared.Get(); (await options.ShouldHandle(new(context, Outcome.FromResult(0), args))).Should().Be(false); diff --git a/test/Polly.Core.Tests/Hedging/HedgingPredicateArgumentsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingPredicateArgumentsTests.cs index ea2b821d3c1..f3e52668882 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingPredicateArgumentsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingPredicateArgumentsTests.cs @@ -7,6 +7,6 @@ public class HedgingPredicateArgumentsTests [Fact] public void Ctor_Ok() { - this.Invoking(_ => new HedgingPredicateArguments()).Should().NotThrow(); + this.Invoking(_ => default(HedgingPredicateArguments)).Should().NotThrow(); } } diff --git a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs index fd322bea149..cdf470a53ba 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingStrategyOptionsTests.cs @@ -49,7 +49,7 @@ public async Task HedgingActionGenerator_EnsureDefaults(bool synchronous) public async Task ShouldHandle_EnsureDefaults() { var options = new HedgingStrategyOptions(); - var args = new HedgingPredicateArguments(); + var args = default(HedgingPredicateArguments); var context = ResilienceContextPool.Shared.Get(); (await options.ShouldHandle(new(context, Outcome.FromResult(0), args))).Should().Be(false); diff --git a/test/Polly.Core.Tests/Hedging/OnHedgingArgumentsTests.cs b/test/Polly.Core.Tests/Hedging/OnHedgingArgumentsTests.cs new file mode 100644 index 00000000000..9ece83f440f --- /dev/null +++ b/test/Polly.Core.Tests/Hedging/OnHedgingArgumentsTests.cs @@ -0,0 +1,16 @@ +using Polly.Hedging; + +namespace Polly.Core.Tests.Hedging; + +public class OnHedgingArgumentsTests +{ + [Fact] + public void Ctor_Ok() + { + var args = new OnHedgingArguments(1, true, TimeSpan.FromSeconds(1)); + + args.Attempt.Should().Be(1); + args.HasOutcome.Should().BeTrue(); + args.ExecutionTime.Should().Be(TimeSpan.FromSeconds(1)); + } +} diff --git a/test/Polly.Core.Tests/PredicateBuilderTests.cs b/test/Polly.Core.Tests/PredicateBuilderTests.cs index e937743d65a..68e30389434 100644 --- a/test/Polly.Core.Tests/PredicateBuilderTests.cs +++ b/test/Polly.Core.Tests/PredicateBuilderTests.cs @@ -79,7 +79,7 @@ public async Task Operator_FallbackStrategyOptions_Ok() ShouldHandle = new PredicateBuilder().HandleResult("error") }; - var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), new FallbackPredicateArguments())); + var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), default)); handled.Should().BeTrue(); } @@ -92,7 +92,7 @@ public async Task Operator_HedgingStrategyOptions_Ok() ShouldHandle = new PredicateBuilder().HandleResult("error") }; - var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), new HedgingPredicateArguments())); + var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), default)); handled.Should().BeTrue(); } @@ -105,7 +105,7 @@ public async Task Operator_AdvancedCircuitBreakerStrategyOptions_Ok() ShouldHandle = new PredicateBuilder().HandleResult("error") }; - var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), new CircuitBreakerPredicateArguments())); + var handled = await options.ShouldHandle(new(ResilienceContextPool.Shared.Get(), Outcome.FromResult("error"), default)); handled.Should().BeTrue(); } diff --git a/test/Polly.Core.Tests/Telemetry/ResilienceEventTests.cs b/test/Polly.Core.Tests/Telemetry/ResilienceEventTests.cs index e7ea2db478f..d92482ebdb3 100644 --- a/test/Polly.Core.Tests/Telemetry/ResilienceEventTests.cs +++ b/test/Polly.Core.Tests/Telemetry/ResilienceEventTests.cs @@ -11,15 +11,5 @@ public void Ctor_Ok() ev.ToString().Should().Be("A"); ev.Severity.Should().Be(ResilienceEventSeverity.Warning); - - } - - [Fact] - public void Equality_Ok() - { - (new ResilienceEvent(ResilienceEventSeverity.Warning, "A") == new ResilienceEvent(ResilienceEventSeverity.Warning, "A")).Should().BeTrue(); - (new ResilienceEvent(ResilienceEventSeverity.Warning, "A") != new ResilienceEvent(ResilienceEventSeverity.Warning, "A")).Should().BeFalse(); - (new ResilienceEvent(ResilienceEventSeverity.Warning, "A") == new ResilienceEvent(ResilienceEventSeverity.Warning, "B")).Should().BeFalse(); - (new ResilienceEvent(ResilienceEventSeverity.Information, "A") == new ResilienceEvent(ResilienceEventSeverity.Warning, "A")).Should().BeFalse(); } }