From 4dd3027d47db388dbde7fb302d8ae12845d6efbd Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Fri, 22 Jul 2022 16:33:49 -0400 Subject: [PATCH 1/3] Fix these switch/cases --- .../org/elasticsearch/xpack/core/ilm/AllocateActionTests.java | 2 +- .../xpack/core/ilm/CopyExecutionStateStepTests.java | 2 +- .../xpack/core/ilm/WaitForRolloverReadyStepTests.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 4ca35e6dfc1d0..1fc0afafde353 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -76,7 +76,7 @@ protected AllocateAction mutateInstance(AllocateAction instance) { Map require = instance.getRequire(); Integer numberOfReplicas = instance.getNumberOfReplicas(); Integer totalShardsPerNode = instance.getTotalShardsPerNode(); - switch (randomIntBetween(0, 3)) { + switch (randomIntBetween(0, 4)) { case 0 -> { include = new HashMap<>(include); include.put(randomAlphaOfLengthBetween(11, 15), randomAlphaOfLengthBetween(1, 20)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java index 82f9d624e9a3f..9ec64d9286b8d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java @@ -40,7 +40,7 @@ protected CopyExecutionStateStep mutateInstance(CopyExecutionStateStep instance) BiFunction indexNameSupplier = instance.getTargetIndexNameSupplier(); StepKey targetNextStepKey = instance.getTargetNextStepKey(); - switch (between(0, 2)) { + switch (between(0, 3)) { 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 -> indexNameSupplier = (index, state) -> randomAlphaOfLengthBetween(11, 15) + index; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java index 47ee50c43f261..e177cb99bbb06 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java @@ -83,7 +83,7 @@ protected WaitForRolloverReadyStep mutateInstance(WaitForRolloverReadyStep insta Long maxDocs = instance.getMaxDocs(); Long maxPrimaryShardDocs = instance.getMaxPrimaryShardDocs(); - switch (between(0, 5)) { + switch (between(0, 6)) { case 0 -> key = new Step.StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5)); case 1 -> nextKey = new Step.StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5)); case 2 -> maxSize = randomValueOtherThan(maxSize, () -> { From 1a915d0925da5192b8b04a7c06317d32e58e7631 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Fri, 22 Jul 2022 16:38:04 -0400 Subject: [PATCH 2/3] Fix switch/case for RolloverActionTests As well as the revealed bug w.r.t. equals & hashCode. --- .../org/elasticsearch/xpack/core/ilm/RolloverAction.java | 5 +++-- .../elasticsearch/xpack/core/ilm/RolloverActionTests.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java index 52a2c239a4fe2..9989f440a93c1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java @@ -230,7 +230,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) @Override public int hashCode() { - return Objects.hash(maxSize, maxPrimaryShardSize, maxAge, maxDocs); + return Objects.hash(maxSize, maxPrimaryShardSize, maxAge, maxDocs, maxPrimaryShardDocs); } @Override @@ -245,7 +245,8 @@ public boolean equals(Object obj) { return Objects.equals(maxSize, other.maxSize) && Objects.equals(maxPrimaryShardSize, other.maxPrimaryShardSize) && Objects.equals(maxAge, other.maxAge) - && Objects.equals(maxDocs, other.maxDocs); + && Objects.equals(maxDocs, other.maxDocs) + && Objects.equals(maxPrimaryShardDocs, other.maxPrimaryShardDocs); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java index 8a4ba79b21cb9..b5f38994ffc60 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java @@ -61,7 +61,7 @@ protected RolloverAction mutateInstance(RolloverAction instance) throws IOExcept TimeValue maxAge = instance.getMaxAge(); Long maxDocs = instance.getMaxDocs(); Long maxPrimaryShardDocs = instance.getMaxPrimaryShardDocs(); - switch (between(0, 3)) { + switch (between(0, 4)) { case 0 -> maxSize = randomValueOtherThan(maxSize, () -> { ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values()); return new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit); From af01f3dabb380022a8afb7c9404e2f77b63dcd99 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Fri, 22 Jul 2022 16:38:52 -0400 Subject: [PATCH 3/3] Fix switch/case for ActionConfigStatsTests As well as the revealed bug w.r.t. equals & hashCode. --- .../xpack/core/ilm/IndexLifecycleFeatureSetUsage.java | 2 ++ .../elasticsearch/xpack/core/ilm/ActionConfigStatsTests.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleFeatureSetUsage.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleFeatureSetUsage.java index bfa8fde321844..892113df53085 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleFeatureSetUsage.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/IndexLifecycleFeatureSetUsage.java @@ -506,6 +506,7 @@ public boolean equals(Object o) { && Objects.equals(forceMergeMaxNumberOfSegments, that.forceMergeMaxNumberOfSegments) && Objects.equals(rolloverMaxAge, that.rolloverMaxAge) && Objects.equals(rolloverMaxDocs, that.rolloverMaxDocs) + && Objects.equals(rolloverMaxPrimaryShardDocs, that.rolloverMaxPrimaryShardDocs) && Objects.equals(rolloverMaxPrimaryShardSize, that.rolloverMaxPrimaryShardSize) && Objects.equals(rolloverMaxSize, that.rolloverMaxSize) && Objects.equals(setPriorityPriority, that.setPriorityPriority) @@ -520,6 +521,7 @@ public int hashCode() { forceMergeMaxNumberOfSegments, rolloverMaxAge, rolloverMaxDocs, + rolloverMaxPrimaryShardDocs, rolloverMaxPrimaryShardSize, rolloverMaxSize, setPriorityPriority, diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ActionConfigStatsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ActionConfigStatsTests.java index ad1e141f394f1..e41f4eb930339 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ActionConfigStatsTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ActionConfigStatsTests.java @@ -69,7 +69,7 @@ protected Writeable.Reader instanceReader() { @Override protected ActionConfigStats mutateInstance(ActionConfigStats instance) throws IOException { ActionConfigStats.Builder builder = ActionConfigStats.builder(instance); - switch (between(0, 8)) { + switch (between(0, 9)) { case 0 -> { int numberOfReplicas = randomValueOtherThan(instance.getAllocateNumberOfReplicas(), () -> randomIntBetween(0, 10000)); builder.setAllocateNumberOfReplicas(numberOfReplicas);