Skip to content

Commit d3b4f8a

Browse files
committed
Added a test to see if #588 still exists in the new version of NEST, no parsing errors occur.
1 parent de17f3c commit d3b4f8a

File tree

5 files changed

+308
-7
lines changed

5 files changed

+308
-7
lines changed

src/Tests/Nest.Tests.Unit/BaseJsonTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ protected void deb(string s)
4343
//Lazy programmers for the win!
4444
throw new Exception(s);
4545
}
46-
46+
protected ElasticClient GetFixedReturnClient(MethodBase methodInfo, string fileName)
47+
{
48+
var settings = new ConnectionSettings(Test.Default.Uri, "default-index")
49+
.ExposeRawResponse();
50+
var file = this.GetFileFromMethod(methodInfo, fileName);
51+
var jsonResponse = File.ReadAllText(file);
52+
var connection = new InMemoryConnection(this._settings, jsonResponse);
53+
var client = new ElasticClient(settings, connection);
54+
return client;
55+
}
4756
protected void JsonEquals(object o, MethodBase method, string fileName = null)
4857
{
4958
if (o is byte[])
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
2+
{
3+
"cluster_name": "elasticsearch-test",
4+
"version": 21,
5+
"master_node": "-cjsnLMrS_6gQcEBv085Bw",
6+
"blocks": {},
7+
"nodes": {
8+
"-cjsnLMrS_6gQcEBv085Bw": {
9+
"name": "Chemistro",
10+
"transport_address": "inet[/xxx]",
11+
"attributes": {}
12+
}
13+
},
14+
"metadata": {
15+
"templates": {},
16+
"indices": {
17+
"gene": {
18+
"state": "open",
19+
"settings": {
20+
"index": {
21+
"number_of_replicas": "1",
22+
"number_of_shards": "5",
23+
"uuid": "QLfWpFPQQqSkF5aRHsDfvA",
24+
"version": {
25+
"created": "1000099"
26+
}
27+
}
28+
},
29+
"mappings": {
30+
"geneviewdtos": {
31+
"properties": {
32+
"nCBILink": {
33+
"type": "string"
34+
},
35+
"symbol": {
36+
"type": "string"
37+
},
38+
"geneCardsLink": {
39+
"type": "string"
40+
},
41+
"description": {
42+
"type": "string"
43+
},
44+
"primaryKey": {
45+
"type": "long"
46+
},
47+
"comment": {
48+
"type": "string"
49+
},
50+
"identifier": {
51+
"type": "string"
52+
},
53+
"version": {
54+
"type": "integer"
55+
}
56+
}
57+
}
58+
},
59+
"aliases": []
60+
}
61+
}
62+
},
63+
"routing_table": {
64+
"indices": {
65+
"gene": {
66+
"shards": {
67+
"0": [
68+
{
69+
"state": "STARTED",
70+
"primary": true,
71+
"node": "-cjsnLMrS_6gQcEBv085Bw",
72+
"relocating_node": null,
73+
"shard": 0,
74+
"index": "gene"
75+
},
76+
{
77+
"state": "UNASSIGNED",
78+
"primary": false,
79+
"node": null,
80+
"relocating_node": null,
81+
"shard": 0,
82+
"index": "gene"
83+
}
84+
],
85+
"1": [
86+
{
87+
"state": "STARTED",
88+
"primary": true,
89+
"node": "-cjsnLMrS_6gQcEBv085Bw",
90+
"relocating_node": null,
91+
"shard": 1,
92+
"index": "gene"
93+
},
94+
{
95+
"state": "UNASSIGNED",
96+
"primary": false,
97+
"node": null,
98+
"relocating_node": null,
99+
"shard": 1,
100+
"index": "gene"
101+
}
102+
],
103+
"2": [
104+
{
105+
"state": "STARTED",
106+
"primary": true,
107+
"node": "-cjsnLMrS_6gQcEBv085Bw",
108+
"relocating_node": null,
109+
"shard": 2,
110+
"index": "gene"
111+
},
112+
{
113+
"state": "UNASSIGNED",
114+
"primary": false,
115+
"node": null,
116+
"relocating_node": null,
117+
"shard": 2,
118+
"index": "gene"
119+
}
120+
],
121+
"3": [
122+
{
123+
"state": "STARTED",
124+
"primary": true,
125+
"node": "-cjsnLMrS_6gQcEBv085Bw",
126+
"relocating_node": null,
127+
"shard": 3,
128+
"index": "gene"
129+
},
130+
{
131+
"state": "UNASSIGNED",
132+
"primary": false,
133+
"node": null,
134+
"relocating_node": null,
135+
"shard": 3,
136+
"index": "gene"
137+
}
138+
],
139+
"4": [
140+
{
141+
"state": "STARTED",
142+
"primary": true,
143+
"node": "-cjsnLMrS_6gQcEBv085Bw",
144+
"relocating_node": null,
145+
"shard": 4,
146+
"index": "gene"
147+
},
148+
{
149+
"state": "UNASSIGNED",
150+
"primary": false,
151+
"node": null,
152+
"relocating_node": null,
153+
"shard": 4,
154+
"index": "gene"
155+
}
156+
]
157+
}
158+
}
159+
}
160+
},
161+
"routing_nodes": {
162+
"unassigned": [
163+
{
164+
"state": "UNASSIGNED",
165+
"primary": false,
166+
"node": null,
167+
"relocating_node": null,
168+
"shard": 4,
169+
"index": "gene"
170+
},
171+
{
172+
"state": "UNASSIGNED",
173+
"primary": false,
174+
"node": null,
175+
"relocating_node": null,
176+
"shard": 0,
177+
"index": "gene"
178+
},
179+
{
180+
"state": "UNASSIGNED",
181+
"primary": false,
182+
"node": null,
183+
"relocating_node": null,
184+
"shard": 3,
185+
"index": "gene"
186+
},
187+
{
188+
"state": "UNASSIGNED",
189+
"primary": false,
190+
"node": null,
191+
"relocating_node": null,
192+
"shard": 1,
193+
"index": "gene"
194+
},
195+
{
196+
"state": "UNASSIGNED",
197+
"primary": false,
198+
"node": null,
199+
"relocating_node": null,
200+
"shard": 2,
201+
"index": "gene"
202+
}
203+
],
204+
"nodes": {
205+
"-cjsnLMrS_6gQcEBv085Bw": [
206+
{
207+
"state": "STARTED",
208+
"primary": true,
209+
"node": "-cjsnLMrS_6gQcEBv085Bw",
210+
"relocating_node": null,
211+
"shard": 4,
212+
"index": "gene"
213+
},
214+
{
215+
"state": "STARTED",
216+
"primary": true,
217+
"node": "-cjsnLMrS_6gQcEBv085Bw",
218+
"relocating_node": null,
219+
"shard": 0,
220+
"index": "gene"
221+
},
222+
{
223+
"state": "STARTED",
224+
"primary": true,
225+
"node": "-cjsnLMrS_6gQcEBv085Bw",
226+
"relocating_node": null,
227+
"shard": 3,
228+
"index": "gene"
229+
},
230+
{
231+
"state": "STARTED",
232+
"primary": true,
233+
"node": "-cjsnLMrS_6gQcEBv085Bw",
234+
"relocating_node": null,
235+
"shard": 1,
236+
"index": "gene"
237+
},
238+
{
239+
"state": "STARTED",
240+
"primary": true,
241+
"node": "-cjsnLMrS_6gQcEBv085Bw",
242+
"relocating_node": null,
243+
"shard": 2,
244+
"index": "gene"
245+
}
246+
]
247+
}
248+
},
249+
"allocations": []
250+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Reflection;
3+
using Elasticsearch.Net;
4+
using FluentAssertions;
5+
using NUnit.Framework;
6+
7+
namespace Nest.Tests.Unit.Cluster.State
8+
{
9+
[TestFixture]
10+
public class StateTests : BaseJsonTests
11+
{
12+
[Test]
13+
public void ClusterState()
14+
{
15+
var r = this._client.ClusterState();
16+
var u = new Uri(r.ConnectionStatus.RequestUrl);
17+
u.AbsolutePath.Should().StartWith("/_cluster/state");
18+
}
19+
20+
[Test]
21+
public void ClusterStatePerIndex()
22+
{
23+
var r = this._client.ClusterState(h=>h.Index(Test.Default.DefaultIndex).FlatSettings());
24+
var u = new Uri(r.ConnectionStatus.RequestUrl);
25+
u.AbsolutePath.Should().StartWith("/_cluster/state");
26+
u.Query.Should().Contain("flat_settings=true");
27+
}
28+
29+
[Test]
30+
public void CanMapClusterStateReturn()
31+
{
32+
var client = this.GetFixedReturnClient(MethodInfo.GetCurrentMethod(), "ClusterState");
33+
var state = client.ClusterState(s=>s.Metrics(ClusterStateMetric.All));
34+
35+
state.ClusterName.Should().Be("elasticsearch-test");
36+
state.Nodes.Count.Should().Be(1);
37+
38+
var indices = state.Metadata.Indices;
39+
indices.Count.Should().Be(1);
40+
41+
42+
}
43+
}
44+
}

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<Compile Include="BaseJsonTests.cs" />
121121
<Compile Include="Cluster\HealthTests.cs" />
122122
<Compile Include="Cluster\NodeTests.cs" />
123+
<Compile Include="Cluster\State\StateTests.cs" />
123124
<Compile Include="Core\Bulk\BulkTests.cs" />
124125
<Compile Include="Core\Bulk\BulkUrlTests.cs" />
125126
<Compile Include="Core\Map\MappingBehaviourTests.cs" />

src/Tests/Nest.Tests.Unit/Search/Fields/FieldsTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ public class ClassD : BaseClass { }
3030
[Test]
3131
public void FieldsSelectionIsCovariantAsWell()
3232
{
33-
var settings = new ConnectionSettings(Test.Default.Uri, "default-index")
34-
.ExposeRawResponse();
35-
var file = this.GetFileFromMethod(MethodInfo.GetCurrentMethod(), "FixedCovariantSearchResult");
36-
var jsonResponse = File.ReadAllText(file);
37-
var connection = new InMemoryConnection(this._settings, jsonResponse);
38-
var client = new ElasticClient(settings, connection);
33+
34+
var client = GetFixedReturnClient(MethodInfo.GetCurrentMethod(), "FixedCovariantSearchResult");
3935

4036
var results = client.Search<BaseClass>(s => s
4137
.Types(typeof(ClassA),typeof(ClassB),typeof(ClassC),typeof(ClassD))
@@ -56,5 +52,6 @@ public void FieldsSelectionIsCovariantAsWell()
5652

5753
}
5854

55+
5956
}
6057
}

0 commit comments

Comments
 (0)