Skip to content

Commit c86734d

Browse files
committed
Pipeline simulation integration tests
1 parent 54e4bd2 commit c86734d

File tree

4 files changed

+215
-17
lines changed

4 files changed

+215
-17
lines changed

Diff for: src/Nest/Ingest/SimulatePipeline/SimulatePipelineRequest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ namespace Nest
77
public partial interface ISimulatePipelineRequest
88
{
99
[JsonProperty("pipeline")]
10-
Pipeline Pipeline { get; set; }
10+
IPipeline Pipeline { get; set; }
1111

1212
[JsonProperty("docs")]
1313
IEnumerable<ISimulatePipelineDocument> Documents { get; set; }
1414
}
1515

1616
public partial class SimulatePipelineRequest
1717
{
18-
public Pipeline Pipeline { get; set; }
18+
public IPipeline Pipeline { get; set; }
1919

2020
public IEnumerable<ISimulatePipelineDocument> Documents { get; set; }
2121
}
2222

2323
[DescriptorFor("IngestSimulate")]
2424
public partial class SimulatePipelineDescriptor
2525
{
26-
Pipeline ISimulatePipelineRequest.Pipeline { get; set; }
26+
IPipeline ISimulatePipelineRequest.Pipeline { get; set; }
2727

2828
IEnumerable<ISimulatePipelineDocument> ISimulatePipelineRequest.Documents { get; set; }
2929

30-
public SimulatePipelineDescriptor Pipeline(Func<PipelineDescriptor, Pipeline> pipeline) =>
30+
public SimulatePipelineDescriptor Pipeline(Func<PipelineDescriptor, IPipeline> pipeline) =>
3131
Assign(a => a.Pipeline = pipeline?.Invoke(new PipelineDescriptor()));
3232

3333
public SimulatePipelineDescriptor Documents(IEnumerable<ISimulatePipelineDocument> documents) => Assign(a => a.Documents = documents);

Diff for: src/Nest/Ingest/SimulatePipeline/SimulatePipelineResponse.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public class PipelineSimulation
3030

3131
[JsonProperty("doc")]
3232
public DocumentSimulation Document { get; internal set; }
33-
34-
[JsonProperty("_ingest")]
35-
public Ingest Ingest { get; internal set; }
3633
}
3734

3835
[JsonObject(MemberSerialization.OptIn)]
@@ -60,13 +57,16 @@ public class DocumentSimulation
6057
public long? Ttl { get; internal set; }
6158

6259
[JsonProperty("_source")]
63-
public object Source { get; internal set; }
60+
public ILazyDocument Source { get; internal set; }
61+
62+
[JsonProperty("_ingest")]
63+
public Ingest Ingest { get; internal set; }
6464
}
6565

6666
[JsonObject(MemberSerialization.OptIn)]
6767
public class Ingest
6868
{
69-
[JsonProperty("_timestamp")]
70-
public long? Timestamp { get; internal set; }
69+
[JsonProperty("timestamp")]
70+
public DateTime Timestamp { get; internal set; }
7171
}
7272
}

Diff for: src/Tests/Framework/Integration/Process/ElasticsearchNode.cs

-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ private IObservable<ElasticsearchMessage> UseAlreadyRunningInstance(ManualResetE
252252
return Observable.Empty<ElasticsearchMessage>();
253253
}
254254

255-
private static object _licenseLock = new object();
256-
257255
private void ValidateLicense()
258256
{
259257
var client = TestClient.GetClient();

Diff for: src/Tests/Ingest/SimulatePipeline/SImulatePipelineApiTests.cs

+205-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
using Tests.Framework;
55
using Tests.Framework.Integration;
66
using Xunit;
7+
using Tests.Framework.MockData;
8+
using FluentAssertions;
9+
using System.Linq;
710

811
namespace Tests.Ingest.SimulatePipeline
912
{
1013
[Collection(IntegrationContext.ReadOnly)]
11-
public class SimulatePipelineApiTests : ApiTestBase<ISimulatePipelineResponse, ISimulatePipelineRequest, SimulatePipelineDescriptor, SimulatePipelineRequest>
14+
public class SimulatePipelineApiTests
15+
: ApiIntegrationTestBase<ISimulatePipelineResponse, ISimulatePipelineRequest, SimulatePipelineDescriptor, SimulatePipelineRequest>
1216
{
1317
public SimulatePipelineApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1418

@@ -22,19 +26,215 @@ protected override LazyResponses ClientUsage() => Calls(
2226
);
2327

2428
protected override HttpMethod HttpMethod => HttpMethod.POST;
25-
protected override string UrlPath => $"/_ingest/pipeline/{_id}/_simulate";
26-
29+
protected override string UrlPath => $"/_ingest/pipeline/_simulate";
30+
protected override int ExpectStatusCode => 200;
31+
protected override bool ExpectIsValid => true;
2732
protected override bool SupportsDeserialization => false;
2833

2934
protected override object ExpectJson { get; } = new
3035
{
36+
pipeline = new
37+
{
38+
description = "pipeline simulation",
39+
processors = new object []
40+
{
41+
new
42+
{
43+
set = new
44+
{
45+
field = "name",
46+
value = "buzz"
47+
}
48+
},
49+
new
50+
{
51+
append = new
52+
{
53+
field = "colors",
54+
value = new [] { "blue", "black" }
55+
}
56+
},
57+
new
58+
{
59+
uppercase = new
60+
{
61+
field = "name"
62+
}
63+
}
64+
}
65+
},
66+
docs = new object []
67+
{
68+
new
69+
{
70+
_index = "project",
71+
_type = "project",
72+
_id = Project.Instance.Name,
73+
_source = Project.Instance
74+
},
75+
new
76+
{
77+
_index = "otherindex",
78+
_type = "othertype",
79+
_id = "otherid",
80+
_source = Project.Instance
81+
},
82+
new
83+
{
84+
_index = "otherindex",
85+
_type = "anotherType",
86+
_id = "2",
87+
_source = new { id = "2", colors = new [] { "red" } }
88+
}
89+
}
3190
};
3291

92+
protected override void ExpectResponse(ISimulatePipelineResponse response)
93+
{
94+
response.IsValid.Should().BeTrue();
95+
response.Documents.Should().NotBeNull().And.HaveCount(3);
96+
97+
var simulation = response.Documents.Where(d => d.Document.Id == Project.Instance.Name).FirstOrDefault();
98+
simulation.Should().NotBeNull();
99+
simulation.Document.Ingest.Should().NotBeNull();
100+
simulation.Document.Ingest.Timestamp.Should().NotBe(default(DateTime));
101+
var project = simulation.Document.Source.As<Project>();
102+
project.Should().NotBeNull();
103+
project.Name.Should().Be("BUZZ");
104+
105+
simulation = response.Documents.Where(d => d.Document.Id == "otherid").FirstOrDefault();
106+
simulation.Should().NotBeNull();
107+
simulation.Document.Ingest.Should().NotBeNull();
108+
simulation.Document.Ingest.Timestamp.Should().NotBe(default(DateTime));
109+
project = simulation.Document.Source.As<Project>();
110+
project.Name.Should().Be("BUZZ");
111+
112+
simulation = response.Documents.Where(d => d.Document.Id == "2").FirstOrDefault();
113+
simulation.Document.Ingest.Should().NotBeNull();
114+
simulation.Document.Ingest.Timestamp.Should().NotBe(default(DateTime));
115+
var anotherType = simulation.Document.Source.As<AnotherType>();
116+
anotherType.Should().NotBeNull();
117+
anotherType.Colors.Should().BeEquivalentTo(new string[] { "red", "blue", "black" });
118+
}
119+
120+
public class AnotherType
121+
{
122+
public string Id { get; set; }
123+
public string[] Colors { get; set; }
124+
}
125+
33126
protected override Func<SimulatePipelineDescriptor, ISimulatePipelineRequest> Fluent => d => d
34-
.Id(_id);
127+
.Pipeline(pl => pl
128+
.Description("pipeline simulation")
129+
.Processors(ps => ps
130+
.Set<Project>(s => s
131+
.Field(p => p.Name)
132+
.Value("buzz")
133+
)
134+
.Append<AnotherType>(a => a
135+
.Field(p => p.Colors)
136+
.Value("blue", "black")
137+
)
138+
.Uppercase<Project>(u => u
139+
.Field(p => p.Name)
140+
)
141+
)
142+
)
143+
.Documents(ds => ds
144+
.Document(doc => doc
145+
.Source(Project.Instance)
146+
)
147+
.Document(doc => doc
148+
.Source(Project.Instance)
149+
.Index("otherindex")
150+
.Type("othertype")
151+
.Id("otherid")
152+
)
153+
.Document(doc => doc
154+
.Index("otherindex")
155+
.Type("anotherType")
156+
.Source(new AnotherType { Id = "2", Colors = new string[] { "red" } })
157+
)
158+
);
35159

36-
protected override SimulatePipelineRequest Initializer => new SimulatePipelineRequest(_id)
160+
protected override SimulatePipelineRequest Initializer => new SimulatePipelineRequest
37161
{
162+
Pipeline = new Pipeline
163+
{
164+
Description = "pipeline simulation",
165+
Processors = new IProcessor[]
166+
{
167+
new SetProcessor
168+
{
169+
Field = "name",
170+
Value = "buzz"
171+
},
172+
new AppendProcessor
173+
{
174+
Field = "colors",
175+
Value = new [] { "blue", "black"}
176+
},
177+
new UppercaseProcessor
178+
{
179+
Field = "name"
180+
}
181+
}
182+
},
183+
Documents = new SimulatePipelineDocument[]
184+
{
185+
new SimulatePipelineDocument
186+
{
187+
Source = Project.Instance
188+
},
189+
new SimulatePipelineDocument
190+
{
191+
Source = Project.Instance,
192+
Index = "otherindex",
193+
Type = "othertype",
194+
Id = "otherid"
195+
},
196+
new SimulatePipelineDocument
197+
{
198+
Index = "otherindex",
199+
Type = "anotherType",
200+
Source = new AnotherType { Id = "2", Colors = new [] { "red" } }
201+
}
202+
}
38203
};
39204
}
205+
206+
[Collection(IntegrationContext.ReadOnly)]
207+
public class SimulatePipelineVerboseApiTests : SimulatePipelineApiTests
208+
{
209+
public SimulatePipelineVerboseApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
210+
211+
protected override string UrlPath => $"/_ingest/pipeline/_simulate?verbose=true";
212+
213+
protected override void ExpectResponse(ISimulatePipelineResponse response)
214+
{
215+
response.IsValid.Should().BeTrue();
216+
response.Documents.Count.Should().Be(3);
217+
foreach (var doc in response.Documents)
218+
{
219+
doc.ProcessorResults.Should().NotBeNull();
220+
foreach (var result in doc.ProcessorResults)
221+
{
222+
result.Document.Should().NotBeNull();
223+
result.Document.Ingest.Should().NotBeNull();
224+
}
225+
}
226+
}
227+
228+
protected override Func<SimulatePipelineDescriptor, ISimulatePipelineRequest> Fluent => f => base.Fluent(f.Verbose());
229+
230+
protected override SimulatePipelineRequest Initializer
231+
{
232+
get
233+
{
234+
var initializer = base.Initializer;
235+
initializer.Verbose = true;
236+
return initializer;
237+
}
238+
}
239+
}
40240
}

0 commit comments

Comments
 (0)