Skip to content

Commit 982f7d7

Browse files
Christoph Büschercostin
authored andcommitted
Fix edge cases in CompositeKeyExtractorTests (#30175)
Currently the test picks random java.util.TimeZone ids in some places. Internally we still need to convert back to joda DateTimeZone by id occassionally (e.g. when serializing to pre 6.3 versions). There are some deprecated "SystemV/*" time zones that Jodas DateTimeZone refuses to convert. This change excludes those rare cases from the set of allowed random time zones. It would be quiet odd for them to appear in practice. Closes #30156
1 parent c4fb372 commit 982f7d7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/execution/search/extractor/CompositeKeyExtractorTests.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.joda.time.DateTimeZone;
1616

1717
import java.io.IOException;
18+
import java.util.TimeZone;
1819

1920
import static java.util.Arrays.asList;
2021
import static java.util.Collections.emptyList;
@@ -24,7 +25,7 @@
2425
public class CompositeKeyExtractorTests extends AbstractWireSerializingTestCase<CompositeKeyExtractor> {
2526

2627
public static CompositeKeyExtractor randomCompositeKeyExtractor() {
27-
return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomTimeZone());
28+
return new CompositeKeyExtractor(randomAlphaOfLength(16), randomFrom(asList(Property.values())), randomSafeTimeZone());
2829
}
2930

3031
@Override
@@ -59,7 +60,7 @@ public void testExtractKey() {
5960

6061
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/30156")
6162
public void testExtractDate() {
62-
CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomTimeZone());
63+
CompositeKeyExtractor extractor = new CompositeKeyExtractor(randomAlphaOfLength(16), Property.VALUE, randomSafeTimeZone());
6364

6465
long millis = System.currentTimeMillis();
6566
Bucket bucket = new TestBucket(singletonMap(extractor.key(), millis), randomLong(), new Aggregations(emptyList()));
@@ -74,4 +75,13 @@ public void testExtractIncorrectDateKey() {
7475
SqlIllegalArgumentException exception = expectThrows(SqlIllegalArgumentException.class, () -> extractor.extract(bucket));
7576
assertEquals("Invalid date key returned: " + value, exception.getMessage());
7677
}
77-
}
78+
79+
/**
80+
* We need to exclude SystemV/* time zones because they cannot be converted
81+
* back to DateTimeZone which we currently still need to do internally,
82+
* e.g. in bwc serialization and in the extract() method
83+
*/
84+
private static TimeZone randomSafeTimeZone() {
85+
return randomValueOtherThanMany(tz -> tz.getID().startsWith("SystemV"), () -> randomTimeZone());
86+
}
87+
}

0 commit comments

Comments
 (0)