-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMockRetryPolicy.cs
More file actions
49 lines (42 loc) · 1.54 KB
/
MockRetryPolicy.cs
File metadata and controls
49 lines (42 loc) · 1.54 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
45
46
47
48
using System;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Runtime.Contexts;
using Contentstack.Management.Core.Runtime.Pipeline.RetryHandler;
namespace Contentstack.Management.Core.Unit.Tests.Mokes
{
/// <summary>
/// Mock retry policy for testing RetryHandler in isolation.
/// </summary>
public class MockRetryPolicy : RetryPolicy
{
public bool ShouldRetryValue { get; set; } = true;
public bool CanRetryValue { get; set; } = true;
public bool RetryLimitExceededValue { get; set; } = false;
public TimeSpan WaitDelay { get; set; } = TimeSpan.FromMilliseconds(100);
public Exception LastException { get; private set; }
public int RetryCallCount { get; private set; }
public MockRetryPolicy()
{
RetryOnError = true;
RetryLimit = 5;
}
public override bool RetryForException(IExecutionContext executionContext, Exception exception)
{
LastException = exception;
RetryCallCount++;
return ShouldRetryValue;
}
public override bool CanRetry(IExecutionContext executionContext)
{
return CanRetryValue;
}
public override bool RetryLimitExceeded(IExecutionContext executionContext)
{
return RetryLimitExceededValue;
}
internal override void WaitBeforeRetry(IExecutionContext executionContext)
{
System.Threading.Tasks.Task.Delay(WaitDelay).Wait();
}
}
}