Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor/request-data-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Nov 7, 2024
2 parents 111754f + 0813129 commit 5cf92e1
Show file tree
Hide file tree
Showing 63 changed files with 2,598 additions and 1,044 deletions.
7 changes: 7 additions & 0 deletions Elastic.Transport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Playground", "Playground\Pl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elastic.Elasticsearch.IntegrationTests", "tests\Elastic.Elasticsearch.IntegrationTests\Elastic.Elasticsearch.IntegrationTests.csproj", "{317C118F-FA1E-499A-B7F2-DC932DE66CB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Transport.Tests.Shared", "tests\Elastic.Transport.Tests.Shared\Elastic.Transport.Tests.Shared.csproj", "{13A2597D-F50C-4D7F-ADA9-716991C8E9DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -86,6 +88,10 @@ Global
{317C118F-FA1E-499A-B7F2-DC932DE66CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{317C118F-FA1E-499A-B7F2-DC932DE66CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{317C118F-FA1E-499A-B7F2-DC932DE66CB8}.Release|Any CPU.Build.0 = Release|Any CPU
{13A2597D-F50C-4D7F-ADA9-716991C8E9DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13A2597D-F50C-4D7F-ADA9-716991C8E9DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13A2597D-F50C-4D7F-ADA9-716991C8E9DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13A2597D-F50C-4D7F-ADA9-716991C8E9DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -100,6 +106,7 @@ Global
{ED4E89BE-FBE9-4876-979C-63A0E3BC5419} = {BBB0AC81-F09D-4895-84E2-7E933D608E78}
{5EE4DC72-B337-448B-802A-6158F4D90667} = {7610B796-BB3E-4CB2-8296-79BBFF6D23FC}
{317C118F-FA1E-499A-B7F2-DC932DE66CB8} = {3582B07D-C2B0-49CC-B676-EAF806EB010E}
{13A2597D-F50C-4D7F-ADA9-716991C8E9DE} = {3582B07D-C2B0-49CC-B676-EAF806EB010E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F60C4BB-6216-4E50-B1E4-9C38EB484843}
Expand Down
2 changes: 1 addition & 1 deletion Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

var registration = new ElasticsearchProductRegistration(typeof(Elastic.Clients.Elasticsearch.ElasticsearchClient));

Console.WriteLine(registration.DefaultMimeType ?? "NOT SPECIFIED");
Console.WriteLine(registration.DefaultContentType ?? "NOT SPECIFIED");
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ public ExposingPipelineFactory(TConfiguration configuration)
public override RequestPipeline Create(RequestData requestData) =>
new RequestPipeline(requestData);
}
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Threading;
using System.Threading.Tasks;
using Elastic.Transport.VirtualizedCluster.Products;
Expand Down Expand Up @@ -101,6 +102,8 @@ private static object DefaultResponse
}
}

public ResponseFactory ResponseFactory => _inMemoryRequestInvoker.ResponseFactory;

private void UpdateCluster(VirtualCluster cluster)
{
lock (Lock)
Expand All @@ -109,7 +112,6 @@ private void UpdateCluster(VirtualCluster cluster)
_calls = cluster.Nodes.ToDictionary(n => n.Uri.Port, v => new State());
_productRegistration = cluster.ProductRegistration;
}

}

private bool IsSniffRequest(Endpoint endpoint) => _productRegistration.IsSniffRequest(endpoint);
Expand Down Expand Up @@ -173,7 +175,7 @@ public TResponse Request<TResponse>(Endpoint endpoint, RequestData requestData,
}
catch (TheException e)
{
return requestData.ConnectionSettings.ProductRegistration.ResponseBuilder.ToResponse<TResponse>(endpoint, requestData, postData, e, null, null, Stream.Null, null, -1, null, null);
return ResponseFactory.Create<TResponse>(endpoint, requestData, postData, e, null, null, Stream.Null, null, -1, null, null);
}
}

Expand Down Expand Up @@ -326,3 +328,4 @@ private class State
public int Successes;
}
}
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ internal VirtualizedCluster(TransportConfigurationDescriptor settings)
path: RootPath,
postData: PostData.Serializable(new { }),
openTelemetryData: default,
localConfiguration: r?.Invoke(new RequestConfigurationDescriptor()),
responseBuilder: null
localConfiguration: r?.Invoke(new RequestConfigurationDescriptor())
);
_asyncCall = async (t, r) =>
{
Expand All @@ -44,14 +43,13 @@ internal VirtualizedCluster(TransportConfigurationDescriptor settings)
postData: PostData.Serializable(new { }),
openTelemetryData: default,
localConfiguration: r?.Invoke(new RequestConfigurationDescriptor()),
responseBuilder: null,
CancellationToken.None
).ConfigureAwait(false);
return res;
};
}

public VirtualClusterRequestInvoker Connection => RequestHandler.Configuration.Connection as VirtualClusterRequestInvoker;
public VirtualClusterRequestInvoker Connection => RequestHandler.Configuration.RequestInvoker as VirtualClusterRequestInvoker;
public NodePool ConnectionPool => RequestHandler.Configuration.NodePool;
public ITransport<ITransportConfiguration> RequestHandler => _exposingRequestPipeline?.Transport;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ElasticsearchVirtualCluster MasterEligible(params int[] ports)
foreach (var node in InternalNodes.Where(n => !ports.Contains(n.Uri.Port)))
{
var currentFeatures = node.Features.Count == 0 ? ElasticsearchNodeFeatures.Default : node.Features;
node.Features = currentFeatures.Except(new[] { ElasticsearchNodeFeatures.MasterEligible }).ToList().AsReadOnly();
node.Features = currentFeatures.Except([ElasticsearchNodeFeatures.MasterEligible]).ToList().AsReadOnly();
}
return this;
}
Expand All @@ -77,7 +77,7 @@ public ElasticsearchVirtualCluster StoresNoData(params int[] ports)
foreach (var node in InternalNodes.Where(n => ports.Contains(n.Uri.Port)))
{
var currentFeatures = node.Features.Count == 0 ? ElasticsearchNodeFeatures.Default : node.Features;
node.Features = currentFeatures.Except(new[] { ElasticsearchNodeFeatures.HoldsData }).ToList().AsReadOnly();
node.Features = currentFeatures.Except([ElasticsearchNodeFeatures.HoldsData]).ToList().AsReadOnly();
}
return this;
}
Expand All @@ -88,7 +88,7 @@ public VirtualCluster HttpDisabled(params int[] ports)
foreach (var node in InternalNodes.Where(n => ports.Contains(n.Uri.Port)))
{
var currentFeatures = node.Features.Count == 0 ? ElasticsearchNodeFeatures.Default : node.Features;
node.Features = currentFeatures.Except(new[] { ElasticsearchNodeFeatures.HttpEnabled }).ToList().AsReadOnly();
node.Features = currentFeatures.Except([ElasticsearchNodeFeatures.HttpEnabled]).ToList().AsReadOnly();
}
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Transport.VirtualizedCluster/Rules/RuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public TRule ReturnResponse<T>(T response)
r = ms.ToArray();
}
Self.ReturnResponse = r;
Self.ReturnContentType = RequestData.DefaultMimeType;
Self.ReturnContentType = RequestData.DefaultContentType;
return (TRule)this;
}

public TRule ReturnByteResponse(byte[] response, string responseContentType = RequestData.DefaultMimeType)
public TRule ReturnByteResponse(byte[] response, string responseContentType = RequestData.DefaultContentType)
{
Self.ReturnResponse = response;
Self.ReturnContentType = responseContentType;
Expand Down
Loading

0 comments on commit 5cf92e1

Please sign in to comment.