From 4cf5385e4d4df9e652f5951f5ac0266b3467b926 Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Mon, 2 May 2016 13:50:00 +0200 Subject: [PATCH] Use plain random values for generating *SortBuilders --- .../search/sort/FieldSortBuilderTests.java | 28 +++++++++---------- .../sort/GeoDistanceSortBuilderTests.java | 6 ++-- .../sort/NestedQueryBuilderGenerator.java | 7 ++--- .../search/sort/ScriptSortBuilderTests.java | 11 ++++---- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index abcab363dcc..cab40588777 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -53,27 +53,23 @@ public class FieldSortBuilderTests extends AbstractSortTestCase randomFrom(missingContent))); + builder.missing(randomFrom(missingContent)); } if (randomBoolean()) { - builder.unmappedType(ESTestCase.randomValueOtherThan( - builder.unmappedType(), - () -> ESTestCase.randomAsciiOfLengthBetween(1, 10))); + builder.unmappedType(ESTestCase.randomAsciiOfLengthBetween(1, 10)); } if (randomBoolean()) { - builder.sortMode(ESTestCase.randomValueOtherThan(builder.sortMode(), () -> randomFrom(SortMode.values()))); + builder.sortMode(randomFrom(SortMode.values())); } if (randomBoolean()) { - builder.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(builder.getNestedFilter())); + builder.setNestedFilter(NestedQueryBuilderGenerator.randomNestedFilter()); } if (randomBoolean()) { - builder.setNestedPath(ESTestCase.randomValueOtherThan( - builder.getNestedPath(), - () -> ESTestCase.randomAsciiOfLengthBetween(1, 10))); + builder.setNestedPath(ESTestCase.randomAsciiOfLengthBetween(1, 10)); } return builder; @@ -86,25 +82,27 @@ public class FieldSortBuilderTests extends AbstractSortTestCase ESTestCase.randomAsciiOfLengthBetween(1, 10))); break; case 1: - mutated.setNestedFilter(NestedQueryBuilderGenerator.nestedFilter(mutated.getNestedFilter())); + mutated.setNestedFilter(ESTestCase.randomValueOtherThan( + original.getNestedFilter(), + () -> NestedQueryBuilderGenerator.randomNestedFilter())); break; case 2: - mutated.sortMode(ESTestCase.randomValueOtherThan(mutated.sortMode(), () -> randomFrom(SortMode.values()))); + mutated.sortMode(ESTestCase.randomValueOtherThan(original.sortMode(), () -> randomFrom(SortMode.values()))); break; case 3: mutated.unmappedType(ESTestCase.randomValueOtherThan( - mutated.unmappedType(), + original.unmappedType(), () -> ESTestCase.randomAsciiOfLengthBetween(1, 10))); break; case 4: - mutated.missing(ESTestCase.randomValueOtherThan(mutated.missing(), () -> randomFrom(missingContent))); + mutated.missing(ESTestCase.randomValueOtherThan(original.missing(), () -> randomFrom(missingContent))); break; case 5: - mutated.order(ESTestCase.randomValueOtherThan(mutated.order(), () -> randomFrom(SortOrder.values()))); + mutated.order(ESTestCase.randomValueOtherThan(original.order(), () -> randomFrom(SortOrder.values()))); break; default: throw new IllegalStateException("Unsupported mutation."); diff --git a/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java index 9f1b1a325ef..3da59f79de6 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java @@ -89,7 +89,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase NestedQueryBuilderGenerator.randomNestedFilter())); break; case 7: result.setNestedPath(ESTestCase.randomValueOtherThan( diff --git a/core/src/test/java/org/elasticsearch/search/sort/NestedQueryBuilderGenerator.java b/core/src/test/java/org/elasticsearch/search/sort/NestedQueryBuilderGenerator.java index 7e6f88cffd5..de3318036e8 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/NestedQueryBuilderGenerator.java +++ b/core/src/test/java/org/elasticsearch/search/sort/NestedQueryBuilderGenerator.java @@ -38,10 +38,7 @@ public class NestedQueryBuilderGenerator { new IdsQueryBuilder(), new TermQueryBuilder(ESTestCase.randomAsciiOfLengthBetween(1, 10), ESTestCase.randomDouble())); - public static QueryBuilder nestedFilter(QueryBuilder original) { - @SuppressWarnings("rawtypes") - QueryBuilder nested = ESTestCase.randomValueOtherThan(original, () -> ESTestCase.randomFrom(builders)); - nested.boost((float) ESTestCase.randomDoubleBetween(0, 10, false)); - return nested; + public static QueryBuilder randomNestedFilter() { + return ESTestCase.randomFrom(builders).boost(ESTestCase.randomFloat()); } } diff --git a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java index ba9d608f610..1d7247ba1e4 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService.ScriptType; @@ -63,12 +64,10 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase ESTestCase.randomAsciiOfLengthBetween(1, 10))); + builder.setNestedPath(ESTestCase.randomAsciiOfLengthBetween(1, 10)); } return builder; } @@ -115,7 +114,9 @@ public class ScriptSortBuilderTests extends AbstractSortTestCase NestedQueryBuilderGenerator.randomNestedFilter())); break; case 3: result.setNestedPath(original.getNestedPath() + "_some_suffix");