Skip to content

Commit 0b92314

Browse files
committed
added tests to debug #945 ignored for now but once tests are refactored so we can start nodes in desired states they should become relevant again
1 parent 9b12ea6 commit 0b92314

File tree

5 files changed

+112
-34
lines changed

5 files changed

+112
-34
lines changed

src/Elasticsearch.Net/Connection/RequestState/TransportRequestState.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using Elasticsearch.Net.Connection.Configuration;
8+
using Elasticsearch.Net.ConnectionPool;
89
using PurifyNet;
910

1011
namespace Elasticsearch.Net.Connection.RequestState
@@ -29,6 +30,15 @@ public IRequestConfiguration RequestConfiguration
2930
}
3031
}
3132

33+
public bool UsingPooling
34+
{
35+
get
36+
{
37+
var pool = this.ClientSettings.ConnectionPool;
38+
return pool != null && pool.GetType() != typeof(SingleNodeConnectionPool);
39+
}
40+
}
41+
3242
public string Method { get; private set; }
3343

3444
public string Path { get; private set; }

src/Nest/ElasticClient-DoRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nest
88
public partial class ElasticClient
99
{
1010
/// <summary>
11-
/// Perform any request you want over the configured IConnection synchronously while taking advantage of the cluster failover.
11+
/// Perform any request you want over the configured IConnection while taking advantage of the cluster failover.
1212
/// </summary>
1313
/// <typeparam name="T">The type representing the response JSON</typeparam>
1414
/// <param name="method">the HTTP Method to use</param>

src/Tests/Nest.Tests.Integration/IntegrationSetup.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,41 @@
88
using Nest.Tests.MockData.Domain;
99
using NUnit.Framework;
1010

11-
[SetUpFixture]
12-
public class SetupAndTeardownForIntegrationTests
11+
[SetUpFixture]
12+
public class SetupAndTeardownForIntegrationTests
13+
{
14+
[SetUp]
15+
public void Setup()
1316
{
14-
[SetUp]
15-
public void Setup()
16-
{
17-
var client = new ElasticClient(
18-
//ElasticsearchConfiguration.Settings(hostOverride: new Uri("http://localhost:9200"))
19-
ElasticsearchConfiguration.Settings()
20-
);
21-
22-
try
23-
{
24-
IntegrationSetup.CreateTestIndex(client, ElasticsearchConfiguration.DefaultIndex);
25-
IntegrationSetup.CreateTestIndex(client, ElasticsearchConfiguration.DefaultIndex + "_clone");
17+
var client = new ElasticClient(
18+
//ElasticsearchConfiguration.Settings(hostOverride: new Uri("http://localhost:9200"))
19+
ElasticsearchConfiguration.Settings()
20+
);
2621

27-
IntegrationSetup.IndexDemoData(client);
28-
}
29-
catch (Exception)
30-
{
31-
32-
throw;
33-
}
22+
try
23+
{
24+
IntegrationSetup.CreateTestIndex(client, ElasticsearchConfiguration.DefaultIndex);
25+
IntegrationSetup.CreateTestIndex(client, ElasticsearchConfiguration.DefaultIndex + "_clone");
3426

27+
IntegrationSetup.IndexDemoData(client);
3528
}
36-
[TearDown]
37-
public void TearDown()
29+
catch (Exception)
3830
{
39-
var client = ElasticsearchConfiguration.Client.Value;
40-
client.DeleteIndex(di => di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndex + "*"));
31+
32+
throw;
4133
}
34+
4235
}
36+
[TearDown]
37+
public void TearDown()
38+
{
39+
var client = ElasticsearchConfiguration.Client.Value;
40+
client.DeleteIndex(di => di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndex + "*"));
41+
}
42+
}
43+
4344
namespace Nest.Tests.Integration
4445
{
45-
46-
4746
public static class IntegrationSetup
4847
{
4948
public static void IndexDemoData(IElasticClient client, string index = null)
@@ -78,11 +77,11 @@ public static void CreateTestIndex(IElasticClient client, string indexName)
7877
.AddMapping<ElasticsearchProject>(m => m
7978
.MapFromAttributes()
8079
.Properties(props => props
81-
.String(s=>s
82-
.Name(p=>p.Name)
83-
.FieldData(fd=>fd.Loading(FieldDataLoading.Eager))
84-
.Fields(fields=>fields
85-
.String(ss=>ss
80+
.String(s => s
81+
.Name(p => p.Name)
82+
.FieldData(fd => fd.Loading(FieldDataLoading.Eager))
83+
.Fields(fields => fields
84+
.String(ss => ss
8685
.Name("sort")
8786
.Index(FieldIndexOption.NotAnalyzed)
8887
)
@@ -104,6 +103,6 @@ public static void CreateTestIndex(IElasticClient client, string indexName)
104103
createIndexResult.IsValid.Should().BeTrue();
105104
}
106105

107-
106+
108107
}
109108
}

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<Compile Include="Indices\StatsTests.cs" />
176176
<Compile Include="Core\AsyncTests.cs" />
177177
<Compile Include="Mapping\MappingVisitorTests.cs" />
178+
<Compile Include="Reproduce\Reproduce945Tests.cs" />
178179
<Compile Include="Reproduce\Reproduce769Tests.cs" />
179180
<Compile Include="Search\Filter\AndOrNotFilterTests.cs" />
180181
<Compile Include="Search\Filter\ScriptFilterTests.cs" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Text;
2+
using Elasticsearch.Net.ConnectionPool;
3+
using FluentAssertions;
4+
using Nest.Tests.Integration;
5+
using Nest.Tests.MockData;
6+
using Nest.Tests.MockData.Domain;
7+
using NUnit.Framework;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
12+
namespace Nest.Tests.Integration.Reproduce
13+
{
14+
[TestFixture]
15+
public class Reproduce945Tests
16+
{
17+
[Test]
18+
[Ignore("Depends on setting max request size on server")]
19+
public void WhenPostExceedsHttpLimit_DoNotRetry_UsingConnectionPooling()
20+
{
21+
var pool = new StaticConnectionPool(new []
22+
{
23+
new Uri("http://localhost:9200"),
24+
new Uri("http://127.0.0.1:9200"),
25+
});
26+
var settings = new ConnectionSettings(pool);
27+
var client = new ElasticClient(settings);
28+
29+
30+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
31+
var projects = NestTestData.Data;
32+
var people = NestTestData.People;
33+
var boolTerms = NestTestData.BoolTerms;
34+
var bulk = client.Bulk(b => b
35+
.FixedPath(index)
36+
.IndexMany(projects)
37+
.IndexMany(people)
38+
.IndexMany(boolTerms)
39+
);
40+
41+
bulk.IsValid.Should().BeFalse();
42+
bulk.ConnectionStatus.NumberOfRetries.Should().Be(0);
43+
}
44+
45+
[Test]
46+
[Ignore("Depends on setting max request size on server")]
47+
public void WhenPostExceedsHttpLimit_DoNotRetry_UsingPlainRetry()
48+
{
49+
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
50+
.MaximumRetries(2);
51+
var client = new ElasticClient(settings);
52+
53+
var index = ElasticsearchConfiguration.NewUniqueIndexName();
54+
var projects = NestTestData.Data;
55+
var people = NestTestData.People;
56+
var boolTerms = NestTestData.BoolTerms;
57+
var bulk = client.Bulk(b => b
58+
.FixedPath(index)
59+
.IndexMany(projects)
60+
.IndexMany(people)
61+
.IndexMany(boolTerms)
62+
);
63+
64+
bulk.IsValid.Should().BeFalse();
65+
bulk.ConnectionStatus.NumberOfRetries.Should().Be(0);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)