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
This commit is contained in:
Colin Goodheart-Smithe 2018-05-03 10:18:42 +01:00
parent b5ae7a1aeb
commit 61d88a8fdd
No known key found for this signature in database
GPG Key ID: F975E7BDD739B3C7
15 changed files with 41 additions and 40 deletions

View File

@ -24,7 +24,10 @@ public abstract class AbstractStepTestCase<T extends Step> extends ESTestCase {
} }
public static StepKey randomStepKey() { 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() { public void testStepNameNotError() {

View File

@ -34,8 +34,8 @@ public class DeleteStepTests extends AbstractStepTestCase<DeleteStep> {
@Override @Override
public DeleteStep createRandomInstance() { public DeleteStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
return new DeleteStep(stepKey, nextStepKey, client); return new DeleteStep(stepKey, nextStepKey, client);
} }

View File

@ -32,7 +32,7 @@ public class ErrorStepTests extends AbstractStepTestCase<ErrorStep> {
} }
public void testInvalidStepKey() { public void testInvalidStepKey() {
StepKey invalidKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey invalidKey = randomStepKey();
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new ErrorStep(invalidKey)); 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()); assertEquals("An error step must have a step key whose step name is " + ErrorStep.NAME, exception.getMessage());
} }

View File

@ -28,8 +28,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase<ForceMergeStep> {
@Override @Override
public ForceMergeStep createRandomInstance() { public ForceMergeStep createRandomInstance() {
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int maxNumSegments = randomIntBetween(1, 10); int maxNumSegments = randomIntBetween(1, 10);
return new ForceMergeStep(stepKey, nextStepKey, null, maxNumSegments); return new ForceMergeStep(stepKey, nextStepKey, null, maxNumSegments);
@ -67,8 +67,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase<ForceMergeStep> {
public void testPerformActionComplete() { public void testPerformActionComplete() {
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)) IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int maxNumSegments = randomIntBetween(1, 10); int maxNumSegments = randomIntBetween(1, 10);
Client client = mock(Client.class); Client client = mock(Client.class);
AdminClient adminClient = mock(AdminClient.class); AdminClient adminClient = mock(AdminClient.class);
@ -106,8 +106,8 @@ public class ForceMergeStepTests extends AbstractStepTestCase<ForceMergeStep> {
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)) IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
Exception exception = new RuntimeException("error"); Exception exception = new RuntimeException("error");
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int maxNumSegments = randomIntBetween(1, 10); int maxNumSegments = randomIntBetween(1, 10);
Client client = mock(Client.class); Client client = mock(Client.class);
AdminClient adminClient = mock(AdminClient.class); AdminClient adminClient = mock(AdminClient.class);

View File

@ -20,8 +20,8 @@ public class InitializePolicyContextStepTests extends AbstractStepTestCase<Initi
@Override @Override
public InitializePolicyContextStep createRandomInstance() { public InitializePolicyContextStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
return new InitializePolicyContextStep(stepKey, nextStepKey); return new InitializePolicyContextStep(stepKey, nextStepKey);
} }

View File

@ -21,8 +21,8 @@ public class PhaseAfterStepTests extends AbstractStepTestCase<PhaseAfterStep> {
@Override @Override
public PhaseAfterStep createRandomInstance() { public PhaseAfterStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
TimeValue after = createRandomTimeValue(); TimeValue after = createRandomTimeValue();
return new PhaseAfterStep(null, after, stepKey, nextStepKey); return new PhaseAfterStep(null, after, stepKey, nextStepKey);
} }

View File

@ -28,8 +28,8 @@ public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAll
@Override @Override
public ReplicasAllocatedStep createRandomInstance() { public ReplicasAllocatedStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int numberReplicas = randomIntBetween(0, 100); int numberReplicas = randomIntBetween(0, 100);
return new ReplicasAllocatedStep(stepKey, nextStepKey, numberReplicas); return new ReplicasAllocatedStep(stepKey, nextStepKey, numberReplicas);
} }

View File

@ -46,9 +46,8 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
@Override @Override
public RolloverStep createRandomInstance() { public RolloverStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
String alias = randomAlphaOfLengthBetween(1, 20);
ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values()); ByteSizeUnit maxSizeUnit = randomFrom(ByteSizeUnit.values());
ByteSizeValue maxSize = randomBoolean() ? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit); ByteSizeValue maxSize = randomBoolean() ? null : new ByteSizeValue(randomNonNegativeLong() / maxSizeUnit.toBytes(1), maxSizeUnit);
Long maxDocs = randomBoolean() ? null : randomNonNegativeLong(); Long maxDocs = randomBoolean() ? null : randomNonNegativeLong();

View File

