diff --git a/muted-tests.yml b/muted-tests.yml index f3c4c349332a3..3a2deedaa41fb 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -594,15 +594,9 @@ tests: - class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT method: test {p0=search/510_range_query_out_of_bounds/Test range query for half_float field with out of bounds upper limit} issue: https://github.com/elastic/elasticsearch/issues/135365 -- class: org.elasticsearch.xpack.esql.session.SessionUtilsTests - method: testFromPages - issue: https://github.com/elastic/elasticsearch/issues/135377 - class: org.elasticsearch.xpack.esql.expression.function.scalar.score.DecayTests method: "testEvaluateBlockWithoutNulls {TestCase=, , , <_source> #12}" issue: https://github.com/elastic/elasticsearch/issues/135394 -- class: org.elasticsearch.xpack.esql.session.SessionUtilsTests - method: testCheckPagesBelowSize - issue: https://github.com/elastic/elasticsearch/issues/135398 - class: org.elasticsearch.upgrades.DataStreamsUpgradeIT method: testDataStreamValidationDoesNotBreakUpgrade issue: https://github.com/elastic/elasticsearch/issues/135406 diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/SessionUtilsTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/SessionUtilsTests.java index d599e924066d2..8690b7cc69930 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/SessionUtilsTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/SessionUtilsTests.java @@ -126,39 +126,45 @@ private static PagesRec generatePageSet(BlockFactory blockFactory) { // Generates a list of Pages with one BytesRef block, each of different positions, filled with random bytes. private static PagesRec generatePages(int minBytes, int maxBytes, BlockFactory blockFactory) { - BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(maxBytes); - - byte[] buffer = new byte[maxBytes]; - List pages = new ArrayList<>(); - - int producedBytes = 0; - int producedRows = 0; - int rowsPerPage = randomIntBetween(1, 100); - int rows = 0; - while (producedBytes < maxBytes) { - int rowBytes = Math.min(randomIntBetween(1, maxBytes / minBytes), maxBytes - producedBytes); - byte[] rowValue = randomByteArrayOfLength(rowBytes); - - builder.appendBytesRef(new BytesRef(rowValue)); - System.arraycopy(rowValue, 0, buffer, producedBytes, rowBytes); - - producedBytes += rowBytes; - rows++; - - if (rows > rowsPerPage) { + BytesRefBlock.Builder builder = null; + try { + builder = blockFactory.newBytesRefBlockBuilder(maxBytes); + + byte[] buffer = new byte[maxBytes]; + List pages = new ArrayList<>(); + + int producedBytes = 0; + int producedRows = 0; + int rowsPerPage = randomIntBetween(1, 100); + int rows = 0; + while (producedBytes < maxBytes) { + int rowBytes = Math.min(randomIntBetween(1, maxBytes / minBytes), maxBytes - producedBytes); + byte[] rowValue = randomByteArrayOfLength(rowBytes); + + builder.appendBytesRef(new BytesRef(rowValue)); + System.arraycopy(rowValue, 0, buffer, producedBytes, rowBytes); + + producedBytes += rowBytes; + rows++; + + if (rows > rowsPerPage) { + producedRows += rows; + rows = 0; + enqueueBlock(builder, pages); + Releasables.close(builder); + builder = blockFactory.newBytesRefBlockBuilder(maxBytes); + rowsPerPage = randomIntBetween(1, 100); + } + } + if (rows > 0) { producedRows += rows; - rows = 0; enqueueBlock(builder, pages); - builder = blockFactory.newBytesRefBlockBuilder(maxBytes); - rowsPerPage = randomIntBetween(1, 100); } - } - if (rows > 0) { - producedRows += rows; - enqueueBlock(builder, pages); - } - return new PagesRec(pages, buffer, producedBytes, producedRows); + return new PagesRec(pages, buffer, producedBytes, producedRows); + } finally { + Releasables.close(builder); + } } private BlockFactory blockFactory(long maxBytes) { @@ -172,6 +178,5 @@ private BlockFactory blockFactory(long maxBytes) { private static void enqueueBlock(BytesRefBlock.Builder builder, List pages) { Block block = builder.build(); pages.add(new Page(block)); - Releasables.close(builder); } }