migrate step tests to extend AbstractStepTestCase
This commit is contained in:
parent
c1b00d0154
commit
20b6aaf6b6
|
@ -9,7 +9,7 @@ public class TerminalPolicyStep extends Step {
|
|||
public static final StepKey KEY = new StepKey("completed", "completed", "completed");
|
||||
public static final TerminalPolicyStep INSTANCE = new TerminalPolicyStep(KEY, null);
|
||||
|
||||
private TerminalPolicyStep(StepKey key, StepKey nextStepKey) {
|
||||
TerminalPolicyStep(StepKey key, StepKey nextStepKey) {
|
||||
super(key, nextStepKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
|
||||
public abstract class AbstractStepTestCase<T extends Step> extends ESTestCase {
|
||||
|
||||
protected abstract T createRandomInstance();
|
||||
protected abstract T mutateInstance(T instance);
|
||||
protected abstract T copyInstance(T instance);
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(), this::copyInstance, this::mutateInstance);
|
||||
}
|
||||
}
|
|
@ -17,8 +17,6 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.junit.Before;
|
||||
|
@ -26,14 +24,12 @@ import org.mockito.Mockito;
|
|||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class AliasStepTests extends ESTestCase {
|
||||
public class AliasStepTests extends AbstractStepTestCase<AliasStep> {
|
||||
|
||||
private Client client;
|
||||
|
||||
|
@ -42,12 +38,14 @@ public class AliasStepTests extends ESTestCase {
|
|||
client = Mockito.mock(Client.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AliasStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
return new AliasStep(stepKey, nextStepKey, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AliasStep mutateInstance(AliasStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -61,18 +59,15 @@ public class AliasStepTests extends ESTestCase {
|
|||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new AliasStep(key, nextKey, instance.getClient());
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils
|
||||
.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new AliasStep(instance.getKey(), instance.getNextStepKey(), instance.getClient()),
|
||||
this::mutateInstance);
|
||||
@Override
|
||||
public AliasStep copyInstance(AliasStep instance) {
|
||||
return new AliasStep(instance.getKey(), instance.getNextStepKey(), instance.getClient());
|
||||
}
|
||||
|
||||
public void testPerformAction() throws Exception {
|
||||
public void testPerformAction() {
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
AliasStep step = createRandomInstance();
|
||||
|
@ -124,7 +119,7 @@ public class AliasStepTests extends ESTestCase {
|
|||
Mockito.verify(indicesClient, Mockito.only()).aliases(Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
public void testPerformActionFailure() throws Exception {
|
||||
public void testPerformActionFailure() {
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
Exception exception = new RuntimeException();
|
||||
|
|
|
@ -25,14 +25,13 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AllocationRoutedStepTests extends ESTestCase {
|
||||
public class AllocationRoutedStepTests extends AbstractStepTestCase<AllocationRoutedStep> {
|
||||
|
||||
@Override
|
||||
public AllocationRoutedStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -40,6 +39,7 @@ public class AllocationRoutedStepTests extends ESTestCase {
|
|||
return new AllocationRoutedStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllocationRoutedStep mutateInstance(AllocationRoutedStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -58,9 +58,9 @@ public class AllocationRoutedStepTests extends ESTestCase {
|
|||
return new AllocationRoutedStep(key, nextKey);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new AllocationRoutedStep(instance.getKey(), instance.getNextStepKey()), this::mutateInstance);
|
||||
@Override
|
||||
public AllocationRoutedStep copyInstance(AllocationRoutedStep instance) {
|
||||
return new AllocationRoutedStep(instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
|
|
|
@ -15,8 +15,6 @@ import org.elasticsearch.client.AdminClient;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mockito;
|
||||
|
@ -25,7 +23,7 @@ import org.mockito.stubbing.Answer;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class DeleteStepTests extends ESTestCase {
|
||||
public class DeleteStepTests extends AbstractStepTestCase<DeleteStep> {
|
||||
|
||||
private Client client;
|
||||
|
||||
|
@ -34,6 +32,7 @@ public class DeleteStepTests extends ESTestCase {
|
|||
client = Mockito.mock(Client.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -41,6 +40,7 @@ public class DeleteStepTests extends ESTestCase {
|
|||
return new DeleteStep(stepKey, nextStepKey, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteStep mutateInstance(DeleteStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -59,9 +59,9 @@ public class DeleteStepTests extends ESTestCase {
|
|||
return new DeleteStep(key, nextKey, instance.getClient());
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new DeleteStep(instance.getKey(), instance.getNextStepKey(), instance.getClient()), this::mutateInstance);
|
||||
@Override
|
||||
public DeleteStep copyInstance(DeleteStep instance) {
|
||||
return new DeleteStep(instance.getKey(), instance.getNextStepKey(), instance.getClient());
|
||||
}
|
||||
|
||||
public void testIndexSurvives() {
|
||||
|
|
|
@ -20,9 +20,44 @@ import org.elasticsearch.common.transport.TransportAddress;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
public class EnoughShardsWaitStepTests extends ESTestCase {
|
||||
public class EnoughShardsWaitStepTests extends AbstractStepTestCase<EnoughShardsWaitStep> {
|
||||
|
||||
@Override
|
||||
public EnoughShardsWaitStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
int numberOfShards = randomIntBetween(1, 10);
|
||||
return new EnoughShardsWaitStep(stepKey, nextStepKey, numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnoughShardsWaitStep mutateInstance(EnoughShardsWaitStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
int numberOfShards = instance.getNumberOfShards();
|
||||
switch (between(0, 2)) {
|
||||
case 0:
|
||||
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
case 1:
|
||||
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
break;
|
||||
case 2:
|
||||
numberOfShards = numberOfShards + 1;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new EnoughShardsWaitStep(key, nextKey, numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnoughShardsWaitStep copyInstance(EnoughShardsWaitStep instance) {
|
||||
return new EnoughShardsWaitStep(instance.getKey(), instance.getNextStepKey(), instance.getNumberOfShards());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
int numberOfShards = randomIntBetween(1, 10);
|
||||
|
|
|
@ -16,8 +16,6 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
@ -26,8 +24,9 @@ import static org.mockito.Matchers.any;
|
|||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ForceMergeStepTests extends ESTestCase {
|
||||
public class ForceMergeStepTests extends AbstractStepTestCase<ForceMergeStep> {
|
||||
|
||||
@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));
|
||||
|
@ -36,6 +35,7 @@ public class ForceMergeStepTests extends ESTestCase {
|
|||
return new ForceMergeStep(stepKey, nextStepKey, null, maxNumSegments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForceMergeStep mutateInstance(ForceMergeStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -55,14 +55,13 @@ public class ForceMergeStepTests extends ESTestCase {
|
|||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new ForceMergeStep(key, nextKey, null, maxNumSegments);
|
||||
return new ForceMergeStep(key, nextKey, instance.getClient(), maxNumSegments);
|
||||
}
|
||||
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new ForceMergeStep(instance.getKey(), instance.getNextStepKey(),
|
||||
null, instance.getMaxNumSegments()), this::mutateInstance);
|
||||
@Override
|
||||
public ForceMergeStep copyInstance(ForceMergeStep instance) {
|
||||
return new ForceMergeStep(instance.getKey(), instance.getNextStepKey(),
|
||||
instance.getClient(), instance.getMaxNumSegments());
|
||||
}
|
||||
|
||||
public void testPerformActionComplete() {
|
||||
|
|
|
@ -12,14 +12,13 @@ import org.elasticsearch.cluster.ClusterState;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class InitializePolicyContextStepTests extends ESTestCase {
|
||||
public class InitializePolicyContextStepTests extends AbstractStepTestCase<InitializePolicyContextStep> {
|
||||
|
||||
@Override
|
||||
public InitializePolicyContextStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -27,6 +26,7 @@ public class InitializePolicyContextStepTests extends ESTestCase {
|
|||
return new InitializePolicyContextStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializePolicyContextStep mutateInstance(InitializePolicyContextStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -45,9 +45,9 @@ public class InitializePolicyContextStepTests extends ESTestCase {
|
|||
return new InitializePolicyContextStep(key, nextKey);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new InitializePolicyContextStep(instance.getKey(), instance.getNextStepKey()), this::mutateInstance);
|
||||
@Override
|
||||
public InitializePolicyContextStep copyInstance(InitializePolicyContextStep instance) {
|
||||
return new InitializePolicyContextStep(instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
|
||||
public void testAddCreationDate() {
|
||||
|
|
|
@ -13,14 +13,13 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PhaseAfterStepTests extends ESTestCase {
|
||||
public class PhaseAfterStepTests extends AbstractStepTestCase<PhaseAfterStep> {
|
||||
|
||||
@Override
|
||||
public PhaseAfterStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -32,6 +31,7 @@ public class PhaseAfterStepTests extends ESTestCase {
|
|||
return new TimeValue(randomLongBetween(1, 10000), randomFrom(TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhaseAfterStep mutateInstance(PhaseAfterStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -54,9 +54,10 @@ public class PhaseAfterStepTests extends ESTestCase {
|
|||
return new PhaseAfterStep(instance.getNowSupplier(), after, key, nextKey);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(), instance -> new PhaseAfterStep(instance.getNowSupplier(),
|
||||
instance.getAfter(), instance.getKey(), instance.getNextStepKey()), this::mutateInstance);
|
||||
@Override
|
||||
public PhaseAfterStep copyInstance(PhaseAfterStep instance) {
|
||||
return new PhaseAfterStep(instance.getNowSupplier(), instance.getAfter(),
|
||||
instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
|
|
|
@ -22,12 +22,11 @@ import org.elasticsearch.index.Index;
|
|||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
public class ReplicasAllocatedStepTests extends ESTestCase {
|
||||
public class ReplicasAllocatedStepTests extends AbstractStepTestCase<ReplicasAllocatedStep> {
|
||||
|
||||
@Override
|
||||
public ReplicasAllocatedStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -35,6 +34,7 @@ public class ReplicasAllocatedStepTests extends ESTestCase {
|
|||
return new ReplicasAllocatedStep(stepKey, nextStepKey, numberReplicas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplicasAllocatedStep mutateInstance(ReplicasAllocatedStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -56,10 +56,9 @@ public class ReplicasAllocatedStepTests extends ESTestCase {
|
|||
return new ReplicasAllocatedStep(key, nextKey, numberReplicas);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new ReplicasAllocatedStep(instance.getKey(), instance.getNextStepKey(), instance.getNumberReplicas()),
|
||||
this::mutateInstance);
|
||||
@Override
|
||||
public ReplicasAllocatedStep copyInstance(ReplicasAllocatedStep instance) {
|
||||
return new ReplicasAllocatedStep(instance.getKey(), instance.getNextStepKey(), instance.getNumberReplicas());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
|
|
|
@ -22,8 +22,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.junit.Before;
|
||||
|
@ -34,7 +32,7 @@ import org.mockito.stubbing.Answer;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RolloverStepTests extends ESTestCase {
|
||||
public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
|
||||
private Client client;
|
||||
|
||||
|
@ -43,6 +41,7 @@ public class RolloverStepTests extends ESTestCase {
|
|||
client = Mockito.mock(Client.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloverStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -56,6 +55,7 @@ public class RolloverStepTests extends ESTestCase {
|
|||
return new RolloverStep(stepKey, nextStepKey, client, alias, maxSize, maxAge, maxDocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolloverStep mutateInstance(RolloverStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -93,12 +93,10 @@ public class RolloverStepTests extends ESTestCase {
|
|||
return new RolloverStep(key, nextKey, instance.getClient(), alias, maxSize, maxAge, maxDocs);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils
|
||||
.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new RolloverStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(),
|
||||
instance.getAlias(), instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs()),
|
||||
this::mutateInstance);
|
||||
@Override
|
||||
public RolloverStep copyInstance(RolloverStep instance) {
|
||||
return new RolloverStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(),
|
||||
instance.getAlias(), instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs());
|
||||
}
|
||||
|
||||
public void testPerformAction() throws Exception {
|
||||
|
|
|
@ -17,10 +17,8 @@ import org.elasticsearch.client.IndicesAdminClient;
|
|||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.engine.Segment;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -32,8 +30,9 @@ import java.util.Spliterator;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
||||
public class SegmentCountStepTests extends ESTestCase {
|
||||
public class SegmentCountStepTests extends AbstractStepTestCase<SegmentCountStep> {
|
||||
|
||||
@Override
|
||||
public SegmentCountStep createRandomInstance() {
|
||||
Step.StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -43,6 +42,7 @@ public class SegmentCountStepTests extends ESTestCase {
|
|||
return new SegmentCountStep(stepKey, nextStepKey, null, maxNumSegments, bestCompression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SegmentCountStep mutateInstance(SegmentCountStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -69,11 +69,10 @@ public class SegmentCountStepTests extends ESTestCase {
|
|||
return new SegmentCountStep(key, nextKey, null, maxNumSegments, bestCompression);
|
||||
}
|
||||
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new SegmentCountStep(instance.getKey(), instance.getNextStepKey(),
|
||||
null, instance.getMaxNumSegments(), instance.isBestCompression()), this::mutateInstance);
|
||||
@Override
|
||||
public SegmentCountStep copyInstance(SegmentCountStep instance) {
|
||||
return new SegmentCountStep(instance.getKey(), instance.getNextStepKey(),
|
||||
null, instance.getMaxNumSegments(), instance.isBestCompression());
|
||||
}
|
||||
|
||||
public void testIsConditionMet() {
|
||||
|
|
|
@ -20,8 +20,6 @@ import org.elasticsearch.cluster.metadata.AliasMetaData;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.junit.Before;
|
||||
|
@ -33,7 +31,7 @@ import java.util.Collections;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ShrinkStepTests extends ESTestCase {
|
||||
public class ShrinkStepTests extends AbstractStepTestCase<ShrinkStep> {
|
||||
|
||||
private Client client;
|
||||
|
||||
|
@ -42,6 +40,7 @@ public class ShrinkStepTests extends ESTestCase {
|
|||
client = Mockito.mock(Client.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrinkStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -49,6 +48,7 @@ public class ShrinkStepTests extends ESTestCase {
|
|||
return new ShrinkStep(stepKey, nextStepKey, client, numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrinkStep mutateInstance(ShrinkStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -71,12 +71,9 @@ public class ShrinkStepTests extends ESTestCase {
|
|||
return new ShrinkStep(key, nextKey, instance.getClient(), numberOfShards);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils
|
||||
.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new ShrinkStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(),
|
||||
instance.getNumberOfShards()),
|
||||
this::mutateInstance);
|
||||
@Override
|
||||
public ShrinkStep copyInstance(ShrinkStep instance) {
|
||||
return new ShrinkStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(), instance.getNumberOfShards());
|
||||
}
|
||||
|
||||
public void testPerformAction() throws Exception {
|
||||
|
|
|
@ -10,11 +10,36 @@ import org.elasticsearch.cluster.ClusterName;
|
|||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class ShrunkenIndexCheckStepTests extends ESTestCase {
|
||||
public class ShrunkenIndexCheckStepTests extends AbstractStepTestCase<ShrunkenIndexCheckStep> {
|
||||
|
||||
@Override
|
||||
public ShrunkenIndexCheckStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
return new ShrunkenIndexCheckStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrunkenIndexCheckStep mutateInstance(ShrunkenIndexCheckStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
||||
if (randomBoolean()) {
|
||||
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
} else {
|
||||
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
}
|
||||
return new ShrunkenIndexCheckStep(key, nextKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShrunkenIndexCheckStep copyInstance(ShrunkenIndexCheckStep instance) {
|
||||
return new ShrunkenIndexCheckStep(instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
String sourceIndex = randomAlphaOfLengthBetween(1, 10);
|
||||
|
|
|
@ -5,13 +5,37 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
public class TerminalPolicyStepTests extends AbstractStepTestCase<TerminalPolicyStep> {
|
||||
|
||||
public class TerminalPolicyStepTests extends ESTestCase {
|
||||
@Override
|
||||
public TerminalPolicyStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
return new TerminalPolicyStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
public void testKeys() {
|
||||
@Override
|
||||
public TerminalPolicyStep mutateInstance(TerminalPolicyStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
||||
if (randomBoolean()) {
|
||||
key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
} else {
|
||||
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
|
||||
}
|
||||
|
||||
return new TerminalPolicyStep(key, nextKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalPolicyStep copyInstance(TerminalPolicyStep instance) {
|
||||
return new TerminalPolicyStep(instance.getKey(), instance.getNextStepKey());
|
||||
}
|
||||
public void testInstance() {
|
||||
assertEquals(new Step.StepKey("completed", "completed", "completed"), TerminalPolicyStep.INSTANCE.getKey());
|
||||
assertEquals(null, TerminalPolicyStep.INSTANCE.getNextStepKey());
|
||||
assertNull(TerminalPolicyStep.INSTANCE.getNextStepKey());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ import org.elasticsearch.client.Client;
|
|||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.EqualsHashCodeTestUtils;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||
import org.junit.Before;
|
||||
|
@ -26,7 +24,7 @@ import org.mockito.Mockito;
|
|||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
public class UpdateSettingsStepTests extends ESTestCase {
|
||||
public class UpdateSettingsStepTests extends AbstractStepTestCase<UpdateSettingsStep> {
|
||||
|
||||
private Client client;
|
||||
|
||||
|
@ -35,6 +33,7 @@ public class UpdateSettingsStepTests extends ESTestCase {
|
|||
client = Mockito.mock(Client.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateSettingsStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
@ -43,6 +42,7 @@ public class UpdateSettingsStepTests extends ESTestCase {
|
|||
return new UpdateSettingsStep(stepKey, nextStepKey, client, settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateSettingsStep mutateInstance(UpdateSettingsStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
@ -65,9 +65,9 @@ public class UpdateSettingsStepTests extends ESTestCase {
|
|||
return new UpdateSettingsStep(key, nextKey, client, settings);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(), instance -> new UpdateSettingsStep(instance.getKey(),
|
||||
instance.getNextStepKey(), instance.getClient(), instance.getSettings()), this::mutateInstance);
|
||||
@Override
|
||||
public UpdateSettingsStep copyInstance(UpdateSettingsStep instance) {
|
||||
return new UpdateSettingsStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(), instance.getSettings());
|
||||
}
|
||||
|
||||
public void testPerformAction() {
|
||||
|
|
Loading…
Reference in New Issue