mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 14:26:27 +00:00
Remove RolloverIndexTestHelper (#32559)
* Remove RolloverIndexTestHelper This removes the `RolloverIndexTestHelper` class in favor of making a couple of getters publically accessible as well as custom building a response object using JSON parsing. Relates to #29823
This commit is contained in:
parent
aed466d5b6
commit
7ea7dd8018
@ -71,6 +71,10 @@ public abstract class Condition<T> implements NamedWriteable, ToXContentFragment
|
||||
return "[" + name + ": " + value + "]";
|
||||
}
|
||||
|
||||
public T value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holder for index stats used to evaluate conditions
|
||||
*/
|
||||
|
@ -196,7 +196,7 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
|
||||
return dryRun;
|
||||
}
|
||||
|
||||
Map<String, Condition<?>> getConditions() {
|
||||
public Map<String, Condition<?>> getConditions() {
|
||||
return conditions;
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,8 @@ public final class RolloverResponse extends ShardsAcknowledgedResponse implement
|
||||
RolloverResponse() {
|
||||
}
|
||||
|
||||
RolloverResponse(String oldIndex, String newIndex, Map<String, Boolean> conditionResults,
|
||||
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
|
||||
public RolloverResponse(String oldIndex, String newIndex, Map<String, Boolean> conditionResults,
|
||||
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
|
||||
super(acknowledged, shardsAcknowledged);
|
||||
this.oldIndex = oldIndex;
|
||||
this.newIndex = newIndex;
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.action.admin.indices.rollover;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public final class RolloverIndexTestHelper {
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to inspect the
|
||||
// settings in an update settings request. Need to see if we can make the
|
||||
// getter public in ES
|
||||
public static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
|
||||
assertNotNull(request);
|
||||
assertEquals(1, request.indices().length);
|
||||
assertEquals(alias, request.indices()[0]);
|
||||
assertEquals(alias, request.getAlias());
|
||||
assertEquals(expectedConditions.size(), request.getConditions().size());
|
||||
Set<Object> expectedConditionValues = expectedConditions.stream().map(condition -> condition.value).collect(Collectors.toSet());
|
||||
Set<Object> actualConditionValues = request.getConditions().values().stream()
|
||||
.map(condition -> condition.value).collect(Collectors.toSet());
|
||||
assertEquals(expectedConditionValues, actualConditionValues);
|
||||
}
|
||||
|
||||
// NORELEASE this isn't nice but it's currently the only way to create an
|
||||
// UpdateSettingsResponse. Need to see if we can make the constructor public
|
||||
// in ES
|
||||
public static RolloverResponse createMockResponse(RolloverRequest request, boolean rolledOver) {
|
||||
return new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), rolledOver, true, true);
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ import org.elasticsearch.action.admin.indices.rollover.Condition;
|
||||
import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
|
||||
import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
|
||||
import org.elasticsearch.action.admin.indices.rollover.MaxSizeCondition;
|
||||
import org.elasticsearch.action.admin.indices.rollover.RolloverIndexTestHelper;
|
||||
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
||||
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
||||
import org.elasticsearch.client.AdminClient;
|
||||
@ -29,9 +28,11 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@ -97,7 +98,19 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs());
|
||||
}
|
||||
|
||||
public void testPerformAction() throws Exception {
|
||||
private static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
|
||||
assertNotNull(request);
|
||||
assertEquals(1, request.indices().length);
|
||||
assertEquals(alias, request.indices()[0]);
|
||||
assertEquals(alias, request.getAlias());
|
||||
assertEquals(expectedConditions.size(), request.getConditions().size());
|
||||
Set<Object> expectedConditionValues = expectedConditions.stream().map(Condition::value).collect(Collectors.toSet());
|
||||
Set<Object> actualConditionValues = request.getConditions().values().stream()
|
||||
.map(Condition::value).collect(Collectors.toSet());
|
||||
assertEquals(expectedConditionValues, actualConditionValues);
|
||||
}
|
||||
|
||||
public void testPerformAction() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
@ -127,8 +140,8 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
if (step.getMaxDocs() != null) {
|
||||
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
|
||||
}
|
||||
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
listener.onResponse(RolloverIndexTestHelper.createMockResponse(request, true));
|
||||
assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -155,7 +168,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
public void testPerformActionNotComplete() throws Exception {
|
||||
public void testPerformActionNotComplete() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
@ -184,8 +197,8 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
if (step.getMaxDocs() != null) {
|
||||
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
|
||||
}
|
||||
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
listener.onResponse(RolloverIndexTestHelper.createMockResponse(request, false));
|
||||
assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), false, true, true));
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -212,7 +225,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
|
||||
}
|
||||
|
||||
public void testPerformActionFailure() throws Exception {
|
||||
public void testPerformActionFailure() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
@ -242,7 +255,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
||||
if (step.getMaxDocs() != null) {
|
||||
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
|
||||
}
|
||||
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
assertRolloverIndexRequest(request, alias, expectedConditions);
|
||||
listener.onFailure(exception);
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user