Skip to content

Commit

Permalink
Add shards_acknowledged and indices results to CloseIndexResponse (#4066
Browse files Browse the repository at this point in the history
)

Relates: #4001
Relates: elastic/elasticsearch#39687

This commit adds shards_acknowledged and indices resuls to CloseIndexResponse.

(cherry picked from commit 169b784)
  • Loading branch information
russcam committed Sep 4, 2019
1 parent 89dc651 commit e4720d6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
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,6 +1,8 @@
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 @@ -26,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();
}
}
}

0 comments on commit e4720d6

Please sign in to comment.