From 4f483ac37029b964ae94b2e6649529cfb7e5f59f Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 23 Apr 2020 10:38:14 -0400 Subject: [PATCH] Fix half-float range in SupportedTypeTests (#55409) Also adds a comment to the half-float number field type tests indicating why 70000 is used instead of 65504 --- .../elasticsearch/index/mapper/NumberFieldTypeTests.java | 2 ++ .../bucket/significant/SignificantTextAggregatorTests.java | 6 ------ .../metrics/HDRPercentileRanksAggregatorTests.java | 6 ------ .../aggregations/metrics/HDRPercentilesAggregatorTests.java | 6 ------ .../metrics/MedianAbsoluteDeviationAggregatorTests.java | 6 ------ .../search/aggregations/AggregatorTestCase.java | 4 ++-- .../HDRPreAggregatedPercentileRanksAggregatorTests.java | 6 ------ .../mapper/HDRPreAggregatedPercentilesAggregatorTests.java | 6 ------ 8 files changed, 4 insertions(+), 38 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java index 28f1280382a..b0704ce2040 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/NumberFieldTypeTests.java @@ -347,6 +347,8 @@ public class NumberFieldTypeTests extends FieldTypeTestCase { final int numDocs = 10000; for (int i = 0; i < numDocs; ++i) { Document doc = new Document(); + // Note: this test purposefully allows half-floats to be indexed over their dynamic range (65504), which + // ends up being rounded to Infinity by halfFloatToSortableShort() float value = (randomFloat() * 2 - 1) * 70000; float rounded = HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(value)); doc.add(new HalfFloatPoint("half_float", value)); diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTextAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTextAggregatorTests.java index 21f50e55c7f..949d0a35b5d 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTextAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTextAggregatorTests.java @@ -217,10 +217,4 @@ public class SignificantTextAggregatorTests extends AggregatorTestCase { } } } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java index 0c29cdc2003..77a4ab3283b 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksAggregatorTests.java @@ -125,10 +125,4 @@ public class HDRPercentileRanksAggregatorTests extends AggregatorTestCase { assertThat(e.getMessage(), Matchers.equalTo("[values] must not be an empty array: [my_agg]")); } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java index 4bf09e96bb0..076f4cf3bd1 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesAggregatorTests.java @@ -225,10 +225,4 @@ public class HDRPercentilesAggregatorTests extends AggregatorTestCase { } } } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } } diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorTests.java index 7b3bd044a56..2ae30689ad0 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationAggregatorTests.java @@ -283,12 +283,6 @@ public class MedianAbsoluteDeviationAggregatorTests extends AggregatorTestCase { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } - public static class IsCloseToRelative extends TypeSafeMatcher { private final double expected; diff --git a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java index ade6aa983f4..40960d92b08 100644 --- a/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java @@ -725,8 +725,8 @@ public abstract class AggregatorTestCase extends ESTestCase { v = NumericUtils.floatToSortableInt(f); json = "{ \"" + fieldName + "\" : \"" + f + "\" }"; } else if (typeName.equals(NumberFieldMapper.NumberType.HALF_FLOAT.typeName())) { - // Respect half float range - float f = Math.abs((randomFloat() * 2 - 1) * 70000); + // Generate a random float that respects the limits of half float + float f = Math.abs((randomFloat() * 2 - 1) * 65504); v = HalfFloatPoint.halfFloatToSortableShort(f); json = "{ \"" + fieldName + "\" : \"" + f + "\" }"; } else { diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentileRanksAggregatorTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentileRanksAggregatorTests.java index 7b4a9234f94..502fc785c9b 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentileRanksAggregatorTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentileRanksAggregatorTests.java @@ -109,10 +109,4 @@ public class HDRPreAggregatedPercentileRanksAggregatorTests extends AggregatorTe } } } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } } diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentilesAggregatorTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentilesAggregatorTests.java index 4e675cd11ed..d79433cda56 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentilesAggregatorTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HDRPreAggregatedPercentilesAggregatorTests.java @@ -158,10 +158,4 @@ public class HDRPreAggregatedPercentilesAggregatorTests extends AggregatorTestCa } } } - - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/55360") - @Override - public void testSupportedFieldTypes() throws IOException { - super.testSupportedFieldTypes(); - } }