< Summary

Class:Microsoft.Azure.Batch.Common.LinearRetry
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Common\LinearRetry.cs
Covered lines:15
Uncovered lines:1
Coverable lines:16
Total lines:68
Line coverage:93.7% (15 of 16)
Covered branches:11
Total branches:14
Branch coverage:78.5% (11 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_DeltaBackoff()-100%100%
get_MaximumRetries()-100%100%
.ctor(...)-100%100%
ShouldRetryAsync(...)-88.89%78.57%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Common\LinearRetry.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
 4namespace Microsoft.Azure.Batch.Common
 5{
 6    using System;
 7    using System.Threading.Tasks;
 8
 9    /// <summary>
 10    /// Represents a retry policy that performs a specified number of retries, using a specified fixed time interval bet
 11    /// </summary>
 12    public class LinearRetry : IRetryPolicy
 13    {
 14        /// <summary>
 15        /// Gets the backoff interval between retries.
 16        /// </summary>
 3617        public TimeSpan DeltaBackoff { get; private set; }
 18
 19        /// <summary>
 20        /// Gets the maximum number of retry attempts.
 21        /// </summary>
 4222        public int MaximumRetries { get; private set; }
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="LinearRetry"/> class using the specified delta and maximum numb
 26        /// </summary>
 27        /// <param name="deltaBackoff">The backoff interval between retries.</param>
 28        /// <param name="maxRetries">The maximum number of retry attempts.</param>
 1329        public LinearRetry(TimeSpan deltaBackoff, int maxRetries)
 30        {
 1331            RetryPolicyCommon.ValidateArguments(deltaBackoff, maxRetries);
 32
 1133            this.DeltaBackoff = deltaBackoff;
 1134            this.MaximumRetries = maxRetries;
 1135        }
 36
 37        /// <summary>
 38        /// Determines if the operation should be retried and how long to wait until the next retry.
 39        /// </summary>
 40        /// <param name="exception">An <see cref="Exception"/> object that represents the last exception encountered.</p
 41        /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.<
 42        /// <returns>A <see cref="RetryDecision"/> object which specifies if a retry should be performed.</returns>
 43        public Task<RetryDecision> ShouldRetryAsync(Exception exception, OperationContext operationContext)
 44        {
 3045            if (operationContext == null)
 46            {
 047                throw new ArgumentNullException("operationContext");
 48            }
 49
 3050            bool shouldRetry = RetryPolicyCommon.ShouldRetry(exception, operationContext, this.MaximumRetries);
 51
 52            RetryDecision decision;
 3053            if (shouldRetry)
 54            {
 2455                TimeSpan? retryAfter = (exception as BatchException)?.RequestInformation?.RetryAfter;
 2456                var delay = retryAfter.HasValue && this.DeltaBackoff > retryAfter ? retryAfter.Value : this.DeltaBackoff
 57
 2458                decision = RetryDecision.RetryWithDelay(delay);
 59            }
 60            else
 61            {
 662                decision = RetryDecision.NoRetry;
 63            }
 64
 3065            return Task.FromResult(decision);
 66        }
 67    }
 68}