Skip to content

Fix the clock resolution to millis in GetWatchResponseTests #38405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

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;
Expand Down Expand Up @@ -124,15 +126,15 @@ private static BytesReference simpleWatch() {

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<String, ActionStatus> 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(
Expand All @@ -152,16 +154,16 @@ private static WatchStatus randomWatchStatus() {
}

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());
}
}

Expand Down Expand Up @@ -227,4 +229,8 @@ private static ActionStatus.Execution convertHlrcToInternal(org.elasticsearch.cl
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);
}
}