From c99a35a684778e96c34725f20d8da54364ddc579 Mon Sep 17 00:00:00 2001 From: Marios Trivyzas Date: Thu, 25 Oct 2018 13:11:31 +0200 Subject: [PATCH] SQL: Fix and enable test with randomness Increase minimum number of elements for List<> ctor arguments for specific classes that validate the size of the list. Fixes: #34753 --- .../xpack/sql/tree/NodeSubclassTests.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java index 4c763fa95cd260..675a2ce2641e19 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/tree/NodeSubclassTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.sql.tree; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import com.carrotsearch.randomizedtesting.annotations.Seed; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.test.ESTestCase; @@ -16,12 +17,17 @@ import org.elasticsearch.xpack.sql.expression.function.aggregate.AggregateFunction; import org.elasticsearch.xpack.sql.expression.function.aggregate.Avg; import org.elasticsearch.xpack.sql.expression.function.aggregate.InnerAggregate; +import org.elasticsearch.xpack.sql.expression.function.aggregate.Percentile; +import org.elasticsearch.xpack.sql.expression.function.aggregate.PercentileRanks; +import org.elasticsearch.xpack.sql.expression.function.aggregate.Percentiles; import org.elasticsearch.xpack.sql.expression.gen.pipeline.AggExtractorInput; import org.elasticsearch.xpack.sql.expression.gen.pipeline.BinaryPipesTests; import org.elasticsearch.xpack.sql.expression.gen.pipeline.Pipe; import org.elasticsearch.xpack.sql.expression.gen.processor.ConstantProcessor; import org.elasticsearch.xpack.sql.expression.gen.processor.Processor; +import org.elasticsearch.xpack.sql.expression.predicate.In; import org.elasticsearch.xpack.sql.expression.predicate.fulltext.FullTextPredicate; +import org.elasticsearch.xpack.sql.expression.predicate.operator.comparison.InPipe; import org.elasticsearch.xpack.sql.expression.predicate.regex.LikePattern; import org.elasticsearch.xpack.sql.tree.NodeTests.ChildrenAreAProperty; import org.elasticsearch.xpack.sql.tree.NodeTests.Dummy; @@ -50,6 +56,7 @@ import java.util.function.Supplier; import static java.util.Collections.emptyList; +import static java.util.Collections.max; import static java.util.stream.Collectors.toList; import static org.mockito.Mockito.mock; @@ -147,7 +154,6 @@ public void testTransform() throws Exception { /** * Test {@link Node#replaceChildren} implementation on {@link #subclass}. */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34775") public void testReplaceChildren() throws Exception { Constructor ctor = longestCtor(subclass); Object[] nodeCtorArgs = ctorArgs(ctor); @@ -343,11 +349,17 @@ private Object makeArg(Type argType) { */ @SuppressWarnings("unchecked") private static Object makeArg(Class> toBuildClass, Type argType) throws Exception { + int minCollectionLength = 0; + int maxCollectionLength = 10; + if (toBuildClass == In.class || toBuildClass == InPipe.class || toBuildClass == Percentile.class || + toBuildClass == Percentiles.class || toBuildClass == PercentileRanks.class) { + minCollectionLength = 2; + } if (argType instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) argType; if (pt.getRawType() == Map.class) { Map map = new HashMap<>(); - int size = between(0, 10); + int size = between(minCollectionLength, maxCollectionLength); while (map.size() < size) { Object key = makeArg(toBuildClass, pt.getActualTypeArguments()[0]); Object value = makeArg(toBuildClass, pt.getActualTypeArguments()[1]); @@ -356,7 +368,7 @@ private static Object makeArg(Class> toBuildClass, Type argTyp return map; } if (pt.getRawType() == List.class) { - return makeList(toBuildClass, pt, between(1, 10)); + return makeList(toBuildClass, pt, between(minCollectionLength, maxCollectionLength)); } if (pt.getRawType() == EnumSet.class) { @SuppressWarnings("rawtypes")