From 963b474f2f2ab2edfbbb22c1eedebe7c841cd5ae Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Tue, 5 Feb 2019 18:27:24 +0100 Subject: [PATCH] Fix the clock resolution to millis in GetWatchResponseTests (#38405) the clock resolution changed from jdk8->jdk10, hence the test is passing in jdk8 but failing in jdk10. The Watcher's objects are serialised and deserialised with milliseconds precision, making test to fail in jdk 10 and higher closes #38400 --- .../xpack/watcher/GetWatchResponseTests.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java index 52ac74acc30..9b71079a6e5 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java @@ -23,6 +23,8 @@ import org.elasticsearch.xpack.core.watcher.watch.WatchStatus; import java.io.IOException; import java.io.InputStream; +import java.time.Clock; +import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Collections; @@ -124,15 +126,15 @@ public class GetWatchResponseTests extends private static WatchStatus randomWatchStatus() { long version = randomLongBetween(-1, Long.MAX_VALUE); - WatchStatus.State state = new WatchStatus.State(randomBoolean(), ZonedDateTime.now(ZoneOffset.UTC)); + WatchStatus.State state = new WatchStatus.State(randomBoolean(), nowWithMillisResolution()); ExecutionState executionState = randomFrom(ExecutionState.values()); - ZonedDateTime lastChecked = rarely() ? null : ZonedDateTime.now(ZoneOffset.UTC); - ZonedDateTime lastMetCondition = rarely() ? null : ZonedDateTime.now(ZoneOffset.UTC); + ZonedDateTime lastChecked = rarely() ? null : nowWithMillisResolution(); + ZonedDateTime lastMetCondition = rarely() ? null : nowWithMillisResolution(); int size = randomIntBetween(0, 5); Map actionMap = new HashMap<>(); for (int i = 0; i < size; i++) { ActionStatus.AckStatus ack = new ActionStatus.AckStatus( - ZonedDateTime.now(ZoneOffset.UTC), + nowWithMillisResolution(), randomFrom(ActionStatus.AckStatus.State.values()) ); ActionStatus actionStatus = new ActionStatus( @@ -152,16 +154,16 @@ public class GetWatchResponseTests extends } private static ActionStatus.Throttle randomThrottle() { - return new ActionStatus.Throttle(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20)); + return new ActionStatus.Throttle(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20)); } private static ActionStatus.Execution randomExecution() { if (randomBoolean()) { return null; } else if (randomBoolean()) { - return ActionStatus.Execution.failure(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20)); + return ActionStatus.Execution.failure(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20)); } else { - return ActionStatus.Execution.successful(ZonedDateTime.now(ZoneOffset.UTC)); + return ActionStatus.Execution.successful(nowWithMillisResolution()); } } @@ -227,4 +229,8 @@ public class GetWatchResponseTests extends private static ActionStatus.Throttle convertHlrcToInternal(org.elasticsearch.client.watcher.ActionStatus.Throttle throttle) { return new ActionStatus.Throttle(throttle.timestamp(), throttle.reason()); } + + private static ZonedDateTime nowWithMillisResolution() { + return Instant.ofEpochMilli(Clock.systemUTC().millis()).atZone(ZoneOffset.UTC); + } }