|
|
@@ -37,7 +37,6 @@ import org.apache.lucene.util.TestRuleMarkFailure;
|
|
|
import org.apache.lucene.util.TimeUnits;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.bootstrap.BootstrapForTesting;
|
|
|
-import org.elasticsearch.jdk.JavaVersion;
|
|
|
import org.elasticsearch.client.Requests;
|
|
|
import org.elasticsearch.cluster.ClusterModule;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
@@ -101,7 +100,6 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.elasticsearch.transport.LeakTracker;
|
|
|
import org.elasticsearch.transport.nio.MockNioTransportPlugin;
|
|
|
-import org.joda.time.DateTimeZone;
|
|
|
import org.junit.After;
|
|
|
import org.junit.AfterClass;
|
|
|
import org.junit.Before;
|
|
|
@@ -172,7 +170,6 @@ import static org.hamcrest.Matchers.hasItem;
|
|
|
@LuceneTestCase.SuppressReproduceLine
|
|
|
public abstract class ESTestCase extends LuceneTestCase {
|
|
|
|
|
|
- protected static final List<String> JODA_TIMEZONE_IDS;
|
|
|
protected static final List<String> JAVA_TIMEZONE_IDS;
|
|
|
protected static final List<String> JAVA_ZONE_IDS;
|
|
|
|
|
|
@@ -228,18 +225,29 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|
|
|
|
|
BootstrapForTesting.ensureInitialized();
|
|
|
|
|
|
- // filter out joda timezones that are deprecated for the java time migration
|
|
|
- List<String> jodaTZIds = DateTimeZone.getAvailableIDs().stream()
|
|
|
- .filter(s -> DateUtils.DEPRECATED_SHORT_TZ_IDS.contains(s) == false).sorted().collect(Collectors.toList());
|
|
|
- JODA_TIMEZONE_IDS = Collections.unmodifiableList(jodaTZIds);
|
|
|
+ /*
|
|
|
+ * 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 tests do not send time zone ids back to versions of ES using Joda
|
|
|
+ */
|
|
|
+ Set<String> unsupportedJodaTZIds = Set.of(
|
|
|
+ "ACT", "AET", "AGT", "ART", "AST", "BET", "BST", "CAT", "CNT", "CST", "CTT", "EAT", "ECT", "EST",
|
|
|
+ "HST", "IET", "IST", "JST", "MIT", "MST", "NET", "NST", "PLT", "PNT", "PRT", "PST", "SST", "VST"
|
|
|
+ );
|
|
|
+ Predicate<String> unsupportedZoneIdsPredicate = tz -> tz.startsWith("System/") || tz.equals("Eire");
|
|
|
+ Predicate<String> unsupportedTZIdsPredicate = unsupportedJodaTZIds::contains;
|
|
|
|
|
|
- List<String> javaTZIds = Arrays.asList(TimeZone.getAvailableIDs());
|
|
|
- Collections.sort(javaTZIds);
|
|
|
- JAVA_TIMEZONE_IDS = Collections.unmodifiableList(javaTZIds);
|
|
|
+ JAVA_TIMEZONE_IDS = Arrays.stream(TimeZone.getAvailableIDs())
|
|
|
+ .filter(unsupportedTZIdsPredicate.negate())
|
|
|
+ .filter(unsupportedZoneIdsPredicate.negate())
|
|
|
+ .sorted()
|
|
|
+ .collect(Collectors.toUnmodifiableList());
|
|
|
|
|
|
- List<String> javaZoneIds = new ArrayList<>(ZoneId.getAvailableZoneIds());
|
|
|
- Collections.sort(javaZoneIds);
|
|
|
- JAVA_ZONE_IDS = Collections.unmodifiableList(javaZoneIds);
|
|
|
+ JAVA_ZONE_IDS = ZoneId.getAvailableZoneIds().stream()
|
|
|
+ .filter(unsupportedZoneIdsPredicate.negate())
|
|
|
+ .sorted()
|
|
|
+ .collect(Collectors.toUnmodifiableList());
|
|
|
}
|
|
|
@SuppressForbidden(reason = "force log4j and netty sysprops")
|
|
|
private static void setTestSysProps() {
|
|
|
@@ -868,13 +876,6 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|
|
return randomTimeValue(1, 1000);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * generate a random DateTimeZone from the ones available in joda library
|
|
|
- */
|
|
|
- public static DateTimeZone randomDateTimeZone() {
|
|
|
- return DateTimeZone.forID(randomFrom(JODA_TIMEZONE_IDS));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* generate a random epoch millis in a range 1 to 9999-12-31T23:59:59.999
|
|
|
*/
|
|
|
@@ -886,35 +887,14 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|
|
* generate a random TimeZone from the ones available in java.util
|
|
|
*/
|
|
|
public static TimeZone randomTimeZone() {
|
|
|
- return TimeZone.getTimeZone(randomJodaAndJavaSupportedTimezone(JAVA_TIMEZONE_IDS));
|
|
|
+ return TimeZone.getTimeZone(randomFrom(JAVA_TIMEZONE_IDS));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* generate a random TimeZone from the ones available in java.time
|
|
|
*/
|
|
|
public static ZoneId randomZone() {
|
|
|
- // work around a JDK bug, where java 8 cannot parse the timezone GMT0 back into a temporal accessor
|
|
|
- // see https://bugs.openjdk.java.net/browse/JDK-8138664
|
|
|
- if (JavaVersion.current().getVersion().get(0) == 8) {
|
|
|
- ZoneId timeZone;
|
|
|
- do {
|
|
|
- timeZone = ZoneId.of(randomJodaAndJavaSupportedTimezone(JAVA_ZONE_IDS));
|
|
|
- } while (timeZone.equals(ZoneId.of("GMT0")));
|
|
|
- return timeZone;
|
|
|
- } else {
|
|
|
- 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<String> zoneIds) {
|
|
|
- return randomValueOtherThanMany(id -> JODA_TIMEZONE_IDS.contains(id) == false,
|
|
|
- () -> randomFrom(zoneIds));
|
|
|
+ return ZoneId.of(randomFrom(JAVA_ZONE_IDS));
|
|
|
}
|
|
|
|
|
|
/**
|