Skip to content

Commit

Permalink
Fix geogrid with bounds test edge cases (#51118)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
talevy committed Jan 27, 2020
1 parent 8ab0a64 commit ab5a9a9
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
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<T extends InternalGeoGridBucket> 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.
Expand Down Expand Up @@ -126,15 +128,21 @@ public void testWithSeveralDocs() throws IOException {
});
}

@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");

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<Double, Double> encodeDecodeLat = (lat) -> GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
Function<Double, Double> 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<LatLonDocValuesField> docs = new ArrayList<>();
Expand Down

0 comments on commit ab5a9a9

Please sign in to comment.