From 6ae7915b9ddf93d839aca0de75163a624819428f Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Tue, 12 Feb 2019 10:39:18 +0100 Subject: [PATCH] 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 --- .../xpack/monitoring/MonitoringTestUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringTestUtils.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringTestUtils.java index 647835bf931..4c8d167514c 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringTestUtils.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringTestUtils.java @@ -23,6 +23,9 @@ import static org.elasticsearch.test.ESTestCase.buildNewFakeTransportAddress; public final class MonitoringTestUtils { + // maximum number of milliseconds before a five digit year comes in, which could change formatting + private static final long MAX_MILLIS_BEFORE_10000 = 253402300799999L; + private MonitoringTestUtils() { } @@ -37,7 +40,7 @@ public final class MonitoringTestUtils { final String host = fakeTransportAddress.address().getHostString(); final String transportAddress = fakeTransportAddress.toString(); final String ip = fakeTransportAddress.getAddress(); - final long timestamp = RandomNumbers.randomLongBetween(random, 0, Long.MAX_VALUE); + final long timestamp = RandomNumbers.randomLongBetween(random, 0, MAX_MILLIS_BEFORE_10000); return new MonitoringDoc.Node(id, host, transportAddress, ip, name, timestamp); } @@ -87,8 +90,7 @@ public final class MonitoringTestUtils { final MonitoredSystem system, final String type) throws IOException { final String id = random.nextBoolean() ? RandomStrings.randomAsciiLettersOfLength(random, 5) : null; - // ending date is the last second of 9999, should be sufficient - final long timestamp = RandomNumbers.randomLongBetween(random, 0L, 253402300799000L); + final long timestamp = RandomNumbers.randomLongBetween(random, 0L, MAX_MILLIS_BEFORE_10000); final long interval = RandomNumbers.randomLongBetween(random, 0L, Long.MAX_VALUE); return new MonitoringBulkDoc(system, type, id, timestamp, interval, source, xContentType); }