Skip to content

Commit f0f0eeb

Browse files
authored
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
1 parent 21b97c2 commit f0f0eeb

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.Response;
1212
import org.elasticsearch.client.WarningFailureException;
13-
import org.elasticsearch.cluster.metadata.DataStream;
1413
import org.elasticsearch.cluster.metadata.IndexMetadata;
1514
import org.elasticsearch.cluster.metadata.Template;
1615
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -81,20 +80,15 @@ public void testRolloverAction() throws Exception {
8180

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

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

10094
public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
@@ -104,15 +98,18 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
10498

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

107-
String firstGenerationIndex = DataStream.getDefaultBackingIndexName(dataStream, 1);
101+
String firstGenerationIndex = getBackingIndices(client(), dataStream).getFirst();
108102
assertBusy(
109103
() -> assertThat(getStepKeyForIndex(client(), firstGenerationIndex).name(), equalTo(WaitForRolloverReadyStep.NAME)),
110104
30,
111105
TimeUnit.SECONDS
112106
);
113107

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

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

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

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

163-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
163+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
164164
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
165165

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

194-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
194+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
195195
assertBusy(
196196
() -> assertThat(
197197
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
@@ -226,7 +226,7 @@ public void testFreezeAction() throws Exception {
226226
indexDocument(client(), dataStream, true);
227227

228228
// The freeze action is a noop action with only noop steps and should pass through to complete the phase asap.
229-
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
229+
String backingIndexName = getBackingIndices(client(), dataStream).getFirst();
230230
assertBusy(() -> {
231231
try {
232232
assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME));
@@ -248,7 +248,7 @@ public void checkForceMergeAction(String codec) throws Exception {
248248
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
249249
indexDocument(client(), dataStream, true);
250250

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

0 commit comments

Comments
 (0)