Skip to content

Commit

Permalink
Refactor WaitForIndexColorStepTests (elastic#89652)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarouli authored Aug 26, 2022
1 parent 1b8c650 commit f7ee9e9
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
public class WaitForIndexColorStepTests extends AbstractStepTestCase<WaitForIndexColorStep> {

private static ClusterHealthStatus randomColor() {
String[] colors = new String[] { "green", "yellow", "red" };
int randomColor = randomIntBetween(0, colors.length - 1);
return ClusterHealthStatus.fromString(colors[randomColor]);
return randomFrom(ClusterHealthStatus.values());
}

@Override
Expand All @@ -51,17 +49,13 @@ protected WaitForIndexColorStep createRandomInstance() {
protected WaitForIndexColorStep mutateInstance(WaitForIndexColorStep instance) {
StepKey key = instance.getKey();
StepKey nextKey = instance.getNextStepKey();
ClusterHealthStatus color = instance.getColor(), newColor = randomColor();
ClusterHealthStatus color = instance.getColor();
BiFunction<String, LifecycleExecutionState, String> indexNameSupplier = instance.getIndexNameSupplier();

while (color.equals(newColor)) {
newColor = randomColor();
}

switch (between(0, 2)) {
case 0 -> key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
case 1 -> nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
case 2 -> color = newColor;
case 1 -> nextKey = new StepKey(nextKey.getPhase(), nextKey.getAction(), nextKey.getName() + randomAlphaOfLength(5));
case 2 -> color = randomValueOtherThan(color, WaitForIndexColorStepTests::randomColor);
}

return new WaitForIndexColorStep(key, nextKey, color, indexNameSupplier);
Expand Down

0 comments on commit f7ee9e9

Please sign in to comment.