Skip to content

Commit 3fa4335

Browse files
committed
Move test to a more appropriate place
1 parent cd4e3fa commit 3fa4335

File tree

2 files changed

+78
-51
lines changed

2 files changed

+78
-51
lines changed

modules/data-streams/src/test/java/org/elasticsearch/datastreams/action/GetDataStreamsResponseTests.java

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.elasticsearch.cluster.metadata.DataStream.getDefaultBackingIndexName;
3232
import static org.elasticsearch.cluster.metadata.DataStream.getDefaultFailureStoreName;
3333
import static org.hamcrest.Matchers.is;
34+
import static org.hamcrest.Matchers.notNullValue;
3435
import static org.hamcrest.Matchers.nullValue;
3536

3637
public class GetDataStreamsResponseTests extends ESTestCase {
@@ -136,16 +137,16 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
136137

137138
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
138139
var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName());
139-
List<Object> failureStoresRepresentation = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName());
140-
Map<String, Object> failureStoreRepresentation = (Map<String, Object>) failureStoresRepresentation.get(0);
141-
assertThat(failureStoreRepresentation.get("index_name"), is(failureStoreIndex.getName()));
142-
assertThat(failureStoreRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), is(false));
140+
List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName());
141+
Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0);
142+
assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName()));
143+
assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), nullValue());
143144
assertThat(
144-
failureStoreRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()),
145+
failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()),
145146
is(nullValue())
146147
);
147148
assertThat(
148-
failureStoreRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()),
149+
failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()),
149150
is(ManagedBy.LIFECYCLE.displayValue)
150151
);
151152
}
@@ -230,21 +231,86 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti
230231

231232
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
232233
var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName());
233-
List<Object> failureStoresRepresentation = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName());
234-
Map<String, Object> failureStoreRepresentation = (Map<String, Object>) failureStoresRepresentation.get(0);
235-
assertThat(failureStoreRepresentation.get("index_name"), is(failureStoreIndex.getName()));
236-
assertThat(failureStoreRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), is(false));
234+
List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName());
235+
Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0);
236+
assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName()));
237+
assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), nullValue());
237238
assertThat(
238-
failureStoreRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()),
239+
failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()),
239240
is(nullValue())
240241
);
241242
assertThat(
242-
failureStoreRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()),
243+
failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()),
243244
is(ManagedBy.UNMANAGED.displayValue)
244245
);
245246
}
246247
}
247248
}
249+
250+
{
251+
// one failure index that have ILM policy
252+
DataStream logs = DataStream.builder("logs", indices)
253+
.setGeneration(3)
254+
.setAllowCustomRouting(true)
255+
.setIndexMode(IndexMode.STANDARD)
256+
.setLifecycle(DataStreamLifecycle.DEFAULT_DATA_LIFECYCLE)
257+
.setDataStreamOptions(DataStreamOptions.FAILURE_STORE_ENABLED)
258+
.setFailureIndices(DataStream.DataStreamIndices.failureIndicesBuilder(failureStores).build())
259+
.build();
260+
261+
String ilmPolicyName = "rollover-30days";
262+
Map<Index, Response.IndexProperties> indexSettingsValues = Map.of(
263+
firstGenerationIndex,
264+
new Response.IndexProperties(true, ilmPolicyName, ManagedBy.ILM, null),
265+
secondGenerationIndex,
266+
new Response.IndexProperties(false, ilmPolicyName, ManagedBy.LIFECYCLE, null),
267+
writeIndex,
268+
new Response.IndexProperties(true, null, ManagedBy.LIFECYCLE, null),
269+
failureStoreIndex,
270+
new Response.IndexProperties(randomBoolean(), ilmPolicyName, ManagedBy.LIFECYCLE, null)
271+
);
272+
273+
Response.DataStreamInfo dataStreamInfo = new Response.DataStreamInfo(
274+
logs,
275+
true,
276+
ClusterHealthStatus.GREEN,
277+
"index-template",
278+
null,
279+
null,
280+
indexSettingsValues,
281+
false,
282+
null,
283+
null
284+
);
285+
Response response = new Response(List.of(dataStreamInfo));
286+
XContentBuilder contentBuilder = XContentFactory.jsonBuilder();
287+
response.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS);
288+
289+
BytesReference bytes = BytesReference.bytes(contentBuilder);
290+
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
291+
Map<String, Object> map = parser.map();
292+
List<Object> dataStreams = (List<Object>) map.get(Response.DATA_STREAMS_FIELD.getPreferredName());
293+
assertThat(dataStreams.size(), is(1));
294+
Map<String, Object> dataStreamMap = (Map<String, Object>) dataStreams.get(0);
295+
assertThat(dataStreamMap.get(DataStream.NAME_FIELD.getPreferredName()), is(dataStreamName));
296+
297+
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
298+
var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName());
299+
List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName());
300+
Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0);
301+
assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName()));
302+
assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), notNullValue());
303+
assertThat(
304+
failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()),
305+
is(ilmPolicyName)
306+
);
307+
assertThat(
308+
failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()),
309+
is(ManagedBy.LIFECYCLE.displayValue)
310+
);
311+
}
312+
}
313+
}
248314
}
249315

250316
public void testManagedByDisplayValuesDontAccidentalyChange() {

server/src/test/java/org/elasticsearch/action/datastreams/GetDataStreamActionTests.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -63,45 +63,6 @@ public void testDataStreamInfoToXContent() throws IOException {
6363
}
6464
}
6565

66-
@SuppressWarnings("unchecked")
67-
public void testFailureStoreIndexManagedByIlmToXContent() throws IOException {
68-
{
69-
70-
Index failureIndex = new Index("my-fs", randomUUID());
71-
var failureIndexProperties = new GetDataStreamAction.Response.IndexProperties(
72-
randomBoolean(),
73-
"my-policy",
74-
randomFrom(GetDataStreamAction.Response.ManagedBy.values()),
75-
null
76-
);
77-
var dataStream = DataStream.builder(
78-
randomAlphaOfLength(50),
79-
List.of(new Index(randomAlphaOfLength(10), randomAlphaOfLength(10)))
80-
)
81-
.setGeneration(randomLongBetween(1, 1000))
82-
.setFailureIndices(DataStream.DataStreamIndices.failureIndicesBuilder(List.of(failureIndex)).build())
83-
.build();
84-
var dataStreamInfo = new GetDataStreamAction.Response.DataStreamInfo(
85-
dataStream,
86-
randomBoolean(),
87-
randomFrom(ClusterHealthStatus.values()),
88-
null,
89-
null,
90-
null,
91-
Map.of(failureIndex, failureIndexProperties),
92-
randomBoolean(),
93-
null,
94-
null
95-
);
96-
Map<String, Object> failureStoreMap = (Map<String, Object>) getXContentMap(dataStreamInfo, null, null).get("failure_store");
97-
Map<String, Object> failureIndexMap = ((List<Map<String, Object>>) failureStoreMap.get("indices")).get(0);
98-
assertThat(failureIndexMap.get("index_name"), equalTo(failureIndex.getName()));
99-
assertThat(failureIndexMap.get("managed_by"), equalTo(failureIndexProperties.managedBy().displayValue));
100-
assertThat(failureIndexMap.get("prefer_ilm"), equalTo(failureIndexProperties.preferIlm()));
101-
assertThat(failureIndexMap.get("ilm_policy"), equalTo(failureIndexProperties.ilmPolicyName()));
102-
}
103-
}
104-
10566
/*
10667
* Calls toXContent on the given dataStreamInfo, and converts the response to a Map
10768
*/

0 commit comments

Comments
 (0)