From fc2d875c9f6cfb6fa2f106e88ada3ffb2630b1c1 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Mon, 27 Jan 2020 12:14:40 -0800 Subject: [PATCH] Fix geogrid with bounds test edge cases (#51118) This commit modifies the bounding box for geogrid unit tests to only consider bounding boxes that have significant longitudinal width and whose coordinates are normalized to quantized space Closes #51103. --- .../bucket/geogrid/GeoGridAggregatorTestCase.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java index 15d6f503d03..e5d2f0af5de 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorTestCase.java @@ -46,12 +46,14 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Function; import static org.hamcrest.Matchers.equalTo; public abstract class GeoGridAggregatorTestCase extends AggregatorTestCase { private static final String FIELD_NAME = "location"; + protected static final double GEOHASH_TOLERANCE = 1E-5D; /** * Generate a random precision according to the rules of the given aggregation. @@ -126,7 +128,6 @@ public abstract class GeoGridAggregatorTestCase }); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/51103") public void testBounds() throws IOException { final int numDocs = randomIntBetween(64, 256); final GeoGridAggregationBuilder builder = createBuilder("_name"); @@ -134,7 +135,14 @@ public abstract class GeoGridAggregatorTestCase expectThrows(IllegalArgumentException.class, () -> builder.precision(-1)); expectThrows(IllegalArgumentException.class, () -> builder.precision(30)); - GeoBoundingBox bbox = GeoBoundingBoxTests.randomBBox(); + // only consider bounding boxes that are at least GEOHASH_TOLERANCE wide and have quantized coordinates + GeoBoundingBox bbox = randomValueOtherThanMany( + (b) -> Math.abs(GeoUtils.normalizeLon(b.right()) - GeoUtils.normalizeLon(b.left())) < GEOHASH_TOLERANCE, + GeoBoundingBoxTests::randomBBox); + Function encodeDecodeLat = (lat) -> GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat)); + Function encodeDecodeLon = (lon) -> GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lon)); + bbox.topLeft().reset(encodeDecodeLat.apply(bbox.top()), encodeDecodeLon.apply(bbox.left())); + bbox.bottomRight().reset(encodeDecodeLat.apply(bbox.bottom()), encodeDecodeLon.apply(bbox.right())); int in = 0, out = 0; List docs = new ArrayList<>();