Skip to content

Commit 76f181f

Browse files
authored
Rename ResilienceStrategy to ResiliencePipeline (#1483)
1 parent 4e6afb3 commit 76f181f

File tree

144 files changed

+1641
-1642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+1641
-1642
lines changed

bench/Polly.Core.Benchmarks/BridgeBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public class BridgeBenchmark
99
public void Setup()
1010
{
1111
_policy = Policy.NoOpAsync<string>();
12-
_policyWrapped = NullResilienceStrategy<string>.Instance.AsAsyncPolicy();
12+
_policyWrapped = NullResiliencePipeline<string>.Instance.AsAsyncPolicy();
1313
}
1414

1515
[Benchmark(Baseline = true)]
1616
public Task NoOpAsync() => _policy!.ExecuteAsync(() => Task.FromResult("dummy"));
1717

1818
[Benchmark]
19-
public Task NullResilienceStrategy() => _policyWrapped!.ExecuteAsync(() => Task.FromResult("dummy"));
19+
public Task NullResiliencePipeline() => _policyWrapped!.ExecuteAsync(() => Task.FromResult("dummy"));
2020
}

bench/Polly.Core.Benchmarks/CircuitBreakerBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ namespace Polly.Core.Benchmarks;
22

33
public class CircuitBreakerBenchmark
44
{
5-
private object? _strategyV7;
6-
private object? _strategyV8;
5+
private object? _circuitBreakerV7;
6+
private object? _circuitBreakerV8;
77

88
[GlobalSetup]
99
public void Setup()
1010
{
11-
_strategyV7 = Helper.CreateCircuitBreaker(PollyVersion.V7);
12-
_strategyV8 = Helper.CreateCircuitBreaker(PollyVersion.V8);
11+
_circuitBreakerV7 = Helper.CreateCircuitBreaker(PollyVersion.V7);
12+
_circuitBreakerV8 = Helper.CreateCircuitBreaker(PollyVersion.V8);
1313
}
1414

1515
[Benchmark(Baseline = true)]
16-
public ValueTask ExecuteCircuitBreaker_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
16+
public ValueTask ExecuteCircuitBreaker_V7() => _circuitBreakerV7!.ExecuteAsync(PollyVersion.V7);
1717

1818
[Benchmark]
19-
public ValueTask ExecuteCircuitBreaker_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
19+
public ValueTask ExecuteCircuitBreaker_V8() => _circuitBreakerV8!.ExecuteAsync(PollyVersion.V8);
2020
}

bench/Polly.Core.Benchmarks/CircuitBreakerOpenedBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ namespace Polly.Core.Benchmarks;
22

