Skip to content

Commit a527d53

Browse files
authored
Refactoring for v8 alpha client (#38)
* Consolidated refactoring and renaming - Adds support for overriding response builders * Serializer uses ValueTask Also fixes some inefficiencies with the LowLevel serializer now we pin STJ to > 6.0
1 parent 7b32264 commit a527d53

File tree

101 files changed

+2415
-984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2415
-984
lines changed

benchmarks/Elastic.Transport.Benchmarks/TransportBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class TransportBenchmarks
1616
public void Setup()
1717
{
1818
var connection = new InMemoryConnection();
19-
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
19+
var pool = new SingleNodePool(new Uri("http://localhost:9200"));
2020
var settings = new TransportConfiguration(pool, connection);
2121

2222
_transport = new Transport(settings);

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.100",
3+
"version": "6.0.100",
44
"rollForward": "latestFeature",
55
"allowPrerelease": false
66
}

src/Elastic.Transport.VirtualizedCluster/Audit/Auditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ private Auditor(Components.VirtualizedCluster cluster, Components.VirtualizedClu
2626
StartedUp = true;
2727
}
2828

29-
public Action<IConnectionPool> AssertPoolAfterCall { get; set; }
30-
public Action<IConnectionPool> AssertPoolAfterStartup { get; set; }
29+
public Action<NodePool> AssertPoolAfterCall { get; set; }
30+
public Action<NodePool> AssertPoolAfterStartup { get; set; }
3131

32-
public Action<IConnectionPool> AssertPoolBeforeCall { get; set; }
33-
public Action<IConnectionPool> AssertPoolBeforeStartup { get; set; }
32+
public Action<NodePool> AssertPoolBeforeCall { get; set; }
33+
public Action<NodePool> AssertPoolBeforeStartup { get; set; }
3434

3535
public IReadOnlyCollection<Elastic.Transport.Diagnostics.Auditing.Audit> AsyncAuditTrail { get; set; }
3636
public IReadOnlyCollection<Elastic.Transport.Diagnostics.Auditing.Audit> AuditTrail { get; set; }

src/Elastic.Transport.VirtualizedCluster/Audit/Audits.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public ClientCall() { }
2727

2828
public ClientCall(Func<RequestConfigurationDescriptor, IRequestConfiguration> requestOverrides) => RequestOverrides = requestOverrides;
2929

30-
public Action<IConnectionPool> AssertPoolAfterCall { get; private set; }
30+
public Action<NodePool> AssertPoolAfterCall { get; private set; }
3131
public Action<ITransportResponse> AssertResponse { get; private set; }
3232
public Func<RequestConfigurationDescriptor, IRequestConfiguration> RequestOverrides { get; }
3333

@@ -37,7 +37,7 @@ public ClientCall() { }
3737

3838
public void Add(AuditEvent key) => Add(new CallTraceState(key));
3939

40-
public void Add(Action<IConnectionPool> pool) => AssertPoolAfterCall = pool;
40+
public void Add(Action<NodePool> pool) => AssertPoolAfterCall = pool;
4141

4242
public void Add(AuditEvent key, int port, Action<ITransportResponse> assertResponse)
4343
{

src/Elastic.Transport.VirtualizedCluster/Components/SealedVirtualCluster.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ namespace Elastic.Transport.VirtualizedCluster.Components
1111
/// <summary>
1212
/// A continuation of <see cref="VirtualCluster"/>'s builder methods that creates
1313
/// an instance of <see cref="TransportConfiguration"/> for the cluster after which the components such as
14-
/// <see cref="IConnection"/> and <see cref="IConnectionPool"/> can no longer be updated.
14+
/// <see cref="ITransportClient"/> and <see cref="NodePool"/> can no longer be updated.
1515
/// </summary>
1616
public class SealedVirtualCluster
1717
{
18-
private readonly IConnection _connection;
19-
private readonly IConnectionPool _connectionPool;
18+
private readonly ITransportClient _connection;
19+
private readonly NodePool _connectionPool;
2020
private readonly TestableDateTimeProvider _dateTimeProvider;
2121
private readonly IMockProductRegistration _productRegistration;
2222

23-
internal SealedVirtualCluster(VirtualCluster cluster, IConnectionPool pool, TestableDateTimeProvider dateTimeProvider, IMockProductRegistration productRegistration)
23+
internal SealedVirtualCluster(VirtualCluster cluster, NodePool pool, TestableDateTimeProvider dateTimeProvider, IMockProductRegistration productRegistration)
2424
{
2525
_connectionPool = pool;
2626
_connection = new VirtualClusterConnection(cluster, dateTimeProvider);

src/Elastic.Transport.VirtualizedCluster/Components/VirtualCluster.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,33 @@ public VirtualCluster ClientCalls(Func<ClientCallRule, IClientCallRule> selector
7373
public SealedVirtualCluster SingleNodeConnection(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
7474
{
7575
var nodes = seedNodesSelector?.Invoke(InternalNodes) ?? InternalNodes;
76-
return new SealedVirtualCluster(this, new SingleNodeConnectionPool(nodes.First().Uri), DateTimeProvider, ProductRegistration);
76+
return new SealedVirtualCluster(this, new SingleNodePool(nodes.First().Uri), DateTimeProvider, ProductRegistration);
7777
}
7878

79-
public SealedVirtualCluster StaticConnectionPool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
79+
public SealedVirtualCluster StaticNodePool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
8080
{
8181
var nodes = seedNodesSelector?.Invoke(InternalNodes) ?? InternalNodes;
82-
return new SealedVirtualCluster(this, new StaticConnectionPool(nodes, false, DateTimeProvider), DateTimeProvider, ProductRegistration);
82+
return new SealedVirtualCluster(this, new StaticNodePool(nodes, false, DateTimeProvider), DateTimeProvider, ProductRegistration);
8383
}
8484

85-
public SealedVirtualCluster SniffingConnectionPool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
85+
public SealedVirtualCluster SniffingNodePool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
8686
{
8787
var nodes = seedNodesSelector?.Invoke(InternalNodes) ?? InternalNodes;
88-
return new SealedVirtualCluster(this, new SniffingConnectionPool(nodes, false, DateTimeProvider), DateTimeProvider, ProductRegistration);
88+
return new SealedVirtualCluster(this, new SniffingNodePool(nodes, false, DateTimeProvider), DateTimeProvider, ProductRegistration);
8989
}
9090

91-
public SealedVirtualCluster StickyConnectionPool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
91+
public SealedVirtualCluster StickyNodePool(Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null)
9292
{
9393
var nodes = seedNodesSelector?.Invoke(InternalNodes) ?? InternalNodes;
94-
return new SealedVirtualCluster(this, new StickyConnectionPool(nodes, DateTimeProvider), DateTimeProvider, ProductRegistration);
94+
return new SealedVirtualCluster(this, new StickyNodePool(nodes, DateTimeProvider), DateTimeProvider, ProductRegistration);
9595
}
9696

97-
public SealedVirtualCluster StickySniffingConnectionPool(Func<Node, float> sorter = null,
97+
public SealedVirtualCluster StickySniffingNodePool(Func<Node, float> sorter = null,
9898
Func<IList<Node>, IEnumerable<Node>> seedNodesSelector = null
9999
)
100100
{
101101
var nodes = seedNodesSelector?.Invoke(InternalNodes) ?? InternalNodes;
102-
return new SealedVirtualCluster(this, new StickySniffingConnectionPool(nodes, sorter, DateTimeProvider), DateTimeProvider, ProductRegistration);
102+
return new SealedVirtualCluster(this, new StickySniffingNodePool(nodes, sorter, DateTimeProvider), DateTimeProvider, ProductRegistration);
103103
}
104104
}
105105
}

src/Elastic.Transport.VirtualizedCluster/Components/VirtualClusterConnection.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static VirtualClusterConnection Success(byte[] response) =>
5656
Virtual.Elasticsearch
5757
.Bootstrap(1)
5858
.ClientCalls(r => r.SucceedAlways().ReturnByteResponse(response))
59-
.StaticConnectionPool()
59+
.StaticNodePool()
6060
.AllDefaults()
6161
.Connection;
6262

@@ -67,7 +67,7 @@ public static VirtualClusterConnection Error() =>
6767
Virtual.Elasticsearch
6868
.Bootstrap(1)
6969
.ClientCalls(r => r.FailAlways(400))
70-
.StaticConnectionPool()
70+
.StaticNodePool()
7171
.AllDefaults()
7272
.Connection;
7373

@@ -109,11 +109,11 @@ private void UpdateCluster(VirtualCluster cluster)
109109

110110
private bool IsPingRequest(RequestData requestData) => _productRegistration.IsPingRequest(requestData);
111111

112-
/// <inheritdoc cref="IConnection.RequestAsync{TResponse}"/>>
112+
/// <inheritdoc cref="ITransportClient.RequestAsync{TResponse}"/>>
113113
public override Task<TResponse> RequestAsync<TResponse>(RequestData requestData, CancellationToken cancellationToken) =>
114114
Task.FromResult(Request<TResponse>(requestData));
115115

116-
/// <inheritdoc cref="IConnection.Request{TResponse}"/>>
116+
/// <inheritdoc cref="ITransportClient.Request{TResponse}"/>>
117117
public override TResponse Request<TResponse>(RequestData requestData)
118118
{
119119
if (!_calls.ContainsKey(requestData.Uri.Port))
@@ -158,7 +158,7 @@ public override TResponse Request<TResponse>(RequestData requestData)
158158
}
159159
catch (TheException e)
160160
{
161-
return ResponseBuilder.ToResponse<TResponse>(requestData, e, null, null, Stream.Null);
161+
return requestData.ConnectionSettings.ProductRegistration.ResponseBuilder.ToResponse<TResponse>(requestData, e, null, null, Stream.Null, null, -1);
162162
}
163163
}
164164

src/Elastic.Transport.VirtualizedCluster/Components/VirtualizedCluster.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ internal VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, Transport
3737
var res = await t.RequestAsync<VirtualResponse>
3838
(
3939
HttpMethod.GET, "/",
40-
CancellationToken.None,
4140
PostData.Serializable(new { }),
4241
new RequestParameters()
4342
{
4443
RequestConfiguration = r?.Invoke(new RequestConfigurationDescriptor(null))
45-
}
44+
},
45+
CancellationToken.None
4646
).ConfigureAwait(false);
4747
return (ITransportResponse)res;
4848
};
4949
}
5050

5151
public VirtualClusterConnection Connection => Transport.Settings.Connection as VirtualClusterConnection;
52-
public IConnectionPool ConnectionPool => Transport.Settings.ConnectionPool;
52+
public NodePool ConnectionPool => Transport.Settings.NodePool;
5353
public ITransport<ITransportConfiguration> Transport => _exposingRequestPipeline?.Transport;
5454

5555
public VirtualizedCluster TransportProxiesTo(

src/Elastic.Transport.VirtualizedCluster/Elastic.Transport.VirtualizedCluster.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<PackageId>Elastic.Transport.VirtualizedCluster</PackageId>
4-
<Title>Elastic.Transport.VirtualizedCluster - An in memory IConnection that can simulate large cluster</Title>
4+
<Title>Elastic.Transport.VirtualizedCluster - An in memory ITransportClient that can simulate large cluster</Title>
55
<PackageTags>elasticsearch;elastic;search;lucene;nest</PackageTags>
66
<Description>Provides a way to assert transport behaviour through a rule engine backed VirtualClusterConnection</Description>
77
<NoWarn>CS1591;$(NoWarn);IDT001</NoWarn>

src/Elastic.Transport.VirtualizedCluster/Products/IMockProductRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IMockProductRegistration
1919
IProductRegistration ProductRegistration { get; }
2020

2121
/// <summary>
22-
/// Return the sniff response for the product as raw bytes for <see cref="IConnection.Request{TResponse}"/> to return.
22+
/// Return the sniff response for the product as raw bytes for <see cref="ITransportClient.Request{TResponse}"/> to return.
2323
/// </summary>
2424
/// <param name="nodes">The nodes we expect to be returned in the response</param>
2525
/// <param name="stackVersion">The current version under test</param>

0 commit comments

Comments
 (0)