Skip to content

Commit 1a8825e

Browse files
authored
Remove test usages of DataStream#getDefaultBackingIndexName in ILM integration tests (elastic#124319) (elastic#124467) (elastic#124482)
* Incorporate review comments (cherry picked from commit 44dd44b) # Conflicts: # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java (cherry picked from commit 474d223) # Conflicts: # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java
1 parent 90cf9cd commit 1a8825e

File tree

9 files changed

+89
-58
lines changed

9 files changed

+89
-58
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder;
4949
import org.elasticsearch.action.bulk.BulkRequestBuilder;
5050
import org.elasticsearch.action.bulk.BulkResponse;
51+
import org.elasticsearch.action.datastreams.GetDataStreamAction;
5152
import org.elasticsearch.action.index.IndexRequestBuilder;
5253
import org.elasticsearch.action.search.ClearScrollResponse;
5354
import org.elasticsearch.action.search.SearchRequest;
@@ -74,6 +75,7 @@
7475
import org.elasticsearch.cluster.InternalClusterInfoService;
7576
import org.elasticsearch.cluster.coordination.ElasticsearchNodeCommand;
7677
import org.elasticsearch.cluster.health.ClusterHealthStatus;
78+
import org.elasticsearch.cluster.metadata.DataStream;
7779
import org.elasticsearch.cluster.metadata.IndexMetadata;
7880
import org.elasticsearch.cluster.metadata.Metadata;
7981
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -871,6 +873,22 @@ private static Settings.Builder getExcludeSettings(int num, Settings.Builder bui
871873
return builder;
872874
}
873875

876+
/**
877+
* Returns a list of the data stream's backing index names.
878+
*/
879+
public List<String> getDataStreamBackingIndexNames(String dataStreamName) {
880+
GetDataStreamAction.Response response = safeGet(
881+
client().execute(
882+
GetDataStreamAction.INSTANCE,
883+
new GetDataStreamAction.Request(TEST_REQUEST_TIMEOUT, new String[] { dataStreamName })
884+
)
885+
);
886+
assertThat(response.getDataStreams().size(), equalTo(1));
887+
DataStream dataStream = response.getDataStreams().get(0).getDataStream();
888+
assertThat(dataStream.getName(), equalTo(dataStreamName));
889+
return dataStream.getIndices().stream().map(Index::getName).toList();
890+
}
891+
874892
/**
875893
* Waits until all nodes have no pending tasks.
876894
*/

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,20 @@ protected static boolean aliasExists(String index, String alias) throws IOExcept
19501950
return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode();
19511951
}
19521952

