Skip to content

Commit

Permalink
Fix TimeSeriesRateAggregatorTests file leak (elastic#115278)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbuescher authored and jfreden committed Nov 4, 2024
1 parent c74c00e commit f6ca84f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.elasticsearch.index.cache.bitset.BitsetFilterCache;
import org.elasticsearch.index.cache.query.DisabledQueryCache;
import org.elasticsearch.index.cache.query.TrivialQueryCachingPolicy;
import org.elasticsearch.index.engine.Engine;
import org.elasticsearch.index.fielddata.FieldDataContext;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
Expand Down Expand Up @@ -749,6 +750,7 @@ protected <T extends AggregationBuilder, V extends InternalAggregation> void tes
new SortField(TimeSeriesIdFieldMapper.NAME, SortField.Type.STRING, false),
new SortedNumericSortField(DataStreamTimestampFieldMapper.DEFAULT_PATH, SortField.Type.LONG, true)
);
config.setParentField(Engine.ROOT_DOC_FIELD_NAME);
config.setIndexSort(sort);
}
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith;

public class TimeSeriesRateAggregatorTests extends AggregatorTestCase {

Expand Down Expand Up @@ -155,14 +156,14 @@ public void testNestedWithinAutoDateHistogram() throws IOException {

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

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

0 comments on commit f6ca84f

Please sign in to comment.