Skip to content

Commit ed3583d

Browse files
committed
use randomValueOtherThanMany
1 parent 063fddf commit ed3583d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,11 @@ private static String randomSeparator() {
258258
}
259259

260260
private static String randomTimestamp() {
261-
ZonedDateTime zonedDateTime;
262-
do {
263-
long millis = randomMillisUpToYear9999();
264-
zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), randomZone());
265-
266-
// 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
267-
// selected timezone. Since the date formatter cannot handle years greater than 9999, select another date.
268-
} while (zonedDateTime.getYear() == 10000);
269-
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(t -> t.getYear() == 10000, () ->
264+
ZonedDateTime.ofInstant(Instant.ofEpochMilli(randomMillisUpToYear9999()), randomZone())
265+
);
270266
DateFormatter formatter = DateFormatter.forPattern(randomDateFormatterPattern()).withLocale(randomLocale(random()));
271267
return formatter.format(zonedDateTime);
272268
}

0 commit comments

Comments
 (0)