Skip to content

Commit 16d8254

Browse files
committed
Fix exporter tests to have reasonable dates (#38436)
The java time formatter used in the exporter adds a plus sign to the year, if a year with more than five digits is used. This changes the creation of those timestamp to only have a date up to 9999. Closes #38378
1 parent dd2ce2f commit 16d8254

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringTestUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
public final class MonitoringTestUtils {
2525

26+
// maximum number of milliseconds before a five digit year comes in, which could change formatting
27+
private static final long MAX_MILLIS_BEFORE_10000 = 253402300799999L;
28+
2629
private MonitoringTestUtils() {
2730
}
2831

@@ -37,7 +40,7 @@ public static MonitoringDoc.Node randomMonitoringNode(final Random random) {
3740
final String host = fakeTransportAddress.address().getHostString();
3841
final String transportAddress = fakeTransportAddress.toString();
3942
final String ip = fakeTransportAddress.getAddress();
40-
final long timestamp = RandomNumbers.randomLongBetween(random, 0, Long.MAX_VALUE);
43+
final long timestamp = RandomNumbers.randomLongBetween(random, 0, MAX_MILLIS_BEFORE_10000);
4144

4245
return new MonitoringDoc.Node(id, host, transportAddress, ip, name, timestamp);
4346
}
@@ -87,8 +90,7 @@ public static MonitoringBulkDoc randomMonitoringBulkDoc(final Random random,
8790
final MonitoredSystem system,
8891
final String type) throws IOException {
8992
final String id = random.nextBoolean() ? RandomStrings.randomAsciiLettersOfLength(random, 5) : null;
90-
// ending date is the last second of 9999, should be sufficient
91-
final long timestamp = RandomNumbers.randomLongBetween(random, 0L, 253402300799000L);
93+
final long timestamp = RandomNumbers.randomLongBetween(random, 0L, MAX_MILLIS_BEFORE_10000);
9294
final long interval = RandomNumbers.randomLongBetween(random, 0L, Long.MAX_VALUE);
9395
return new MonitoringBulkDoc(system, type, id, timestamp, interval, source, xContentType);
9496
}

0 commit comments

Comments
 (0)