Skip to content

Commit 7d3ccbc

Browse files
committed
Fix StatelessRealTimeTermVectorsIT
1 parent 2f28fc5 commit 7d3ccbc

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,6 @@ tests:
470470
- class: org.elasticsearch.search.aggregations.metrics.LargeTopHitsIT
471471
method: test500Queries
472472
issue: https://github.com/elastic/elasticsearch/issues/148056
473-
- class: org.elasticsearch.xpack.stateless.StatelessRealTimeTermVectorsIT
474-
method: testUpdatedDocsNotInLiveVersionMapDoNotRefresh
475-
issue: https://github.com/elastic/elasticsearch/issues/148067
476473
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
477474
method: test {p0=mtermvectors/10_basic/Tests catching other exceptions per item}
478475
issue: https://github.com/elastic/elasticsearch/issues/148096
@@ -488,9 +485,6 @@ tests:
488485
- class: org.elasticsearch.xpack.esql.qa.mixed.EsqlClientYamlIT
489486
method: test {p0=esql/50_index_patterns/_index LIKE with overly complex pattern}
490487
issue: https://github.com/elastic/elasticsearch/issues/148134
491-
- class: org.elasticsearch.xpack.stateless.StatelessRealTimeTermVectorsIT
492-
method: testDocsNotInLiveVersionMapDoNotRefresh
493-
issue: https://github.com/elastic/elasticsearch/issues/148138
494488
- class: org.elasticsearch.index.engine.LuceneChangesSnapshotTests
495489
method: testUpdateAndReadChangesConcurrently
496490
issue: https://github.com/elastic/elasticsearch/issues/148145

x-pack/plugin/stateless/src/internalClusterTest/java/org/elasticsearch/xpack/stateless/StatelessRealTimeTermVectorsIT.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.elasticsearch.xcontent.XContentBuilder;
2828
import org.elasticsearch.xpack.stateless.engine.IndexEngine;
2929

30+
import java.util.ArrayList;
31+
import java.util.List;
3032
import java.util.concurrent.atomic.AtomicInteger;
3133
import java.util.function.Supplier;
3234

@@ -168,7 +170,7 @@ public void doTestDocsInLiveVersionMapRefresh(TestDocsType testDocsType, boolean
168170

169171
final int numDocs = randomIntBetween(1, 20);
170172
createIndexWithTermVectorMappings(1, 1);
171-
indexTestDocuments(numDocs);
173+
List<String> indexedDocumentIds = indexTestDocuments(numDocs);
172174

173175
// If true, we test that the term vectors API will refresh appropriately depending on whether the second (not the first) version
174176
// of the updated documents is in the live version map (i.e., not yet searchable) of the indexing shard.
@@ -197,6 +199,8 @@ public void doTestDocsInLiveVersionMapRefresh(TestDocsType testDocsType, boolean
197199
// No additional refreshes are expected in the test.
198200
refresh(INDEX_NAME);
199201
refresh(INDEX_NAME);
202+
// Ensure that version map archive is empty since it is cleared asynchronously via `IndexEngine.commitSuccess()`.
203+
assertDocumentNotInLiveVersionMapArchive(indexedDocumentIds.getLast());
200204
}
201205
}
202206

@@ -236,14 +240,7 @@ public void doTestDocsInLiveVersionMapRefresh(TestDocsType testDocsType, boolean
236240
// After the expected number of refreshes from the first docs, wait to ensure that the async
237241
// IndexEngine.commitSuccess() has been called to move out the docs from the live version map archive.
238242
// That way, the next term request should not do any other refreshes.
239-
assertBusy(() -> assertTrue(findIndexShard(INDEX_NAME).withEngine(e -> {
240-
assertThat(e, instanceOf(IndexEngine.class));
241-
final var indexEngine = (IndexEngine) e;
242-
final var archive = getArchive(indexEngine.getLiveVersionMap());
243-
assertNotNull(archive);
244-
assertNull(archive.get(uid(termVectorsResponse.getId())));
245-
return true;
246-
})));
243+
assertDocumentNotInLiveVersionMapArchive(termVectorsResponse.getId());
247244
}
248245
}
249246
}
@@ -383,11 +380,17 @@ protected void createIndexWithTermVectorMappings(int shards, int replicas) throw
383380
);
384381
}
385382

386-
protected void indexTestDocuments(int numDocs) {
383+
protected List<String> indexTestDocuments(int numDocs) {
384+
var indexedDocumentIds = new ArrayList<String>();
385+
387386
for (int i = 0; i < numDocs; i++) {
388-
final var response = prepareIndex(INDEX_NAME).setId(String.valueOf(i)).setSource("field", "foo bar " + i).get();
387+
String id = String.valueOf(i);
388+
final var response = prepareIndex(INDEX_NAME).setId(id).setSource("field", "foo bar " + i).get();
389389
assertEquals(1, response.getVersion());
390+
indexedDocumentIds.add(id);
390391
}
392+
393+
return indexedDocumentIds;
391394
}
392395

393396
protected void updateTestDocuments(int numDocs) {
@@ -396,4 +399,15 @@ protected void updateTestDocuments(int numDocs) {
396399
assertEquals(2, response.getVersion());
397400
}
398401
}
402+
403+
private void assertDocumentNotInLiveVersionMapArchive(String documentId) throws Exception {
404+
assertBusy(() -> assertTrue(findIndexShard(INDEX_NAME).withEngine(e -> {
405+
assertThat(e, instanceOf(IndexEngine.class));
406+
final var indexEngine = (IndexEngine) e;
407+
final var archive = getArchive(indexEngine.getLiveVersionMap());
408+
assertNotNull(archive);
409+
assertNull(archive.get(uid(documentId)));
410+
return true;
411+
})));
412+
}
399413
}

0 commit comments

Comments
 (0)