Skip to content

Commit d821da0

Browse files
committed
Fixing WatchTests
1 parent cac4a47 commit d821da0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/ActionStatus.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ public boolean equals(Object o) {
7373
Objects.equals(lastThrottle, that.lastThrottle);
7474
}
7575

76+
@Override
77+
public String toString() {
78+
final StringBuilder sb = new StringBuilder("ActionStatus{");
79+
sb.append("ackStatus=").append(ackStatus);
80+
sb.append(", lastExecution=").append(lastExecution);
81+
sb.append(", lastSuccessfulExecution=").append(lastSuccessfulExecution);
82+
sb.append(", lastThrottle=").append(lastThrottle);
83+
sb.append('}');
84+
return sb.toString();
85+
}
86+
7687
@Override
7788
public int hashCode() {
7889
return Objects.hash(ackStatus, lastExecution, lastSuccessfulExecution, lastThrottle);
@@ -216,7 +227,7 @@ static State resolve(byte value) {
216227
private final State state;
217228

218229
public AckStatus(ZonedDateTime timestamp, State state) {
219-
this.timestamp = timestamp.withZoneSameInstant(ZoneOffset.UTC);
230+
this.timestamp = timestamp;
220231
this.state = state;
221232
}
222233

@@ -286,7 +297,7 @@ static void writeTo(AckStatus status, StreamOutput out) throws IOException {
286297
}
287298

288299
static AckStatus readFrom(StreamInput in) throws IOException {
289-
ZonedDateTime timestamp = ZonedDateTime.ofInstant(Instant.ofEpochMilli(in.readLong()), ZoneOffset.UTC);
300+
ZonedDateTime timestamp = Instant.ofEpochMilli(in.readLong()).atZone(ZoneOffset.UTC);
290301
State state = State.resolve(in.readByte());
291302
return new AckStatus(timestamp, state);
292303
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/watch/WatchParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public Watch parseWithSecrets(String id, boolean includeStatus, BytesReference s
112112
private Watch parse(String id, boolean includeStatus, boolean withSecrets, BytesReference source, ZonedDateTime now,
113113
XContentType xContentType, boolean allowRedactedPasswords, long sourceSeqNo, long sourcePrimaryTerm)
114114
throws IOException {
115-
116115
if (logger.isTraceEnabled()) {
117116
logger.trace("parsing watch [{}] ", source.utf8ToString());
118117
}

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ public Trigger parseTrigger(String jobName, XContentParser parser) throws IOExce
246246
}
247247
};
248248

249-
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
249+
Clock fixedClock = Clock.fixed(Instant.now(), ZoneOffset.UTC);
250+
250251
ClockMock clock = ClockMock.frozen();
252+
ZonedDateTime now = Instant.ofEpochMilli(fixedClock.millis()).atZone(ZoneOffset.UTC);
251253
clock.setTime(now);
252254

253255
List<ActionWrapper> actions = randomActions();
@@ -260,7 +262,7 @@ public Trigger parseTrigger(String jobName, XContentParser parser) throws IOExce
260262
WatchParser watchParser = new WatchParser(triggerService, actionRegistry, inputRegistry, null, clock);
261263
XContentBuilder builder = jsonBuilder().startObject().startObject("trigger").endObject().field("status", watchStatus).endObject();
262264
Watch watch = watchParser.parse("foo", true, BytesReference.bytes(builder), XContentType.JSON, 1L, 1L);
263-
assertThat(watch.status().state().getTimestamp().toInstant(), is(clock.millis()));
265+
assertThat(watch.status().state().getTimestamp().toInstant().toEpochMilli(), is(clock.millis()));
264266
for (ActionWrapper action : actions) {
265267
assertThat(watch.status().actionStatus(action.id()), is(actionsStatuses.get(action.id())));
266268
}

0 commit comments

Comments
 (0)