1953+
/**
1954+
* Returns a list of the data stream's backing index names.
1955+
*/
1956+
@SuppressWarnings("unchecked")
1957+
protected static List<String> getDataStreamBackingIndexNames(String dataStreamName) throws IOException {
1958+
Map<String, Object> response = getAsMap(client(), "/_data_stream/" + dataStreamName);
1959+
List<?> dataStreams = (List<?>) response.get("data_streams");
1960+
assertThat(dataStreams.size(), equalTo(1));
1961+
Map<?, ?> dataStream = (Map<?, ?>) dataStreams.get(0);
1962+
assertThat(dataStream.get("name"), equalTo(dataStreamName));
1963+
List<?> indices = (List<?>) dataStream.get("indices");
1964+
return indices.stream().map(index -> ((Map<String, String>) index).get("index_name")).toList();
1965+
}
1966+
19531967
@SuppressWarnings("unchecked")
19541968
protected static Map<String, Object> getAlias(final String index, final String alias) throws IOException {
19551969
String endpoint = "/_alias";

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.client.Request;
1212
import org.elasticsearch.client.Response;
1313
import org.elasticsearch.client.ResponseException;
14-
import org.elasticsearch.cluster.metadata.DataStream;
1514
import org.elasticsearch.cluster.metadata.Template;
1615
import org.elasticsearch.common.Strings;
1716
import org.elasticsearch.common.settings.Settings;
@@ -30,6 +29,7 @@
3029
import org.junit.Before;
3130

3231
import java.io.IOException;
32+
import java.util.List;
3333
import java.util.Locale;
3434
import java.util.Map;
3535
import java.util.concurrent.TimeUnit;
@@ -41,6 +41,7 @@
4141
import static org.elasticsearch.xpack.TimeSeriesRestDriver.indexDocument;
4242
import static org.elasticsearch.xpack.TimeSeriesRestDriver.rolloverMaxOneDocCondition;
4343
import static org.hamcrest.CoreMatchers.containsStringIgnoringCase;
44+
import static org.hamcrest.Matchers.equalTo;
4445
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4546
import static org.hamcrest.Matchers.is;
4647

@@ -107,7 +108,9 @@ public void testSearchableSnapshotActionErrorsOnInvalidLicense() throws Exceptio
107108
// rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index
108109
rolloverMaxOneDocCondition(client(), dataStream);
109110

110-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1L);
111+
List<String> backingIndices = getDataStreamBackingIndexNames(dataStream);
112+
assertThat(backingIndices.size(), equalTo(2));
113+
String backingIndexName = backingIndices.get(0);
111114
// the searchable_snapshot action should start failing (and retrying) due to invalid license
112115
assertBusy(() -> {
113116
Map<String, Object> explainIndex = explainIndex(client(), backingIndexName);

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
4040
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createSnapshotRepo;
4141
import static org.elasticsearch.xpack.TimeSeriesRestDriver.explainIndex;
42-
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getBackingIndices;
4342
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getOnlyIndexSettings;
4443
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
4544
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getTemplate;
@@ -80,12 +79,12 @@ public void testRolloverAction() throws Exception {
8079
indexDocument(client(), dataStream, true);
8180

8281
assertBusy(() -> {
83-
final var backingIndices = getBackingIndices(client(), dataStream);
82+
final var backingIndices = getDataStreamBackingIndexNames(dataStream);
8483
assertEquals(2, backingIndices.size());
8584
assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.get(1)).get("index.hidden")));
8685
});
8786
assertBusy(() -> {
88-
final var backingIndices = getBackingIndices(client(), dataStream);
87+
final var backingIndices = getDataStreamBackingIndexNames(dataStream);
8988
assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.get(0)));
9089
});
9190
}
@@ -97,7 +96,7 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
9796

9897
indexDocument(client(), dataStream, true);
9998

100-
String firstGenerationIndex = getBackingIndices(client(), dataStream).get(0);
99+
String firstGenerationIndex = getDataStreamBackingIndexNames(dataStream).get(0);
101100
assertBusy(
102101
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)),
103102
30,
@@ -106,7 +105,7 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
106105

107106
rolloverMaxOneDocCondition(client(), dataStream);
108107
assertBusy(() -> {
109-
final var backingIndices = getBackingIndices(client(), dataStream);
108+
final var backingIndices = getDataStreamBackingIndexNames(dataStream);
110109
assertEquals(2, backingIndices.size());
111110
}, 30, TimeUnit.SECONDS);
112111

@@ -124,7 +123,7 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
124123
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
125124
indexDocument(client(), dataStream, true);
126125

