Tidies up unit tests
Also fixes failing EnoughShardsWaitStep
This commit is contained in:
parent
1c2e7bc431
commit
088894019e
|
@ -9,6 +9,8 @@ import org.elasticsearch.action.support.ActiveShardCount;
|
|||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class EnoughShardsWaitStep extends ClusterStateWaitStep {
|
||||
public static final String NAME = "enough-shards-allocated";
|
||||
private final int numberOfShards;
|
||||
|
@ -28,4 +30,22 @@ public class EnoughShardsWaitStep extends ClusterStateWaitStep {
|
|||
return clusterState.metaData().index(index).getNumberOfShards() == numberOfShards &&
|
||||
ActiveShardCount.ALL.enoughShardsActive(clusterState, index.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), numberOfShards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
EnoughShardsWaitStep other = (EnoughShardsWaitStep) obj;
|
||||
return super.equals(obj) &&
|
||||
Objects.equals(numberOfShards, other.numberOfShards);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* 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.indexlifecycle;
|
||||
package org.elasticsearch.xpack.core.indexlifecycle;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
|
@ -15,18 +15,6 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.InitializePolicyContextStep;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.MockAction;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.MockStep;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Phase;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.PhaseAfterStep;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -72,7 +60,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
|
|||
return randomLifecyclePolicy(lifecycleName);
|
||||
}
|
||||
|
||||
static LifecyclePolicy randomLifecyclePolicy(@Nullable String lifecycleName) {
|
||||
public static LifecyclePolicy randomLifecyclePolicy(@Nullable String lifecycleName) {
|
||||
int numberPhases = randomInt(5);
|
||||
Map<String, Phase> phases = new HashMap<>(numberPhases);
|
||||
for (int i = 0; i < numberPhases; i++) {
|
|
@ -39,7 +39,9 @@ public class StepKeyTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testHashcodeAndEquals() {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new StepKey(instance.getPhase(), instance.getAction(), instance.getName()), this::mutateInstance);
|
||||
for (int runs = 0; runs < 20; runs++) {
|
||||
EqualsHashCodeTestUtils.checkEqualsAndHashCode(createRandomInstance(),
|
||||
instance -> new StepKey(instance.getPhase(), instance.getAction(), instance.getName()), this::mutateInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.transport.TransportAddress;
|
|||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.MockStep;
|
||||
import org.elasticsearch.xpack.core.indexlifecycle.Step;
|
||||
|
||||
|
@ -22,7 +23,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.xpack.indexlifecycle.LifecyclePolicyTests.randomLifecyclePolicy;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class PolicyStepsRegistryTests extends ESTestCase {
|
||||
|
@ -76,7 +76,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testUpdateFromNothingToSomethingToNothing() {
|
||||
LifecyclePolicy newPolicy = randomLifecyclePolicy(randomAlphaOfLength(5));
|
||||
LifecyclePolicy newPolicy = LifecyclePolicyTests.randomLifecyclePolicy(randomAlphaOfLength(5));
|
||||
List<Step> policySteps = newPolicy.toSteps(null, () -> 0L);
|
||||
Map<String, LifecyclePolicy> policyMap = Collections.singletonMap(newPolicy.getName(), newPolicy);
|
||||
MetaData metaData = MetaData.builder()
|
||||
|
@ -130,7 +130,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
|
|||
|
||||
public void testUpdateChangedPolicy() {
|
||||
String policyName = randomAlphaOfLengthBetween(5, 10);
|
||||
LifecyclePolicy newPolicy = randomLifecyclePolicy(policyName);
|
||||
LifecyclePolicy newPolicy = LifecyclePolicyTests.randomLifecyclePolicy(policyName);
|
||||
Map<String, LifecyclePolicy> policyMap = Collections.singletonMap(newPolicy.getName(), newPolicy);
|
||||
MetaData metaData = MetaData.builder()
|
||||
.persistentSettings(settings(Version.CURRENT).build())
|
||||
|
@ -149,7 +149,7 @@ public class PolicyStepsRegistryTests extends ESTestCase {
|
|||
registry.update(currentState, null, () -> 0L);
|
||||
|
||||
// swap out policy
|
||||
newPolicy = randomLifecyclePolicy(policyName);
|
||||
newPolicy = LifecyclePolicyTests.randomLifecyclePolicy(policyName);
|
||||
currentState = ClusterState.builder(currentState)
|
||||
.metaData(
|
||||
MetaData.builder(metaData)
|
||||
|
|
Loading…
Reference in New Issue