< Summary

Class:Microsoft.Azure.Batch.RetryPolicyProvider
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\RetryPolicyProvider.cs
Covered lines:9
Uncovered lines:2
Coverable lines:11
Total lines:71
Line coverage:81.8% (9 of 11)
Covered branches:2
Total branches:2
Branch coverage:100% (2 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Policy()-100%100%
NoRetryProvider()-0%100%
LinearRetryProvider(...)-0%100%
ExponentialRetryProvider(...)-100%100%
.ctor(...)-100%100%
SetRetryPolicyInterceptor(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\RetryPolicyProvider.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for license information.
 3
 4
 5namespace Microsoft.Azure.Batch
 6{
 7    using System;
 8    using Common;
 9
 10    /// <summary>
 11    /// A RequestInterceptor that sets the RetryPolicy.
 12    /// </summary>
 13    public class RetryPolicyProvider : Protocol.RequestInterceptor
 14    {
 15        /// <summary>
 16        /// Gets or sets the retry policy to use.
 17        /// </summary>
 68918        public IRetryPolicy Policy { get; set; }
 19
 20        /// <summary>
 21        /// Creates a new <see cref="RetryPolicyProvider"/> using the <see cref="NoRetry"/> policy.
 22        /// </summary>
 23        /// <returns>A provider configured to perform no retries.</returns>
 24        public static RetryPolicyProvider NoRetryProvider()
 25        {
 026            return new RetryPolicyProvider(new NoRetry());
 27        }
 28
 29        /// <summary>
 30        /// Creates a new <see cref="RetryPolicyProvider"/> using the <see cref="LinearRetry"/> policy.
 31        /// </summary>
 32        /// <param name="deltaBackoff">The backoff interval between retries.</param>
 33        /// <param name="maxRetries">The maximum number of retry attempts.</param>
 34        /// <returns>A provider configured to perform linear retries using the specified backoff and max retries.</retur
 35        public static RetryPolicyProvider LinearRetryProvider(TimeSpan deltaBackoff, int maxRetries)
 36        {
 037            return new RetryPolicyProvider(new LinearRetry(deltaBackoff, maxRetries));
 38        }
 39
 40        /// <summary>
 41        /// Creates a new <see cref="RetryPolicyProvider"/> using the <see cref="ExponentialRetry"/> policy.
 42        /// </summary>
 43        /// <param name="deltaBackoff">The backoff interval between retries, where the resulting backoff is 2^n * deltaB
 44        /// <param name="maxRetries">The maximum number of retry attempts.</param>
 45        /// <param name="maxBackoff">The maximum amount of time to back off between attempts.</param>
 46        /// <returns>A provider configured to perform exponential retries using the specified backoff and max retries.</
 47        public static RetryPolicyProvider ExponentialRetryProvider(TimeSpan deltaBackoff, int maxRetries, TimeSpan? maxB
 48        {
 65349            return new RetryPolicyProvider(new ExponentialRetry(deltaBackoff, maxRetries, maxBackoff));
 50        }
 51
 52        /// <summary>
 53        /// Initializes a new behavior to set the retry policy.
 54        /// </summary>
 55        /// <param name="retryPolicy">The retry policy to set.</param>
 65956        public RetryPolicyProvider(IRetryPolicy retryPolicy)
 57        {
 65958            this.Policy = retryPolicy;
 59
 65960            base.ModificationInterceptHandler = SetRetryPolicyInterceptor;
 65961        }
 62
 63        private void SetRetryPolicyInterceptor(Protocol.IBatchRequest request)
 64        {
 1965            if (null != this.Policy)
 66            {
 1967                request.RetryPolicy = this.Policy;
 68            }
 1969        }
 70    }
 71}