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:
Alexander Reelsen 2019-01-31 08:52:35 +01:00 committed by GitHub
parent 1a93976ff7
commit 160d1bd4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -426,14 +426,11 @@ public class SearchQueryIT extends ESIntegTestCase {
assertThat(e.toString(), containsString("unit [D] not supported for date math")); assertThat(e.toString(), containsString("unit [D] not supported for date math"));
} }
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37814")
// Issue #7880 // Issue #7880
public void testDateRangeInQueryStringWithTimeZone_7880() { public void testDateRangeInQueryStringWithTimeZone_7880() {
//the mapping needs to be provided upfront otherwise we are not sure how many failures we get back //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 //as with dynamic mappings some shards might be lacking behind and parse a different query
assertAcked(prepareCreate("test").addMapping( assertAcked(prepareCreate("test").addMapping("type", "past", "type=date"));
"type", "past", "type=date"
));
ZoneId timeZone = randomZone(); ZoneId timeZone = randomZone();
String now = DateFormatter.forPattern("strict_date_optional_time").format(Instant.now().atZone(timeZone)); String now = DateFormatter.forPattern("strict_date_optional_time").format(Instant.now().atZone(timeZone));

View File

@ -48,6 +48,7 @@ import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.TimeUnits; import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.bootstrap.BootstrapForTesting; import org.elasticsearch.bootstrap.BootstrapForTesting;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.metadata.IndexMetaData; 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 * generate a random TimeZone from the ones available in java.time
*/ */
public static ZoneId randomZone() { 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)); return ZoneId.of(randomFrom(JAVA_ZONE_IDS));
} }
}
/** /**
* helper to randomly perform on <code>consumer</code> with <code>value</code> * helper to randomly perform on <code>consumer</code> with <code>value</code>