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 f65050ca9ce..77d04d6cae2 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/GeoDistanceSortBuilderTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; import org.elasticsearch.index.query.GeoValidationMethod; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; +import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.geo.RandomGeoGenerator; import java.io.IOException; @@ -80,13 +81,13 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase randomFrom(DistanceUnit.values()))); } if (randomBoolean()) { result.order(RandomSortDataGenerator.order(null)); } if (randomBoolean()) { - result.sortMode(mode(result.sortMode())); + result.sortMode(ESTestCase.randomValueOtherThan(SortMode.SUM, () -> randomFrom(SortMode.values()))); } if (randomBoolean()) { result.setNestedFilter(RandomSortDataGenerator.nestedFilter(result.getNestedFilter())); @@ -95,7 +96,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase randomFrom(GeoValidationMethod.values()))); } return result; @@ -108,30 +109,6 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase randomFrom(DistanceUnit.values()))); break; case 4: result.order(RandomSortDataGenerator.order(original.order())); break; case 5: - result.sortMode(mode(original.sortMode())); + result.sortMode(ESTestCase.randomValueOtherThanMany( + Arrays.asList(SortMode.SUM, result.sortMode()), + () -> randomFrom(SortMode.values()))); break; case 6: result.setNestedFilter(RandomSortDataGenerator.nestedFilter(original.getNestedFilter())); @@ -185,7 +164,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase randomFrom(GeoValidationMethod.values()))); break; } return result; diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 8bbc95fe2ad..d8a3221c88f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -417,6 +417,17 @@ public abstract class ESTestCase extends LuceneTestCase { return randomValue; } + /** + * helper to get a random value in a certain range that's different from the input + */ + public static T randomValueOtherThanMany(Collection input, Supplier randomSupplier) { + T randomValue = null; + do { + randomValue = randomSupplier.get(); + } while (input.contains(randomValue)); + return randomValue; + } + /** * Runs the code block for 10 seconds waiting for no assertion to trip. */