Skip to content

Commit c8c16d0

Browse files
authored
[8.16] Fix failing test(s) in TimeSeriesDataStreamsIT (#123378) (#123475)
* Fix failing test(s) in `TimeSeriesDataStreamsIT` (#123378) When these tests were run around midnight, the use of `DataStream#getDefaultBackingIndexName` could result in a potential mismatch in the generated index name and the one that the cluster actually created. Instead, we need to obtain the backing index and extract the desired index name from there. Fixes #123086 Relates #123376 (cherry picked from commit f0f0eeb) # Conflicts: # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java * Fix compilation
1 parent 19402e2 commit c8c16d0

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

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

+24-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.Response;
12-
import org.elasticsearch.cluster.metadata.DataStream;
1312
import org.elasticsearch.cluster.metadata.IndexMetadata;
1413
import org.elasticsearch.cluster.metadata.Template;
1514
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -80,20 +79,15 @@ public void testRolloverAction() throws Exception {
8079

8180
indexDocument(client(), dataStream, true);
8281

83-
assertBusy(() -> assertTrue(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2))));
84-
assertBusy(
85-
() -> assertTrue(
86-
Boolean.parseBoolean(
87-
(String) getIndexSettingsAsMap(DataStream.getDefaultBackingIndexName(dataStream, 2)).get("index.hidden")
88-
)
89-
)
90-
);
91-
assertBusy(
92-
() -> assertThat(
93-
getStepKeyForIndex(client(), DataStream.getDefaultBackingIndexName(dataStream, 1)),
94-
equalTo(PhaseCompleteStep.finalStep("hot").getKey())
95-
)
96-
);
82+
assertBusy(() -> {
83+
final var backingIndices = getBackingIndices(client(), dataStream);
84+
assertEquals(2, backingIndices.size());
85+
assertTrue(Boolean.parseBoolean((String) getIndexSettingsAsMap(backingIndices.get(1)).get("index.hidden")));
86+
});
87+
assertBusy(() -> {
88+
final var backingIndices = getBackingIndices(client(), dataStream);
89+
assertEquals(PhaseCompleteStep.finalStep("hot").getKey(), getStepKeyForIndex(client(), backingIndices.get(0)));
90+
});
9791
}
9892

9993
public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
@@ -103,15 +97,18 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
10397

10498
indexDocument(client(), dataStream, true);
10599

106-
String firstGenerationIndex = DataStream.getDefaultBackingIndexName(dataStream, 1);
100+
String firstGenerationIndex = getBackingIndices(client(), dataStream).get(0);
107101
assertBusy(
108102
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)),
109103
30,
110104
TimeUnit.SECONDS
111105
);
112106

113107
rolloverMaxOneDocCondition(client(), dataStream);
114-
assertBusy(() -> assertThat(indexExists(DataStream.getDefaultBackingIndexName(dataStream, 2)), is(true)), 30, TimeUnit.SECONDS);
108+
assertBusy(() -> {
109+
final var backingIndices = getBackingIndices(client(), dataStream);
110+
assertEquals(2, backingIndices.size());
111+
}, 30, TimeUnit.SECONDS);
115112

116113
// even though the first index doesn't have 2 documents to fulfill the rollover condition, it should complete the rollover action
117114
// because it's not the write index anymore
@@ -128,7 +125,7 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
128125
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
129126
indexDocument(client(), dataStream, true);
130127

131-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
128+
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
132129
assertBusy(
133130
() -> assertThat(
134131
"original index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -142,8 +139,11 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
142139
// Manual rollover the original index such that it's not the write index in the data stream anymore
143140
rolloverMaxOneDocCondition(client(), dataStream);
144141
// Wait for rollover to happen
145-
String rolloverIndex = DataStream.getDefaultBackingIndexName(dataStream, 2);
146-
assertBusy(() -> assertTrue("the rollover action created the rollover index", indexExists(rolloverIndex)), 30, TimeUnit.SECONDS);
142+
assertBusy(
143+
() -> assertEquals("the rollover action created the rollover index", 2, getBackingIndices(client(), dataStream).size()),
144+
30,
145+
TimeUnit.SECONDS
146+
);
147147

148148
String shrunkenIndex = waitAndGetShrinkIndexName(client(), backingIndexName);
149149
assertBusy(() -> assertTrue(indexExists(shrunkenIndex)), 30, TimeUnit.SECONDS);
@@ -159,7 +159,7 @@ public void testSearchableSnapshotAction() throws Exception {
159159
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
160160
indexDocument(client(), dataStream, true);
161161

162-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
162+
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
163163
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
164164

165165
assertBusy(
@@ -190,7 +190,7 @@ public void testReadOnlyAction() throws Exception {
190190
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
191191
indexDocument(client(), dataStream, true);
192192

193-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
193+
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
194194
assertBusy(
195195
() -> assertThat(
196196
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -220,7 +220,7 @@ public void testFreezeAction() throws Exception {
220220
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
221221
indexDocument(client(), dataStream, true);
222222

223-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
223+
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
224224
assertBusy(
225225
() -> assertThat(
226226
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -249,7 +249,7 @@ public void checkForceMergeAction(String codec) throws Exception {
249249
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
250250
indexDocument(client(), dataStream, true);
251251

252-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
252+
String backingIndexName = getBackingIndices(client(), dataStream).get(0);
253253
assertBusy(
254254
() -> assertThat(
255255
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",

0 commit comments

Comments
 (0)