|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Linq; |
| 7 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
| 8 | +using Elasticsearch.Net; |
| 9 | +using FluentAssertions; |
| 10 | +using Nest; |
| 11 | +using Tests.Core.Extensions; |
| 12 | +using Tests.Core.ManagedElasticsearch.Clusters; |
| 13 | +using Tests.Framework.EndpointTests; |
| 14 | +using Tests.Framework.EndpointTests.TestState; |
| 15 | + |
| 16 | +namespace Tests.Indices.IndexManagement.AddBlock |
| 17 | +{ |
| 18 | + [SkipVersion("<7.9.0", "indices add index introduced in 7.9.0")] |
| 19 | + public class AddIndexBlockApiTests |
| 20 | + : ApiIntegrationTestBase<WritableCluster, AddIndexBlockResponse, IAddIndexBlockRequest, AddIndexBlockDescriptor, AddIndexBlockRequest> |
| 21 | + { |
| 22 | + public AddIndexBlockApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 23 | + |
| 24 | + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) |
| 25 | + { |
| 26 | + foreach (var value in values) |
| 27 | + { |
| 28 | + var createIndexResponse = client.Indices.Create(value.Value, c => c |
| 29 | + .Settings(s => s |
| 30 | + .NumberOfShards(1) |
| 31 | + .NumberOfReplicas(0) |
| 32 | + ) |
| 33 | + ); |
| 34 | + |
| 35 | + if (!createIndexResponse.IsValid) |
| 36 | + throw new Exception($"exception whilst setting up integration test: {createIndexResponse.DebugInformation}"); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + protected override bool ExpectIsValid => true; |
| 41 | + |
| 42 | + protected override int ExpectStatusCode => 200; |
| 43 | + |
| 44 | + protected override Func<AddIndexBlockDescriptor, IAddIndexBlockRequest> Fluent => d => d; |
| 45 | + |
| 46 | + protected override HttpMethod HttpMethod => HttpMethod.PUT; |
| 47 | + |
| 48 | + protected override AddIndexBlockRequest Initializer => new AddIndexBlockRequest(CallIsolatedValue, IndexBlock.Write); |
| 49 | + |
| 50 | + protected override string UrlPath => $"/{CallIsolatedValue}/_block/write"; |
| 51 | + |
| 52 | + protected override LazyResponses ClientUsage() => Calls( |
| 53 | + (client, f) => client.Indices.AddBlock(CallIsolatedValue, IndexBlock.Write, f), |
| 54 | + (client, f) => client.Indices.AddBlockAsync(CallIsolatedValue, IndexBlock.Write, f), |
| 55 | + (client, r) => client.Indices.AddBlock(r), |
| 56 | + (client, r) => client.Indices.AddBlockAsync(r) |
| 57 | + ); |
| 58 | + |
| 59 | + protected override AddIndexBlockDescriptor NewDescriptor() => new AddIndexBlockDescriptor(CallIsolatedValue, IndexBlock.Write); |
| 60 | + |
| 61 | + protected override void ExpectResponse(AddIndexBlockResponse response) |
| 62 | + { |
| 63 | + response.ShouldBeValid(); |
| 64 | + response.Acknowledged.Should().BeTrue(); |
| 65 | + response.ShardsAcknowledged.Should().BeTrue(); |
| 66 | + response.Indices.Should().HaveCount(1); |
| 67 | + var first = response.Indices.First(); |
| 68 | + first.Name.Should().Be(CallIsolatedValue); |
| 69 | + first.Blocked.Should().BeTrue(); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments