diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index db2f96b6a87..2a35cd4fdaf 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -831,7 +831,7 @@ public abstract class ESTestCase extends LuceneTestCase { * generate a random TimeZone from the ones available in java.util */ public static TimeZone randomTimeZone() { - return TimeZone.getTimeZone(randomFrom(JAVA_TIMEZONE_IDS)); + return TimeZone.getTimeZone(randomJodaAndJavaSupportedTimezone(JAVA_TIMEZONE_IDS)); } /** @@ -843,14 +843,25 @@ public abstract class ESTestCase extends LuceneTestCase { if (JavaVersion.current().getVersion().get(0) == 8) { ZoneId timeZone; do { - timeZone = ZoneId.of(randomFrom(JAVA_ZONE_IDS)); + timeZone = ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS)); } while (timeZone.equals(ZoneId.of("GMT0"))); return timeZone; } else { - return ZoneId.of(randomFrom(JAVA_ZONE_IDS)); + return ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS)); } } + /** + * We need to exclude time zones not supported by joda (like SystemV* timezones) + * 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 + * //TODO remove once joda is not supported + */ + private static String randomJodaAndJavaSupportedTimezone(List zoneIds) { + return randomValueOtherThanMany(id -> JODA_TIMEZONE_IDS.contains(id) == false, + () -> randomFrom(zoneIds)); + } + /** * helper to randomly perform on consumer with value */ diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlWireSerializingTestCase.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlWireSerializingTestCase.java index 6f8dae854f4..f04f24fbf4b 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlWireSerializingTestCase.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/AbstractSqlWireSerializingTestCase.java @@ -32,28 +32,18 @@ public abstract class AbstractSqlWireSerializingTestCase ex } } } - + /** * Returns a {@link Writeable.Reader} that can be used to de-serialize the instance */ protected abstract Writeable.Reader instanceReader(); protected ZoneId instanceZoneId(T instance) { - return randomSafeZone(); + return randomZone(); } @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { return new NamedWriteableRegistry(Cursors.getNamedWriteables()); } - - - /** - * 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 - */ - protected static ZoneId randomSafeZone() { - return randomValueOtherThanMany(zi -> zi.getId().startsWith("SystemV"), () -> randomZone()); - } } diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/CompositeAggregationCursorTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/CompositeAggregationCursorTests.java index ae17b00f340..f8b11570842 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/CompositeAggregationCursorTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/CompositeAggregationCursorTests.java @@ -22,7 +22,7 @@ import java.util.function.Supplier; public class CompositeAggregationCursorTests extends AbstractSqlWireSerializingTestCase { public static CompositeAggCursor randomCompositeCursor() { int extractorsSize = between(1, 20); - ZoneId id = randomSafeZone(); + ZoneId id = randomZone(); List extractors = new ArrayList<>(extractorsSize); for (int i = 0; i < extractorsSize; i++) { extractors.add(randomBucketExtractor(id)); @@ -70,7 +70,7 @@ public class CompositeAggregationCursorTests extends AbstractSqlWireSerializingT return zoneId; } } - return randomSafeZone(); + return randomZone(); } static BitSet randomBitSet(int size) { 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 bd8b427339b..fbea81b6411 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 @@ -26,7 +26,7 @@ import static org.elasticsearch.xpack.sql.util.DateUtils.UTC; public class CompositeKeyExtractorTests extends AbstractSqlWireSerializingTestCase { public static CompositeKeyExtractor randomCompositeKeyExtractor() { - return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomSafeZone(), randomBoolean()); + return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomZone(), randomBoolean()); } public static CompositeKeyExtractor randomCompositeKeyExtractor(ZoneId zoneId) { @@ -73,7 +73,7 @@ public class CompositeKeyExtractorTests extends AbstractSqlWireSerializingTestCa } public void testExtractDate() { - CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomSafeZone(), true); + CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomZone(), true); long millis = System.currentTimeMillis(); Bucket bucket = new TestBucket(singletonMap(extractor.key(), millis), randomLong(), new Aggregations(emptyList()));