Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
271cfd7
Add core RateLimiter implementations
reisenberger Mar 23, 2019
7d70287
Add example async TResult rate-limiter policy implementation
reisenberger Mar 23, 2019
6aa1e2a
Add example syntax
reisenberger Mar 23, 2019
8354e6d
Make the retryAfterFactory take Timespan as an input parameter!
reisenberger Mar 24, 2019
cba0b51
Initial LockFreeTokenBucketRateLimiterTests
reisenberger Jul 4, 2019
193b356
Tidy BulkheadSpecsHelper
reisenberger Jul 4, 2019
5496e66
Factor out test helpers
reisenberger Jul 4, 2019
4b17e56
Factor out common tests; add tests on lock-based rate limiter
reisenberger Jul 4, 2019
bfc3251
Allow for slow-running on CI servers
reisenberger Jul 4, 2019
8fbb193
Add tests on full bucket capacity
reisenberger Jul 4, 2019
d1c7ec8
Fix RateLimitRejectedException
reisenberger Jul 4, 2019
416c6ff
Remove unused configuration overloads
reisenberger Jul 4, 2019
fcaf1ac
Introduce a factory for obtaining the preferred rate-limiter implemen…
reisenberger Jul 4, 2019
ebd8a56
Pull some test helper methods into a common base-class
reisenberger Jul 4, 2019
c7af7e4
Add first specs on async policy syntax
reisenberger Jul 4, 2019
a2f6566
Add full set of specs on rate-limit policies thus far
reisenberger Jul 5, 2019
c92cb6b
Add tests on retryAfterFactory
reisenberger Jul 5, 2019
1532500
Add tests on context passed to retryAfterFactory
reisenberger Jul 5, 2019
56fea85
Add async non-generic syntax and specs
reisenberger Jul 5, 2019
182c635
Improve code layout
reisenberger Jul 5, 2019
2a1c508
Add sync rate-limit policies
reisenberger Jul 5, 2019
fd609ad
Add initial rate-limit doco; bump to v7.2.0
reisenberger Jul 9, 2019
0121b3d
Improve bulkhead doco in readme
reisenberger Jul 9, 2019
e061d50
Minor expressivity refinements
reisenberger Jul 15, 2019
db47862
Neaten bulkhead tests commentary
reisenberger Jul 16, 2019
daa42cb
Control visibility of IRateLimiter components
reisenberger Jul 16, 2019
c916be5
Fix non-generic rate-limit tests to be genuinely non-generic
reisenberger Jul 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unused configuration overloads
  • Loading branch information
reisenberger committed Jul 4, 2019
commit 416c6ffea8034767532dc39fcaa2c0424fdefbd4
80 changes: 6 additions & 74 deletions src/Polly/RateLimit/AsyncRateLimitTResultSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,12 @@
using System;
using System.Globalization;
using System.Net;
using System.Net.Http;
using Polly.RateLimit;

