-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathActionTransientOperation.cs
More file actions
41 lines (36 loc) · 1.43 KB
/
Copy pathActionTransientOperation.cs
File metadata and controls
41 lines (36 loc) · 1.43 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
using System;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Threading;
namespace Cuemon.Resilience.Assets
{
public static class ActionTransientOperation
{
public static void MethodThatReturnsOkString(Guid id, ConcurrentDictionary<Guid, int> retryTracker)
{
retryTracker[id] += 1;
}
public static void FailUntilExpectedRetryAttemptsIsReached(Guid id, int expectedRetryAttempts, ConcurrentDictionary<Guid, int> retryTracker)
{
retryTracker[id] += 1;
if (retryTracker[id] < expectedRetryAttempts) { throw new HttpRequestException(); }
}
public static void TriggerTransientFaultException(Guid id, ConcurrentDictionary<Guid, int> retryTracker)
{
retryTracker[id] += 1;
throw new HttpRequestException();
}
public static void TriggerLatencyException(Guid id, ConcurrentDictionary<Guid, int> retryTracker)
{
Thread.Sleep(750);
retryTracker[id] += 1;
throw new HttpRequestException();
}
public static void FailWithNonTransientFaultException(Guid id, int expectedRetryAttempts, ConcurrentDictionary<Guid, int> retryTracker)
{
retryTracker[id] += 1;
if (retryTracker[id] < expectedRetryAttempts) { throw new HttpRequestException(); }
throw new InvalidOperationException();
}
}
}