Skip to content

Commit

Permalink
Use CURRENT_VERSION in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidan committed Jul 19, 2023
1 parent 788741b commit 8775cfb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.awaitLatch;
import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING;
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleActionsRegistry.VERSION_ONE;
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleActionsRegistry.CURRENT_VERSION;
import static org.elasticsearch.xpack.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -782,7 +782,7 @@ public void testGetCurrentStep() {
StepKey secondStepKey = new StepKey("phase_1", "action_1", "step_2");
Step firstStep = new MockStep(firstStepKey, secondStepKey);
Map<VersionedPolicyKey, Step> firstStepMap = new HashMap<>();
firstStepMap.put(new VersionedPolicyKey(VERSION_ONE, policyName), firstStep);
firstStepMap.put(new VersionedPolicyKey(CURRENT_VERSION, policyName), firstStep);
Map<VersionedPolicyKey, Map<StepKey, Step>> stepMap = new HashMap<>();
Index index = new Index("test", "uuid");

Expand Down Expand Up @@ -839,10 +839,10 @@ public void testIsReadyToTransition() {
)
)
);
Map<VersionedPolicyKey, Step> firstStepMap = Collections.singletonMap(new VersionedPolicyKey(VERSION_ONE, policyName), step);
Map<VersionedPolicyKey, Step> firstStepMap = Collections.singletonMap(new VersionedPolicyKey(CURRENT_VERSION, policyName), step);
Map<StepKey, Step> policySteps = Collections.singletonMap(step.getKey(), step);
Map<VersionedPolicyKey, Map<StepKey, Step>> stepMap = Collections.singletonMap(
new VersionedPolicyKey(VERSION_ONE, policyName),
new VersionedPolicyKey(CURRENT_VERSION, policyName),
policySteps
);
PolicyStepsRegistry policyStepsRegistry = new PolicyStepsRegistry(
Expand Down Expand Up @@ -1249,11 +1249,11 @@ public static MockPolicyStepsRegistry createMultiStepPolicyStepRegistry(String p
SortedMap<String, LifecyclePolicyMetadata> lifecyclePolicyMap = new TreeMap<>();
lifecyclePolicyMap.put(policyName, new LifecyclePolicyMetadata(policy, new HashMap<>(), 1, 1));
Map<VersionedPolicyKey, Step> firstStepMap = new HashMap<>();
firstStepMap.put(new VersionedPolicyKey(VERSION_ONE, policyName), steps.get(0));
firstStepMap.put(new VersionedPolicyKey(CURRENT_VERSION, policyName), steps.get(0));
Map<VersionedPolicyKey, Map<StepKey, Step>> stepMap = new HashMap<>();
Map<StepKey, Step> policySteps = new HashMap<>();
steps.forEach(step -> policySteps.put(step.getKey(), step));
stepMap.put(new VersionedPolicyKey(VERSION_ONE, policyName), policySteps);
stepMap.put(new VersionedPolicyKey(CURRENT_VERSION, policyName), policySteps);
Client client = mock(Client.class);
when(client.settings()).thenReturn(Settings.EMPTY);
return new MockPolicyStepsRegistry(lifecyclePolicyMap, firstStepMap, stepMap, REGISTRY, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleActionsRegistry.CURRENT_VERSION;
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleActionsRegistry.VERSION_ONE;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -249,7 +250,8 @@ public void testUpdateFromNothingToSomethingToNothing() throws Exception {
assertThat(registry.getLifecyclePolicyMap().get(newPolicy.getName()).getHeaders(), equalTo(headers));
assertThat(registry.getFirstStepMap().size(), equalTo(1));
assertThat(registry.getStepMap().size(), equalTo(1));
Map<Step.StepKey, Step> registeredStepsForPolicy = registry.getStepMap().get(new VersionedPolicyKey(1, newPolicy.getName()));
Map<Step.StepKey, Step> registeredStepsForPolicy = registry.getStepMap()
.get(new VersionedPolicyKey(CURRENT_VERSION, newPolicy.getName()));
assertThat(registeredStepsForPolicy.size(), equalTo(policySteps.size()));
for (Step step : policySteps) {
LifecycleExecutionState.Builder newIndexState = LifecycleExecutionState.builder();
Expand Down Expand Up @@ -409,7 +411,8 @@ public void testUpdatePolicyButNoPhaseChangeIndexStepsDontChange() throws Except
// add new policy
registry.update(currentState.metadata().custom(IndexLifecycleMetadata.TYPE));

Map<Step.StepKey, Step> registeredStepsForPolicy = registry.getStepMap().get(new VersionedPolicyKey(1, newPolicy.getName()));
Map<Step.StepKey, Step> registeredStepsForPolicy = registry.getStepMap()
.get(new VersionedPolicyKey(CURRENT_VERSION, newPolicy.getName()));
Step shrinkStep = registeredStepsForPolicy.entrySet()
.stream()
.filter(e -> e.getKey().phase().equals("warm") && e.getKey().name().equals("shrink"))
Expand Down Expand Up @@ -438,7 +441,7 @@ public void testUpdatePolicyButNoPhaseChangeIndexStepsDontChange() throws Except
// Update the policies
registry.update(currentState.metadata().custom(IndexLifecycleMetadata.TYPE));

registeredStepsForPolicy = registry.getStepMap().get(new VersionedPolicyKey(1, newPolicy.getName()));
registeredStepsForPolicy = registry.getStepMap().get(new VersionedPolicyKey(CURRENT_VERSION, newPolicy.getName()));
shrinkStep = registeredStepsForPolicy.entrySet()
.stream()
.filter(e -> e.getKey().phase().equals("warm") && e.getKey().name().equals("shrink"))
Expand Down

0 comments on commit 8775cfb

Please sign in to comment.