-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAsyncActionTransientOperation.cs
More file actions
44 lines (39 loc) · 1.67 KB
/
Copy pathAsyncActionTransientOperation.cs
File metadata and controls
44 lines (39 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Cuemon.Resilience.Assets
{
public static class AsyncActionTransientOperation
{
public static Task MethodThatReturnsOkStringAsync(Guid id, ConcurrentDictionary<Guid, int> retryTracker, CancellationToken ct)
{
retryTracker[id] += 1;
return Task.CompletedTask;
}
public static Task FailUntilExpectedRetryAttemptsIsReachedAsync(Guid id, int expectedRetryAttempts, ConcurrentDictionary<Guid, int> retryTracker, CancellationToken ct)
{
retryTracker[id] += 1;
if (retryTracker[id] < expectedRetryAttempts) { throw new HttpRequestException(); }
return Task.CompletedTask;
}
public static Task TriggerTransientFaultExceptionAsync(Guid id, ConcurrentDictionary<Guid, int> retryTracker, CancellationToken ct)
{
retryTracker[id] += 1;
throw new HttpRequestException();
}
public static Task TriggerLatencyExceptionAsync(Guid id, ConcurrentDictionary<Guid, int> retryTracker, CancellationToken ct)
{
Thread.Sleep(750);
retryTracker[id] += 1;
throw new HttpRequestException();
}
public static Task FailWithNonTransientFaultExceptionAsync(Guid id, int expectedRetryAttempts, ConcurrentDictionary<Guid, int> retryTracker, CancellationToken ct)
{
retryTracker[id] += 1;
if (retryTracker[id] < expectedRetryAttempts) { throw new HttpRequestException(); }
throw new InvalidOperationException();
}
}
}