Adds more missing equality tests
Specifically for the initialPolicyContextStep and the PhaseAfterStep
This commit is contained in:
parent
482de191f2
commit
20485cf7fb
|
@ -10,6 +10,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
public class PhaseAfterStep extends ClusterStateWaitStep {
|
||||
|
@ -29,4 +30,30 @@ public class PhaseAfterStep extends ClusterStateWaitStep {
|
|||
.getAsLong(LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE, -1L);
|
||||
return nowSupplier.getAsLong() >= lifecycleDate + after.getMillis();
|
||||
}
|
||||
|
||||
TimeValue getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
LongSupplier getNowSupplier() {
|
||||
return nowSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PhaseAfterStep other = (PhaseAfterStep) obj;
|
||||
return super.equals(obj) &&
|
||||
Objects.equals(after, other.after);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,43 @@ 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 InitializePolicyContextStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
|
||||
return new InitializePolicyContextStep(stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
public InitializePolicyContextStep mutateInstance(InitializePolicyContextStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
|
||||
switch (between(0, 1)) {
|
||||
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;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
return new InitializePolicyContextStep(key, nextKey);
|
||||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new InitializePolicyContextStep(instance.getKey(), instance.getNextStepKey()), this::mutateInstance);
|
||||
}
|
||||
|
||||
public void testAddCreationDate() {
|
||||
long creationDate = randomNonNegativeLong();
|
||||
IndexMetaData indexMetadata = IndexMetaData.builder(randomAlphaOfLength(5))
|
||||
|
|
|
@ -14,9 +14,51 @@ 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 PhaseAfterStep createRandomInstance() {
|
||||
StepKey stepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
StepKey nextStepKey = new StepKey(randomAlphaOfLength(10), randomAlphaOfLength(10), randomAlphaOfLength(10));
|
||||
TimeValue after = createRandomTimeValue();
|
||||
return new PhaseAfterStep(null, after, stepKey, nextStepKey);
|
||||
}
|
||||
|
||||
private TimeValue createRandomTimeValue() {
|
||||
return new TimeValue(randomLongBetween(1, 10000), randomFrom(TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS));
|
||||
}
|
||||
|
||||
public PhaseAfterStep mutateInstance(PhaseAfterStep instance) {
|
||||
StepKey key = instance.getKey();
|
||||
StepKey nextKey = instance.getNextStepKey();
|
||||
TimeValue after = instance.getAfter();
|
||||
|
||||
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:
|
||||
after = randomValueOtherThan(after, this::createRandomTimeValue);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void testConditionMet() {
|
||||
long creationDate = randomNonNegativeLong();
|
||||
IndexMetaData indexMetadata = IndexMetaData.builder(randomAlphaOfLength(5))
|
||||
|
|
Loading…
Reference in New Issue