Skip to content

Commit be5fcaf

Browse files
committed
finished integration tests for all the cat api endpoints
1 parent b16f4f9 commit be5fcaf

File tree

5 files changed

+150
-36
lines changed

5 files changed

+150
-36
lines changed

src/Nest/Domain/Mapping/Descriptors/StringMappingDescriptor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Linq.Expressions;
45

@@ -135,7 +136,7 @@ public StringMappingDescriptor<T> Fields(Func<CorePropertiesDescriptor<T>, CoreP
135136
var value = p.Value as IElasticCoreType;
136137
if (value == null)
137138
continue;
138-
139+
if (_Mapping.Fields == null) _Mapping.Fields = new Dictionary<PropertyNameMarker, IElasticCoreType>();
139140
_Mapping.Fields[p.Key] = value;
140141
}
141142
return this;

src/Nest/Resolvers/Converters/CatFielddataRecordConverter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
2727
var o = new CatFielddataRecord() { FieldSizes = new Dictionary<string, string>() };
2828
while (reader.Read())
2929
{
30-
var prop = reader.Value as JProperty;
31-
switch (prop.Name)
30+
var prop = reader.Value as string;
31+
if (prop == null) return o;
32+
33+
switch (prop)
3234
{
3335
case "id":
3436
o.Id = reader.ReadAsString();
@@ -47,7 +49,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4749
o.Total = reader.ReadAsString();
4850
continue;
4951
default:
50-
o.FieldSizes[prop.Name] = reader.ReadAsString();
52+
var value = reader.ReadAsString();
53+
o.FieldSizes[prop] = value;
5154
continue;
5255
}
5356
}