127-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
126+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
128127
assertBusy(
129128
() -> assertThat(
130129
"original index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -139,7 +138,7 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
139138
rolloverMaxOneDocCondition(client(), dataStream);
140139
// Wait for rollover to happen
141140
assertBusy(
142-
() -> assertEquals("the rollover action created the rollover index", 2, getBackingIndices(client(), dataStream).size()),
141+
() -> assertEquals("the rollover action created the rollover index", 2, getDataStreamBackingIndexNames(dataStream).size()),
143142
30,
144143
TimeUnit.SECONDS
145144
);
@@ -158,7 +157,7 @@ public void testSearchableSnapshotAction() throws Exception {
158157
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
159158
indexDocument(client(), dataStream, true);
160159

161-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
160+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
162161
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
163162

164163
assertBusy(
@@ -189,7 +188,7 @@ public void testReadOnlyAction() throws Exception {
189188
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
190189
indexDocument(client(), dataStream, true);
191190

192-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
191+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
193192
assertBusy(
194193
() -> assertThat(
195194
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -219,7 +218,7 @@ public void testFreezeAction() throws Exception {
219218
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
220219
indexDocument(client(), dataStream, true);
221220

222-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
221+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
223222
assertBusy(
224223
() -> assertThat(
225224
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -248,7 +247,7 @@ public void checkForceMergeAction(String codec) throws Exception {
248247
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
249248
indexDocument(client(), dataStream, true);
250249

251-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
250+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
252251
assertBusy(
253252
() -> assertThat(
254253
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -322,7 +321,7 @@ public void testDataStreamWithMultipleIndicesAndWriteIndexInDeletePhase() throws
322321
client().performRequest(new Request("POST", dataStream + "/_rollover"));
323322
indexDocument(client(), dataStream, true);
324323

325-
String secondGenerationIndex = getBackingIndices(client(), dataStream).get(1);
324+
String secondGenerationIndex = getDataStreamBackingIndexNames(dataStream).get(1);
326325
assertBusy(() -> {
327326
Request explainRequest = new Request("GET", "/_data_stream/" + dataStream);
328327
Response response = client().performRequest(explainRequest);

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.client.Request;
1515
import org.elasticsearch.client.Response;
1616
import org.elasticsearch.client.ResponseException;
17-
import org.elasticsearch.cluster.metadata.DataStream;
1817
import org.elasticsearch.cluster.metadata.IndexMetadata;
1918
import org.elasticsearch.common.Strings;
2019
import org.elasticsearch.common.settings.Settings;
@@ -1222,7 +1221,7 @@ private void assertHistoryIsPresent(
12221221
}
12231222

12241223
// Finally, check that the history index is in a good state
1225-
String historyIndexName = DataStream.getDefaultBackingIndexName("ilm-history-7", 1);
1224+
String historyIndexName = getDataStreamBackingIndexNames("ilm-history-7").get(0);
12261225
Response explainHistoryIndex = client().performRequest(new Request("GET", historyIndexName + "/_lifecycle/explain"));
12271226
Map<String, Object> responseMap;
12281227
try (InputStream is = explainHistoryIndex.getEntity().getContent()) {

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/DownsampleActionIT.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.ResponseException;
1313
import org.elasticsearch.client.RestClient;
14-
import org.elasticsearch.cluster.metadata.DataStream;
1514
import org.elasticsearch.cluster.metadata.IndexMetadata;
1615
import org.elasticsearch.cluster.metadata.IndexMetadata.DownsampleTaskStatus;
1716
import org.elasticsearch.common.Strings;
@@ -49,7 +48,6 @@
4948
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
5049
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
5150
import static org.elasticsearch.xpack.TimeSeriesRestDriver.explainIndex;
52-
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getBackingIndices;
5351
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getOnlyIndexSettings;
5452
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
5553
import static org.elasticsearch.xpack.TimeSeriesRestDriver.index;
@@ -318,7 +316,7 @@ public void testTsdbDataStreams() throws Exception {
318316

319317
index(client(), dataStream, true, null, "@timestamp", "2020-01-01T05:10:00Z", "volume", 11.0, "metricset", randomAlphaOfLength(5));
320318

321-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
319+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
322320
assertBusy(
323321
() -> assertThat(
324322
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -365,7 +363,7 @@ public void testILMWaitsForTimeSeriesEndTimeToLapse() throws Exception {
365363
String now = DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(Instant.now());
366364
index(client(), dataStream, true, null, "@timestamp", now, "volume", 11.0, "metricset", randomAlphaOfLength(5));
367365

368-
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
366+
String backingIndexName = getDataStreamBackingIndexNames(dataStream).get(0);
369367
assertBusy(
370368
() -> assertThat(
371369
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -459,7 +457,7 @@ public void testDownsampleTwice() throws Exception {
459457

460458
index(client(), dataStream, true, null, "@timestamp", "2020-01-01T05:10:00Z", "volume", 11.0, "metricset", randomAlphaOfLength(5));
461459

462-
String firstBackingIndex = DataStream.getDefaultBackingIndexName(dataStream, 1);
460+
String firstBackingIndex = getDataStreamBackingIndexNames(dataStream).get(0);
463461
logger.info("--> firstBackingIndex: {}", firstBackingIndex);
464462
assertBusy(
465463
() -> assertThat(
@@ -540,7 +538,7 @@ public void testDownsampleTwiceSameInterval() throws Exception {
540538

541539
index(client(), dataStream, true, null, "@timestamp", "2020-01-01T05:10:00Z", "volume", 11.0, "metricset", randomAlphaOfLength(5));
542540

543-
String firstBackingIndex = getBackingIndices(client(), dataStream).get(0);
541+
String firstBackingIndex = getDataStreamBackingIndexNames(dataStream).get(0);
544542
logger.info("--> firstBackingIndex: {}", firstBackingIndex);
545543
assertBusy(
546544
() -> assertThat(

0 commit comments

Comments
 (0)