Skip to content

Commit f74b3c6

Browse files
committed
Fix the clock resolution to millis in GetWatchResponseTests
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 elastic#38400
1 parent 89feaa0 commit f74b3c6

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 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,17 @@ 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+
132+
//Instant.ofEpochMilli(fixedClock.millis()).atZone(ZoneOffset.UTC);
133+
ZonedDateTime lastChecked = rarely() ? null : nowWithMillisResolution();
134+
ZonedDateTime lastMetCondition = rarely() ? null : nowWithMillisResolution();
131135
int size = randomIntBetween(0, 5);
132136
Map<String, ActionStatus> actionMap = new HashMap<>();
133137
for (int i = 0; i < size; i++) {
134138
ActionStatus.AckStatus ack = new ActionStatus.AckStatus(
135-
ZonedDateTime.now(ZoneOffset.UTC),
139+
nowWithMillisResolution(),
136140
randomFrom(ActionStatus.AckStatus.State.values())
137141
);
138142
ActionStatus actionStatus = new ActionStatus(
@@ -152,16 +156,16 @@ private static WatchStatus randomWatchStatus() {
152156
}
153157

154158
private static ActionStatus.Throttle randomThrottle() {
155-
return new ActionStatus.Throttle(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20));
159+
return new ActionStatus.Throttle(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20));
156160
}
157161

158162
private static ActionStatus.Execution randomExecution() {
159163
if (randomBoolean()) {
160164
return null;
161165
} else if (randomBoolean()) {
162-
return ActionStatus.Execution.failure(ZonedDateTime.now(ZoneOffset.UTC), randomAlphaOfLengthBetween(10, 20));
166+
return ActionStatus.Execution.failure(nowWithMillisResolution(), randomAlphaOfLengthBetween(10, 20));
163167
} else {
164-
return ActionStatus.Execution.successful(ZonedDateTime.now(ZoneOffset.UTC));
168+
return ActionStatus.Execution.successful(nowWithMillisResolution());
165169
}
166170
}
167171

@@ -227,4 +231,8 @@ private static ActionStatus.Execution convertHlrcToInternal(org.elasticsearch.cl
227231
private static ActionStatus.Throttle convertHlrcToInternal(org.elasticsearch.client.watcher.ActionStatus.Throttle throttle) {
228232
return new ActionStatus.Throttle(throttle.timestamp(), throttle.reason());
229233
}
234+
235+
private static ZonedDateTime nowWithMillisResolution() {
236+
return Instant.ofEpochMilli(Clock.systemUTC().millis()).atZone(ZoneOffset.UTC);
237+
}
230238
}

0 commit comments

Comments
 (0)