Exclude SystemV timezones from randomZone method (#58549) (#58655)

RandomZone test method returns a ZoneId from the set of ids supported by
java. The only difference between joda and java supported timezones are
SystemV* timezones.
These should be excluded from randomZone method as they would break
testing. They also do not bring much confidence when used in testing as
I suspect they are rarely used.
That exclude should be removed for simplification once joda support is removed.
This commit is contained in:
Przemyslaw Gomulka 2020-06-30 12:45:53 +02:00 committed by GitHub
parent 7b80ea7218
commit 3923a10165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 19 deletions

View File

@ -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<String> zoneIds) {
return randomValueOtherThanMany(id -> JODA_TIMEZONE_IDS.contains(id) == false,
() -> randomFrom(zoneIds));
}
/**
* helper to randomly perform on <code>consumer</code> with <code>value</code>
*/

View File

@ -32,28 +32,18 @@ public abstract class AbstractSqlWireSerializingTestCase<T extends Writeable> ex
}
}
}
/**
* Returns a {@link Writeable.Reader} that can be used to de-serialize the instance
*/
protected abstract Writeable.Reader<T> 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());
}
}

View File

@ -22,7 +22,7 @@ import java.util.function.Supplier;
public class CompositeAggregationCursorTests extends AbstractSqlWireSerializingTestCase<CompositeAggCursor> {
public static CompositeAggCursor randomCompositeCursor() {
int extractorsSize = between(1, 20);
ZoneId id = randomSafeZone();
ZoneId id = randomZone();
List<BucketExtractor> 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) {

View File

@ -26,7 +26,7 @@ import static org.elasticsearch.xpack.sql.util.DateUtils.UTC;
public class CompositeKeyExtractorTests extends AbstractSqlWireSerializingTestCase<CompositeKeyExtractor> {
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()));