33
public class CircuitBreakerOpenedBenchmark
44
{
5-
private ResilienceStrategy? _strategy;
6-
private ResilienceStrategy? _strategyHandlesOutcome;
5+
private ResiliencePipeline? _pipeline;
6+
private ResiliencePipeline? _reactivePipeline;
77
private IAsyncPolicy<string>? _policy;
88

99
[GlobalSetup]
1010
public void Setup()
1111
{
12-
_strategyHandlesOutcome = (ResilienceStrategy?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: true);
13-
_strategy = (ResilienceStrategy?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: false);
12+
_reactivePipeline = (ResiliencePipeline?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: true);
13+
_pipeline = (ResiliencePipeline?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: false);
1414
_policy = (IAsyncPolicy<string>?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V7, handleOutcome: false);
1515
}
1616

@@ -32,7 +32,7 @@ public async ValueTask ExecuteAsync_Exception_V8()
3232
{
3333
try
3434
{
35-
await _strategy!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
35+
await _pipeline!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
3636
}
3737
catch (BrokenCircuitException)
3838
{
@@ -43,6 +43,6 @@ public async ValueTask ExecuteAsync_Exception_V8()
4343
[Benchmark(Baseline = true)]
4444
public async ValueTask ExecuteAsync_Outcome_V8()
4545
{
46-
await _strategyHandlesOutcome!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
46+
await _reactivePipeline!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
4747
}
4848
}

bench/Polly.Core.Benchmarks/CreationBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void Fallback_V7()
1515
[Benchmark]
1616
public static void Fallback_V8()
1717
{
18-
new CompositeStrategyBuilder<string>()
18+
new ResiliencePipelineBuilder<string>()
1919
.AddFallback(new()
2020
{
2121
FallbackAction = _ => Outcome.FromResultAsTask("fallback")

bench/Polly.Core.Benchmarks/HedgingBenchmark.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ namespace Polly.Core.Benchmarks;
22

33
public class HedgingBenchmark
44
{
5-
private ResilienceStrategy<string>? _strategy;
5+
private ResiliencePipeline<string>? _pipeline;
66

77
[GlobalSetup]
8-
public void Setup() =>
9-
_strategy = Helper.CreateHedging();
8+
public void Setup() => _pipeline = Helper.CreateHedging();
109

1110
[Benchmark(Baseline = true)]
1211
public async ValueTask Hedging_Primary()
13-
=> await _strategy!.ExecuteAsync(static _ => new ValueTask<string>("primary")).ConfigureAwait(false);
12+
=> await _pipeline!.ExecuteAsync(static _ => new ValueTask<string>("primary")).ConfigureAwait(false);
1413

1514
[Benchmark]
1615
public async ValueTask Hedging_Secondary()
17-
=> await _strategy!.ExecuteAsync(static _ => new ValueTask<string>(Helper.Failure)).ConfigureAwait(false);
16+
=> await _pipeline!.ExecuteAsync(static _ => new ValueTask<string>(Helper.Failure)).ConfigureAwait(false);
1817

1918
[Benchmark]
2019
public async ValueTask Hedging_Primary_AsyncWork()
21-
=> await _strategy!.ExecuteAsync(
20+
=> await _pipeline!.ExecuteAsync(
2221
static async _ =>
2322
{
2423
await Task.Yield();
@@ -27,7 +26,7 @@ public async ValueTask Hedging_Primary_AsyncWork()
2726

2827
[Benchmark]
2928
public async ValueTask Hedging_Secondary_AsyncWork()
30-
=> await _strategy!.ExecuteAsync(
29+
=> await _pipeline!.ExecuteAsync(
3130
static async _ =>
3231
{
3332
await Task.Yield();

bench/Polly.Core.Benchmarks/MultipleStrategiesBenchmark.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ namespace Polly.Core.Benchmarks;
55
public class MultipleStrategiesBenchmark
66
{
77
private MeterListener? _meterListener;
8-
private object? _strategyV7;
9-
private object? _strategyV8;
10-
private object? _strategyTelemetryV8;
11-
private ResilienceStrategy? _nonGeneric;
12-
private ResilienceStrategy? _nonGenericTelemetry;
8+
private object? _pipelineV7;
9+
private object? _pipelineV8;
10+
private object? _pipelineTelemetryV8;
11+
private ResiliencePipeline? _nonGeneric;
12+
private ResiliencePipeline? _nonGenericTelemetry;
1313

1414
[GlobalSetup]
1515
public void Setup()
1616
{
1717
_meterListener = MeteringUtil.ListenPollyMetrics();
18-
_strategyV7 = Helper.CreateStrategyPipeline(PollyVersion.V7, false);
19-
_strategyV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, false);
20-
_strategyTelemetryV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, true);
18+
_pipelineV7 = Helper.CreateStrategyPipeline(PollyVersion.V7, false);
19+
_pipelineV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, false);
20+
_pipelineTelemetryV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, true);
2121
_nonGeneric = Helper.CreateNonGenericStrategyPipeline(telemetry: false);
2222
_nonGenericTelemetry = Helper.CreateNonGenericStrategyPipeline(telemetry: true);
2323
}
@@ -26,13 +26,13 @@ public void Setup()
2626
public void Cleanup() => _meterListener?.Dispose();
2727

2828
[Benchmark(Baseline = true)]
29-
public ValueTask ExecuteStrategyPipeline_Generic_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
29+
public ValueTask ExecuteStrategyPipeline_Generic_V7() => _pipelineV7!.ExecuteAsync(PollyVersion.V7);
3030

3131
[Benchmark]
32-
public ValueTask ExecuteStrategyPipeline_Generic_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
32+
public ValueTask ExecuteStrategyPipeline_Generic_V8() => _pipelineV8!.ExecuteAsync(PollyVersion.V8);
3333

3434
[Benchmark]
35-
public ValueTask ExecuteStrategyPipeline_GenericTelemetry_V8() => _strategyTelemetryV8!.ExecuteAsync(PollyVersion.V8);
35+
public ValueTask ExecuteStrategyPipeline_GenericTelemetry_V8() => _pipelineTelemetryV8!.ExecuteAsync(PollyVersion.V8);
3636

3737
[Benchmark]
3838
public async ValueTask ExecuteStrategyPipeline_NonGeneric_V8()

bench/Polly.Core.Benchmarks/PipelineBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ namespace Polly.Core.Benchmarks;
22

33
public class PipelineBenchmark
44
{
5-
private object? _strategyV7;
6-
private object? _strategyV8;
5+
private object? _pipelineV7;
6+
private object? _pipelineV8;
77

88
[GlobalSetup]
99
public void Setup()
1010
{
11-
_strategyV7 = Helper.CreatePipeline(PollyVersion.V7, Components);
12-
_strategyV8 = Helper.CreatePipeline(PollyVersion.V8, Components);
11+
_pipelineV7 = Helper.CreatePipeline(PollyVersion.V7, Components);
12+
_pipelineV8 = Helper.CreatePipeline(PollyVersion.V8, Components);
1313
}
1414

1515
[Params(1, 2, 5, 10)]
1616
public int Components { get; set; }
1717

1818
[Benchmark(Baseline = true)]
19-
public ValueTask ExecutePipeline_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
19+
public ValueTask ExecutePipeline_V7() => _pipelineV7!.ExecuteAsync(PollyVersion.V7);
2020

2121
[Benchmark]
22-
public ValueTask ExecutePipeline_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
22+
public ValueTask ExecutePipeline_V8() => _pipelineV8!.ExecuteAsync(PollyVersion.V8);
2323
}

bench/Polly.Core.Benchmarks/RateLimiterBenchmark.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ namespace Polly.Core.Benchmarks;
22

33
public class RateLimiterBenchmark
44
{
5-
private object? _strategyV7;
6-
private object? _strategyV8;
5+
private object? _rateLimiterV7;
6+
private object? _rateLimiterV8;
77

88
[GlobalSetup]
99
public void Setup()
1010
{
11-
_strategyV7 = Helper.CreateRateLimiter(PollyVersion.V7);
12-
_strategyV8 = Helper.CreateRateLimiter(PollyVersion.V8);
11+
_rateLimiterV7 = Helper.CreateRateLimiter(PollyVersion.V7);
12+
_rateLimiterV8 = Helper.CreateRateLimiter(PollyVersion.V8);
1313
}
1414

1515
[Benchmark(Baseline = true)]
16-
public ValueTask ExecuteRateLimiter_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
16+
public ValueTask ExecuteRateLimiter_V7() => _rateLimiterV7!.ExecuteAsync(PollyVersion.V7);
1717

1818
[Benchmark]
19-
public ValueTask ExecuteRateLimiter_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
19+
public ValueTask ExecuteRateLimiter_V8() => _rateLimiterV8!.ExecuteAsync(PollyVersion.V8);
2020
}

bench/Polly.Core.Benchmarks/ResilienceStrategyBenchmark.cs renamed to bench/Polly.Core.Benchmarks/ResiliencePipelineBenchmark.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,54 @@ namespace Polly.Core.Benchmarks;
44

55
#pragma warning disable CA1822 // Mark members as static
66

7-
public class ResilienceStrategyBenchmark
7+
public class ResiliencePipelineBenchmark
88
{
99
[Benchmark(Baseline = true)]
1010
public async ValueTask ExecuteOutcomeAsync()
1111
{
1212
var context = ResilienceContextPool.Shared.Get();
13-
await NullResilienceStrategy.Instance.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
13+
await NullResiliencePipeline.Instance.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
1414
ResilienceContextPool.Shared.Return(context);
1515
}
1616

1717
[Benchmark]
1818
public async ValueTask ExecuteAsync_ResilienceContextAndState()
1919
{
2020
var context = ResilienceContextPool.Shared.Get();
21-
await NullResilienceStrategy.Instance.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
21+
await NullResiliencePipeline.Instance.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
2222
ResilienceContextPool.Shared.Return(context);
2323
}
2424

2525
[Benchmark]
2626
public async ValueTask ExecuteAsync_CancellationToken()
2727
{
28-
await NullResilienceStrategy.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
28+
await NullResiliencePipeline.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
2929
}
3030

3131
[Benchmark]
3232
public async ValueTask ExecuteAsync_GenericStrategy_CancellationToken()
3333
{
34-
await NullResilienceStrategy<string>.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
34+
await NullResiliencePipeline<string>.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
3535
}
3636

3737
[Benchmark]
3838
public void Execute_ResilienceContextAndState()
3939
{
4040
var context = ResilienceContextPool.Shared.Get();
41-
NullResilienceStrategy.Instance.Execute((_, _) => "dummy", context, "state");
41+
NullResiliencePipeline.Instance.Execute((_, _) => "dummy", context, "state");
4242
ResilienceContextPool.Shared.Return(context);
4343
}
4444

4545
[Benchmark]
4646
public void Execute_CancellationToken()
4747
{
48-
NullResilienceStrategy.Instance.Execute(_ => "dummy", CancellationToken.None);
48+
NullResiliencePipeline.Instance.Execute(_ => "dummy", CancellationToken.None);
4949
}
5050

5151
[Benchmark]
5252
public void Execute_GenericStrategy_CancellationToken()
5353
{
54-
NullResilienceStrategy<string>.Instance.Execute(_ => "dummy", CancellationToken.None);
54+
NullResiliencePipeline<string>.Instance.Execute(_ => "dummy", CancellationToken.None);
5555
}
5656

5757
public class NonGenericStrategy
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace Polly.Core.Benchmarks;
4+
5+
public class ResiliencePipelineProviderBenchmark
6+
{
7+
private ResiliencePipelineProvider<string>? _provider;
8+
9+
[GlobalSetup]
10+
public void Setup()
11+
{
12+
_provider = new ServiceCollection()
13+
.AddResiliencePipeline("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
14+
.AddResiliencePipeline<string, string>("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
15+
.BuildServiceProvider()
16+
.GetRequiredService<ResiliencePipelineProvider<string>>();
17+
}
18+
19+
[Benchmark]
20+
public void GetPipeline_Ok() => _provider!.GetPipeline("dummy");
21+
22+
[Benchmark]
23+
public void GetPipeline_Generic_Ok() => _provider!.GetPipeline<string>("dummy");
24+
}

0 commit comments

Comments
 (0)