namespace Polly
{
public partial class Policy
{

/* Maybe these commented out overloads with TimeSpan permitOneExecutionPer are not as intuitive as the overloads left uncommented.

/// <summary>
/// Builds a RateLimit <see cref="AsyncPolicy{TResult}"/> that will rate-limit executions to one per the timespan given.
/// A <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.
/// </summary>
/// <param name="permitOneExecutionPer">How often one execution is permitted.</param>
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(TimeSpan permitOneExecutionPer)
{
return RateLimitAsync<TResult>(permitOneExecutionPer, null);
}

/// <summary>
/// Builds a RateLimit <see cref="AsyncPolicy{TResult}"/> that will rate-limit executions to one per the timespan given,
/// with a maximum burst size of <paramref name="maxBurst"/>.
/// A <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.
/// </summary>
/// <param name="permitOneExecutionPer">How often one execution is permitted.</param>
/// <param name="maxBurst">The maximum number of executions that will be permitted in a single burst (for example if none have been executed for a while).
/// This equates to the bucket-capacity of a token-bucket implementation.</param>
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(TimeSpan permitOneExecutionPer, int maxBurst)
{
return RateLimitAsync<TResult>(permitOneExecutionPer, maxBurst, null);
}

/// <summary>
/// Builds a RateLimit <see cref="AsyncPolicy{TResult}"/> that will rate-limit executions to one per the timespan given.
/// </summary>
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <param name="permitOneExecutionPer">How often one execution is permitted.</param>
/// <param name="retryAfterFactory">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.
/// <remarks>This parameter can be null. If null, a <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
TimeSpan permitOneExecutionPer,
Func<TimeSpan, Context, TResult> retryAfterFactory)
{
return RateLimitAsync(permitOneExecutionPer, 1, retryAfterFactory);
}

/// <summary>
/// Builds a RateLimit <see cref="AsyncPolicy{TResult}"/> that will rate-limit executions to one per the timespan given,
/// with a maximum burst size of <paramref name="maxBurst"/>
/// </summary>
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <param name="permitOneExecutionPer">How often one execution is permitted.</param>
/// <param name="maxBurst">The maximum number of executions that will be permitted in a single burst (for example if none have been executed for a while).
/// This equates to the bucket-capacity of a token-bucket implementation.</param>
/// <param name="retryAfterFactory">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.
/// <remarks>This parameter can be null. If null, a <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
TimeSpan permitOneExecutionPer,
int maxBurst,
Func<TimeSpan, Context, TResult> retryAfterFactory)
{
return RateLimitAsync(new TokenBucketRateLimiter(permitOneExecutionPer, maxBurst), retryAfterFactory);
}
*/

private static readonly Func<TimeSpan, int, IRateLimiter> DefaultRateLimiterFactory = (onePer, bucketCapacity) => new LockFreeTokenBucketRateLimiter(onePer, bucketCapacity);
// private readonly Func<TimeSpan, int, IRateLimiter> DefaultRateLimiterFactory = (onePer, bucketCapacity) => new LockBasedTokenBucketRateLimiter(onePer, bucketCapacity);
/* private readonly Func<TimeSpan, int, IRateLimiter> DefaultRateLimiterFactory = (onePer, bucketCapacity) => new LockBasedTokenBucketRateLimiter(onePer, bucketCapacity); */

/// <summary>
/// Builds a RateLimit <see cref="AsyncPolicy{TResult}"/> that will rate-limit executions to <paramref name="numberOfExecutions"/> per the timespan given.
Expand All @@ -96,8 +28,8 @@ public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <param name="numberOfExecutions">The number of executions (call it N) permitted per timespan.</param>
/// <param name="perTimeSpan">How often N executions are permitted.</param>
/// <param name="retryAfterFactory">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.
/// <remarks>This parameter can be null. If null, a <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <param name="retryAfterFactory">An (optional) factory to express the recommended retry-after time back to the caller, when an operation is rate-limited.
/// <remarks>If null, a <see cref="RateLimitRejectedException"/> with property <see cref="RateLimitRejectedException.RetryAfter"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
int numberOfExecutions,
Expand All @@ -117,7 +49,7 @@ public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
/// <param name="maxBurst">The maximum number of executions that will be permitted in a single burst (for example if none have been executed for a while).
/// This equates to the bucket-capacity of a token-bucket implementation.</param>
/// <param name="retryAfterFactory">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.
/// <remarks>This parameter can be null. If null, a <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <remarks>If null, a <see cref="RateLimitRejectedException"/> with property <see cref="RateLimitRejectedException.RetryAfter"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
int numberOfExecutions,
Expand All @@ -134,9 +66,9 @@ public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
/// <typeparam name="TResult">The type of return values this policy will handle.</typeparam>
/// <param name="rateLimiter">The rate-limiter to use to determine whether the execution is permitted.</param>
/// <param name="retryAfterFactory">An (optional) factory to use to express retry-after back to the caller, when an operation is rate-limited.
/// <remarks>This parameter can be null. If null, a <see cref="RateLimitRejectedException"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <remarks>If null, a <see cref="RateLimitRejectedException"/> with property <see cref="RateLimitRejectedException.RetryAfter"/> will be thrown to indicate rate-limiting.</remarks></param>
/// <returns>The policy instance.</returns>
public static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
private static AsyncRateLimitPolicy<TResult> RateLimitAsync<TResult>(
IRateLimiter rateLimiter,
Func<TimeSpan, Context, TResult> retryAfterFactory)
{
Expand Down