From 982f7d70aa059e7dde6432482e6a3085df52a79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 26 Apr 2018 20:06:47 +0200 Subject: [PATCH] Fix edge cases in CompositeKeyExtractorTests (#30175) Currently the test picks random java.util.TimeZone ids in some places. Internally we still need to convert back to joda DateTimeZone by id occassionally (e.g. when serializing to pre 6.3 versions). There are some deprecated "SystemV/*" time zones that Jodas DateTimeZone refuses to convert. This change excludes those rare cases from the set of allowed random time zones. It would be quiet odd for them to appear in practice. Closes #30156 --- .../extractor/CompositeKeyExtractorTests.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/extractor/CompositeKeyExtractorTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/extractor/CompositeKeyExtractorTests.java index 3c333080025e6..9336eb75a2ba8 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/extractor/CompositeKeyExtractorTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/extractor/CompositeKeyExtractorTests.java @@ -15,6 +15,7 @@ import org.joda.time.DateTimeZone; import java.io.IOException; +import java.util.TimeZone; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; @@ -24,7 +25,7 @@ public class CompositeKeyExtractorTests extends AbstractWireSerializingTestCase { public static CompositeKeyExtractor randomCompositeKeyExtractor() { - return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomTimeZone()); + return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomSafeTimeZone()); } @Override @@ -59,7 +60,7 @@ public void testExtractKey() { @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/30156") public void testExtractDate() { - CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomTimeZone()); + CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomSafeTimeZone()); long millis = System.currentTimeMillis(); Bucket bucket = new TestBucket(singletonMap(extractor.key(), millis), randomLong(), new Aggregations(emptyList())); @@ -74,4 +75,13 @@ public void testExtractIncorrectDateKey() { SqlIllegalArgumentException exception = expectThrows(SqlIllegalArgumentException.class, () -> extractor.extract(bucket)); assertEquals("Invalid date key returned: " + value, exception.getMessage()); } -} + + /** + * We need to exclude SystemV/* time zones because they cannot be converted + * back to DateTimeZone which we currently still need to do internally, + * e.g. in bwc serialization and in the extract() method + */ + private static TimeZone randomSafeTimeZone() { + return randomValueOtherThanMany(tz -> tz.getID().startsWith("SystemV"), () -> randomTimeZone()); + } +} \ No newline at end of file