@@ -99,7 +99,7 @@ protected LifecyclePolicy createTestInstance() {
99
99
public static LifecyclePolicy randomTimeseriesLifecyclePolicyWithAllPhases (@ Nullable String lifecycleName ) {
100
100
List <String > phaseNames = TimeseriesLifecycleType .VALID_PHASES ;
101
101
Map <String , Phase > phases = new HashMap <>(phaseNames .size ());
102
- Function <String , Set <String >> validActions = (phase ) -> {
102
+ Function <String , Set <String >> validActions = (phase ) -> {
103
103
switch (phase ) {
104
104
case "hot" :
105
105
return TimeseriesLifecycleType .VALID_HOT_ACTIONS ;
@@ -112,14 +112,14 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicyWithAllPhases(@Null
112
112
default :
113
113
throw new IllegalArgumentException ("invalid phase [" + phase + "]" );
114
114
}};
115
- Function <String , LifecycleAction > randomAction = (action ) -> {
115
+ Function <String , LifecycleAction > randomAction = (action ) -> {
116
116
switch (action ) {
117
117
case AllocateAction .NAME :
118
118
return AllocateActionTests .randomInstance ();
119
119
case DeleteAction .NAME :
120
120
return new DeleteAction ();
121
121
case WaitForSnapshotAction .NAME :
122
- return WaitForSnapshotActionTests .randomInstance ();
122
+ return WaitForSnapshotActionTests .randomInstance ();
123
123
case ForceMergeAction .NAME :
124
124
return ForceMergeActionTests .randomInstance ();
125
125
case ReadOnlyAction .NAME :
@@ -157,7 +157,7 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicy(@Nullable String l
157
157
List <String > phaseNames = randomSubsetOf (
158
158
between (0 , TimeseriesLifecycleType .VALID_PHASES .size () - 1 ), TimeseriesLifecycleType .VALID_PHASES );
159
159
Map <String , Phase > phases = new HashMap <>(phaseNames .size ());
160
- Function <String , Set <String >> validActions = (phase ) -> {
160
+ Function <String , Set <String >> validActions = (phase ) -> {
161
161
switch (phase ) {
162
162
case "hot" :
163
163
return TimeseriesLifecycleType .VALID_HOT_ACTIONS ;
@@ -170,7 +170,7 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicy(@Nullable String l
170
170
default :
171
171
throw new IllegalArgumentException ("invalid phase [" + phase + "]" );
172
172
}};
173
- Function <String , LifecycleAction > randomAction = (action ) -> {
173
+ Function <String , LifecycleAction > randomAction = (action ) -> {
174
174
switch (action ) {
175
175
case AllocateAction .NAME :
176
176
return AllocateActionTests .randomInstance ();
@@ -204,8 +204,9 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicy(@Nullable String l
204
204
Map <String , LifecycleAction > actions = new HashMap <>();
205
205
List <String > actionNames = randomSubsetOf (validActions .apply (phase ));
206
206
207
- // If the hot phase contains a forcemerge, also make sure to add a rollover, or else the policy will not validate
208
- if (phase .equals (TimeseriesLifecycleType .HOT_PHASE ) && actionNames .contains (ForceMergeAction .NAME )) {
207
+ // If the hot phase has any actions that require a rollover, then ensure there is one so that the policy will validate
208
+ if (phase .equals (TimeseriesLifecycleType .HOT_PHASE )
209
+ && actionNames .stream ().anyMatch (TimeseriesLifecycleType .HOT_ACTIONS_THAT_REQUIRE_ROLLOVER ::contains )) {
209
210
actionNames .add (RolloverAction .NAME );
210
211
}
211
212
@@ -238,16 +239,16 @@ protected LifecyclePolicy mutateInstance(LifecyclePolicy instance) throws IOExce
238
239
String name = instance .getName ();
239
240
Map <String , Phase > phases = instance .getPhases ();
240
241
switch (between (0 , 1 )) {
241
- case 0 :
242
- name = name + randomAlphaOfLengthBetween (1 , 5 );
243
- break ;
244
- case 1 :
245
- String phaseName = randomValueOtherThanMany (phases ::containsKey , () -> randomFrom (TimeseriesLifecycleType .VALID_PHASES ));
246
- phases = new LinkedHashMap <>(phases );
247
- phases .put (phaseName , new Phase (phaseName , TimeValue .timeValueSeconds (randomIntBetween (1 , 1000 )), Collections .emptyMap ()));
248
- break ;
249
- default :
250
- throw new AssertionError ("Illegal randomisation branch" );
242
+ case 0 :
243
+ name = name + randomAlphaOfLengthBetween (1 , 5 );
244
+ break ;
245
+ case 1 :
246
+ String phaseName = randomValueOtherThanMany (phases ::containsKey , () -> randomFrom (TimeseriesLifecycleType .VALID_PHASES ));
247
+ phases = new LinkedHashMap <>(phases );
248
+ phases .put (phaseName , new Phase (phaseName , TimeValue .timeValueSeconds (randomIntBetween (1 , 1000 )), Collections .emptyMap ()));
249
+ break ;
250
+ default :
251
+ throw new AssertionError ("Illegal randomisation branch" );
251
252
}
252
253
return new LifecyclePolicy (TimeseriesLifecycleType .INSTANCE , name , phases );
253
254
}
@@ -300,7 +301,7 @@ public void testToStepsWithTwoPhases() {
300
301
MockStep secondActionStep = new MockStep (new StepKey ("second_phase" , "test2" , "test" ),
301
302
PhaseCompleteStep .finalStep ("second_phase" ).getKey ());
302
303
MockStep secondAfter = new MockStep (new StepKey ("first_phase" , PhaseCompleteStep .NAME , PhaseCompleteStep .NAME ),
303
- secondActionStep .getKey ());
304
+ secondActionStep .getKey ());
304
305
MockStep firstActionAnotherStep = new MockStep (new StepKey ("first_phase" , "test" , "bar" ), secondAfter .getKey ());
305
306
MockStep firstActionStep = new MockStep (new StepKey ("first_phase" , "test" , "foo" ), firstActionAnotherStep .getKey ());
306
307
MockStep firstAfter = new MockStep (new StepKey ("new" , PhaseCompleteStep .NAME , PhaseCompleteStep .NAME ), firstActionStep .getKey ());
@@ -352,30 +353,30 @@ public void testIsActionSafe() {
352
353
assertFalse (policy .isActionSafe (new StepKey ("second_phase" , MockAction .NAME , randomAlphaOfLength (10 ))));
353
354
354
355
IllegalArgumentException exception = expectThrows (IllegalArgumentException .class ,
355
- () -> policy .isActionSafe (new StepKey ("non_existant_phase" , MockAction .NAME , randomAlphaOfLength (10 ))));
356
+ () -> policy .isActionSafe (new StepKey ("non_existant_phase" , MockAction .NAME , randomAlphaOfLength (10 ))));
356
357
assertEquals ("Phase [non_existant_phase] does not exist in policy [" + policy .getName () + "]" , exception .getMessage ());
357
358
358
359
exception = expectThrows (IllegalArgumentException .class ,
359
- () -> policy .isActionSafe (new StepKey ("first_phase" , "non_existant_action" , randomAlphaOfLength (10 ))));
360
+ () -> policy .isActionSafe (new StepKey ("first_phase" , "non_existant_action" , randomAlphaOfLength (10 ))));
360
361
assertEquals ("Action [non_existant_action] in phase [first_phase] does not exist in policy [" + policy .getName () + "]" ,
361
- exception .getMessage ());
362
+ exception .getMessage ());
362
363
363
364
assertTrue (policy .isActionSafe (new StepKey ("new" , randomAlphaOfLength (10 ), randomAlphaOfLength (10 ))));
364
365
}
365
366
366
367
public void testValidatePolicyName () {
367
- expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 ,10 ) +
368
- "," + randomAlphaOfLengthBetween (0 ,10 )));
369
- expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 ,10 ) +
370
- " " + randomAlphaOfLengthBetween (0 ,10 )));
368
+ expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 , 10 ) +
369
+ "," + randomAlphaOfLengthBetween (0 , 10 )));
370
+ expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 , 10 ) +
371
+ " " + randomAlphaOfLengthBetween (0 , 10 )));
371
372
expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName ("_" + randomAlphaOfLengthBetween (1 , 20 )));
372
373
expectThrows (IllegalArgumentException .class , () -> LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (256 , 1000 )));
373
374
374
- LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (1 ,10 ) + "_" + randomAlphaOfLengthBetween (0 ,10 ));
375
+ LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (1 , 10 ) + "_" + randomAlphaOfLengthBetween (0 , 10 ));
375
376
376
- LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 ,10 ) + "-" + randomAlphaOfLengthBetween (0 ,10 ));
377
- LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 ,10 ) + "+" + randomAlphaOfLengthBetween (0 ,10 ));
377
+ LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 , 10 ) + "-" + randomAlphaOfLengthBetween (0 , 10 ));
378
+ LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (0 , 10 ) + "+" + randomAlphaOfLengthBetween (0 , 10 ));
378
379
379
- LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (1 ,255 ));
380
+ LifecyclePolicy .validatePolicyName (randomAlphaOfLengthBetween (1 , 255 ));
380
381
}
381
382
}
0 commit comments