Browse Source

[TEST] fixes mutate methods in aggs tests

Closes #26121
Colin Goodheart-Smithe 8 years ago
parent
commit
20b7258d41

+ 15 - 5
core/src/test/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroidTests.java

@@ -95,15 +95,25 @@ public class InternalGeoCentroidTests extends InternalAggregationTestCase<Intern
             break;
         case 1:
             count += between(1, 100);
+            if (centroid == null) {
+                // if the new count is > 0 then we need to make sure there is a
+                // centroid or the constructor will throw an exception
+                centroid = new GeoPoint(randomDoubleBetween(-90, 90, false), randomDoubleBetween(-180, 180, false));
+            }
             break;
         case 2:
-            GeoPoint newCentroid = new GeoPoint(centroid);
-            if (randomBoolean()) {
-                newCentroid.resetLat(centroid.getLat() / 2.0);
+            if (centroid == null) {
+                centroid = new GeoPoint(randomDoubleBetween(-90, 90, false), randomDoubleBetween(-180, 180, false));
+                count = between(1, 100);
             } else {
-                newCentroid.resetLon(centroid.getLon() / 2.0);
+                GeoPoint newCentroid = new GeoPoint(centroid);
+                if (randomBoolean()) {
+                    newCentroid.resetLat(centroid.getLat() / 2.0);
+                } else {
+                    newCentroid.resetLon(centroid.getLon() / 2.0);
+                }
+                centroid = newCentroid;
             }
-            centroid = newCentroid;
             break;
         case 3:
             if (metaData == null) {

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

@@ -206,7 +206,7 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
             break;
         case 1:
             Object newValue = randomValue(valueTypes, 0);
-            while ((newValue == null && value == null) || newValue.equals(value)) {
+            while ((newValue == null && value == null) || (newValue != null && newValue.equals(value))) {
                 int levels = randomIntBetween(1, 3);
                 Supplier[] valueTypes = new Supplier[levels];
                 for (int i = 0; i < levels; i++) {