Skip to content

Commit 5bd94ca

Browse files
committed
ConnectionSettings() [NEST] and ConnectionConfiguration() [Elasticsearch.net] do not expose properties in fluent interface
1 parent db7c7ba commit 5bd94ca

10 files changed

+268
-226
lines changed

Diff for: src/Elasticsearch.Net.Tests.Unit/Connection/ConcurrencyTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public ConcurrencyTests()
3838
{
3939
_connectionPool = new SniffingConnectionPool(_uris);
4040
_config = new ConnectionConfiguration(_connectionPool)
41-
.SnifsOnConnectionFault()
41+
.SniffOnConnectionFault()
4242
.SniffOnStartup()
43-
.SetMaxRetries(5);
43+
.MaximumRetries(5);
4444
}
4545

4646
private void ProvideTransport(AutoFake fake)

Diff for: src/Elasticsearch.Net.Tests.Unit/Connection/RetryTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class RetryTests
2323
//we do not pass a Uri or IConnectionPool so this config
2424
//defaults to SingleNodeConnectionPool()
2525
private readonly ConnectionConfiguration _connectionConfig = new ConnectionConfiguration()
26-
.SetMaxRetries(_retries);
26+
.MaximumRetries(_retries);
2727

2828
private void ProvideTransport(AutoFake fake)
2929
{

Diff for: src/Elasticsearch.Net.Tests.Unit/Connection/SniffingConnectionPoolTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void SniffOnConnectionFaultCausesSniffOn503()
142142

143143
var connectionPool = new SniffingConnectionPool(new[] { new Uri("http://localhost:9200") });
144144
var config = new ConnectionConfiguration(connectionPool)
145-
.SnifsOnConnectionFault();
145+
.SniffOnConnectionFault();
146146
fake.Provide<IConnectionConfigurationValues>(config);
147147
fake.Provide<ITransport>(fake.Resolve<Transport>());
148148
var connection = fake.Resolve<IConnection>();
@@ -184,7 +184,7 @@ public void HostsReturnedBySniffAreVisited()
184184
new Uri("http://localhost:9201")
185185
}, randomizeOnStartup: false);
186186
var config = new ConnectionConfiguration(connectionPool)
187-
.SnifsOnConnectionFault();
187+
.SniffOnConnectionFault();
188188
fake.Provide<IConnectionConfigurationValues>(config);
189189
fake.Provide<ITransport>(fake.Resolve<Transport>());
190190
var connection = fake.Resolve<IConnection>();

Diff for: src/Elasticsearch.Net.Tests.Unit/Connection/StaticConnectionPoolRetryTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void HardRetryLimitTakesPrecedenceOverNumberOfNodes()
122122
//setup config values with a hight retry count
123123
fake.Provide<IConnectionConfigurationValues>(
124124
new ConnectionConfiguration(_connectionPool)
125-
.SetMaxRetries(7)
125+
.MaximumRetries(7)
126126
);
127127
var getCall = A.CallTo(() => fake.Resolve<IConnection>().GetSync(A<Uri>._));
128128
getCall.Throws<Exception>();
@@ -152,7 +152,7 @@ public void AConnectionMustBeMadeEvenIfAllNodesAreDead()
152152
//original call + 4 retries == 5
153153
fake.Provide<IConnectionConfigurationValues>(
154154
new ConnectionConfiguration(_connectionPool)
155-
.SetMaxRetries(4)
155+
.MaximumRetries(4)
156156
);
157157
//set up our GET to / to return 4 503's followed by a 200
158158
var getCall = A.CallTo(() => fake.Resolve<IConnection>().GetSync(A<Uri>._));
@@ -254,7 +254,7 @@ public void IfAConnectionComesBackToLifeOnItsOwnItShouldBeMarked()
254254
//set retries to 4
255255
fake.Provide<IConnectionConfigurationValues>(
256256
new ConnectionConfiguration(connectionPool)
257-
.SetMaxRetries(4)
257+
.MaximumRetries(4)
258258
);
259259

