Skip to content

Commit 16050af

Browse files
committed
[TEST] fixes mutate methods in aggs tests
Closes #26121
1 parent 90baf57 commit 16050af

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,25 @@ protected InternalGeoCentroid mutateInstance(InternalGeoCentroid instance) {
9595
break;
9696
case 1:
9797
count += between(1, 100);
98+
if (centroid == null) {
99+
// if the new count is > 0 then we need to make sure there is a
100+
// centroid or the constructor will throw an exception
101+
centroid = new GeoPoint(randomDoubleBetween(-90, 90, false), randomDoubleBetween(-180, 180, false));
102+
}
98103
break;
99104
case 2:
100-
GeoPoint newCentroid = new GeoPoint(centroid);
101-
if (randomBoolean()) {
102-
newCentroid.resetLat(centroid.getLat() / 2.0);
105+
if (centroid == null) {
106+
centroid = new GeoPoint(randomDoubleBetween(-90, 90, false), randomDoubleBetween(-180, 180, false));
107+
count = between(1, 100);
103108
} else {
104-
newCentroid.resetLon(centroid.getLon() / 2.0);
109+
GeoPoint newCentroid = new GeoPoint(centroid);
110+
if (randomBoolean()) {
111+
newCentroid.resetLat(centroid.getLat() / 2.0);
112+
} else {
113+
newCentroid.resetLon(centroid.getLon() / 2.0);
114+
}
115+
centroid = newCentroid;
105116
}
106-
centroid = newCentroid;
107117
break;
108118
case 3:
109119
if (metaData == null) {

core/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/InternalScriptedMetricTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected InternalScriptedMetric mutateInstance(InternalScriptedMetric instance)
206206
break;
207207
case 1:
208208
Object newValue = randomValue(valueTypes, 0);
209-
while ((newValue == null && value == null) || newValue.equals(value)) {
209+
while ((newValue == null && value == null) || (newValue != null && newValue.equals(value))) {
210210
int levels = randomIntBetween(1, 3);
211211
Supplier[] valueTypes = new Supplier[levels];
212212
for (int i = 0; i < levels; i++) {

0 commit comments

Comments
 (0)