Skip to content

Commit

Permalink
SQL: Fix and enable test with randomness
Browse files Browse the repository at this point in the history
Increase minimum number of elements for List<> ctor arguments
for specific classes that validate the size of the list.

Fixes: elastic#34753
  • Loading branch information
matriv committed Oct 25, 2018
1 parent b97546a commit c99a35a
Showing 1 changed file with 15 additions and 3 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<T> ctor = longestCtor(subclass);
Object[] nodeCtorArgs = ctorArgs(ctor);
Expand Down Expand Up @@ -343,11 +349,17 @@ private Object makeArg(Type argType) {
*/
@SuppressWarnings("unchecked")
private static Object makeArg(Class<? extends Node<?>> 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<Object, Object> 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]);
Expand All @@ -356,7 +368,7 @@ private static Object makeArg(Class<? extends Node<?>> 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")
Expand Down

0 comments on commit c99a35a

Please sign in to comment.