Work around JDK8 timezone bug in tests (#37968)
The timezone GMT0 cannot be properly parsed on java8. The randomZone() method now excludes GMT0, if java8 is used. Closes #37814
This commit is contained in:
parent
1a93976ff7
commit
160d1bd4dd
|
@ -426,14 +426,11 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertThat(e.toString(), containsString("unit [D] not supported for date math"));
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37814")
|
||||
// Issue #7880
|
||||
public void testDateRangeInQueryStringWithTimeZone_7880() {
|
||||
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
|
||||
//as with dynamic mappings some shards might be lacking behind and parse a different query
|
||||
assertAcked(prepareCreate("test").addMapping(
|
||||
"type", "past", "type=date"
|
||||
));
|
||||
assertAcked(prepareCreate("test").addMapping("type", "past", "type=date"));
|
||||
|
||||
ZoneId timeZone = randomZone();
|
||||
String now = DateFormatter.forPattern("strict_date_optional_time").format(Instant.now().atZone(timeZone));
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.apache.lucene.util.TestUtil;
|
|||
import org.apache.lucene.util.TimeUnits;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.bootstrap.BootstrapForTesting;
|
||||
import org.elasticsearch.bootstrap.JavaVersion;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.ClusterModule;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -784,8 +785,18 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
* 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(randomFrom(JAVA_ZONE_IDS));
|
||||
} while (timeZone.equals(ZoneId.of("GMT0")));
|
||||
return timeZone;
|
||||
} else {
|
||||
return ZoneId.of(randomFrom(JAVA_ZONE_IDS));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* helper to randomly perform on <code>consumer</code> with <code>value</code>
|
||||
|
|
Loading…
Reference in New Issue