@ -18,7 +18,6 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.engine.Segment; import org.elasticsearch.index.engine.Segment;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,8 +33,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
@Override @Override
public SegmentCountStep createRandomInstance() { public SegmentCountStep createRandomInstance() {
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int maxNumSegments = randomIntBetween(1, 10); int maxNumSegments = randomIntBetween(1, 10);
boolean bestCompression = randomBoolean(); boolean bestCompression = randomBoolean();
@ -101,8 +100,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
Mockito.when(client.admin()).thenReturn(adminClient); Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient); Mockito.when(adminClient.indices()).thenReturn(indicesClient);
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
boolean bestCompression = randomBoolean(); boolean bestCompression = randomBoolean();
Mockito.doAnswer(invocationOnMock -> { Mockito.doAnswer(invocationOnMock -> {
@ -156,8 +155,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
Mockito.when(client.admin()).thenReturn(adminClient); Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient); Mockito.when(adminClient.indices()).thenReturn(indicesClient);
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
boolean bestCompression = randomBoolean(); boolean bestCompression = randomBoolean();
Mockito.doAnswer(invocationOnMock -> { Mockito.doAnswer(invocationOnMock -> {
@ -194,8 +193,8 @@ public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep
Mockito.when(client.admin()).thenReturn(adminClient); Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient); Mockito.when(adminClient.indices()).thenReturn(indicesClient);
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); Step.StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int maxNumSegments = randomIntBetween(3, 10); int maxNumSegments = randomIntBetween(3, 10);
boolean bestCompression = randomBoolean(); boolean bestCompression = randomBoolean();

View File

@ -40,8 +40,8 @@ public class ShrinkSetAliasStepTests extends AbstractStepTestCase<ShrinkSetAlias
@Override @Override
public ShrinkSetAliasStep createRandomInstance() { public ShrinkSetAliasStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
String shrunkIndexPrefix = randomAlphaOfLength(10); String shrunkIndexPrefix = randomAlphaOfLength(10);
return new ShrinkSetAliasStep(stepKey, nextStepKey, client, shrunkIndexPrefix); return new ShrinkSetAliasStep(stepKey, nextStepKey, client, shrunkIndexPrefix);
} }

View File

@ -42,8 +42,8 @@ public class ShrinkStepTests extends AbstractStepTestCase<ShrinkStep> {
@Override @Override
public ShrinkStep createRandomInstance() { public ShrinkStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int numberOfShards = randomIntBetween(1, 20); int numberOfShards = randomIntBetween(1, 20);
String shrunkIndexPrefix = randomAlphaOfLength(10); String shrunkIndexPrefix = randomAlphaOfLength(10);
return new ShrinkStep(stepKey, nextStepKey, client, numberOfShards, shrunkIndexPrefix); return new ShrinkStep(stepKey, nextStepKey, client, numberOfShards, shrunkIndexPrefix);

View File

@ -26,8 +26,8 @@ public class ShrunkShardsAllocatedStepTests extends AbstractStepTestCase<ShrunkS
@Override @Override
public ShrunkShardsAllocatedStep createRandomInstance() { public ShrunkShardsAllocatedStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
int numberOfShards = randomIntBetween(1, 10); int numberOfShards = randomIntBetween(1, 10);
String shrunkIndexPrefix = randomAlphaOfLength(10); String shrunkIndexPrefix = randomAlphaOfLength(10);
return new ShrunkShardsAllocatedStep(stepKey, nextStepKey, numberOfShards, shrunkIndexPrefix); return new ShrunkShardsAllocatedStep(stepKey, nextStepKey, numberOfShards, shrunkIndexPrefix);

View File

@ -18,8 +18,8 @@ public class ShrunkenIndexCheckStepTests extends AbstractStepTestCase<ShrunkenIn
@Override @Override
public ShrunkenIndexCheckStep createRandomInstance() { public ShrunkenIndexCheckStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
String shrunkIndexPrefix = randomAlphaOfLength(10); String shrunkIndexPrefix = randomAlphaOfLength(10);
return new ShrunkenIndexCheckStep(stepKey, nextStepKey, shrunkIndexPrefix); return new ShrunkenIndexCheckStep(stepKey, nextStepKey, shrunkIndexPrefix);
} }

View File

@ -11,8 +11,8 @@ public class TerminalPolicyStepTests extends AbstractStepTestCase<TerminalPolicy
@Override @Override
public TerminalPolicyStep createRandomInstance() { public TerminalPolicyStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
return new TerminalPolicyStep(stepKey, nextStepKey); return new TerminalPolicyStep(stepKey, nextStepKey);
} }

View File

@ -35,8 +35,8 @@ public class UpdateSettingsStepTests extends AbstractStepTestCase<UpdateSettings
@Override @Override
public UpdateSettingsStep createRandomInstance() { public UpdateSettingsStep createRandomInstance() {
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey stepKey = randomStepKey();
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10)); StepKey nextStepKey = randomStepKey();
Settings settings = Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build(); Settings settings = Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build();
return new UpdateSettingsStep(stepKey, nextStepKey, client, settings); return new UpdateSettingsStep(stepKey, nextStepKey, client, settings);