-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #1 include better integration tests for IndexChannel and DataStre…
…amChannel (#2) * fix #1 include better integration tests for IndexChannel and DataStreamChannel * include shared Elastic DotSettings file * update license headers * remove unwanted linefeed in shared settings to apply standard license header
- Loading branch information
Showing
39 changed files
with
761 additions
and
91 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/DataStreams/DataStreamChannel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/DataStreams/DataStreamChannelOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/DataStreams/DataStreamName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/ElasticsearchBufferOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/ElasticsearchChannelOptionsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/Serialization/BulkOperationHeader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/Serialization/BulkResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Elastic.Ingest.Elasticsearch/Serialization/BulkResponseItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/Elastic.Ingest.Elasticsearch.IntegrationTests/DataStreamIngestionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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 System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elastic.Clients.Elasticsearch.IndexManagement; | ||
using Elastic.Elasticsearch.Managed; | ||
using Elastic.Ingest.Elasticsearch.DataStreams; | ||
using Elastic.Transport; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.IntegrationTests | ||
{ | ||
public class DataStreamIngestionTests : IntegrationTestBase | ||
{ | ||
public DataStreamIngestionTests(IngestionCluster cluster, ITestOutputHelper output) : base(cluster, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task EnsureDocumentsEndUpInDataStream() | ||
{ | ||
// logs-* will use data streams by default in Elasticsearch. | ||
var targetDataStream = new DataStreamName("logs", "dotnet"); | ||
var slim = new CountdownEvent(1); | ||
var options = new DataStreamChannelOptions<TimeSeriesDocument>(Client.Transport) | ||
{ | ||
DataStream = targetDataStream, | ||
BufferOptions = new ElasticsearchBufferOptions<TimeSeriesDocument> | ||
{ | ||
WaitHandle = slim, MaxConsumerBufferSize = 1, | ||
} | ||
}; | ||
var ecsChannel = new DataStreamChannel<TimeSeriesDocument>(options); | ||
|
||
var dataStream = | ||
await Client.Indices.GetDataStreamAsync(new GetDataStreamRequest(targetDataStream.ToString())); | ||
dataStream.DataStreams.Should().BeNullOrEmpty(); | ||
|
||
ecsChannel.TryWrite(new TimeSeriesDocument { Timestamp = DateTimeOffset.Now, Message = "hello-world" }); | ||
if (!slim.WaitHandle.WaitOne(TimeSpan.FromSeconds(10))) | ||
throw new Exception("ecs document was not persisted within 10 seconds"); | ||
|
||
var refreshResult = await Client.Indices.RefreshAsync(targetDataStream.ToString()); | ||
refreshResult.IsValidResponse.Should().BeTrue("{0}", refreshResult.DebugInformation); | ||
var searchResult = await Client.SearchAsync<TimeSeriesDocument>(s => s.Indices(targetDataStream.ToString())); | ||
searchResult.Total.Should().Be(1); | ||
|
||
var storedDocument = searchResult.Documents.First(); | ||
storedDocument.Message.Should().Be("hello-world"); | ||
|
||
var hit = searchResult.Hits.First(); | ||
hit.Index.Should().StartWith($".ds-{targetDataStream}-"); | ||
|
||
// the following throws in the 8.0.4 version of the client | ||
// The JSON value could not be converted to Elastic.Clients.Elasticsearch.HealthStatus. Path: $.data_stre... | ||
// await Client.Indices.GetDataStreamAsync(new GetDataStreamRequest(targetDataStream.ToString()) | ||
var getDataStream = | ||
await Client.Transport.RequestAsync<StringResponse>(HttpMethod.GET, $"/_data_stream/{targetDataStream}"); | ||
|
||
getDataStream.ApiCallDetails.HttpStatusCode.Should() | ||
.Be(200, "{0}", getDataStream.ApiCallDetails.DebugInformation); | ||
|
||
} | ||
} | ||
} |
File renamed without changes.
70 changes: 70 additions & 0 deletions
70
tests/Elastic.Ingest.Elasticsearch.IntegrationTests/IndexIngestionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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 System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elastic.Clients.Elasticsearch; | ||
using Elastic.Clients.Elasticsearch.IndexManagement; | ||
using Elastic.Elasticsearch.Managed; | ||
using Elastic.Ingest.Elasticsearch.DataStreams; | ||
using Elastic.Ingest.Elasticsearch.Indices; | ||
using Elastic.Transport; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.IntegrationTests | ||
{ | ||
public class IndexIngestionTests : IntegrationTestBase | ||
{ | ||
public IndexIngestionTests(IngestionCluster cluster, ITestOutputHelper output) : base(cluster, output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task EnsureDocumentsEndUpInIndex() | ||
{ | ||
var indexPrefix = "catalog-data-"; | ||
var slim = new CountdownEvent(1); | ||
var options = new IndexChannelOptions<CatalogDocument>(Client.Transport) | ||
{ | ||
IndexFormat = indexPrefix + "{0:yyyy.MM.dd}", | ||
BulkOperationIdLookup = c => c.Id, | ||
TimestampLookup = c => c.Created, | ||
BufferOptions = new ElasticsearchBufferOptions<CatalogDocument> | ||
{ | ||
WaitHandle = slim, MaxConsumerBufferSize = 1, | ||
} | ||
}; | ||
var ecsChannel = new IndexChannel<CatalogDocument>(options); | ||
|
||
var date = DateTimeOffset.Now; | ||
var indexName = string.Format(options.IndexFormat, date); | ||
|
||
var index = await Client.Indices.GetAsync(new GetIndexRequest(indexName)); | ||
index.Indices.Should().BeNullOrEmpty(); | ||
|
||
ecsChannel.TryWrite(new CatalogDocument { Created = date, Title = "Hello World!", Id = "hello-world" }); | ||
if (!slim.WaitHandle.WaitOne(TimeSpan.FromSeconds(10))) | ||
throw new Exception("ecs document was not persisted within 10 seconds"); | ||
|
||
var refreshResult = await Client.Indices.RefreshAsync(indexName); | ||
refreshResult.IsValidResponse.Should().BeTrue("{0}", refreshResult.DebugInformation); | ||
var searchResult = await Client.SearchAsync<CatalogDocument>(s => s.Indices(indexName)); | ||
searchResult.Total.Should().Be(1); | ||
|
||
var storedDocument = searchResult.Documents.First(); | ||
storedDocument.Id.Should().Be("hello-world"); | ||
storedDocument.Title.Should().Be("Hello World!"); | ||
|
||
var hit = searchResult.Hits.First(); | ||
hit.Index.Should().Be(indexName); | ||
|
||
index = await Client.Indices.GetAsync(new GetIndexRequest(indexName)); | ||
index.Indices.Should().NotBeNullOrEmpty(); | ||
|
||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Elastic.Ingest.Elasticsearch.IntegrationTests/IngestionCluster.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// 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 System; | ||
using System.Linq; | ||
using Elastic.Clients.Elasticsearch; | ||
using Elastic.Elasticsearch.Xunit; | ||
using Elastic.Transport; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
[assembly: TestFramework("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")] | ||
|
||
namespace Elastic.Ingest.Elasticsearch.IntegrationTests | ||
{ | ||
/// <summary> Declare our cluster that we want to inject into our test classes </summary> | ||
public class IngestionCluster : XunitClusterBase | ||
{ | ||
public IngestionCluster() : base(new XunitClusterConfiguration("8.3.1") { StartingPortNumber = 9202 }) { } | ||
|
||
public ElasticsearchClient CreateClient(ITestOutputHelper output) => | ||
this.GetOrAddClient(c => | ||
{ | ||
var hostName = (System.Diagnostics.Process.GetProcessesByName("mitmproxy").Any() | ||
? "ipv4.fiddler" | ||
: "localhost"); | ||
var nodes = NodesUris(hostName); | ||
var connectionPool = new StaticNodePool(nodes); | ||
var settings = new ElasticsearchClientSettings(connectionPool) | ||
.Proxy(new Uri("http://ipv4.fiddler:8080"), (string)null, (string)null) | ||
.OnRequestCompleted(d => | ||
{ | ||
try { output.WriteLine(d.DebugInformation);} | ||
catch { } | ||
}) | ||
.EnableDebugMode(); | ||
return new ElasticsearchClient(settings); | ||
}); | ||
} | ||
} |
Oops, something went wrong.