Skip to content

Commit 6d0711a

Browse files
Throw away test dates with year greater than 9999 (#133615)
The patterned_text random testing code picks dates with year less 10000, as the date formatter cannot handle years with 5 digits. Since a random time zone is used, if a date is within 1 day of year 10k, the formatted date in the selected timezone may be year 10k. If this occurs, just pick a different date. Fixes #133598
1 parent a09eaad commit 6d0711a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

x-pack/plugin/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/patternedtext/PatternedTextVsMatchOnlyTextTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,12 @@ private static String randomSeparator() {
258258
}
259259

260260
private static String randomTimestamp() {
261-
long millis = randomMillisUpToYear9999();
262-
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());
261+
// The random millis are below year 10000 in UTC, but if the date is within 1 day of year 10000, the year can be 10000 in the
262+
// selected timezone. Since the date formatter cannot handle years greater than 9999, select another date.
263+
var zonedDateTime = randomValueOtherThanMany(
264+
t -> t.getYear() == 10000,
265+
() -> ZonedDateTime.ofInstant(Instant.ofEpochMilli(randomMillisUpToYear9999()), randomZone())
266+
);
263267
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random()));
264268
return formatter.format(zonedDateTime);
265269
}

0 commit comments

Comments
 (0)