示例#1
0
        public async Task setup_scenario()
        {
            var retryManager = new StubRetryManager {
                Delay = new StubRetryDelay(10), Predicate = new StubRetryPredicate(2)
            };

            _baseHttpClient = new StubHttpClient();
            var configuration = new RetryingConfiguration {
                RetryPolicy = "default"
            };
            var httpClient = _baseHttpClient.AddRetrying(
                configuration,
                retryManager,
                new [] { _callback });

            var message = new HttpRequestMessage(HttpMethod.Get, "/get-content");

            message.Properties.Add("propertyA", "valueA");
            message.Properties.Add("propertyB", 12358);

            try
            {
                await httpClient.SendAsync(message);
            }
            catch
            {
                // Ignore the exception
            }
        }
示例#2
0
        public static DisposableHttpClient CreateClientWithRetrying(this StubHttpApi api, IHttpClientEventCallback callback, int retries, int delayMs, int timeoutMs = 3000)
        {
            var retryManager = new StubRetryManager {
                Delay = new StubRetryDelay(delayMs), Predicate = new StubRetryPredicate(retries)
            };

            var configuration = new RetryingConfiguration {
                Uri = api.BaseUri, TimeoutMs = timeoutMs, RetryPolicy = "default"
            };
            var httpClient = new DefaultHttpClient(configuration);

            return(new DisposableHttpClient(httpClient, httpClient.AddRetrying(configuration, retryManager, new [] { callback })));
        }
        public async Task setup_scenario()
        {
            _exceptionToThrow = new Exception();
            var retryManager = new StubRetryManager {
                Delay = new StubRetryDelay(10), Predicate = new StubRetryPredicate(ExpectedRetries)
            };
            var baseHttpClient = new StubHttpClient(_exceptionToThrow);
            var configuration  = new RetryingConfiguration {
                RetryPolicy = "default"
            };
            var httpClient = baseHttpClient.AddRetrying(configuration, retryManager, new[] { _callback });

            try
            {
                await httpClient.GetAsync("/ping");
            }
            catch (Exception e)
            {
                _caughtException = e;
            }
        }
示例#4
0
        public async Task setup_scenario()
        {
            var retryManager = new StubRetryManager {
                Delay = new StubRetryDelay(10), Predicate = new StubRetryPredicate(1)
            };
            var baseHttpClient = new StubHttpClient(new Exception());
            var configuration  = new RetryingConfiguration {
                RetryPolicy = "default"
            };
            var httpClient = baseHttpClient.AddRetrying(
                configuration,
                retryManager,
                new[] { _callback });

            try
            {
                await httpClient.GetAsync("/ping");
            }
            catch
            {
                // Ignore the exception
            }
        }