Skip to content

Move intrusive xpack tests to own cluster #4446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/scripts/scripts.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="FSharp.Core" Version="4.7.0" />

<PackageReference Include="Bullseye" Version="3.1.0" />
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20191209T135928" />
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20200224T155731" />

<PackageReference Include="Fake.Core.Environment" Version="5.15.0" />
<PackageReference Include="Fake.Core.SemVer" Version="5.15.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,63 @@ var myGeoHashGrid = response.Aggregations.GeoHash("my_geohash_grid");
myGeoHashGrid.Should().NotBeNull();
----

==== Fluent DSL example

[source,csharp]
----
a => a
.GeoHash("my_geohash_grid", g => g
.Field(p => p.LocationPoint)
.Bounds(b => b
.TopLeft(90,-180)
.BottomRight(-90, 180)
)
)
----

==== Object Initializer syntax example

[source,csharp]
----
new GeoHashGridAggregation("my_geohash_grid")
{
Field = Field<Project>(p => p.LocationPoint),
Bounds = new BoundingBox
{
TopLeft = new GeoLocation(90, -180),
BottomRight = new GeoLocation(-90, 180)
}
}
----

[source,javascript]
.Example json output
----
{
"my_geohash_grid": {
"geohash_grid": {
"field": "locationPoint",
"bounds": {
"top_left": {
"lat": 90.0,
"lon": -180.0
},
"bottom_right": {
"lat": -90.0,
"lon": 180.0
}
}
}
}
}
----

==== Handling Responses

[source,csharp]
----
response.ShouldBeValid();
var myGeoHashGrid = response.Aggregations.GeoHash("my_geohash_grid");
myGeoHashGrid.Should().NotBeNull();
----

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ q
new RankFeatureQuery()
{
Name = "named_query",
Boost = 1.1,
Boost = 1.1,
Field = Infer.Field<Project>(f => f.Rank),
Function = new RankFeatureSaturationFunction()
}
Expand All @@ -63,3 +63,39 @@ new RankFeatureQuery()
}
----

==== Fluent DSL example

[source,csharp]
----
q
.RankFeature(rf => rf
.Name("named_query")
.Boost(1.1)
.Field(f => f.Rank)
)
----

==== Object Initializer syntax example

[source,csharp]
----
new RankFeatureQuery
{
Name = "named_query",
Boost = 1.1,
Field = Infer.Field<Project>(f => f.Rank),
}
----

[source,javascript]
.Example json output
----
{
"rank_feature": {
"_name": "named_query",
"boost": 1.1,
"field": "rank"
}
}
----

2 changes: 1 addition & 1 deletion tests/Tests.Configuration/Tests.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20191209T135928" />
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20200224T155731" />
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions tests/Tests.Core/Extensions/ClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Elasticsearch.Net;
using Nest;

namespace Tests.Core.Extensions
{
public static class ClientExtensions
{
public static ClusterHealthResponse WaitForSecurityIndices(this IElasticClient client) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it's called?

client.Cluster.Health(new ClusterHealthRequest(".security-*") { WaitForStatus = WaitForStatus.Green });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ protected virtual ConnectionSettings ConnectionSettings(ConnectionSettings s) =>
protected sealed override void SeedCluster()
{
Client.Cluster.Health(new ClusterHealthRequest { WaitForStatus = WaitForStatus.Green });
Client.Cluster.Health(new ClusterHealthRequest(".security-7") { WaitForStatus = WaitForStatus.Green });
SeedNode();
Client.Cluster.Health(new ClusterHealthRequest { WaitForStatus = WaitForStatus.Green });
Client.Cluster.Health(new ClusterHealthRequest(".security-7") { WaitForStatus = WaitForStatus.Green });
}

protected virtual void SeedNode() => new DefaultSeeder(Client).SeedNode();
Expand Down
2 changes: 1 addition & 1 deletion tests/Tests.Core/Tests.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="coverlet.collector" Version="1.1.0" />
<PackageReference Include="Elastic.Xunit" Version="0.1.0-ci20191209T135928" />
<PackageReference Include="Elastic.Xunit" Version="0.1.0-ci20200224T155731" />
<PackageReference Include="FluentAssertions" Version="5.7.0" />

<PackageReference Include="DiffPlex" Version="1.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Tests.Domain/Tests.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="22.1.2" />
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20191209T135928" />
<PackageReference Include="Elastic.Managed" Version="0.1.0-ci20200224T155731" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<ProjectReference Include="$(SolutionRoot)\tests\Tests.Configuration\Tests.Configuration.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Tests.Modules.SnapshotAndRestore.Repositories.CleanupRepository
{
// TODO NOT an integration tests, move SnapshotCrud tests over to a coordinatedtestbase so we can inject this in the request pipeline in order
// todo meaningful assertions
public class CleanupRepositoryApiTests
: ApiTestBase<ReadOnlyCluster, CleanupRepositoryResponse, ICleanupRepositoryRequest, CleanupRepositoryDescriptor, CleanupRepositoryRequest>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,14 @@
namespace Tests.Modules.SnapshotAndRestore.Repositories.GetRepository
{
public class GetRepositoryApiTests
: ApiIntegrationTestBase<WritableCluster, GetRepositoryResponse, IGetRepositoryRequest, GetRepositoryDescriptor, GetRepositoryRequest>
: ApiTestBase<WritableCluster, GetRepositoryResponse, IGetRepositoryRequest, GetRepositoryDescriptor, GetRepositoryRequest>
{
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
foreach (var callUniqueValue in values)
{
var createRepositoryResponse = client.Snapshot.CreateRepository(callUniqueValue.Value, d => d
.SourceOnly(so => so
.FileSystem(fs => fs
.Settings("some/location", s => s
.Compress()
.ConcurrentStreams(5)
.ChunkSize("64mb")
.RestoreBytesPerSecondMaximum("100mb")
.SnapshotBytesPerSecondMaximum("200mb")
)
)
)
);

if (!createRepositoryResponse.IsValid)
throw new Exception($"Error in integration setup: {createRepositoryResponse.DebugInformation}");
}
}

protected override void IntegrationTeardown(IElasticClient client, CallUniqueValues values)
{
foreach (var callUniqueValue in values)
{
var deleteRepositoryResponse = client.Snapshot.DeleteRepository(callUniqueValue.Value);

if (!deleteRepositoryResponse.IsValid)
throw new Exception($"Error in integration teardown: {deleteRepositoryResponse.DebugInformation}");
}
}

public GetRepositoryApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override Func<GetRepositoryDescriptor, IGetRepositoryRequest> Fluent => d => d.RepositoryName(CallIsolatedValue);

protected override HttpMethod HttpMethod => HttpMethod.GET;

protected override bool ExpectIsValid => true;

protected override int ExpectStatusCode => 200;
protected override GetRepositoryRequest Initializer => new GetRepositoryRequest(CallIsolatedValue);

protected override bool SupportsDeserialization => false;
Expand All @@ -67,19 +30,5 @@ protected override LazyResponses ClientUsage() => Calls(
(client, r) => client.Snapshot.GetRepositoryAsync(r)
);

protected override void ExpectResponse(GetRepositoryResponse response)
{
response.ShouldBeValid();

response.Repositories.Should().ContainKey(CallIsolatedValue);

var repository = response.Repositories[CallIsolatedValue];
repository.Type.Should().Be("source");

var sourceOnlyRespository = repository as ISourceOnlyRepository;
sourceOnlyRespository.Should().NotBeNull();
sourceOnlyRespository.DelegateType.Should().Be("fs");
sourceOnlyRespository.DelegateSettings.Should().BeAssignableTo<IFileSystemRepositorySettings>();
}
}
}
39 changes: 4 additions & 35 deletions tests/Tests/XPack/Enrich/DeletePolicy/DeletePolicyApiTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using Elastic.Xunit.XunitPlumbing;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Core.Xunit;
using Tests.Domain;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;
using static Elasticsearch.Net.HttpMethod;
Expand All @@ -14,46 +9,20 @@ namespace Tests.XPack.Enrich.DeletePolicy
{
[SkipVersion("<7.5.0", "Introduced in 7.5.0")]
public class DeletePolicyApiTests
: ApiIntegrationTestBase<XPackCluster, DeleteEnrichPolicyResponse, IDeleteEnrichPolicyRequest, DeleteEnrichPolicyDescriptor, DeleteEnrichPolicyRequest>
: ApiTestBase<EnrichCluster, DeleteEnrichPolicyResponse, IDeleteEnrichPolicyRequest, DeleteEnrichPolicyDescriptor, DeleteEnrichPolicyRequest>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to unit tests?

{
public DeletePolicyApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
public DeletePolicyApiTests(EnrichCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override bool ExpectIsValid => true;
protected override int ExpectStatusCode => 200;
protected override HttpMethod HttpMethod => DELETE;

protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
foreach (var callUniqueValue in values)
{
var putPolicyResponse = client.Enrich.PutPolicy<Project>(callUniqueValue.Value, p => p
.Match(m => m
.Indices(typeof(Project))
.MatchField(f => f.Name)
.EnrichFields(f => f
.Field(ff => ff.Description)
.Field(ff => ff.Tags)
)
)
);

if (!putPolicyResponse.IsValid)
throw new Exception($"Failure setting up integration test: {putPolicyResponse.DebugInformation}");
}
}
protected override string UrlPath => $"/_enrich/policy/{CallIsolatedValue}";

protected override DeleteEnrichPolicyRequest Initializer => new DeleteEnrichPolicyRequest(CallIsolatedValue);

protected override string UrlPath => $"/_enrich/policy/{CallIsolatedValue}";

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Enrich.DeletePolicy(CallIsolatedValue, f),
(client, f) => client.Enrich.DeletePolicyAsync(CallIsolatedValue, f),
(client, r) => client.Enrich.DeletePolicy(r),
(client, r) => client.Enrich.DeletePolicyAsync(r)
);

protected override void ExpectResponse(DeleteEnrichPolicyResponse response) =>
response.Acknowledged.Should().BeTrue();
}
}
Loading