src/Nest/Resolvers/Converters/CatThreadPoolRecordConverter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
3838
var o = new CatThreadPoolRecord();
3939
while (reader.Read())
4040
{
41-
var prop = reader.Value as JProperty;
42-
switch (prop.Name)
41+
var prop = reader.Value as string;
42+
if (prop == null) return o;
43+
switch (prop)
4344
{
4445
case "id":
4546
case "nodeId":
@@ -151,9 +152,9 @@ private void SetThreadPool(string threadPool, CatThreadPoolRecord o, string fiel
151152
}
152153
}
153154

154-
private static Tuple<string, string> GetThreadPoolAndField(JProperty prop)
155+
private static Tuple<string, string> GetThreadPoolAndField(string prop)
155156
{
156-
var tokens = prop.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
157+
var tokens = prop.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
157158
if (tokens.Length == 0 || tokens.Length > 2) return null;
158159
if (tokens.Length == 2) return Tuple.Create(tokens[0], tokens[1]);
159160
var match = _combinations.FirstOrDefault(c => c.Item1 + c.Item2 == tokens[0]);

src/Tests/Nest.Tests.Integration/Core/Cat/CatTests.cs

Lines changed: 121 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,71 +42,166 @@ private async Task TestCatAsync<TRecord>(Func<Task<ICatResponse<TRecord>>> call,
4242

4343

4444
[Test]
45-
public void CatAliases() { TestCat(() => this._client.CatAliases(s => s.V()), r => !r.Alias.IsNullOrEmpty()); }
45+
public void CatAliases()
46+
{
47+
TestCat(() => this._client.CatAliases(s => s.V()), r => !r.Alias.IsNullOrEmpty());
48+
}
4649

4750
[Test]
48-
public async void CatAliasesAsync() { await TestCatAsync(() => this._client.CatAliasesAsync(), r => !r.Alias.IsNullOrEmpty()); }
51+
public async void CatAliasesAsync()
52+
{
53+
await TestCatAsync(() => this._client.CatAliasesAsync(), r => !r.Alias.IsNullOrEmpty());
54+
}
4955

5056
[Test]
51-
public void CatAllocation() { TestCat(() => this._client.CatAllocation(), r => !r.Ip.IsNullOrEmpty()); }
57+
public void CatAllocation()
58+
{
59+
TestCat(() => this._client.CatAllocation(), r => !r.Node.IsNullOrEmpty());
60+
}
5261

5362
[Test]
54-
public async void CatAllocationAsync() { await TestCatAsync(() => this._client.CatAllocationAsync(), r => !r.Ip.IsNullOrEmpty()); }
63+
public async void CatAllocationAsync()
64+
{
65+
await TestCatAsync(() => this._client.CatAllocationAsync(), r => !r.Node.IsNullOrEmpty());
66+
}
67+
5568
[Test]
56-
public void CatCount() { TestCat(() => this._client.CatCount(), r => !r.Epoch.IsNullOrEmpty()); }
69+
public void CatCount()
70+
{
71+
TestCat(() => this._client.CatCount(), r => !r.Epoch.IsNullOrEmpty());
72+
}
5773

5874
[Test]
59-
public async void CatCountAsync() { await TestCatAsync(() => this._client.CatCountAsync(), r => !r.Timestamp.IsNullOrEmpty()); }
75+
public async void CatCountAsync()
76+
{
77+
await TestCatAsync(() => this._client.CatCountAsync(), r => !r.Timestamp.IsNullOrEmpty());
78+
}
79+
6080
[Test]
61-
public void CatFielddata() { TestCat(() => this._client.CatFielddata(v => v.Fields<ElasticsearchProject>(p => p.Name)), r => r.FieldSizes.ContainsKey("name")); }
81+
public void CatFielddata()
82+
{
83+
TestCat(() => this._client.CatFielddata(
84+
v => v.Fields<ElasticsearchProject>(p => p.Name)),
85+
r =>
86+
r.FieldSizes.ContainsKey("name"));
87+
}
6288

6389
[Test]
64-
public async void CatFielddataAsync() { await TestCatAsync(() => this._client.CatFielddataAsync(v => v.Fields<ElasticsearchProject>(p => p.Name)), r => r.FieldSizes.ContainsKey("name")); }
90+
public async void CatFielddataAsync()
91+
{
92+
await TestCatAsync(() => this._client.CatFielddataAsync(v => v.Fields<ElasticsearchProject>(p => p.Name)), r => r.FieldSizes.ContainsKey("name"));
93+
}
94+
6595
[Test]
66-
public void CatHealth() { TestCat(() => this._client.CatHealth(), r => !r.Cluster.IsNullOrEmpty()); }
96+
public void CatHealth()
97+
{
98+
TestCat(() => this._client.CatHealth(), r => !r.Cluster.IsNullOrEmpty());
99+
}
67100

68101
[Test]
69-
public async void CatHealthAsync() { await TestCatAsync(() => this._client.CatHealthAsync(), r => !r.NodeTotal.IsNullOrEmpty()); }
102+
public async void CatHealthAsync()
103+
{
104+
await TestCatAsync(() => this._client.CatHealthAsync(), r => !r.NodeTotal.IsNullOrEmpty());
105+
}
106+
70107
[Test]
71-
public void CatIndices() { TestCat(() => this._client.CatIndices(), r => !r.Index.IsNullOrEmpty()); }
108+
public void CatIndices()
109+
{
110+
TestCat(() => this._client.CatIndices(), r => !r.Index.IsNullOrEmpty());
111+
}
72112

73113
[Test]
74-
public async void CatIndicesAsync() { await TestCatAsync(() => this._client.CatIndicesAsync(), r => !r.DocsDeleted.IsNullOrEmpty()); }
114+
public async void CatIndicesAsync()
115+
{
116+
await TestCatAsync(() => this._client.CatIndicesAsync(), r => !r.DocsDeleted.IsNullOrEmpty());
117+
}
118+
75119
[Test]
76-
public void CatMaster() { TestCat(() => this._client.CatMaster(), r => !r.Ip.IsNullOrEmpty()); }
120+
public void CatMaster()
121+
{
122+
TestCat(() => this._client.CatMaster(), r => !r.Ip.IsNullOrEmpty());
123+
}
77124

78125
[Test]
79-
public async void CatMasterAsync() { await TestCatAsync(() => this._client.CatMasterAsync(), r => !r.Node.IsNullOrEmpty()); }
126+
public async void CatMasterAsync()
127+
{
128+
await TestCatAsync(() => this._client.CatMasterAsync(), r => !r.Node.IsNullOrEmpty());
129+
}
80130

81131
[Test]
82-
public void CatNodes() { TestCat(() => this._client.CatNodes(v => v.H("b")), r => !r.Build.IsNullOrEmpty()); }
132+
public void CatNodes()
133+
{
134+
TestCat(() => this._client.CatNodes(v => v.H("b")), r => !r.Build.IsNullOrEmpty());
135+
}
136+
83137
[Test]
84-
public async void CatNodesAsync() { await TestCatAsync(() => this._client.CatNodesAsync(v => v.Help()), r => !r.Master.IsNullOrEmpty()); }
138+
public async void CatNodesAsync()
139+
{
140+
await TestCatAsync(() => this._client.CatNodesAsync(), r => !r.Master.IsNullOrEmpty());
141+
}
85142

86143
[Test]
87-
public void CatPendingTasks() { TestCat(() => this._client.CatPendingTasks(), r => r.InsertOrder.HasValue); }
144+
public void CatPendingTasks()
145+
{
146+
var response = this._client.CatPendingTasks();
147+
response.Should().NotBeNull();
148+
response.IsValid.Should().BeTrue();
149+
}
150+
88151
[Test]
89-
public async void CatPendingTasksAsync() { await TestCatAsync(() => this._client.CatPendingTasksAsync(), r => !r.Priority.IsNullOrEmpty()); }
152+
public async void CatPendingTasksAsync()
153+
{
154+
var response = await this._client.CatPendingTasksAsync();
155+
response.Should().NotBeNull();
156+
response.IsValid.Should().BeTrue();
157+
}
90158

91159
[Test]
92-
public void CatPlugins() { TestCat(() => this._client.CatPlugins(), r => !r.Version.IsNullOrEmpty()); }
160+
public void CatPlugins()
161+
{
162+
TestCat(() => this._client.CatPlugins(), r => !r.Version.IsNullOrEmpty());
163+
}
164+
93165
[Test]
94-
public async void CatPluginsAsync() { await TestCatAsync(() => this._client.CatPluginsAsync(), r => !r.Type.IsNullOrEmpty()); }
166+
public async void CatPluginsAsync()
167+
{
168+
await TestCatAsync(() => this._client.CatPluginsAsync(), r => !r.Type.IsNullOrEmpty());
169+
}
95170

96171
[Test]
97-
public void CatRecovery() { TestCat(() => this._client.CatRecovery(), r => !r.Shard.IsNullOrEmpty()); }
172+
public void CatRecovery()
173+
{
174+
TestCat(() => this._client.CatRecovery(), r => !r.Shard.IsNullOrEmpty());
175+
}
176+
98177
[Test]
99-
public async void CatRecoveryAsync() { await TestCatAsync(() => this._client.CatRecoveryAsync(), r => !r.Files.IsNullOrEmpty()); }
178+
public async void CatRecoveryAsync()
179+
{
180+
await TestCatAsync(() => this._client.CatRecoveryAsync(), r => !r.Files.IsNullOrEmpty());
181+
}
100182

101183
[Test]
102-
public void CatThreadPool() { TestCat(() => this._client.CatThreadPool(), r => !r.Ip.IsNullOrEmpty()); }
184+
public void CatThreadPool()
185+
{
186+
TestCat(() => this._client.CatThreadPool(), r => !r.Ip.IsNullOrEmpty());
187+
}
103188
[Test]
104-
public async void CatThreadPoolAsync() { await TestCatAsync(() => this._client.CatThreadPoolAsync(v => v.H("bc")), r => r.Bulk != null && !r.Bulk.Completed.IsNullOrEmpty()); }
189+
public async void CatThreadPoolAsync()
190+
{
191+
await TestCatAsync(() => this._client.CatThreadPoolAsync(v => v.H("bc")), r => r.Bulk != null && !r.Bulk.Completed.IsNullOrEmpty());
192+
}
105193

106194
[Test]
107-
public void CatShards() { TestCat(() => this._client.CatShards(), r => !r.Node.IsNullOrEmpty()); }
195+
public void CatShards()
196+
{
197+
TestCat(() => this._client.CatShards(), r => !r.Node.IsNullOrEmpty());
198+
}
199+
108200
[Test]
109-
public async void CatShardsAsync() { await TestCatAsync(() => this._client.CatShardsAsync(), r => !r.Docs.IsNullOrEmpty()); }
201+
public async void CatShardsAsync()
202+
{
203+
await TestCatAsync(() => this._client.CatShardsAsync(), r => !r.Docs.IsNullOrEmpty());
204+
}
110205

111206
}
112207
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ public static void CreateTestIndex(IElasticClient client, string indexName)
7777
.NumberOfShards(1)
7878
.AddMapping<ElasticsearchProject>(m => m
7979
.MapFromAttributes()
80-
.Properties(p => p
81-
.String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))
80+
.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
86+
.Name("sort")
87+
.Index(FieldIndexOption.NotAnalyzed)
88+
)
89+
)
90+
)
91+
.String(s => s
92+
.Name(ep => ep.Content)
93+
.TermVector(TermVectorOption.WithPositionsOffsetsPayloads)
94+
)
8295
)
8396
)
97+
.AddAlias(indexName + "-aliased")
8498
.AddMapping<Person>(m => m.MapFromAttributes())
8599
.AddMapping<BoolTerm>(m => m.Properties(pp => pp
86100
.String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.NotAnalyzed))

0 commit comments

Comments
 (0)