260260
//fake getsync handler that return a 503 4 times and then a 200

Diff for: src/Elasticsearch.Net/Connection/ConnectionConfiguration.cs

+66-47
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,57 @@ public ConnectionConfiguration(IConnectionPool connectionPool)
2727
public class ConnectionConfiguration<T> : IConnectionConfigurationValues
2828
where T : ConnectionConfiguration<T>
2929
{
30-
public IConnectionPool ConnectionPool { get; private set; }
31-
//public Uri Uri { get; private set; }
32-
//public string Host { get; private set; }
33-
//public int Port { get; private set; }
34-
public int Timeout { get; private set; }
35-
public int? PingTimeout { get; private set; }
36-
public int? DeadTimeout { get; private set; }
37-
public int? MaxDeadTimeout { get; private set; }
38-
public string ProxyUsername { get; private set; }
39-
public string ProxyPassword { get; private set; }
40-
public bool DisablePings { get; private set; }
41-
public string ProxyAddress { get; private set; }
42-
public int MaximumAsyncConnections { get; private set; }
43-
public int? MaxRetries { get; private set; }
44-
public bool UsesPrettyResponses { get; private set; }
45-
public bool SniffsOnStartup { get; private set; }
46-
public bool SniffsOnConnectionFault { get; private set; }
47-
public TimeSpan? SniffInformationLifeSpan { get; private set; }
48-
public bool TraceEnabled { get; private set; }
49-
public Action<ElasticsearchResponse> ConnectionStatusHandler { get; private set; }
50-
public NameValueCollection QueryStringParameters { get; private set; }
51-
public bool UriSpecifiedBasicAuth { get; private set; }
30+
private IConnectionPool _connectionPool;
31+
IConnectionPool IConnectionConfigurationValues.ConnectionPool { get { return _connectionPool; } }
32+
33+
private int _timeout;
34+
int IConnectionConfigurationValues.Timeout { get { return _timeout; }}
35+
private int? _pingTimeout;
36+
int? IConnectionConfigurationValues.PingTimeout { get{ return _pingTimeout; } }
37+
38+
private int? _deadTimeout;
39+
int? IConnectionConfigurationValues.DeadTimeout { get{ return _deadTimeout; } }
40+
private int? _maxDeadTimeout;
41+
int? IConnectionConfigurationValues.MaxDeadTimeout { get{ return _maxDeadTimeout; } }
42+
private string _proxyUsername;
43+
string IConnectionConfigurationValues.ProxyUsername { get{ return _proxyUsername; } }
44+
private string _proxyPassword;
45+
string IConnectionConfigurationValues.ProxyPassword { get{ return _proxyPassword; } }
46+
private bool _disablePings;
47+
bool IConnectionConfigurationValues.DisablePings { get{ return _disablePings; } }
48+
private string _proxyAddress;
49+
string IConnectionConfigurationValues.ProxyAddress { get{ return _proxyAddress; } }
50+
51+
private int _maximumAsyncConnections;
52+
int IConnectionConfigurationValues.MaximumAsyncConnections { get{ return _maximumAsyncConnections; } }
53+
private int? _maxRetries;
54+
int? IConnectionConfigurationValues.MaxRetries { get{ return _maxRetries; } }
55+
private bool _usePrettyResponses;
56+
bool IConnectionConfigurationValues.UsesPrettyResponses { get{ return _usePrettyResponses; } }
57+
private bool _sniffOnStartup;
58+
bool IConnectionConfigurationValues.SniffsOnStartup { get{ return _sniffOnStartup; } }
59+
private bool _sniffOnConectionFault;
60+
bool IConnectionConfigurationValues.SniffsOnConnectionFault { get{ return _sniffOnConectionFault; } }
61+
private TimeSpan? _sniffLifeSpan;
62+
TimeSpan? IConnectionConfigurationValues.SniffInformationLifeSpan { get{ return _sniffLifeSpan; } }
63+
private bool _traceEnabled;
64+
bool IConnectionConfigurationValues.TraceEnabled { get{ return _traceEnabled; } }
65+
private Action<ElasticsearchResponse> _connectionStatusHandler;
66+
Action<ElasticsearchResponse> IConnectionConfigurationValues.ConnectionStatusHandler { get{ return _connectionStatusHandler; } }
67+
private NameValueCollection _queryString;
68+
NameValueCollection IConnectionConfigurationValues.QueryStringParameters { get{ return _queryString; } }
69+
70+
5271
IElasticsearchSerializer IConnectionConfigurationValues.Serializer { get; set; }
5372

5473
public ConnectionConfiguration(IConnectionPool connectionPool)
5574
{
56-
this.Timeout = 60*1000;
75+
this._timeout = 60*1000;
5776
//this.UriSpecifiedBasicAuth = !uri.UserInfo.IsNullOrEmpty();
5877
//this.Uri = uri;
59-
this.ConnectionStatusHandler = this.ConnectionStatusDefaultHandler;
60-
this.MaximumAsyncConnections = 0;
61-
this.ConnectionPool = connectionPool;
78+
this._connectionStatusHandler = this.ConnectionStatusDefaultHandler;
79+
this._maximumAsyncConnections = 0;
80+
this._connectionPool = connectionPool;
6281
}
6382

6483
public ConnectionConfiguration(Uri uri = null)
@@ -68,25 +87,25 @@ public ConnectionConfiguration(Uri uri = null)
6887
//this.Port = uri.Port;
6988
}
7089

