Skip to content
Browse files

NCBC-158: Set view timeout default to 75 seconds

Change-Id: If88029c0e0df5f2d3af829786ad5e6f549f3183f
Reviewed-on: http://review.couchbase.org/22734
Reviewed-by: Matt Ingenthron <matt@couchbase.com>
Tested-by: John C. Zablocki <john@couchbase.com>
  • Loading branch information...
1 parent 610f5d4 commit 3463755cb8b37ef0dbdf2216a2ec6a4ac4b34eba @johnzablocki johnzablocki committed with John C. Zablocki Nov 21, 2012
View
2 src/Couchbase.Tests/App.config
@@ -116,6 +116,6 @@
<servers bucket="default">
<add uri="http://localhost:8091/pools" />
</servers>
- <httpClient initializeConnection="false" />
+ <httpClient initializeConnection="false" timeout="00:00:45"/>
</httpclient-config-noinitconn>
</configuration>
View
28 src/Couchbase.Tests/DefaultCouchbaseClientConfigurationTests.cs
@@ -25,7 +25,7 @@ public void When_Using_Code_Config_And_Http_Client_Factory_Is_Not_Set_Hammock_Fa
//HammockHttpClient is an internal class to the Couchbase assembly,
//therefore the explicit type can't be checked for using Is.InstanceOf<T>
- var typeName = (config.HttpClientFactory.Create(config.Urls[0], "", "", true).GetType().Name);
+ var typeName = (config.HttpClientFactory.Create(config.Urls[0], "", "", TimeSpan.FromMinutes(1), true).GetType().Name);
Assert.That(typeName, Is.StringContaining("HammockHttpClient"));
}
@@ -39,7 +39,7 @@ public void When_Using_App_Config_And_Http_Client_Factory_Is_Not_Set_Hammock_Fac
//HammockHttpClient is an internal class to the Couchbase assembly,
//therefore the explicit type can't be checked for using Is.InstanceOf<T>
- var typeName = (config.HttpClientFactory.CreateInstance().Create(config.Servers.Urls.ToUriCollection()[0], "", "", true).GetType().Name);
+ var typeName = (config.HttpClientFactory.CreateInstance().Create(config.Servers.Urls.ToUriCollection()[0], "", "", TimeSpan.FromMinutes(1), true).GetType().Name);
Assert.That(typeName, Is.StringContaining("HammockHttpClient"));
}
@@ -180,6 +180,30 @@ public void When_Initialize_Connection_Is_Not_Set_In_Code_Default_Is_True()
Assert.That(config, Is.Not.Null, "Config was null");
Assert.That(config.HttpClient.InitializeConnection, Is.True);
}
+
+ [Test]
+ public void When_Http_Client_Timeout_Is_Not_Set_In_App_Config_Default_Is_True()
+ {
+ var config = ConfigurationManager.GetSection("min-config") as CouchbaseClientSection;
+ Assert.That(config, Is.Not.Null, "Config was null");
+ Assert.That(config.HttpClient.Timeout, Is.EqualTo(TimeSpan.Parse("00:01:15")));
+ }
+
+ [Test]
+ public void When_Http_Client_Timeout_Is_Set_In_App_Config_Property_Changes_From_Default()
+ {
+ var config = ConfigurationManager.GetSection("httpclient-config-noinitconn") as CouchbaseClientSection;
+ Assert.That(config, Is.Not.Null, "Config was null");
+ Assert.That(config.HttpClient.Timeout, Is.EqualTo(TimeSpan.Parse("00:00:45")));
+ }
+
+ [Test]
+ public void When_Http_Client_Timeout_Is_Not_Set_In_Code_Default_Is_75_Seconds()
+ {
+ var config = new CouchbaseClientConfiguration();
+ Assert.That(config, Is.Not.Null, "Config was null");
+ Assert.That(config.HttpClient.Timeout, Is.EqualTo(TimeSpan.Parse("00:01:15")));
+ }
#endregion
}
}
View
4 src/Couchbase.Tests/Mocks/MockHttpClientFactory.cs
@@ -9,9 +9,9 @@ public class MockHttpClientFactory : IHttpClientFactory
{
public IHttpClient Client { get; set; }
- public IHttpClient Create(Uri baseUri, string username, string password, bool shouldInitializeConnection)
+ public IHttpClient Create(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitializeConnection)
{
- return (Client = new MockHttpClient() { BaseUri = baseUri });
+ return (Client = new MockHttpClient() { BaseUri = baseUri });
}
}
}
View
8 src/Couchbase/Configuration/CouchbaseClientConfiguration.cs
@@ -33,7 +33,7 @@ public CouchbaseClientConfiguration()
this.HeartbeatMonitor = new HeartbeatMonitorElement();
- this.HttpClient = new HttpClientElement();
+ this.HttpClient = new HttpClientElement() { Timeout = TimeSpan.Parse("00:01:15") };
}
/// <summary>
@@ -50,7 +50,7 @@ INameTransformer ICouchbaseClientConfiguration.CreateDesignDocumentNameTransform
IHttpClient ICouchbaseClientConfiguration.CreateHttpClient(Uri baseUri)
{
- return this.HttpClientFactory.Create(baseUri, Bucket, BucketPassword, HttpClient.InitializeConnection);
+ return this.HttpClientFactory.Create(baseUri, Bucket, BucketPassword, HttpClient.Timeout, HttpClient.InitializeConnection);
}
#endregion
@@ -419,14 +419,16 @@ public HBM(IHeartbeatMonitorConfiguration original)
private class HCC : IHttpClientConfiguration
{
private bool initializeConnectio;
+ private TimeSpan timeout;
public HCC(IHttpClientConfiguration original)
{
this.initializeConnectio = original.InitializeConnection;
+ this.timeout = original.Timeout;
}
bool IHttpClientConfiguration.InitializeConnection { get { return this.initializeConnectio; } set { } }
-
+ TimeSpan IHttpClientConfiguration.Timeout { get { return this.timeout; } set { } }
}
}
View
2 src/Couchbase/Configuration/CouchbaseClientSection.cs
@@ -161,7 +161,7 @@ protected override void PostDeserialize()
Debug.Assert(this.clientFactory != null);
- return this.clientFactory.Create(baseUri, Servers.Bucket, Servers.BucketPassword, HttpClient.InitializeConnection);
+ return this.clientFactory.Create(baseUri, Servers.Bucket, Servers.BucketPassword, HttpClient.Timeout, HttpClient.InitializeConnection);
}
#endregion
View
10 src/Couchbase/Configuration/HttpClientElement.cs
@@ -17,6 +17,16 @@ public bool InitializeConnection
get { return (bool)base["initializeConnection"]; }
set { base["initializeConnection"] = value; }
}
+
+ /// <summary>
+ /// Gets or sets the timeout for http client connections
+ /// </summary>
+ [ConfigurationProperty("timeout", IsRequired = false, DefaultValue = "00:01:15")]
+ public TimeSpan Timeout
+ {
+ get { return (TimeSpan)base["timeout"]; }
+ set { base["timeout"] = value; }
+ }
}
}
View
5 src/Couchbase/Configuration/IHttpClientConfiguration.cs
@@ -12,6 +12,11 @@ public interface IHttpClientConfiguration
/// to initialize the ServicePoint for future requests
/// </summary>
bool InitializeConnection { get; set; }
+
+ /// <summary>
+ /// Timeout applied to HTTP requests
+ /// </summary>
+ TimeSpan Timeout { get; set; }
}
}
View
7 src/Couchbase/HammockHttpClient.cs
@@ -18,7 +18,7 @@ internal class HammockHttpClient : IHttpClient
private RestClient client;
- public HammockHttpClient(Uri baseUri, string username, string password, bool shouldInitConnection)
+ public HammockHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection)
{
this.client = new RestClient { Authority = baseUri.ToString() };
@@ -36,6 +36,7 @@ public HammockHttpClient(Uri baseUri, string username, string password, bool sho
client.AddHeader("Authorization", "Basic " + base64Credentials);
}
+ client.Timeout = timeout;
client.RetryPolicy = new RetryPolicy
{
RetryConditions =
@@ -158,9 +159,9 @@ public class HammockHttpClientFactory : IHttpClientFactory
{
public static readonly IHttpClientFactory Instance = new HammockHttpClientFactory();
- IHttpClient IHttpClientFactory.Create(Uri baseUri, string username, string password, bool shouldInitializeConnection)
+ IHttpClient IHttpClientFactory.Create(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitializeConnection)
{
- return new HammockHttpClient(baseUri, username, password, shouldInitializeConnection);
+ return new HammockHttpClient(baseUri, username, password, timeout, shouldInitializeConnection);
}
}
}
View
2 src/Couchbase/IHttpClient.cs
@@ -54,7 +54,7 @@ public interface IHttpRequest
/// </summary>
public interface IHttpClientFactory
{
- IHttpClient Create(Uri baseUri, string username, string password, bool shouldInitializeConnection);
+ IHttpClient Create(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitializeConnection);
}
public enum HttpMethod

0 comments on commit 3463755

Please sign in to comment.
Something went wrong with that request. Please try again.