Skip to content

Commit

Permalink
Add small fixes trying to reintegrate into the clients locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Oct 21, 2020
1 parent 81e4b4c commit ede0d9e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>

<SolutionRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.bat))</SolutionRoot>

<MinVerDefaultPreReleasePhase>canary</MinVerDefaultPreReleasePhase>
<MinVerMinimumMajorMinor>0.1</MinVerMinimumMajorMinor>

<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>False</IsPackable>

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(SolutionRoot)\build\keys\keypair.snk</AssemblyOriginatorKeyFile>

<DefineConstants Condition="'$(TargetFramework)'=='net461'">$(DefineConstants);FULLFRAMEWORK</DefineConstants>
<DefineConstants Condition="$(DefineConstants.Contains(FULLFRAMEWORK)) == False">$(DefineConstants);DOTNETCORE</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Transport.Products;
using Elastic.Transport.Products.Elasticsearch;
using Elastic.Transport.VirtualizedCluster.Products;

namespace Elastic.Transport.VirtualizedCluster.Components
{
/// <summary>
/// An implementation that exposes all the components so that <see cref="VirtualCluster"/> can reference them directly.
/// </summary>
internal class ExposingPipelineFactory : IRequestPipelineFactory
public class ExposingPipelineFactory : IRequestPipelineFactory
{
public ExposingPipelineFactory(ITransportConfigurationValues connectionSettings, IDateTimeProvider dateTimeProvider)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Transport/Products/DefaultProductRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public bool HttpStatusCodeClassifier(HttpMethod method, int statusCode) =>
statusCode >= 200 && statusCode < 300;

/// <inheritdoc cref="IProductRegistration.TryGetServerErrorReason{TResponse}"/>>
public bool TryGetServerErrorReason<TResponse>(TResponse response, out string o)
public bool TryGetServerErrorReason<TResponse>(TResponse response, out string reason)
where TResponse : ITransportResponse
{
o = null;
reason = null;
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public bool NodePredicate(Node node) =>
!node.HasFeature(ElasticsearchNodeFeatures.HoldsData));

/// <inheritdoc cref="IProductRegistration.HttpStatusCodeClassifier"/>
public bool HttpStatusCodeClassifier(HttpMethod method, int statusCode) =>
public virtual bool HttpStatusCodeClassifier(HttpMethod method, int statusCode) =>
statusCode >= 200 && statusCode < 300;

/// <inheritdoc cref="IProductRegistration.TryGetServerErrorReason{TResponse}"/>>
public bool TryGetServerErrorReason<TResponse>(TResponse response, out string o)
public virtual bool TryGetServerErrorReason<TResponse>(TResponse response, out string reason)
where TResponse : ITransportResponse
{
o = null;
if (response is StringResponse s && s.TryGetElasticsearchServerError(out var e)) o = e.Error?.ToString();
else if (response is BytesResponse b && b.TryGetElasticsearchServerError(out e)) o = e.Error?.ToString();
else if (response.TryGetElasticsearchServerError(out e)) o = e.Error?.ToString();
reason = null;
if (response is StringResponse s && s.TryGetElasticsearchServerError(out var e)) reason = e.Error?.ToString();
else if (response is BytesResponse b && b.TryGetElasticsearchServerError(out e)) reason = e.Error?.ToString();
else if (response.TryGetElasticsearchServerError(out e)) reason = e.Error?.ToString();
return e != null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Transport/Products/IProductRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ IMemoryStreamFactory memoryStreamFactory
bool HttpStatusCodeClassifier(HttpMethod method, int statusCode);

/// <summary> Try to obtain a server error from the response, this is used for debugging and exception messages </summary>
bool TryGetServerErrorReason<TResponse>(TResponse response, out string o) where TResponse : ITransportResponse;
bool TryGetServerErrorReason<TResponse>(TResponse response, out string reason) where TResponse : ITransportResponse;
}
}
4 changes: 2 additions & 2 deletions src/Elastic.Transport/Requests/Body/PostData.MultiJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract partial class PostData
/// Create a <see cref="PostData"/> instance that will write the <paramref name="listOfString"/> as multiline/ndjson.
/// </summary>
public static PostData MultiJson(IEnumerable<string> listOfString) =>
new PostDataMultiJson<object>(listOfString);
new PostDataMultiJson<string>(listOfString);

/// <summary>
/// Create a <see cref="PostData"/> instance that will serialize the <paramref name="listOfSerializables"/> as multiline/ndjson.
Expand Down Expand Up @@ -68,7 +68,7 @@ public override void Write(Stream writableStream, ITransportConfigurationValues
stream.Write(NewLineByteArray, 0, 1);
} while (enumerator.MoveNext());

return;
break;
}
case PostType.EnumerableOfObject:
{
Expand Down
22 changes: 22 additions & 0 deletions tests/Elastic.Transport.Tests/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Elastic.Transport.Products.Elasticsearch;

namespace Elastic.Transport.Tests
{
public class Test
{
public void Usage()
{
var pool = new StaticConnectionPool(new [] { new Node(new Uri("http://localhost:9200")) });
var connection = new HttpConnection();
var serializer = LowLevelRequestResponseSerializer.Instance;

var product = ElasticsearchProductRegistration.Default;
var settings = new TransportConfiguration(pool, connection, serializer, product);
var transport = new Transport<TransportConfiguration>(settings);

var response = transport.Request<StringResponse>(HttpMethod.GET, "/");
}

}
}

0 comments on commit ede0d9e

Please sign in to comment.