From 199617e34e09a479d99118e4429fd8127a5ab4bb Mon Sep 17 00:00:00 2001 From: ChrisHegarty Date: Wed, 20 Sep 2023 16:43:38 +0100 Subject: [PATCH] update block factory tests --- .../compute/TestBlockFactoryParamaters.java | 25 ----------- .../compute/TestBlockFactoryParameters.java | 42 +++++++++++++++++++ .../compute/data/BlockFactoryTests.java | 29 +++++++++++-- ...search.compute.data.BlockFactoryParameters | 2 +- 4 files changed, 68 insertions(+), 30 deletions(-) delete mode 100644 x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParamaters.java create mode 100644 x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParameters.java diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParamaters.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParamaters.java deleted file mode 100644 index a138125aa1a04..0000000000000 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParamaters.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.compute; - -import org.elasticsearch.common.breaker.CircuitBreaker; -import org.elasticsearch.common.breaker.NoopCircuitBreaker; -import org.elasticsearch.common.util.BigArrays; -import org.elasticsearch.compute.data.BlockFactoryParameters; - -public class TestBlockFactoryParamaters implements BlockFactoryParameters { - @Override - public CircuitBreaker breaker() { - return new NoopCircuitBreaker("ESQL-test-breaker"); - } - - @Override - public BigArrays bigArrays() { - return BigArrays.NON_RECYCLING_INSTANCE; - } -} diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParameters.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParameters.java new file mode 100644 index 0000000000000..a5957035aef79 --- /dev/null +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/TestBlockFactoryParameters.java @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.compute; + +import org.elasticsearch.common.breaker.CircuitBreaker; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.MockBigArrays; +import org.elasticsearch.common.util.PageCacheRecycler; +import org.elasticsearch.compute.data.BlockFactoryParameters; +import org.elasticsearch.indices.breaker.CircuitBreakerService; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TestBlockFactoryParameters implements BlockFactoryParameters { + + final CircuitBreaker breaker; + final BigArrays bigArrays; + + public TestBlockFactoryParameters() { + breaker = new CountingCircuitBreaker("ESQL-test-breaker"); + + var breakerService = mock(CircuitBreakerService.class); + when(breakerService.getBreaker(CircuitBreaker.REQUEST)).thenReturn(breaker); + bigArrays = new MockBigArrays(PageCacheRecycler.NON_RECYCLING_INSTANCE, breakerService); + } + + @Override + public CircuitBreaker breaker() { + return breaker; + } + + @Override + public BigArrays bigArrays() { + return bigArrays; + } +} diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockFactoryTests.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockFactoryTests.java index 0a727dcf1fe29..87763e82e98a3 100644 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockFactoryTests.java +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BlockFactoryTests.java @@ -7,6 +7,9 @@ package org.elasticsearch.compute.data; +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + import org.apache.lucene.util.Accountable; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.breaker.CircuitBreaker; @@ -23,6 +26,8 @@ import org.junit.Before; import java.util.BitSet; +import java.util.List; +import java.util.function.Supplier; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.is; @@ -34,16 +39,32 @@ // @com.carrotsearch.randomizedtesting.annotations.Repeat(iterations = 1000) public class BlockFactoryTests extends ESTestCase { - final CircuitBreaker breaker = new CountingCircuitBreaker("ESQL-test-breaker"); - final BigArrays bigArrays = bigArrays(); - final BlockFactory blockFactory = BlockFactory.getInstance(breaker, bigArrays); + final CircuitBreaker breaker; + final BigArrays bigArrays; + final BlockFactory blockFactory; - BigArrays bigArrays() { + static BigArrays bigArrays(CircuitBreaker breaker) { var breakerService = mock(CircuitBreakerService.class); when(breakerService.getBreaker(CircuitBreaker.REQUEST)).thenReturn(breaker); return new MockBigArrays(PageCacheRecycler.NON_RECYCLING_INSTANCE, breakerService); } + @ParametersFactory + public static List params() { + List> l = List.of(() -> { + CircuitBreaker breaker = new CountingCircuitBreaker("ESQL-test-breaker"); + BigArrays bigArrays = bigArrays(breaker); + return BlockFactory.getInstance(breaker, bigArrays); + }, BlockFactory::getGlobalInstance); + return l.stream().map(s -> new Object[] { s }).toList(); + } + + public BlockFactoryTests(@Name("blockFactorySupplier") Supplier blockFactorySupplier) { + this.blockFactory = blockFactorySupplier.get(); + this.breaker = blockFactory.breaker(); + this.bigArrays = blockFactory.bigArrays(); + } + @Before @After public void checkBreaker() { diff --git a/x-pack/plugin/esql/compute/src/test/resources/META-INF/services/org.elasticsearch.compute.data.BlockFactoryParameters b/x-pack/plugin/esql/compute/src/test/resources/META-INF/services/org.elasticsearch.compute.data.BlockFactoryParameters index 612e36ced6a31..2536d1e189285 100644 --- a/x-pack/plugin/esql/compute/src/test/resources/META-INF/services/org.elasticsearch.compute.data.BlockFactoryParameters +++ b/x-pack/plugin/esql/compute/src/test/resources/META-INF/services/org.elasticsearch.compute.data.BlockFactoryParameters @@ -5,4 +5,4 @@ # 2.0. # -org.elasticsearch.compute.TestBlockFactoryParamaters +org.elasticsearch.compute.TestBlockFactoryParameters