Skip to content

Commit 7b52d6c

Browse files
authored
[6.x] Switch default memory stream factory (#5750)
* Switch default memory stream factory * Update test matrix * Update test matrix labels
1 parent c703802 commit 7b52d6c

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

azure-pipelines.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ jobs:
3636
strategy:
3737
maxParallel: 5
3838
matrix:
39-
es682:
40-
esVersion: '6.8.2'
39+
es6816:
40+
esVersion: '6.8.16'
4141
es672:
4242
esVersion: '6.7.2'
4343
es662:
4444
esVersion: '6.6.2'
4545
es654:
4646
esVersion: '6.5.4'
47-
es642:
48-
esVersion: '6.4.2'
47+
es643:
48+
esVersion: '6.4.3'
4949
es632:
5050
esVersion: '6.3.2'
5151
es624:
@@ -74,16 +74,16 @@ jobs:
7474
strategy:
7575
maxParallel: 5
7676
matrix:
77-
es682:
78-
esVersion: '6.8.2'
77+
es6816:
78+
esVersion: '6.8.16'
7979
es672:
8080
esVersion: '6.7.2'
8181
es662:
8282
esVersion: '6.6.2'
8383
es654:
8484
esVersion: '6.5.4'
85-
es642:
86-
esVersion: '6.4.2'
85+
es643:
86+
esVersion: '6.4.3'
8787
es632:
8888
esVersion: '6.3.2'
8989
es624:

src/Elasticsearch.Net/Configuration/ConnectionConfiguration.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public ConnectionConfiguration(IConnectionPool connectionPool, IConnection conne
129129
public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValues, IHideObjectMembers
130130
where T : ConnectionConfiguration<T>
131131
{
132+
public static IMemoryStreamFactory DefaultMemoryStreamFactory { get; } = Elasticsearch.Net.MemoryStreamFactory.Default;
133+
132134
private readonly IConnection _connection;
133135
private readonly IConnectionPool _connectionPool;
134136
private readonly NameValueCollection _headers = new NameValueCollection();
@@ -141,9 +143,7 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
141143
private Action<IApiCallDetails> _completedRequestHandler = DefaultCompletedRequestHandler;
142144
private int _connectionLimit;
143145
private TimeSpan? _deadTimeout;
144-
145146
private bool _disableAutomaticProxyDetection = false;
146-
147147
private bool _disableDirectStreaming = false;
148148
private bool _disableMetaHeader;
149149
private bool _disablePings;
@@ -154,12 +154,12 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
154154
private TimeSpan? _maxDeadTimeout;
155155
private int? _maxRetries;
156156
private TimeSpan? _maxRetryTimeout;
157+
private IMemoryStreamFactory _memoryStreamFactory = DefaultMemoryStreamFactory;
157158
private Func<Node, bool> _nodePredicate = DefaultNodePredicate;
158159
private Action<RequestData> _onRequestDataCreated = DefaultRequestDataCreated;
159160
private TimeSpan? _pingTimeout;
160161
private bool _prettyJson;
161162
private string _proxyAddress;
162-
163163
private string _proxyPassword;
164164
private string _proxyUsername;
165165
private TimeSpan _requestTimeout;
@@ -217,8 +217,7 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co
217217
TimeSpan? IConnectionConfigurationValues.MaxDeadTimeout => _maxDeadTimeout;
218218
int? IConnectionConfigurationValues.MaxRetries => _maxRetries;
219219
TimeSpan? IConnectionConfigurationValues.MaxRetryTimeout => _maxRetryTimeout;
220-
IMemoryStreamFactory IConnectionConfigurationValues.MemoryStreamFactory { get; } = new RecyclableMemoryStreamFactory();
221-
220+
IMemoryStreamFactory IConnectionConfigurationValues.MemoryStreamFactory => _memoryStreamFactory;
222221
Func<Node, bool> IConnectionConfigurationValues.NodePredicate => _nodePredicate;
223222
Action<IApiCallDetails> IConnectionConfigurationValues.OnRequestCompleted => _completedRequestHandler;
224223
Action<RequestData> IConnectionConfigurationValues.OnRequestDataCreated => _onRequestDataCreated;
@@ -585,6 +584,11 @@ public T SkipDeserializationForStatusCodes(params int[] statusCodes) =>
585584
/// </summary>
586585
public T UserAgent(string userAgent) => Assign(userAgent, (a, v) => a._userAgent = v);
587586

587+
/// <summary>
588+
/// The memory stream factory to use, defaults to <see cref="MemoryStreamFactory.Default"/>.
589+
/// </summary>
590+
public T MemoryStreamFactory(IMemoryStreamFactory memoryStreamFactory) => Assign(memoryStreamFactory, (a, v) => a._memoryStreamFactory = v);
591+
588592
protected virtual void DisposeManagedResources()
589593
{
590594
_connectionPool?.Dispose();

src/Elasticsearch.Net/Configuration/IConnectionConfigurationValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public interface IConnectionConfigurationValues : IDisposable
120120
/// </summary>
121121
TimeSpan? MaxRetryTimeout { get; }
122122

123-
/// <summary> Provides a memory stream factory</summary>
123+
/// <summary> Provides a memory stream factory.</summary>
124124
IMemoryStreamFactory MemoryStreamFactory { get; }
125125

126126
/// <summary>

src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
namespace Elasticsearch.Net
44
{
55
/// <summary>
6-
/// A factory for creating memory streams using instances of <see cref="MemoryStream" />
6+
/// A factory for creating memory streams using instances of <see cref="MemoryStream" />.
77
/// </summary>
88
public class MemoryStreamFactory : IMemoryStreamFactory
99
{
10+
public static MemoryStreamFactory Default { get; } = new MemoryStreamFactory();
11+
1012
/// <summary>
11-
/// Creates a memory stream using <see cref="MemoryStream" />
13+
/// Creates a memory stream using <see cref="MemoryStream" />.
1214
/// </summary>
1315
public MemoryStream Create() => new MemoryStream();
1416

1517
/// <summary>
16-
/// Creates a memory stream using <see cref="MemoryStream" /> with the bytes written to the stream
18+
/// Creates a memory stream using <see cref="MemoryStream" /> with the bytes written to the stream.
1719
/// </summary>
1820
public MemoryStream Create(byte[] bytes) => new MemoryStream(bytes);
1921
}

src/Elasticsearch.Net/Providers/RecyclableMemoryStreamFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace Elasticsearch.Net
44
{
55
/// <summary>
6-
/// A factory for creating memory streams using a recyclable pool of <see cref="MemoryStream" /> instances
6+
/// A factory for creating memory streams using a recyclable pool of <see cref="MemoryStream" /> instances.
77
/// </summary>
88
public class RecyclableMemoryStreamFactory : IMemoryStreamFactory
99
{
10+
public static RecyclableMemoryStreamFactory Default { get; } = new RecyclableMemoryStreamFactory();
11+
1012
private readonly RecyclableMemoryStreamManager _manager;
1113

1214
public RecyclableMemoryStreamFactory() =>

0 commit comments

Comments
 (0)