71-
public T SetMaxRetries(int maxRetries)
90+
public T MaximumRetries(int maxRetries)
7291
{
73-
this.MaxRetries = maxRetries;
92+
this._maxRetries = maxRetries;
7493
return (T) this;
7594
}
7695

77-
public T SnifsOnConnectionFault(bool sniffsOnConnectionFault = true)
96+
public T SniffOnConnectionFault(bool sniffsOnConnectionFault = true)
7897
{
79-
this.SniffsOnConnectionFault = sniffsOnConnectionFault;
98+
this._sniffOnConectionFault = sniffsOnConnectionFault;
8099
return (T)this;
81100
}
82101
public T SniffOnStartup(bool sniffsOnStartup = true)
83102
{
84-
this.SniffsOnStartup = sniffsOnStartup;
103+
this._sniffOnStartup = sniffsOnStartup;
85104
return (T)this;
86105
}
87106
public T SniffLifeSpan(TimeSpan sniffTimeSpan)
88107
{
89-
this.SniffInformationLifeSpan = sniffTimeSpan;
108+
this._sniffLifeSpan = sniffTimeSpan;
90109
return (T)this;
91110
}
92111

@@ -95,7 +114,7 @@ public T SniffLifeSpan(TimeSpan sniffTimeSpan)
95114
/// </summary>
96115
public T EnableTrace(bool enabled = true)
97116
{
98-
this.TraceEnabled = enabled;
117+
this._traceEnabled = enabled;
99118
return (T) this;
100119
}
101120

@@ -106,19 +125,19 @@ public T EnableTrace(bool enabled = true)
106125
/// </summary>
107126
public T DisablePing(bool disable = true)
108127
{
109-
this.DisablePings = disable;
128+
this._disablePings = disable;
110129
return (T) this;
111130
}
112131
/// <summary>
113132
/// This NameValueCollection will be appended to every url NEST calls, great if you need to pass i.e an API key.
114133
/// </summary>
115134
public T SetGlobalQueryStringParameters(NameValueCollection queryStringParameters)
116135
{
117-
if (this.QueryStringParameters != null)
136+
if (this._queryString != null)
118137
{
119-
this.QueryStringParameters.Add(queryStringParameters);
138+
this._queryString.Add(queryStringParameters);
120139
}
121-
this.QueryStringParameters = queryStringParameters;
140+
this._queryString = queryStringParameters;
122141
return (T) this;
123142
}
124143

