23
23
24
24
import java .io .IOException ;
25
25
import java .io .InputStream ;
26
+ import java .time .Clock ;
27
+ import java .time .Instant ;
26
28
import java .time .ZoneOffset ;
27
29
import java .time .ZonedDateTime ;
28
30
import java .util .Collections ;
@@ -124,15 +126,15 @@ private static BytesReference simpleWatch() {
124
126
125
127
private static WatchStatus randomWatchStatus () {
126
128
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 ( ));
128
130
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 ( );
131
133
int size = randomIntBetween (0 , 5 );
132
134
Map <String , ActionStatus > actionMap = new HashMap <>();
133
135
for (int i = 0 ; i < size ; i ++) {
134
136
ActionStatus .AckStatus ack = new ActionStatus .AckStatus (
135
- ZonedDateTime . now ( ZoneOffset . UTC ),
137
+ nowWithMillisResolution ( ),
136
138
randomFrom (ActionStatus .AckStatus .State .values ())
137
139
);
138
140
ActionStatus actionStatus = new ActionStatus (
@@ -152,16 +154,16 @@ private static WatchStatus randomWatchStatus() {
152
154
}
153
155
154
156
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 ));
156
158
}
157
159
158
160
private static ActionStatus .Execution randomExecution () {
159
161
if (randomBoolean ()) {
160
162
return null ;
161
163
} else if (randomBoolean ()) {
162
- return ActionStatus .Execution .failure (ZonedDateTime . now ( ZoneOffset . UTC ), randomAlphaOfLengthBetween (10 , 20 ));
164
+ return ActionStatus .Execution .failure (nowWithMillisResolution ( ), randomAlphaOfLengthBetween (10 , 20 ));
163
165
} else {
164
- return ActionStatus .Execution .successful (ZonedDateTime . now ( ZoneOffset . UTC ));
166
+ return ActionStatus .Execution .successful (nowWithMillisResolution ( ));
165
167
}
166
168
}
167
169
@@ -227,4 +229,8 @@ private static ActionStatus.Execution convertHlrcToInternal(org.elasticsearch.cl
227
229
private static ActionStatus .Throttle convertHlrcToInternal (org .elasticsearch .client .watcher .ActionStatus .Throttle throttle ) {
228
230
return new ActionStatus .Throttle (throttle .timestamp (), throttle .reason ());
229
231
}
232
+
233
+ private static ZonedDateTime nowWithMillisResolution () {
234
+ return Instant .ofEpochMilli (Clock .systemUTC ().millis ()).atZone (ZoneOffset .UTC );
235
+ }
230
236
}
0 commit comments