7
7
using System . Linq ;
8
8
using System . Threading . Tasks ;
9
9
using Elastic . Elasticsearch . Xunit . XunitPlumbing ;
10
+ using Elasticsearch . Net ;
10
11
using FluentAssertions ;
11
12
using Nest ;
12
13
using Tests . Core . ManagedElasticsearch . Clusters ;
13
14
using Tests . Domain ;
14
15
using Tests . Framework . EndpointTests ;
15
16
using Tests . Framework . EndpointTests . TestState ;
17
+ using static Elasticsearch . Net . HttpMethod ;
16
18
17
19
namespace Tests . XPack . Ilm
18
20
{
19
21
[ SkipVersion ( "<6.7.0" , "All APIs exist in Elasticsearch 6.7.0" ) ]
20
22
public class IlmApiTests : CoordinatedIntegrationTestBase < XPackCluster >
21
23
{
22
- private const string IlmGetStatusStep = nameof ( IlmGetStatusStep ) ;
23
- private const string IlmPutLifecycleStep = nameof ( IlmPutLifecycleStep ) ;
24
- private const string IlmGetLifecycleStep = nameof ( IlmGetLifecycleStep ) ;
25
- private const string IlmGeAllLifecycleStep = nameof ( IlmGeAllLifecycleStep ) ;
26
24
private const string IlmDeleteLifecycleStep = nameof ( IlmDeleteLifecycleStep ) ;
27
- private const string PutDocumentStep = nameof ( PutDocumentStep ) ;
28
25
private const string IlmExplainLifecycleStep = nameof ( IlmExplainLifecycleStep ) ;
26
+ private const string IlmGeAllLifecycleStep = nameof ( IlmGeAllLifecycleStep ) ;
27
+ private const string IlmGetLifecycleStep = nameof ( IlmGetLifecycleStep ) ;
28
+ private const string IlmGetStatusStep = nameof ( IlmGetStatusStep ) ;
29
+ private const string IlmPutLifecycleStep = nameof ( IlmPutLifecycleStep ) ;
29
30
private const string IlmRemovePolicyStep = nameof ( IlmRemovePolicyStep ) ;
30
31
private const string IlmStopStep = nameof ( IlmStopStep ) ;
32
+ private const string PutDocumentStep = nameof ( PutDocumentStep ) ;
31
33
32
34
public IlmApiTests ( XPackCluster cluster , EndpointUsage usage ) : base ( new CoordinatedUsage ( cluster , usage )
33
35
{
@@ -42,14 +44,15 @@ public IlmApiTests(XPackCluster cluster, EndpointUsage usage) : base(new Coordin
42
44
)
43
45
} ,
44
46
{
45
- IlmExplainLifecycleStep , u => u . Calls < ExplainLifecycleDescriptor , ExplainLifecycleRequest , IExplainLifecycleRequest , ExplainLifecycleResponse > (
46
- v => new ExplainLifecycleRequest ( "project" ) ,
47
- ( v , d ) => d ,
48
- ( v , c , f ) => c . IndexLifecycleManagement . ExplainLifecycle ( "project" , f ) ,
49
- ( v , c , f ) => c . IndexLifecycleManagement . ExplainLifecycleAsync ( "project" , f ) ,
50
- ( v , c , r ) => c . IndexLifecycleManagement . ExplainLifecycle ( r ) ,
51
- ( v , c , r ) => c . IndexLifecycleManagement . ExplainLifecycleAsync ( r )
52
- )
47
+ IlmExplainLifecycleStep , u =>
48
+ u . Calls < ExplainLifecycleDescriptor , ExplainLifecycleRequest , IExplainLifecycleRequest , ExplainLifecycleResponse > (
49
+ v => new ExplainLifecycleRequest ( "project" ) ,
50
+ ( v , d ) => d ,
51
+ ( v , c , f ) => c . IndexLifecycleManagement . ExplainLifecycle ( "project" , f ) ,
52
+ ( v , c , f ) => c . IndexLifecycleManagement . ExplainLifecycleAsync ( "project" , f ) ,
53
+ ( v , c , r ) => c . IndexLifecycleManagement . ExplainLifecycle ( r ) ,
54
+ ( v , c , r ) => c . IndexLifecycleManagement . ExplainLifecycleAsync ( r )
55
+ )
53
56
} ,
54
57
{
55
58
IlmGetStatusStep , u => u . Calls < GetIlmStatusDescriptor , GetIlmStatusRequest , IGetIlmStatusRequest , GetIlmStatusResponse > (
@@ -73,32 +76,15 @@ public IlmApiTests(XPackCluster cluster, EndpointUsage usage) : base(new Coordin
73
76
{
74
77
Actions = new LifecycleActions
75
78
{
76
- new FreezeLifecycleAction ( ) ,
77
- new SetPriorityLifecycleAction
78
- {
79
- Priority = 50
80
- }
79
+ new FreezeLifecycleAction ( ) , new SetPriorityLifecycleAction { Priority = 50 }
81
80
}
82
81
} ,
83
82
Warm = new Phase
84
83
{
85
84
MinimumAge = "10d" ,
86
- Actions = new LifecycleActions
87
- {
88
- new ForceMergeLifecycleAction
89
- {
90
- MaximumNumberOfSegments = 1
91
- }
92
- }
85
+ Actions = new LifecycleActions { new ForceMergeLifecycleAction { MaximumNumberOfSegments = 1 } }
93
86
} ,
94
- Delete = new Phase
95
- {
96
- MinimumAge = "30d" ,
97
- Actions = new LifecycleActions
98
- {
99
- new DeleteLifecycleAction ( )
100
- }
101
- }
87
+ Delete = new Phase { MinimumAge = "30d" , Actions = new LifecycleActions { new DeleteLifecycleAction ( ) } }
102
88
}
103
89
}
104
90
} ,
@@ -163,14 +149,15 @@ public IlmApiTests(XPackCluster cluster, EndpointUsage usage) : base(new Coordin
163
149
)
164
150
} ,
165
151
{
166
- IlmDeleteLifecycleStep , u => u . Calls < DeleteLifecycleDescriptor , DeleteLifecycleRequest , IDeleteLifecycleRequest , DeleteLifecycleResponse > (
167
- v => new DeleteLifecycleRequest ( "policy" + v ) ,
168
- ( v , d ) => d ,
169
- ( v , c , f ) => c . IndexLifecycleManagement . DeleteLifecycle ( "policy" + v , f ) ,
170
- ( v , c , f ) => c . IndexLifecycleManagement . DeleteLifecycleAsync ( "policy" + v , f ) ,
171
- ( v , c , r ) => c . IndexLifecycleManagement . DeleteLifecycle ( r ) ,
172
- ( v , c , r ) => c . IndexLifecycleManagement . DeleteLifecycleAsync ( r )
173
- )
152
+ IlmDeleteLifecycleStep , u =>
153
+ u . Calls < DeleteLifecycleDescriptor , DeleteLifecycleRequest , IDeleteLifecycleRequest , DeleteLifecycleResponse > (
154
+ v => new DeleteLifecycleRequest ( "policy" + v ) ,
155
+ ( v , d ) => d ,
156
+ ( v , c , f ) => c . IndexLifecycleManagement . DeleteLifecycle ( "policy" + v , f ) ,
157
+ ( v , c , f ) => c . IndexLifecycleManagement . DeleteLifecycleAsync ( "policy" + v , f ) ,
158
+ ( v , c , r ) => c . IndexLifecycleManagement . DeleteLifecycle ( r ) ,
159
+ ( v , c , r ) => c . IndexLifecycleManagement . DeleteLifecycleAsync ( r )
160
+ )
174
161
} ,
175
162
{
176
163
IlmStopStep , u => u . Calls < StopIlmDescriptor , StopIlmRequest , IStopIlmRequest , StopIlmResponse > (
@@ -285,4 +272,68 @@ [I] public async Task IlmDeleteLifecycleResponse() => await Assert<DeleteLifecyc
285
272
r . Acknowledged . Should ( ) . BeTrue ( ) ;
286
273
} ) ;
287
274
}
275
+
276
+ [ SkipVersion ( "<7.14.0" , "_meta introduced in 7.14.0" ) ]
277
+ public class PutIlmLifecyclePolicyApiTests
278
+ : ApiTestBase < XPackCluster , PutLifecycleResponse , IPutLifecycleRequest , PutLifecycleDescriptor , PutLifecycleRequest >
279
+ {
280
+ public PutIlmLifecyclePolicyApiTests ( XPackCluster cluster , EndpointUsage usage ) : base ( cluster , usage ) { }
281
+
282
+ protected override object ExpectJson => new
283
+ {
284
+ policy = new
285
+ {
286
+ _meta = new { foo = "bar" } ,
287
+ phases = new { cold = new { actions = new { freeze = new object ( ) , set_priority = new { priority = 50 } } } }
288
+ }
289
+ } ;
290
+
291
+ protected override Func < PutLifecycleDescriptor , IPutLifecycleRequest > Fluent => f => f
292
+ . Policy ( p => p
293
+ . Phases ( a => a
294
+ . Cold ( w => w
295
+ . Actions ( ac => ac
296
+ . Freeze ( fr => fr )
297
+ . SetPriority ( pr => pr . Priority ( 50 ) )
298
+ )
299
+ )
300
+ )
301
+ . Meta ( m => m
302
+ . Add ( "foo" , "bar" )
303
+ )
304
+ ) ;
305
+
306
+ protected override HttpMethod HttpMethod => PUT ;
307
+
308
+ protected override PutLifecycleRequest Initializer => new ( CallIsolatedValue )
309
+ {
310
+ Policy = new Policy
311
+ {
312
+ Phases = new Phases
313
+ {
314
+ Cold = new Phase
315
+ {
316
+ Actions = new LifecycleActions
317
+ {
318
+ new FreezeLifecycleAction ( ) , new SetPriorityLifecycleAction { Priority = 50 }
319
+ }
320
+ }
321
+ } ,
322
+ Meta = new Dictionary < string , object > { { "foo" , "bar" } }
323
+ }
324
+ } ;
325
+
326
+ protected override bool SupportsDeserialization => false ;
327
+
328
+ protected override string UrlPath => $ "/_ilm/policy/{ CallIsolatedValue } ";
329
+
330
+ protected override PutLifecycleDescriptor NewDescriptor ( ) => new ( CallIsolatedValue ) ;
331
+
332
+ protected override LazyResponses ClientUsage ( ) => Calls (
333
+ ( client , f ) => client . IndexLifecycleManagement . PutLifecycle ( CallIsolatedValue , f ) ,
334
+ ( client , f ) => client . IndexLifecycleManagement . PutLifecycleAsync ( CallIsolatedValue , f ) ,
335
+ ( client , r ) => client . IndexLifecycleManagement . PutLifecycle ( r ) ,
336
+ ( client , r ) => client . IndexLifecycleManagement . PutLifecycleAsync ( r )
337
+ ) ;
338
+ }
288
339
}
0 commit comments