Skip to content

Commit 3b4fa1c

Browse files
dakronejasontedor
authored andcommitted
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
1 parent 866fd4a commit 3b4fa1c

File tree

4 files changed

+28
-50
lines changed

4 files changed

+28
-50
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public final String toString() {
7171
return "[" + name + ": " + value + "]";
7272
}
7373

74+
public T value() {
75+
return value;
76+
}
77+
7478
/**
7579
* Holder for index stats used to evaluate conditions
7680
*/

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public final class RolloverResponse extends ShardsAcknowledgedResponse implement
6868
RolloverResponse() {
6969
}
7070

71-
RolloverResponse(String oldIndex, String newIndex, Map<String, Boolean> conditionResults,
72-
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
71+
public RolloverResponse(String oldIndex, String newIndex, Map<String, Boolean> conditionResults,
72+
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
7373
super(acknowledged, shardsAcknowledged);
7474
this.oldIndex = oldIndex;
7575
this.newIndex = newIndex;

x-pack/plugin/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverIndexTestHelper.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/RolloverStepTests.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.action.admin.indices.rollover.MaxAgeCondition;
1313
import org.elasticsearch.action.admin.indices.rollover.MaxDocsCondition;
1414
import org.elasticsearch.action.admin.indices.rollover.MaxSizeCondition;
15-
import org.elasticsearch.action.admin.indices.rollover.RolloverIndexTestHelper;
1615
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
1716
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
1817
import org.elasticsearch.client.AdminClient;
@@ -29,9 +28,11 @@
2928
import org.mockito.invocation.InvocationOnMock;
3029
import org.mockito.stubbing.Answer;
3130

31+
import java.util.Collections;
3232
import java.util.HashSet;
3333
import java.util.Locale;
3434
import java.util.Set;
35+
import java.util.stream.Collectors;
3536

3637
import static org.hamcrest.Matchers.equalTo;
3738

@@ -97,7 +98,19 @@ public RolloverStep copyInstance(RolloverStep instance) {
9798
instance.getMaxSize(), instance.getMaxAge(), instance.getMaxDocs());
9899
}
99100

100-
public void testPerformAction() throws Exception {
101+
private static void assertRolloverIndexRequest(RolloverRequest request, String alias, Set<Condition<?>> expectedConditions) {
102+
assertNotNull(request);
103+
assertEquals(1, request.indices().length);
104+
assertEquals(alias, request.indices()[0]);
105+
assertEquals(alias, request.getAlias());
106+
assertEquals(expectedConditions.size(), request.getConditions().size());
107+
Set<Object> expectedConditionValues = expectedConditions.stream().map(Condition::value).collect(Collectors.toSet());
108+
Set<Object> actualConditionValues = request.getConditions().values().stream()
109+
.map(Condition::value).collect(Collectors.toSet());
110+
assertEquals(expectedConditionValues, actualConditionValues);
111+
}
112+
113+
public void testPerformAction() {
101114
String alias = randomAlphaOfLength(5);
102115
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
103116
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
@@ -127,8 +140,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
127140
if (step.getMaxDocs() != null) {
128141
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
129142
}
130-
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
131-
listener.onResponse(RolloverIndexTestHelper.createMockResponse(request, true));
143+
assertRolloverIndexRequest(request, alias, expectedConditions);
144+
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true));
132145
return null;
133146
}
134147

@@ -155,7 +168,7 @@ public void onFailure(Exception e) {
155168
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
156169
}
157170

158-
public void testPerformActionNotComplete() throws Exception {
171+
public void testPerformActionNotComplete() {
159172
String alias = randomAlphaOfLength(5);
160173
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
161174
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
@@ -184,8 +197,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
184197
if (step.getMaxDocs() != null) {
185198
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
186199
}
187-
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
188-
listener.onResponse(RolloverIndexTestHelper.createMockResponse(request, false));
200+
assertRolloverIndexRequest(request, alias, expectedConditions);
201+
listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), false, true, true));
189202
return null;
190203
}
191204

@@ -212,7 +225,7 @@ public void onFailure(Exception e) {
212225
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
213226
}
214227

215-
public void testPerformActionFailure() throws Exception {
228+
public void testPerformActionFailure() {
216229
String alias = randomAlphaOfLength(5);
217230
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
218231
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
@@ -242,7 +255,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
242255
if (step.getMaxDocs() != null) {
243256
expectedConditions.add(new MaxDocsCondition(step.getMaxDocs()));
244257
}
245-
RolloverIndexTestHelper.assertRolloverIndexRequest(request, alias, expectedConditions);
258+
assertRolloverIndexRequest(request, alias, expectedConditions);
246259
listener.onFailure(exception);
247260
return null;
248261
}

0 commit comments

Comments
 (0)