diff --git a/Apache.Phoenix/Apache.Phoenix.csproj b/Apache.Phoenix/Apache.Phoenix.csproj index 703ead1..6e16420 100644 --- a/Apache.Phoenix/Apache.Phoenix.csproj +++ b/Apache.Phoenix/Apache.Phoenix.csproj @@ -1,68 +1,80 @@ - - - - - Debug - AnyCPU - {8B32B5CC-94F1-464F-9CF9-A455361BAFA1} - Library - Properties - Apache.Phoenix - Apache.Phoenix - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll - True - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {8B32B5CC-94F1-464F-9CF9-A455361BAFA1} + Library + Properties + Apache.Phoenix + Apache.Phoenix + v4.5.2 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + false + + + ETKey.snk + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + True + + + ..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll + True + + + + + + + + + + + + + + + + + + + + + + --> \ No newline at end of file diff --git a/Apache.Phoenix/App.config b/Apache.Phoenix/App.config index 8e15646..3c88dd4 100644 --- a/Apache.Phoenix/App.config +++ b/Apache.Phoenix/App.config @@ -1,6 +1,6 @@ - - - - - - \ No newline at end of file + + + + + + diff --git a/Apache.Phoenix/packages.config b/Apache.Phoenix/packages.config index ae4b16f..ea52645 100644 --- a/Apache.Phoenix/packages.config +++ b/Apache.Phoenix/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/PhoenixSharp.Interfaces/App.config b/PhoenixSharp.Interfaces/App.config index 8e15646..3c88dd4 100644 --- a/PhoenixSharp.Interfaces/App.config +++ b/PhoenixSharp.Interfaces/App.config @@ -1,6 +1,6 @@ - - - - - - \ No newline at end of file + + + + + + diff --git a/PhoenixSharp.Interfaces/PhoenixSharp.Interfaces.csproj b/PhoenixSharp.Interfaces/PhoenixSharp.Interfaces.csproj index bb59d0a..2a2cb1b 100644 --- a/PhoenixSharp.Interfaces/PhoenixSharp.Interfaces.csproj +++ b/PhoenixSharp.Interfaces/PhoenixSharp.Interfaces.csproj @@ -1,75 +1,87 @@ - - - - - Debug - AnyCPU - {7EC374E2-048E-4AB5-8994-97C5F2DDF057} - Library - Properties - PhoenixSharp.Interfaces - PhoenixSharp.Interfaces - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll - True - - - - - - - - - - - - - - - - - - - - - - - {8b32b5cc-94f1-464f-9cf9-a455361bafa1} - Apache.Phoenix - - - + + + + + Debug + AnyCPU + {7EC374E2-048E-4AB5-8994-97C5F2DDF057} + Library + Properties + PhoenixSharp.Interfaces + PhoenixSharp.Interfaces + v4.5.2 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + false + + + ETKey.snk + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + True + + + ..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll + True + + + + + + + + + + + + + + + + + + + + + + + + {8b32b5cc-94f1-464f-9cf9-a455361bafa1} + Apache.Phoenix + + + + --> \ No newline at end of file diff --git a/PhoenixSharp.Interfaces/RequestOptions.cs b/PhoenixSharp.Interfaces/RequestOptions.cs index a5488f2..88f9d4e 100644 --- a/PhoenixSharp.Interfaces/RequestOptions.cs +++ b/PhoenixSharp.Interfaces/RequestOptions.cs @@ -1,70 +1,66 @@ -// Copyright (c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy -// of the License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED -// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -namespace PhoenixSharp.Interfaces -{ - using System.Collections.Generic; - - public class RequestOptions - { - //public RetryPolicy RetryPolicy { get; set; } - public string AlternativeEndpoint { get; set; } - public bool KeepAlive { get; set; } - public int TimeoutMillis { get; set; } - //public int SerializationBufferSize { get; set; } - //public int ReceiveBufferSize { get; set; } - public bool UseNagle { get; set; } - public int Port { get; set; } - public Dictionary AdditionalHeaders { get; set; } - public string AlternativeHost { get; set; } - - public void Validate() - { - - } - - public static RequestOptions GetGatewayDefaultOptions() - { - return new RequestOptions() - { - //RetryPolicy = RetryPolicy.DefaultExponential, - KeepAlive = true, - TimeoutMillis = 30000, - //ReceiveBufferSize = 1024 * 1024 * 1, - //SerializationBufferSize = 1024 * 1024 * 1, - UseNagle = false, - AlternativeEndpoint = null, - Port = 443, - AlternativeHost = null - }; - } - - public static RequestOptions GetVNetDefaultOptions() - { - return new RequestOptions() - { - //RetryPolicy = RetryPolicy.DefaultExponential, - KeepAlive = true, - TimeoutMillis = 30000, - //ReceiveBufferSize = 1024 * 1024 * 1, - //SerializationBufferSize = 1024 * 1024 * 1, - UseNagle = false, - AlternativeEndpoint = null, - Port = 8765, - AlternativeHost = null - }; - } - } -} +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABLITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling; + +namespace PhoenixSharp.Interfaces +{ + using System.Collections.Generic; + + public class RequestOptions + { + public RetryPolicy RetryPolicy { get; set; } + public string AlternativeEndpoint { get; set; } + public bool KeepAlive { get; set; } + public int TimeoutMillis { get; set; } + public bool UseNagle { get; set; } + public int Port { get; set; } + public Dictionary AdditionalHeaders { get; set; } + public string AlternativeHost { get; set; } + + public void Validate() + { + + } + + public static RequestOptions GetGatewayDefaultOptions() + { + return new RequestOptions() + { + RetryPolicy = RetryPolicy.NoRetry, + KeepAlive = true, + TimeoutMillis = 30000, + UseNagle = false, + AlternativeEndpoint = null, + Port = 443, + AlternativeHost = null + }; + } + + public static RequestOptions GetVNetDefaultOptions() + { + return new RequestOptions() + { + RetryPolicy = RetryPolicy.NoRetry, + KeepAlive = true, + TimeoutMillis = 30000, + UseNagle = false, + AlternativeEndpoint = null, + Port = 8765, + AlternativeHost = null + }; + } + } +} diff --git a/PhoenixSharp.Interfaces/packages.config b/PhoenixSharp.Interfaces/packages.config index ae4b16f..4012b82 100644 --- a/PhoenixSharp.Interfaces/packages.config +++ b/PhoenixSharp.Interfaces/packages.config @@ -1,4 +1,5 @@ - - - + + + + \ No newline at end of file diff --git a/PhoenixSharp.UnitTests/ConnectionRetryTests.cs b/PhoenixSharp.UnitTests/ConnectionRetryTests.cs new file mode 100644 index 0000000..7d99e06 --- /dev/null +++ b/PhoenixSharp.UnitTests/ConnectionRetryTests.cs @@ -0,0 +1,62 @@ +using System; +using System.Linq.Expressions; +using System.Net; +using System.Text; +using Apache.Phoenix; +using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling; +using NUnit.Framework; +using PhoenixSharp.Interfaces; +using pbc = Google.Protobuf.Collections; + +namespace PhoenixSharp.UnitTests +{ + public class ConnectionRetryTests + { + private RequestOptions _options; + private PhoenixClient _client; + private string _connId; + private const int RETRYCOUNT = 5; + private int _retryCounter; + + [SetUp] + public void Setup() + { + _client = new PhoenixClient(null); + _connId = Guid.NewGuid().ToString(); + _options = RequestOptions.GetVNetDefaultOptions(); + + _retryCounter = 0; + var retryCount = 5; + var minBackoff = new TimeSpan(0, 0, 0, 0, 5); + var maxBackoff = new TimeSpan(0, 0, 0, 0, 1000); + var interval = new TimeSpan(0, 0, 0, 0, 200); + var exponentialBackoff = new ExponentialBackoff(retryCount, minBackoff, maxBackoff, interval); + _options.RetryPolicy = new RetryPolicy(exponentialBackoff); + _options.AlternativeEndpoint = "10.255.255.1"; + _options.Port = 8765; + _options.TimeoutMillis = 100; + + _options.RetryPolicy.Retrying += (sender, largs) => + { + // Log details of the retry. + var msg = String.Format("Retry - Count:{0}, Delay:{1}, Exception:{2}", + largs.CurrentRetryCount, largs.Delay, largs.LastException.GetType().ToString()); + System.Diagnostics.Debug.WriteLine(msg, "Information"); + + _retryCounter++; + }; + } + + /// + /// Load config, Insert Rows and Read back rows + /// + [Test] + [ExpectedException(typeof(AggregateException))] + public void TestRetry() + { + var info = new pbc::MapField(); + _client.OpenConnectionRequestAsync(_connId, info, _options).Wait(); + Assert.AreEqual(RETRYCOUNT, _retryCounter); + } + } +} diff --git a/PhoenixSharp.UnitTests/PhoenixSharp.UnitTests.csproj b/PhoenixSharp.UnitTests/PhoenixSharp.UnitTests.csproj index 01b7e75..66c19f2 100644 --- a/PhoenixSharp.UnitTests/PhoenixSharp.UnitTests.csproj +++ b/PhoenixSharp.UnitTests/PhoenixSharp.UnitTests.csproj @@ -1,70 +1,77 @@ - - - - Debug - AnyCPU - {65F62218-0D86-4BA0-B1F1-E1303153E26D} - Library - PhoenixSharp.UnitTests - PhoenixSharp.UnitTests - v4.5 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - true - bin\Release - prompt - 4 - false - - - - ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll - True - - - - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - - - - - - - - - - - - PreserveNewest - - - - - {8B32B5CC-94F1-464F-9CF9-A455361BAFA1} - Apache.Phoenix - - - {5012BFFB-AACF-41E6-A4A0-E82A5086A2E9} - PhoenixSharp - - - {7EC374E2-048E-4AB5-8994-97C5F2DDF057} - PhoenixSharp.Interfaces - - - - - - + + + + Debug + AnyCPU + {65F62218-0D86-4BA0-B1F1-E1303153E26D} + Library + PhoenixSharp.UnitTests + PhoenixSharp.UnitTests + v4.5.2 + + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + True + + + ..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll + True + + + + ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + + + + + + + + + + + + + + PreserveNewest + + + + + {8B32B5CC-94F1-464F-9CF9-A455361BAFA1} + Apache.Phoenix + + + {5012BFFB-AACF-41E6-A4A0-E82A5086A2E9} + PhoenixSharp + + + {7EC374E2-048E-4AB5-8994-97C5F2DDF057} + PhoenixSharp.Interfaces + + + + + + \ No newline at end of file diff --git a/PhoenixSharp.UnitTests/TestErrorDetectionStrategy.cs b/PhoenixSharp.UnitTests/TestErrorDetectionStrategy.cs new file mode 100644 index 0000000..8e7699a --- /dev/null +++ b/PhoenixSharp.UnitTests/TestErrorDetectionStrategy.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling; + +namespace PhoenixSharp.UnitTests +{ + public class AllErrorsTransientDetectionStrategy : ITransientErrorDetectionStrategy + { + public bool IsTransient(Exception ex) + { + return true; + } + } +} diff --git a/PhoenixSharp.UnitTests/packages.config b/PhoenixSharp.UnitTests/packages.config index 7b74276..6b22269 100644 --- a/PhoenixSharp.UnitTests/packages.config +++ b/PhoenixSharp.UnitTests/packages.config @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/PhoenixSharp/App.config b/PhoenixSharp/App.config index 8e15646..3c88dd4 100644 --- a/PhoenixSharp/App.config +++ b/PhoenixSharp/App.config @@ -1,6 +1,6 @@ - - - - - - \ No newline at end of file + + + + + + diff --git a/PhoenixSharp/PhoenixClient.cs b/PhoenixSharp/PhoenixClient.cs index 005bb86..b4a1234 100644 --- a/PhoenixSharp/PhoenixClient.cs +++ b/PhoenixSharp/PhoenixClient.cs @@ -775,7 +775,7 @@ private async Task ExecuteMethodAsync( { using (var input = new MemoryStream(request)) { - return await _requester.IssueWebRequestAsync(method: method, input: input, options: options); + return await options.RetryPolicy.ExecuteAsync(() => _requester.IssueWebRequestAsync(method: method, input: input, options: options)); } } diff --git a/PhoenixSharp/PhoenixSharp.csproj b/PhoenixSharp/PhoenixSharp.csproj index 9ad36ac..2c84dbe 100644 --- a/PhoenixSharp/PhoenixSharp.csproj +++ b/PhoenixSharp/PhoenixSharp.csproj @@ -1,82 +1,94 @@ - - - - - Debug - AnyCPU - {5012BFFB-AACF-41E6-A4A0-E82A5086A2E9} - Library - Properties - PhoenixSharp - PhoenixSharp - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - ..\packages\Google.Protobuf.3.0.0\lib\net45\Google.Protobuf.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - {8b32b5cc-94f1-464f-9cf9-a455361bafa1} - Apache.Phoenix - - - {7ec374e2-048e-4ab5-8994-97c5f2ddf057} - PhoenixSharp.Interfaces - - - - + + + + + Debug + AnyCPU + {5012BFFB-AACF-41E6-A4A0-E82A5086A2E9} + Library + Properties + PhoenixSharp + PhoenixSharp + v4.5.2 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + false + + + ETKey.snk + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + True + + + ..\packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8\Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + {8b32b5cc-94f1-464f-9cf9-a455361bafa1} + Apache.Phoenix + + + {7ec374e2-048e-4ab5-8994-97c5f2ddf057} + PhoenixSharp.Interfaces + + + + + --> \ No newline at end of file diff --git a/PhoenixSharp/packages.config b/PhoenixSharp/packages.config index ae4b16f..4012b82 100644 --- a/PhoenixSharp/packages.config +++ b/PhoenixSharp/packages.config @@ -1,4 +1,5 @@ - - - + + + + \ No newline at end of file