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,17 @@ 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
+
132
+ //Instant.ofEpochMilli(fixedClock.millis()).atZone(ZoneOffset.UTC);
133
+ ZonedDateTime lastChecked = rarely () ? null : nowWithMillisResolution ();
134
+ ZonedDateTime lastMetCondition = rarely () ? null : nowWithMillisResolution ();
131
135
int size = randomIntBetween (0 , 5 );
132
136
Map <String , ActionStatus > actionMap = new HashMap <>();
133
137
for (int i = 0 ; i < size ; i ++) {
134
138
ActionStatus .AckStatus ack = new ActionStatus .AckStatus (
135
- ZonedDateTime . now ( ZoneOffset . UTC ),
139
+ nowWithMillisResolution ( ),
136
140
randomFrom (ActionStatus .AckStatus .State .values ())
137
141
);
138
142
ActionStatus actionStatus = new ActionStatus (
@@ -152,16 +156,16 @@ private static WatchStatus randomWatchStatus() {
152
156
}
153
157
154
158
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 ));
156
160
}
157
161
158
162
private static ActionStatus .Execution randomExecution () {
159
163
if (randomBoolean ()) {
160
164
return null ;
161
165
} else if (randomBoolean ()) {
162
- return ActionStatus .Execution .failure (ZonedDateTime . now ( ZoneOffset . UTC ), randomAlphaOfLengthBetween (10 , 20 ));
166
+ return ActionStatus .Execution .failure (nowWithMillisResolution ( ), randomAlphaOfLengthBetween (10 , 20 ));
163
167
} else {
164
- return ActionStatus .Execution .successful (ZonedDateTime . now ( ZoneOffset . UTC ));
168
+ return ActionStatus .Execution .successful (nowWithMillisResolution ( ));
165
169
}
166
170
}
167
171
@@ -227,4 +231,8 @@ private static ActionStatus.Execution convertHlrcToInternal(org.elasticsearch.cl
227
231
private static ActionStatus .Throttle convertHlrcToInternal (org .elasticsearch .client .watcher .ActionStatus .Throttle throttle ) {
228
232
return new ActionStatus .Throttle (throttle .timestamp (), throttle .reason ());
229
233
}
234
+
235
+ private static ZonedDateTime nowWithMillisResolution () {
236
+ return Instant .ofEpochMilli (Clock .systemUTC ().millis ()).atZone (ZoneOffset .UTC );
237
+ }
230
238
}
0 commit comments