Skip to content

Commit 963b474

Browse files
authored
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
1 parent b7ab521 commit 963b474

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/protocol/xpack/watcher/GetWatchResponseTests.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.time.Clock;
27+
import java.time.Instant;
2628
import java.time.ZoneOffset;
2729
import java.time.ZonedDateTime;
2830
import java.util.Collections;
@@ -124,15 +126,15 @@ private static BytesReference simpleWatch() {
124126

125127
private static WatchStatus randomWatchStatus() {
126128
long version = randomLongBetween(-1, Long.MAX_VALUE);
127-
WatchStatus.State state = new WatchStatus.State(randomBoolean(), ZonedDateTime.now(ZoneOffset.UTC));
129+
WatchStatus.State state = new WatchStatus.State(randomBoolean(), nowWithMillisResolution());
128130
ExecutionState executionState = randomFrom(ExecutionState.values());
129-
ZonedDateTime lastChecked = rarely() ? null : ZonedDateTime.now(ZoneOffset.UTC);
130-
ZonedDateTime lastMetCondition = rarely() ? null : ZonedDateTime.now(ZoneOffset.UTC);
131+
ZonedDateTime lastChecked = rarely() ? null : nowWithMillisResolution();
132+
ZonedDateTime lastMetCondition = rarely() ? null : nowWithMillisResolution();
131133
int size = randomIntBetween(0, 5);
132134
Map<String, ActionStatus> actionMap = new HashMap<>();
133135
for (int i = 0; i < size; i++) {
134136
ActionStatus.AckStatus ack = new ActionStatus.AckStatus(
135-
ZonedDateTime.now(ZoneOffset.UTC),
137+
nowWithMillisResolution(),
136138
randomFrom(ActionStatus.AckStatus.State.values())
137139
);
138140
ActionStatus actionStatus = new ActionStatus(
@@ -152,16 +154,16 @@ private static WatchStatus randomWatchStatus() {
152154
}
153155

154156
private static ActionStatus.Throttle randomThrottle() {
155-
return new ActionStatus.Throttle(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20));
157+
return new ActionStatus.Throttle(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20));
156158
}
157159

158160
private static ActionStatus.Execution randomExecution() {
159161
if (randomBoolean()) {
160162
return null;
161163
} else if (randomBoolean()) {
162-
return ActionStatus.Execution.failure(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20));
164+
return ActionStatus.Execution.failure(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20));
163165
} else {
164-
return ActionStatus.Execution.successful(ZonedDateTime.now(ZoneOffset.UTC));
166+
return ActionStatus.Execution.successful(nowWithMillisResolution());
165167
}
166168
}
167169

@@ -227,4 +229,8 @@ private static ActionStatus.Execution convertHlrcToInternal(org.elasticsearch.cl
227229
private static ActionStatus.Throttle convertHlrcToInternal(org.elasticsearch.client.watcher.ActionStatus.Throttle throttle) {
228230
return new ActionStatus.Throttle(throttle.timestamp(), throttle.reason());
229231
}
232+
233+
private static ZonedDateTime nowWithMillisResolution() {
234+
return Instant.ofEpochMilli(Clock.systemUTC().millis()).atZone(ZoneOffset.UTC);
235+
}
230236
}

0 commit comments

Comments
 (0)