|
5 | 5 | using System;
|
6 | 6 | using System.Collections.Generic;
|
7 | 7 | using Elastic.Transport;
|
| 8 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
8 | 9 | using Elasticsearch.Net;
|
9 | 10 | using FluentAssertions;
|
10 | 11 | using Nest;
|
@@ -167,4 +168,165 @@ protected override void ExpectResponse(RolloverIndexResponse response)
|
167 | 168 | response.Conditions["[max_docs: 1000]"].Should().BeTrue();
|
168 | 169 | }
|
169 | 170 | }
|
| 171 | + |
| 172 | + [SkipVersion("<7.12.0", "Tests all parameters available in 7.12.0 and higher")] |
| 173 | + public class RolloverIndexApiWithAllParametersTests |
| 174 | + : ApiIntegrationTestBase<WritableCluster, RolloverIndexResponse, IRolloverIndexRequest, RolloverIndexDescriptor, RolloverIndexRequest> |
| 175 | + { |
| 176 | + public RolloverIndexApiWithAllParametersTests(WritableCluster cluster, EndpointUsage usage) |
| 177 | + : base(cluster, usage) { } |
| 178 | + |
| 179 | + protected override bool ExpectIsValid => true; |
| 180 | + protected override int ExpectStatusCode => 200; |
| 181 | + protected override HttpMethod HttpMethod => HttpMethod.POST; |
| 182 | + protected override bool SupportsDeserialization => false; |
| 183 | + protected override string UrlPath => $"/{CallIsolatedValue}-alias/_rollover/{CallIsolatedValue}-new"; |
| 184 | + |
| 185 | + protected override object ExpectJson => new |
| 186 | + { |
| 187 | + conditions = new |
| 188 | + { |
| 189 | + max_age = "7d", |
| 190 | + max_docs = 1000, |
| 191 | + max_size = "5gb", |
| 192 | + max_primary_shard_size = "2gb" |
| 193 | + }, |
| 194 | + settings = new Dictionary<string, object> |
| 195 | + { |
| 196 | + { "index.number_of_shards", 1 }, |
| 197 | + { "index.number_of_replicas", 1 } |
| 198 | + }, |
| 199 | + mappings = new |
| 200 | + { |
| 201 | + properties = new |
| 202 | + { |
| 203 | + branches = new |
| 204 | + { |
| 205 | + type = "text", |
| 206 | + fields = new |
| 207 | + { |
| 208 | + keyword = new |
| 209 | + { |
| 210 | + type = "keyword", |
| 211 | + ignore_above = 256 |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + }, |
| 217 | + aliases = new Dictionary<string, object> |
| 218 | + { |
| 219 | + { CallIsolatedValue + "-new_projects", new { } } |
| 220 | + } |
| 221 | + }; |
| 222 | + |
| 223 | + protected override Func<RolloverIndexDescriptor, IRolloverIndexRequest> Fluent => f => f |
| 224 | + .NewIndex(CallIsolatedValue + "-new") |
| 225 | + .Conditions(c => c |
| 226 | + .MaxAge("7d") |
| 227 | + .MaxDocs(1000) |
| 228 | + .MaxSize("5gb") |
| 229 | + .MaxPrimaryShardSize("2gb") |
| 230 | + ) |
| 231 | + .Settings(s => s |
| 232 | + .NumberOfShards(1) |
| 233 | + .NumberOfReplicas(1) |
| 234 | + ) |
| 235 | + .Map<Project>(p => p |
| 236 | + .Properties(pp => pp |
| 237 | + .Text(t => t |
| 238 | + .Name(n => n.Branches) |
| 239 | + .Fields(pf => pf |
| 240 | + .Keyword(k => k |
| 241 | + .Name("keyword") |
| 242 | + .IgnoreAbove(256) |
| 243 | + ) |
| 244 | + ) |
| 245 | + ) |
| 246 | + ) |
| 247 | + ) |
| 248 | + .Aliases(a => a |
| 249 | + .Alias(CallIsolatedValue + "-new_projects") |
| 250 | + ); |
| 251 | + |
| 252 | + protected override RolloverIndexRequest Initializer => new RolloverIndexRequest(CallIsolatedValue + "-alias", CallIsolatedValue + "-new") |
| 253 | + { |
| 254 | + Conditions = new RolloverConditions |
| 255 | + { |
| 256 | + MaxAge = "7d", |
| 257 | + MaxDocs = 1000, |
| 258 | + MaxSize = "5gb", |
| 259 | + MaxPrimaryShardSize = "2gb" |
| 260 | + }, |
| 261 | + Settings = new Nest.IndexSettings |
| 262 | + { |
| 263 | + NumberOfShards = 1, |
| 264 | + NumberOfReplicas = 1 |
| 265 | + }, |
| 266 | + Mappings = new TypeMapping |
| 267 | + { |
| 268 | + Properties = new Properties<Project> |
| 269 | + { |
| 270 | + { |
| 271 | + p => p.Branches, new TextProperty |
| 272 | + { |
| 273 | + Fields = new Properties |
| 274 | + { |
| 275 | + { |
| 276 | + "keyword", new KeywordProperty |
| 277 | + { |
| 278 | + IgnoreAbove = 256 |
| 279 | + } |
| 280 | + } |
| 281 | + } |
| 282 | + } |
| 283 | + } |
| 284 | + } |
| 285 | + }, |
| 286 | + Aliases = new Aliases |
| 287 | + { |
| 288 | + { CallIsolatedValue + "-new_projects", new Alias() } |
| 289 | + } |
| 290 | + }; |
| 291 | + |
| 292 | + protected override void OnBeforeCall(IElasticClient client) |
| 293 | + { |
| 294 | + var create = client.Indices.Create(CallIsolatedValue, c => c |
| 295 | + .Aliases(a => a |
| 296 | + .Alias(CallIsolatedValue + "-alias") |
| 297 | + ) |
| 298 | + ); |
| 299 | + create.ShouldBeValid(); |
| 300 | + var someDocs = client.Bulk(b => b |
| 301 | + .Index(CallIsolatedValue) |
| 302 | + .Refresh(Refresh.True) |
| 303 | + .IndexMany(Project.Generator.Generate(1200)) |
| 304 | + ); |
| 305 | + someDocs.ShouldBeValid(); |
| 306 | + |
| 307 | + } |
| 308 | + |
| 309 | + protected override LazyResponses ClientUsage() => Calls( |
| 310 | + (client, f) => client.Indices.Rollover(CallIsolatedValue + "-alias", f), |
| 311 | + (client, f) => client.Indices.RolloverAsync(CallIsolatedValue + "-alias", f), |
| 312 | + (client, r) => client.Indices.Rollover(r), |
| 313 | + (client, r) => client.Indices.RolloverAsync(r) |
| 314 | + ); |
| 315 | + |
| 316 | + protected override RolloverIndexDescriptor NewDescriptor() => new RolloverIndexDescriptor(CallIsolatedValue + "-alias"); |
| 317 | + |
| 318 | + protected override void ExpectResponse(RolloverIndexResponse response) |
| 319 | + { |
| 320 | + response.ShouldBeValid(); |
| 321 | + response.OldIndex.Should().NotBeNullOrEmpty(); |
| 322 | + response.NewIndex.Should().NotBeNullOrEmpty(); |
| 323 | + response.RolledOver.Should().BeTrue(); |
| 324 | + response.ShardsAcknowledged.Should().BeTrue(); |
| 325 | + response.Conditions.Should().NotBeNull().And.HaveCount(4); |
| 326 | + response.Conditions["[max_age: 7d]"].Should().BeFalse(); |
| 327 | + response.Conditions["[max_docs: 1000]"].Should().BeTrue(); |
| 328 | + response.Conditions["[max_size: 5gb]"].Should().BeFalse(); |
| 329 | + response.Conditions["[max_primary_shard_size: 2gb]"].Should().BeFalse(); |
| 330 | + } |
| 331 | + } |
170 | 332 | }
|
0 commit comments