Skip to content

Add shards_acknowledged and indices results to CloseIndexResponse #4066

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 1 commit into from
Sep 4, 2019
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
namespace Nest
using System.Collections.Generic;
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
public class CloseIndexResponse : AcknowledgedResponseBase { }
public class CloseIndexResponse : AcknowledgedResponseBase
{
/// <summary>
/// Individual index responses
/// <para />
/// Valid only for Elasticsearch 7.3.0+
/// </summary>
[DataMember(Name = "indices")]
public IReadOnlyDictionary<string, CloseIndexResult> Indices { get; internal set; } = EmptyReadOnly<string, CloseIndexResult>.Dictionary;

/// <summary>
/// Acknowledgement from shards
/// <para />
/// Valid only for Elasticsearch 7.2.0+
/// </summary>
[DataMember(Name = "shards_acknowledged")]
public bool ShardsAcknowledged { get; internal set; }
}

[DataContract]
public class CloseIndexResult
{
[DataMember(Name = "closed")]
public bool Closed { get; internal set; }

[DataMember(Name = "shards")]
public IReadOnlyDictionary<string, CloseShardResult> Shards { get; internal set; } = EmptyReadOnly<string, CloseShardResult>.Dictionary;
}

[DataContract]
public class CloseShardResult
{
[DataMember(Name = "failures")]
public IReadOnlyCollection<ShardFailure> Failures { get; internal set; } = EmptyReadOnly<ShardFailure>.Collection;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Elasticsearch.Net;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Core.Extensions;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;
Expand All @@ -25,4 +28,36 @@ protected override LazyResponses ClientUsage() => Calls(
(client, r) => client.Indices.CloseAsync(r)
);
}

[SkipVersion("<7.3.0", "individual index results only available in 7.3.0+")]
public class CloseIndexWithShardsAcknowledgedApiTests
: ApiIntegrationAgainstNewIndexTestBase<WritableCluster, CloseIndexResponse, ICloseIndexRequest, CloseIndexDescriptor, CloseIndexRequest>
{
public CloseIndexWithShardsAcknowledgedApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

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

protected override CloseIndexRequest Initializer => new CloseIndexRequest(CallIsolatedValue);
protected override string UrlPath => $"/{CallIsolatedValue}/_close";

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.Indices.Close(CallIsolatedValue),
(client, f) => client.Indices.CloseAsync(CallIsolatedValue),
(client, r) => client.Indices.Close(r),
(client, r) => client.Indices.CloseAsync(r)
);

protected override void ExpectResponse(CloseIndexResponse response)
{
response.ShouldBeValid();
response.ShardsAcknowledged.Should().BeTrue();
response.Indices.Should().NotBeNull().And.ContainKey(CallIsolatedValue);

var closeIndexResult = response.Indices[CallIsolatedValue];
closeIndexResult.Closed.Should().BeTrue();
closeIndexResult.Shards.Should().NotBeNull();
}
}
}