From 61d88a8fdd94f51954ce6e787b2135e901ece832 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Thu, 3 May 2018 10:18:42 +0100 Subject: [PATCH] Makes all step tests use `randomStepKey()` x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/AbstractStepTestCase.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/DeleteStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ErrorStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ForceMergeStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/InitializePolicyContextStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/PhaseAfterStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ReplicasAllocatedStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/RolloverStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/SegmentCountStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ShrinkSetAliasStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ShrinkStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ShrunkShardsAllocatedStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/ShrunkenIndexCheckStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/TerminalPolicyStepTests.java x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifec ycle/UpdateSettingsStepTests.java --- .../indexlifecycle/AbstractStepTestCase.java | 5 ++++- .../core/indexlifecycle/DeleteStepTests.java | 4 ++-- .../core/indexlifecycle/ErrorStepTests.java | 2 +- .../indexlifecycle/ForceMergeStepTests.java | 12 ++++++------ .../InitializePolicyContextStepTests.java | 4 ++-- .../indexlifecycle/PhaseAfterStepTests.java | 4 ++-- .../ReplicasAllocatedStepTests.java | 4 ++-- .../core/indexlifecycle/RolloverStepTests.java | 5 ++--- .../indexlifecycle/SegmentCountStepTests.java | 17 ++++++++--------- .../indexlifecycle/ShrinkSetAliasStepTests.java | 4 ++-- .../core/indexlifecycle/ShrinkStepTests.java | 4 ++-- .../ShrunkShardsAllocatedStepTests.java | 4 ++-- .../ShrunkenIndexCheckStepTests.java | 4 ++-- .../indexlifecycle/TerminalPolicyStepTests.java | 4 ++-- .../indexlifecycle/UpdateSettingsStepTests.java | 4 ++-- 15 files changed, 41 insertions(+), 40 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/AbstractStepTestCase.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/AbstractStepTestCase.java index 30c5f295a1a..2757a0499aa 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/AbstractStepTestCase.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/AbstractStepTestCase.java @@ -24,7 +24,10 @@ public abstract class AbstractStepTestCase extends ESTestCase { } public static StepKey randomStepKey() { - return new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + String randomPhase = randomAlphaOfLength(10); + String randomAction = randomAlphaOfLength(10); + String randomStepName = randomAlphaOfLength(10); + return new StepKey(randomPhase, randomAction, randomStepName); } public void testStepNameNotError() { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/DeleteStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/DeleteStepTests.java index 4af508d6242..2a1f95ee5ac 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/DeleteStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/DeleteStepTests.java @@ -34,8 +34,8 @@ public class DeleteStepTests extends AbstractStepTestCase { @Override public DeleteStep createRandomInstance() { - StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); return new DeleteStep(stepKey, nextStepKey, client); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ErrorStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ErrorStepTests.java index 1f7cf109e6f..5bd0cdf230d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ErrorStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ErrorStepTests.java @@ -32,7 +32,7 @@ public class ErrorStepTests extends AbstractStepTestCase { } public void testInvalidStepKey() { - StepKey invalidKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + StepKey invalidKey = randomStepKey(); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new ErrorStep(invalidKey)); assertEquals("An error step must have a step key whose step name is " + ErrorStep.NAME, exception.getMessage()); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ForceMergeStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ForceMergeStepTests.java index cbdeece2fd9..9a38ddf3a26 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ForceMergeStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ForceMergeStepTests.java @@ -28,8 +28,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase { @Override public ForceMergeStep createRandomInstance() { - Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + Step.StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); int maxNumSegments = randomIntBetween(1, 10); return new ForceMergeStep(stepKey, nextStepKey, null, maxNumSegments); @@ -67,8 +67,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase { public void testPerformActionComplete() { IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); - Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + Step.StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); int maxNumSegments = randomIntBetween(1, 10); Client client = mock(Client.class); AdminClient adminClient = mock(AdminClient.class); @@ -106,8 +106,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase { IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); Exception exception = new RuntimeException("error"); - Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + Step.StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); int maxNumSegments = randomIntBetween(1, 10); Client client = mock(Client.class); AdminClient adminClient = mock(AdminClient.class); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/InitializePolicyContextStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/InitializePolicyContextStepTests.java index 9f9a5339218..b4096b10541 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/InitializePolicyContextStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/InitializePolicyContextStepTests.java @@ -20,8 +20,8 @@ public class InitializePolicyContextStepTests extends AbstractStepTestCase { @Override public PhaseAfterStep createRandomInstance() { - StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); TimeValue after = createRandomTimeValue(); return new PhaseAfterStep(null, after, stepKey, nextStepKey); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepTests.java index 2183111953d..3eeb7df0339 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ReplicasAllocatedStepTests.java @@ -28,8 +28,8 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase { @Override public RolloverStep createRandomInstance() { - StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - String alias = randomAlphaOfLengthBetween(1, 20); + StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values()); ByteSizeValue maxSize = randomBoolean() ? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit); Long maxDocs = randomBoolean() ? null : randomNonNegativeLong(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/SegmentCountStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/SegmentCountStepTests.java index 3f52502f5c3..5f7bdb47274 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/SegmentCountStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/SegmentCountStepTests.java @@ -18,7 +18,6 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.engine.Segment; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; - import org.mockito.Mockito; import java.util.ArrayList; @@ -34,8 +33,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase { @@ -156,8 +155,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase { @@ -194,8 +193,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase { @Override public ShrinkStep createRandomInstance() { - StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); - StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); + StepKey stepKey = randomStepKey(); + StepKey nextStepKey = randomStepKey(); int numberOfShards = randomIntBetween(1, 20); String shrunkIndexPrefix = randomAlphaOfLength(10); return new ShrinkStep(stepKey, nextStepKey, client, numberOfShards, shrunkIndexPrefix); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java index 1fb75700acc..9be69c57054 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrunkShardsAllocatedStepTests.java @@ -26,8 +26,8 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase