|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Elasticsearch.Net; |
| 6 | +using FluentAssertions; |
| 7 | +using Nest; |
| 8 | +using Tests.Framework; |
| 9 | +using Tests.Framework.Integration; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace Tests.Indices.Monitoring.IndicesShardStores |
| 13 | +{ |
| 14 | + [Collection(IntegrationContext.OwnIndex)] |
| 15 | + public class IndicesShardStoresApiTests : ApiIntegrationTestBase<IIndicesShardStoresResponse, IIndicesShardStoresRequest, IndicesShardStoresDescriptor, IndicesShardStoresRequest> |
| 16 | + { |
| 17 | + public IndicesShardStoresApiTests(OwnIndexCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 18 | + |
| 19 | + private static string IndexWithUnassignedShards = "nest-" + RandomString(); |
| 20 | + |
| 21 | + protected override void BeforeAllCalls(IElasticClient client, IDictionary<ClientMethod, string> values) |
| 22 | + { |
| 23 | + client.CreateIndex(IndexWithUnassignedShards, s => s |
| 24 | + .Settings(settings => settings |
| 25 | + .NumberOfShards(1) |
| 26 | + .NumberOfReplicas(2) |
| 27 | + ) |
| 28 | + ); |
| 29 | + client.Index(new IndexRequest<object>(IndexWithUnassignedShards) |
| 30 | + { |
| 31 | + Document = new { x = 1 }, |
| 32 | + Refresh = true |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + protected override LazyResponses ClientUsage() => Calls( |
| 37 | + fluent: (client, f) => client.IndicesShardStores(f), |
| 38 | + fluentAsync: (client, f) => client.IndicesShardStoresAsync(f), |
| 39 | + request: (client, r) => client.IndicesShardStores(r), |
| 40 | + requestAsync: (client, r) => client.IndicesShardStoresAsync(r) |
| 41 | + ); |
| 42 | + protected override IndicesShardStoresRequest Initializer => |
| 43 | + new IndicesShardStoresRequest(IndexWithUnassignedShards) |
| 44 | + { |
| 45 | + Status = new[] { "all" } |
| 46 | + }; |
| 47 | + protected override Func<IndicesShardStoresDescriptor, IIndicesShardStoresRequest> Fluent => s => |
| 48 | + s.Index(IndexWithUnassignedShards) |
| 49 | + .Status("all"); |
| 50 | + |
| 51 | + protected override bool ExpectIsValid => true; |
| 52 | + protected override int ExpectStatusCode => 200; |
| 53 | + protected override HttpMethod HttpMethod => HttpMethod.GET; |
| 54 | + protected override string UrlPath => $"/{IndexWithUnassignedShards}/_shard_stores"; |
| 55 | + |
| 56 | + [I] public Task AssertResponse() => AssertOnAllResponses(r => |
| 57 | + { |
| 58 | + r.Indices.Should().NotBeEmpty(); |
| 59 | + var indicesShardStore = r.Indices[IndexWithUnassignedShards]; |
| 60 | + indicesShardStore.Should().NotBeNull(); |
| 61 | + indicesShardStore.Shards.Should().NotBeEmpty().And.ContainKey("0"); |
| 62 | + var shardStoreWrapper = indicesShardStore.Shards["0"]; |
| 63 | + shardStoreWrapper.Stores.Should().NotBeNullOrEmpty(); |
| 64 | + |
| 65 | + var shardStore = shardStoreWrapper.Stores.First(); |
| 66 | + shardStore.Id.Should().NotBeNullOrWhiteSpace(); |
| 67 | + shardStore.Name.Should().NotBeNullOrWhiteSpace(); |
| 68 | + shardStore.TransportAddress.Should().NotBeNullOrWhiteSpace(); |
| 69 | + shardStore.Version.Should().BeGreaterThan(0); |
| 70 | + shardStore.Allocation.Should().Be(ShardStoreAllocation.Primary); |
| 71 | + }); |
| 72 | + } |
| 73 | +} |
0 commit comments