Skip to content

Commit f771030

Browse files
authored
Fix GeoGridTestCase#toXContent (#85093)
This change make sure we create a valid random instance for GeoGridTestCase.
1 parent 3b6af88 commit f771030

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

server/src/test/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridTestCase.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ protected T createTestInstance(String name, Map<String, Object> metadata, Intern
5656
final int precision = randomPrecision();
5757
int size = randomNumberOfBuckets();
5858
List<InternalGeoGridBucket> buckets = new ArrayList<>(size);
59+
final List<Long> seen = new ArrayList<>(size);
60+
int finalSize = 0;
5961
for (int i = 0; i < size; i++) {
6062
double latitude = randomDoubleBetween(-90.0, 90.0, false);
6163
double longitude = randomDoubleBetween(-180.0, 180.0, false);
62-
6364
long hashAsLong = longEncode(longitude, latitude, precision);
64-
buckets.add(createInternalGeoGridBucket(hashAsLong, randomInt(IndexWriter.MAX_DOCS), aggregations));
65+
if (seen.contains(hashAsLong) == false) { // make sure we don't add twice the same bucket
66+
buckets.add(createInternalGeoGridBucket(hashAsLong, randomInt(IndexWriter.MAX_DOCS), aggregations));
67+
seen.add(hashAsLong);
68+
finalSize++;
69+
}
6570
}
66-
return createInternalGeoGrid(name, size, buckets, metadata);
71+
return createInternalGeoGrid(name, finalSize, buckets, metadata);
6772
}
6873

6974
@Override

0 commit comments

Comments
 (0)