Skip to content

Commit 1db4ada

Browse files
committed
tests
1 parent 8013708 commit 1db4ada

17 files changed

+555
-23
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<RepositoryUrl>https://github.com/managedcode/Orleans.RateLimiting</RepositoryUrl>
1818
<PackageProjectUrl>https://github.com/managedcode/Orleans.RateLimiting</PackageProjectUrl>
1919
<Product>Managed Code - Orleans RateLimiting</Product>
20-
<Version>0.0.2</Version>
21-
<PackageVersion>0.0.2</PackageVersion>
20+
<Version>0.0.3</Version>
21+
<PackageVersion>0.0.3</PackageVersion>
2222

2323
</PropertyGroup>
2424
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">

ManagedCode.Orleans.RateLimiting.Core/Attributes/FixedWindowRateLimiterAttribute.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class FixedWindowRateLimiterAttribute : Attribute, ILimiterAttribute<Fixe
1515
/// </summary>
1616
/// <param name="keyType">What key to use to identify RateLimiting, can be overridden by setting key property</param>
1717
/// <param name="key">Custom string as key for RateLimiting</param>
18-
/// <param name="window">
19-
/// Specifies the time window that takes in the requests.
18+
/// <param name="windowInSeconds">
19+
/// Specifies the time window that takes in the requests in seconds.
2020
/// Must be set to a value greater than <see cref="TimeSpan.Zero" /> by the time these options are passed to the constructor of <see cref="FixedWindowRateLimiter"/>.
2121
/// </param>
2222
/// <param name="permitLimit">
@@ -33,7 +33,7 @@ public class FixedWindowRateLimiterAttribute : Attribute, ILimiterAttribute<Fixe
3333
/// </param>
3434
/// <param name="queueProcessingOrder">Determines the behaviour of <see cref="RateLimiter.AcquireAsync"/> when not enough resources can be leased.</param>
3535
public FixedWindowRateLimiterAttribute(KeyType keyType = KeyType.GrainId, string key = default,
36-
TimeSpan window = default,
36+
int windowInSeconds = default,
3737
int permitLimit = default,
3838
int queueLimit = 0,
3939
bool autoReplenishment = true,
@@ -49,7 +49,7 @@ public FixedWindowRateLimiterAttribute(KeyType keyType = KeyType.GrainId, string
4949
}
5050

5151
int? permitLimitNullable = permitLimit > 0 ? permitLimit : null;
52-
TimeSpan? windowNullable = window > TimeSpan.Zero ? window : null;
52+
TimeSpan? windowNullable = windowInSeconds > 0 ? TimeSpan.FromSeconds(windowInSeconds) : null;
5353

5454
if (permitLimitNullable.HasValue || windowNullable.HasValue)
5555
{

ManagedCode.Orleans.RateLimiting.Core/Attributes/SlidingWindowRateLimiterAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class SlidingWindowRateLimiterAttribute : Attribute, ILimiterAttribute<Sl
1515
/// </summary>
1616
/// <param name="keyType">What key to use to identify RateLimiting, can be overridden by setting key property</param>
1717
/// <param name="key">Custom string as key for RateLimiting</param>
18-
/// <param name="window">
19-
/// Specifies the time window that takes in the requests.
18+
/// <param name="windowinSeconds">
19+
/// Specifies the time window that takes in the requests in seconds.
2020
/// Must be set to a value greater than <see cref="TimeSpan.Zero" /> by the time these options are passed to the constructor of <see cref="SlidingWindowRateLimiter"/>.
2121
/// </param>
2222
/// <param name="permitLimit">
@@ -37,7 +37,7 @@ public class SlidingWindowRateLimiterAttribute : Attribute, ILimiterAttribute<Sl
3737
/// </param>
3838
/// <param name="queueProcessingOrder">Determines the behaviour of <see cref="RateLimiter.AcquireAsync"/> when not enough resources can be leased.</param>
3939
public SlidingWindowRateLimiterAttribute(KeyType keyType = KeyType.GrainId, string key = default,
40-
TimeSpan window = default,
40+
int windowinSeconds = default,
4141
int permitLimit = default,
4242
int queueLimit = 0,
4343
int segmentsPerWindow = default,
@@ -54,8 +54,8 @@ public SlidingWindowRateLimiterAttribute(KeyType keyType = KeyType.GrainId, stri
5454
}
5555

5656
int? permitLimitNullable = permitLimit > 0 ? permitLimit : null;
57-
int? segmentsPerWindowNullable = segmentsPerWindow >= 0 ? segmentsPerWindow : null;
58-
TimeSpan? windowNullable = window > TimeSpan.Zero ? window : null;
57+
int? segmentsPerWindowNullable = segmentsPerWindow > 0 ? segmentsPerWindow : null;
58+
TimeSpan? windowNullable = windowinSeconds > 0 ? TimeSpan.FromSeconds(windowinSeconds) : null;
5959

6060

6161
if (permitLimitNullable.HasValue || windowNullable.HasValue || segmentsPerWindowNullable.HasValue)

ManagedCode.Orleans.RateLimiting.Core/Attributes/TokenBucketRateLimiterAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class TokenBucketRateLimiterAttribute : Attribute, ILimiterAttribute<Toke
1515
/// </summary>
1616
/// <param name="keyType">What key to use to identify RateLimiting, can be overridden by setting key property</param>
1717
/// <param name="key">Custom string as key for RateLimiting</param>
18-
/// <param name="replenishmentPeriod">
19-
/// Specifies the minimum period between replenishments.
18+
/// <param name="replenishmentPeriodInSeconds">
19+
/// Specifies the minimum period between replenishments in seconds.
2020
/// Must be set to a value greater than <see cref="TimeSpan.Zero" /> by the time these options are passed to the constructor of <see cref="TokenBucketRateLimiter"/>.
2121
/// </param>
2222
/// <param name="tokensPerPeriod">
@@ -37,7 +37,7 @@ public class TokenBucketRateLimiterAttribute : Attribute, ILimiterAttribute<Toke
3737
/// </param>
3838
/// <param name="queueProcessingOrder">Determines the behaviour of <see cref="RateLimiter.AcquireAsync"/> when not enough resources can be leased.</param>
3939
public TokenBucketRateLimiterAttribute(KeyType keyType = KeyType.GrainId, string key = default,
40-
TimeSpan replenishmentPeriod = default,
40+
int replenishmentPeriodInSeconds = default,
4141
int tokensPerPeriod = default,
4242
int queueLimit = 0,
4343
int tokenLimit = default,
@@ -54,8 +54,8 @@ public TokenBucketRateLimiterAttribute(KeyType keyType = KeyType.GrainId, string
5454
}
5555

5656
int? tokensPerPeriodNullable = tokensPerPeriod > 0 ? tokensPerPeriod : null;
57-
int? tokenLimitNullable = tokenLimit >= 0 ? tokenLimit : null;
58-
TimeSpan? replenishmentPeriodNullable = replenishmentPeriod > TimeSpan.Zero ? replenishmentPeriod : null;
57+
int? tokenLimitNullable = tokenLimit > 0 ? tokenLimit : null;
58+
TimeSpan? replenishmentPeriodNullable = replenishmentPeriodInSeconds > 0 ? TimeSpan.FromSeconds(replenishmentPeriodInSeconds) : null;
5959

6060
if (tokensPerPeriodNullable.HasValue || tokenLimitNullable.HasValue || replenishmentPeriodNullable.HasValue)
6161
{

ManagedCode.Orleans.RateLimiting.Tests/Cluster/Grains/Interfaces/IConcurrencyLimiterGrain.cs renamed to ManagedCode.Orleans.RateLimiting.Tests/Cluster/Grains/Interfaces/ITestConcurrencyLimiterGrain.cs

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains.Interfaces;
2+
3+
public interface ITestFixedWindowRateLimiterGrain : IGrainWithStringKey
4+
{
5+
Task<string> Do();
6+
Task<string> Go();
7+
Task<string> Take();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains.Interfaces;
2+
3+
public interface ITestSlidingWindowRateLimiterGrain : IGrainWithStringKey
4+
{
5+
Task<string> Do();
6+
Task<string> Go();
7+
Task<string> Take();
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains.Interfaces;
2+
3+
public interface ITestTokenBucketRateLimiterGrain : IGrainWithStringKey
4+
{
5+
Task<string> Do();
6+
Task<string> Go();
7+
Task<string> Take();
8+
}

ManagedCode.Orleans.RateLimiting.Tests/Cluster/Grains/ConcurrencyLimiterGrain.cs renamed to ManagedCode.Orleans.RateLimiting.Tests/Cluster/Grains/TestConcurrencyLimiterGrain.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ namespace ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains
66
{
77
public class TestConcurrencyLimiterGrain : Grain, ITestConcurrencyLimiterGrain
88
{
9-
[ConcurrencyLimiter] //GrainId, default options PermitLimit = 10; QueueLimit = 15;
9+
[ConcurrencyLimiter] //GrainId as key, default options
1010
public async Task<string> Do()
1111
{
1212
await Task.Delay(TimeSpan.FromSeconds(5));
1313
return "Do";
1414
}
1515

16-
[ConcurrencyLimiter(KeyType.Key, "go")] //Key, default options PermitLimit = 10; QueueLimit = 15;
16+
[ConcurrencyLimiter(KeyType.Key, "go")] //String as Key, default options
1717
public async Task<string> Go()
1818
{
1919
await Task.Delay(TimeSpan.FromSeconds(5));
2020
return "Go";
2121
}
2222

23-
[ConcurrencyLimiter(KeyType.GrainType, permitLimit:2, queueLimit:1)]
23+
[ConcurrencyLimiter(KeyType.GrainType, permitLimit:2, queueLimit:1)] //GrainType as Key, custom options, some of them are default (check Attribute)
2424
public async Task<string> Take()
2525
{
2626
await Task.Delay(TimeSpan.FromSeconds(5));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using ManagedCode.Orleans.RateLimiting.Core.Attributes;
2+
using ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains.Interfaces;
3+
4+
namespace ManagedCode.Orleans.RateLimiting.Tests.Cluster.Grains;
5+
6+
public class TestFixedWindowRateLimiterGrain : Grain, ITestFixedWindowRateLimiterGrain
7+
{
8+
[FixedWindowRateLimiter] //GrainId as key, default options
9+
public async Task<string> Do()
10+
{
11+
await Task.Delay(TimeSpan.FromSeconds(5));
12+
return "Do";
13+
}
14+
15+
[FixedWindowRateLimiter(KeyType.Key, "go")] //String as Key, default options
16+
public async Task<string> Go()
17+
{
18+
await Task.Delay(TimeSpan.FromSeconds(5));
19+
return "Go";
20+
}
21+
22+
[FixedWindowRateLimiter(KeyType.GrainType, permitLimit:2, queueLimit:1)] //GrainType as Key, custom options, some of them are default (check Attribute)
23+
public async Task<string> Take()
24+
{
25+
await Task.Delay(TimeSpan.FromSeconds(5));
26+
return "Take";
27+
}
28+
}

0 commit comments

Comments
 (0)