/// <summary> /// Gets some information using the Retry resilience pattern. /// /// Upon encountering an Internal Server Error (500), the repository method will perform /// a maximum of 3 retries and will wait respectively 1, 2 and 3 seconds between the attempts. /// </summary> public string GetDataUsingRetryPatternWithSpecifiedTimeouts() { var request = new RestClientWrapper("http://localhost:60540") .SetResource(_endpointWithTransientFaultsRoute) .SetMethod(Method.GET); string response = ExecuteWithRetryAndTimeoutPolicy <string>(() => request.Execute()); return(response); }
public void Api_RestClientWrapper_Execute_TriesToExecute(RestResponse response, bool expectedFromOneAttempt) { var clientMock = new Mock <RestClient>(); clientMock.Setup(x => x.Execute(It.IsAny <IRestRequest>())).Returns(response); var restClientWrapper = new RestClientWrapper(new RestClientWrapperCredentials()); restClientWrapper.Execute(clientMock.Object, It.IsAny <IRestRequest>()); var times = expectedFromOneAttempt ? Times.Once() : Times.AtLeastOnce(); clientMock.Verify(mock => mock.Execute(It.IsAny <IRestRequest>()), times); }
/// <summary> /// Gets some information using both the Circuit Breaker and Retry resilience pattern. /// </summary> public string GetDataUsingRetryAndCircuitBreakerPattern() { var request = new RestClientWrapper("http://localhost:60540") .SetResource(_endpointWithTransientFaultsRoute) .SetMethod(Method.GET); try { var response = ExecuteWithResiliencePolicy <string>(() => request.Execute()); return(response); } catch (BrokenCircuitException ex) { _logger.Information("OUT OF ORDER: Circuit breaker is currently tripped. Sorry."); return("Service unavailable"); } }