Skip to content

Commit

Permalink
Second pass of policy configuration changes (#5759)
Browse files Browse the repository at this point in the history
Fixes: #5632

1. Make all policy classes public
2. Normalizes namespaces to `Azure.Base.Pipeline` and `Azure.Base.Pipeline.Policies`
3. Replaces policy ctor arguments with properties
  • Loading branch information
pakrym authored Apr 11, 2019
1 parent 27dc1a5 commit d137f36
Show file tree
Hide file tree
Showing 53 changed files with 249 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Testing;
using System.Collections.Generic;
using System.IO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Base;
using NUnit.Framework;
using System;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline.Policies;
using NUnit.Framework;
using System;
using System.Threading.Tasks;
Expand All @@ -18,14 +17,15 @@ public async Task ConfiguringRetries()
{
// specify retry policy options
var options = new ConfigurationClientOptions();
options.RetryPolicy = RetryPolicy.CreateFixed(
maxRetries: 10,
delay: TimeSpan.FromSeconds(1),
retriableCodes: new int[] {
500, // Internal Server Error
options.RetryPolicy = new FixedRetryPolicy()
{
MaxRetries = 10,
Delay = TimeSpan.FromSeconds(1),
RetriableCodes = new [] {
500, // Internal Server Error
504 // Gateway Timeout
}
);
};

var connectionString = Environment.GetEnvironmentVariable("AZ_CONFIG_CONNECTION");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License. See License.txt in the project root for
// license information.

using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;
using NUnit.Framework;
using System;
using System.Net.Http;
Expand All @@ -29,14 +29,15 @@ public async Task ConfiguringPipeline()
options.LoggingPolicy = null;

// specify custom retry policy options
options.RetryPolicy = RetryPolicy.CreateFixed(
maxRetries: 10,
delay: TimeSpan.FromSeconds(1),
retriableCodes: new int[] {
options.RetryPolicy = new FixedRetryPolicy()
{
MaxRetries = 10,
Delay = TimeSpan.FromSeconds(1),
RetriableCodes = new [] {
500, // Internal Server Error
504 // Gateway Timeout
}
);
};

// add a policy (custom behavior) that executes once per client call
options.PerCallPolicies.Add(new AddHeaderPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;

namespace Azure.ApplicationModel.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
// license information.

using System;
using System.Collections;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Diagnostics;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;

namespace Azure.ApplicationModel.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
// Licensed under the MIT License.

using System;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;

namespace Azure.ApplicationModel.Configuration
{
public class ConfigurationClientOptions: HttpClientOptions
{
static readonly HttpPipelinePolicy s_defaultRetryPolicy = Base.Http.Pipeline.RetryPolicy.CreateFixed(3, TimeSpan.Zero,
//429, // Too Many Requests TODO (pri 2): this needs to throttle based on x-ms-retry-after
500, // Internal Server Error
503, // Service Unavailable
504 // Gateway Timeout
);
public FixedRetryPolicy RetryPolicy { get; set; }

public HttpPipelinePolicy RetryPolicy { get; set; }
public HttpPipelinePolicy LoggingPolicy { get; set; }

public ConfigurationClientOptions()
{
LoggingPolicy = Base.Http.Pipeline.LoggingPolicy.Shared;
RetryPolicy = s_defaultRetryPolicy;
LoggingPolicy = Base.Pipeline.Policies.LoggingPolicy.Shared;
RetryPolicy = new FixedRetryPolicy()
{
Delay = TimeSpan.Zero,
RetriableCodes = new[]
{
//429, // Too Many Requests TODO (pri 2): this needs to throttle based on x-ms-retry-after
500, // Internal Server Error
503, // Service Unavailable
504 // Gateway Timeout
},
MaxRetries = 3
};
}

public HttpPipelinePolicy LoggingPolicy { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Http;
using Azure.Base.Pipeline;

namespace Azure.ApplicationModel.Configuration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

using System.Threading.Tasks;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using NUnit.Framework;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

using System;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Diagnostics;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using NUnit.Framework;

Expand Down Expand Up @@ -109,4 +108,4 @@ public async Task SendingRequestProducesEvents()
CollectionAssert.AreEqual(new byte[] { 6, 7, 8, 9, 0 }, e.GetProperty<byte[]>("content"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using Azure.Base.Tests.Testing;
using NUnit.Framework;
Expand Down Expand Up @@ -92,14 +93,18 @@ private class ExponentialRetryPolicyMock: ExponentialRetryPolicy
public AsyncGate<TimeSpan, object> DelayGate { get; } = new AsyncGate<TimeSpan, object>();

public ExponentialRetryPolicyMock(int[] retriableCodes, Func<Exception, bool> shouldRetryException = null, int maxRetries = 3, TimeSpan delay = default, TimeSpan maxDelay = default)
: base(retriableCodes, shouldRetryException, maxRetries, delay, maxDelay)
{
RetriableCodes = retriableCodes;
ShouldRetryException = shouldRetryException;
MaxRetries = maxRetries;
Delay = delay;
MaxDelay = maxDelay;
}

internal override Task Delay(TimeSpan time, CancellationToken cancellationToken)
internal override Task DelayAsync(TimeSpan time, CancellationToken cancellationToken)
{
return DelayGate.WaitForRelease(time);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using Azure.Base.Tests.Testing;
using NUnit.Framework;
Expand Down Expand Up @@ -62,11 +63,15 @@ private class FixedRetryPolicyMock: FixedRetryPolicy
{
public AsyncGate<TimeSpan, object> DelayGate { get; } = new AsyncGate<TimeSpan, object>();

public FixedRetryPolicyMock(int[] retriableCodes, Func<Exception, bool> shouldRetryException = null, int maxRetries = 3, TimeSpan delay = default) : base(retriableCodes, shouldRetryException, maxRetries, delay)
public FixedRetryPolicyMock(int[] retriableCodes, Func<Exception, bool> shouldRetryException = null, int maxRetries = 3, TimeSpan delay = default)
{
Delay = delay;
MaxRetries = maxRetries;
RetriableCodes = retriableCodes;
ShouldRetryException = shouldRetryException;
}

internal override Task Delay(TimeSpan time, CancellationToken cancellationToken)
internal override Task DelayAsync(TimeSpan time, CancellationToken cancellationToken)
{
return DelayGate.WaitForRelease(time);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using Azure.Base.Http;
using Azure.Base.Pipeline;
using NUnit.Framework;

namespace Azure.Base.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using NUnit.Framework;

namespace Azure.Base.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;

namespace Azure.Base.Tests
{
Expand All @@ -22,4 +21,4 @@ protected static async Task<HttpPipelineResponse> ExecuteRequest(HttpPipelineReq
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Pipeline.Policies;
using Azure.Base.Testing;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -56,15 +56,15 @@ public async Task ComponentNameAndVersionReadFromAssembly()

class CustomRetryPolicy : RetryPolicy
{
protected override bool ShouldRetryResponse(HttpPipelineMessage message, int attempted, out TimeSpan delay)
protected override bool IsRetriableResponse(HttpPipelineMessage message, int attempted, out TimeSpan delay)
{
delay = TimeSpan.Zero;
if (attempted > 5) return false;
if (message.Response.Status == 1) return false;
return true;
}

protected override bool ShouldRetryException(Exception exception, int attempted, out TimeSpan delay)
protected override bool IsRetriableException(Exception exception, int attempted, out TimeSpan delay)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;

namespace Azure.Base.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Linq;
using System.Threading.Tasks;
using Azure.Base.Diagnostics;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using Azure.Base.Testing;
using Azure.Base.Tests.Testing;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using System.Threading.Tasks;

namespace Azure.Base.Tests.Testing
Expand Down Expand Up @@ -73,4 +72,4 @@ public Task<TOut> WaitForRelease(TIn value = default)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Collections.Generic;
using Azure.Base.Http;
using Azure.Base.Pipeline;

namespace Azure.Base.Testing
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using Azure.Base.Http;
using Azure.Base.Pipeline;

namespace Azure.Base.Testing
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Base.Http;
using Azure.Base.Http.Pipeline;
using Azure.Base.Pipeline;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.Base.Tests;
using Azure.Base.Tests.Testing;

namespace Azure.Base.Testing
Expand Down
Loading

0 comments on commit d137f36

Please sign in to comment.