Skip to content

Commit

Permalink
Minor API cleanup (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk authored Apr 14, 2023
1 parent 26fd4cb commit 378500a
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Moq;
using Polly.Builder;
using Polly.Strategy;
using Polly.Telemetry;
using Polly.Utils;

Expand Down
6 changes: 3 additions & 3 deletions src/Polly.Core.Tests/ResilienceStrategyTests.Async.Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ public static IEnumerable<object[]> ExecuteAsTaskAsync_EnsureCorrectBehavior_Dat

private static IEnumerable<ExecuteParameters> ExecuteAsTaskAsync_EnsureCorrectBehavior_ExecuteParameters()
{
yield return new ExecuteParameters(r => r.ExecuteTaskAsync(async _ => { }))
yield return new ExecuteParameters(r => r.ExecuteAsync(async _ => { }))
{
Caption = "ExecuteAsTaskAsync_NoCancellation",
AssertContext = AssertResilienceContext,
};

yield return new ExecuteParameters(r => r.ExecuteTaskAsync(async t => { t.Should().Be(CancellationToken); }, CancellationToken))
yield return new ExecuteParameters(r => r.ExecuteAsync(async t => { t.Should().Be(CancellationToken); }, CancellationToken))
{
Caption = "ExecuteAsTaskAsync_Cancellation",
AssertContext = AssertResilienceContextAndToken,
};

yield return new ExecuteParameters(r => r.ExecuteTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); }, ResilienceContext.Get(), "dummy-state"))
yield return new ExecuteParameters(r => r.ExecuteAsync(async (_, s) => { s.Should().Be("dummy-state"); }, ResilienceContext.Get(), "dummy-state"))
{
Caption = "ExecuteAsTaskAsync_ResilienceContextAndState",
AssertContext = AssertResilienceContext,
Expand Down
6 changes: 3 additions & 3 deletions src/Polly.Core.Tests/ResilienceStrategyTests.Async.TaskT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ private static IEnumerable<ExecuteParameters> ExecuteAsTaskAsyncT_EnsureCorrectB
{
long result = 12345;

yield return new ExecuteParameters<long>(r => r.ExecuteTaskAsync(async t => result), result)
yield return new ExecuteParameters<long>(r => r.ExecuteAsync(async t => result), result)
{
Caption = "ExecuteAsTaskAsyncT_NoCancellation",
AssertContext = AssertResilienceContext,
};

yield return new ExecuteParameters<long>(r => r.ExecuteTaskAsync(async t => { t.Should().Be(CancellationToken); return result; }, CancellationToken), result)
yield return new ExecuteParameters<long>(r => r.ExecuteAsync(async t => { t.Should().Be(CancellationToken); return result; }, CancellationToken), result)
{
Caption = "ExecuteAsTaskAsyncT_Cancellation",
AssertContext = AssertResilienceContextAndToken,
};

yield return new ExecuteParameters<long>(r => r.ExecuteTaskAsync(async (_, s) => { s.Should().Be("dummy-state"); return result; }, ResilienceContext.Get(), "dummy-state"), result)
yield return new ExecuteParameters<long>(r => r.ExecuteAsync(async (_, s) => { s.Should().Be("dummy-state"); return result; }, ResilienceContext.Get(), "dummy-state"), result)
{
Caption = "ExecuteAsTaskAsyncT_ResilienceContextAndState",
AssertContext = AssertResilienceContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Polly.Builder;
using Polly.Strategy;

namespace Polly.Core.Tests.Builder;
namespace Polly.Core.Tests.Strategy;

public class ResilienceStrategyOptionsTests
{
Expand Down
10 changes: 5 additions & 5 deletions src/Polly.Core.Tests/Timeout/TimeoutResilienceStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task Execute_EnsureOnTimeoutCalled()
_timeProvider.SetupCancelAfterNow(_delay);

var sut = CreateSut();
await sut.Invoking(s => sut.ExecuteTaskAsync(token => Task.Delay(_delay, token))).Should().ThrowAsync<TimeoutRejectedException>();
await sut.Invoking(s => sut.ExecuteAsync(token => Task.Delay(_delay, token))).Should().ThrowAsync<TimeoutRejectedException>();

called.Should().BeTrue();
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task Execute_Timeout(bool defaultCancellationToken)
var sut = CreateSut();

await sut
.Invoking(s => s.ExecuteTaskAsync(token => Delay(token), token))
.Invoking(s => s.ExecuteAsync(token => Delay(token), token))
.Should().ThrowAsync<TimeoutRejectedException>()
.WithMessage("The operation didn't complete within the allowed timeout of '00:00:02'.");

Expand All @@ -123,7 +123,7 @@ public async Task Execute_Cancelled_EnsureNoTimeout()

var sut = CreateSut();

await sut.Invoking(s => s.ExecuteTaskAsync(token => Delay(token, () => cts.Cancel()), cts.Token))
await sut.Invoking(s => s.ExecuteAsync(token => Delay(token, () => cts.Cancel()), cts.Token))
.Should()
.ThrowAsync<OperationCanceledException>();

Expand All @@ -146,7 +146,7 @@ public async Task Execute_NoTimeoutOrCancellation_EnsureCancellationTokenRestore
var context = ResilienceContext.Get();
context.CancellationToken = cts.Token;

await sut.ExecuteTaskAsync(
await sut.ExecuteAsync(
(r, _) =>
{
r.CancellationToken.Should().NotBe(cts.Token);
Expand Down Expand Up @@ -182,7 +182,7 @@ public async Task Execute_EnsureCancellationTokenRegistrationNotExecutedOnSynchr
// Act
try
{
await sut.ExecuteTaskAsync(token => Delay(token, () => cts.Cancel()), cts.Token);
await sut.ExecuteAsync(token => Delay(token, () => cts.Cancel()), cts.Token);
}
catch (OperationCanceledException)
{
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Core/Builder/ResilienceStrategyBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Polly.Strategy;
using Polly.Telemetry;

namespace Polly.Builder;
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Core/ResilienceStrategy.Async.Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract partial class ResilienceStrategy
/// <param name="context">The context associated with the callback.</param>
/// <param name="state">The state associated with the callback.</param>
/// <returns>The instance of <see cref="Task"/> that represents the asynchronous execution.</returns>
public async Task ExecuteTaskAsync<TState>(
public async Task ExecuteAsync<TState>(
Func<ResilienceContext, TState, Task> callback,
ResilienceContext context,
TState state)
Expand All @@ -39,7 +39,7 @@ static async (context, state) =>
/// <param name="callback">The user-provided callback.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> associated with the callback.</param>
/// <returns>The instance of <see cref="Task"/> that represents an asynchronous callback.</returns>
public async Task ExecuteTaskAsync(
public async Task ExecuteAsync(
Func<CancellationToken, Task> callback,
CancellationToken cancellationToken = default)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Core/ResilienceStrategy.Async.TaskT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract partial class ResilienceStrategy
/// <param name="context">The context associated with the callback.</param>
/// <param name="state">The state associated with the callback.</param>
/// <returns>The instance of <see cref="Task"/> that represents the asynchronous execution.</returns>
public async Task<TResult> ExecuteTaskAsync<TResult, TState>(
public async Task<TResult> ExecuteAsync<TResult, TState>(
Func<ResilienceContext, TState, Task<TResult>> callback,
ResilienceContext context,
TState state)
Expand All @@ -37,7 +37,7 @@ static async (context, state) =>
/// <param name="callback">The user-provided callback.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> associated with the callback.</param>
/// <returns>The instance of <see cref="ValueTask"/> that represents the asynchronous execution.</returns>
public async Task<TResult> ExecuteTaskAsync<TResult>(
public async Task<TResult> ExecuteAsync<TResult>(
Func<CancellationToken, Task<TResult>> callback,
CancellationToken cancellationToken = default)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Retry/RetryStrategyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Polly.Builder;
using Polly.Strategy;

namespace Polly.Retry;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace Polly.Builder;
namespace Polly.Strategy;

/// <summary>
/// The options associated with the <see cref="ResilienceStrategy"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/Polly.Core/Timeout/TimeoutStrategyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using Polly.Builder;
using Polly.Strategy;

namespace Polly.Timeout;

Expand Down
2 changes: 1 addition & 1 deletion src/Polly.RateLimiting/RateLimiterStrategyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Threading.RateLimiting;
using Polly.Builder;
using Polly.Strategy;

namespace Polly.RateLimiting;

Expand Down

0 comments on commit 378500a

Please sign in to comment.