@@ -129,7 +148,7 @@ public T SetGlobalQueryStringParameters(NameValueCollection queryStringParameter
129148
/// <param name="timeout">time out in milliseconds</param>
130149
public T SetTimeout(int timeout)
131150
{
132-
this.Timeout = timeout;
151+
this._timeout = timeout;
133152
return (T) this;
134153
}
135154

@@ -139,7 +158,7 @@ public T SetTimeout(int timeout)
139158
/// <param name="timeout">The ping timeout in milliseconds defaults to 50</param>
140159
public T SetPingTimeout(int timeout)
141160
{
142-
this.PingTimeout = timeout;
161+
this._pingTimeout = timeout;
143162
return (T) this;
144163
}
145164

@@ -150,7 +169,7 @@ public T SetPingTimeout(int timeout)
150169
/// <param name="timeout"></param>
151170
public T SetDeadTimeout(int timeout)
152171
{
153-
this.DeadTimeout = timeout;
172+
this._deadTimeout = timeout;
154173
return (T) this;
155174
}
156175

@@ -161,7 +180,7 @@ public T SetDeadTimeout(int timeout)
161180
/// <param name="timeout">The timeout in milliseconds</param>
162181
public T SetMaxDeadTimeout(int timeout)
163182
{
164-
this.MaxDeadTimeout = timeout;
183+
this._maxDeadTimeout = timeout;
165184
return (T) this;
166185
}
167186
/// <summary>
@@ -171,7 +190,7 @@ public T SetMaxDeadTimeout(int timeout)
171190
/// <param name="maximum">defaults to 0 (unbounded)</param>
172191
public T SetMaximumAsyncConnections(int maximum)
173192
{
174-
this.MaximumAsyncConnections = maximum;
193+
this._maximumAsyncConnections = maximum;
175194
return (T) this;
176195
}
177196

@@ -181,9 +200,9 @@ public T SetMaximumAsyncConnections(int maximum)
181200
public T SetProxy(Uri proxyAdress, string username, string password)
182201
{
183202
proxyAdress.ThrowIfNull("proxyAdress");
184-
this.ProxyAddress = proxyAdress.ToString();
185-
this.ProxyUsername = username;
186-
this.ProxyPassword = password;
203+
this._proxyAddress = proxyAdress.ToString();
204+
this._proxyUsername = username;
205+
this._proxyPassword = password;
187206
return (T) this;
188207
}
189208

@@ -192,7 +211,7 @@ public T SetProxy(Uri proxyAdress, string username, string password)
192211
/// </summary>
193212
public T UsePrettyResponses(bool b = true)
194213
{
195-
this.UsesPrettyResponses = b;
214+
this._usePrettyResponses = b;
196215
this.SetGlobalQueryStringParameters(new NameValueCollection {{"pretty", b.ToString().ToLowerInvariant()}});
197216
return (T) this;
198217
}
@@ -208,7 +227,7 @@ protected void ConnectionStatusDefaultHandler(ElasticsearchResponse status)
208227
public T SetConnectionStatusHandler(Action<ElasticsearchResponse> handler)
209228
{
210229
handler.ThrowIfNull("handler");
211-
this.ConnectionStatusHandler = handler;
230+
this._connectionStatusHandler = handler;
212231
return (T) this;
213232
}
214233
}

Diff for: src/Elasticsearch.Net/Connection/IConnectionConfigurationValues.cs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public interface IConnectionConfigurationValues
2323
string ProxyPassword { get; }
2424

2525
bool TraceEnabled { get; }
26-
bool UriSpecifiedBasicAuth { get; }
2726
bool UsesPrettyResponses { get; }
2827

2928
/// <summary>

0 commit comments

Comments
 (0)