Skip to content

Commit 6cec96c

Browse files
authored
Fix TimeSeriesRateAggregatorTests file leak (#115278)
With Lucene 10, IndexWriter requires a parent document field in order to use index sorting with document blocks. This lead to different IAE and file leaks in this test which are fixed by adapting the corresponding location in the test setup.
1 parent 9adbebb commit 6cec96c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
8282
import org.elasticsearch.index.cache.query.DisabledQueryCache;
8383
import org.elasticsearch.index.cache.query.TrivialQueryCachingPolicy;
84+
import org.elasticsearch.index.engine.Engine;
8485
import org.elasticsearch.index.fielddata.FieldDataContext;
8586
import org.elasticsearch.index.fielddata.IndexFieldData;
8687
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
@@ -749,6 +750,7 @@ protected <T extends AggregationBuilder, V extends InternalAggregation> void tes
749750
new SortField(TimeSeriesIdFieldMapper.NAME, SortField.Type.STRING, false),
750751
new SortedNumericSortField(DataStreamTimestampFieldMapper.DEFAULT_PATH, SortField.Type.LONG, true)
751752
);
753+
config.setParentField(Engine.ROOT_DOC_FIELD_NAME);
752754
config.setIndexSort(sort);
753755
}
754756
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory, config);

x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/rate/TimeSeriesRateAggregatorTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static org.hamcrest.Matchers.closeTo;
4343
import static org.hamcrest.Matchers.hasSize;
4444
import static org.hamcrest.Matchers.instanceOf;
45+
import static org.hamcrest.Matchers.startsWith;
4546

4647
public class TimeSeriesRateAggregatorTests extends AggregatorTestCase {
4748

@@ -155,14 +156,14 @@ public void testNestedWithinAutoDateHistogram() throws IOException {
155156

156157
AggTestConfig aggTestConfig = new AggTestConfig(tsBuilder, timeStampField(), counterField("counter_field"))
157158
.withSplitLeavesIntoSeperateAggregators(false);
158-
expectThrows(IllegalArgumentException.class, () -> testCase(iw -> {
159-
for (Document document : docs(2000, "1", 15, 37, 60, /*reset*/ 14)) {
160-
iw.addDocument(document);
161-
}
162-
for (Document document : docs(2000, "2", 74, 150, /*reset*/ 50, 90, /*reset*/ 40)) {
163-
iw.addDocument(document);
164-
}
159+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testCase(iw -> {
160+
iw.addDocuments(docs(2000, "1", 15, 37, 60, /*reset*/ 14));
161+
iw.addDocuments(docs(2000, "2", 74, 150, /*reset*/ 50, 90, /*reset*/ 40));
165162
}, verifier, aggTestConfig));
163+
assertThat(
164+
e.getMessage(),
165+
startsWith("Wrapping a time-series rate aggregation within a DeferableBucketAggregator is not supported.")
166+
);
166167
}
167168

168169
private List<Document> docs(long startTimestamp, String dim, long... values) throws IOException {

0 commit comments

Comments
 (0)