Skip to content

Commit

Permalink
Fix the clock resolution to millis in ScheduledEventTests (elastic#38506
Browse files Browse the repository at this point in the history
)

The clock resolution changed from jdk8 to jdk10, hence the
test is passing in jdk8 but failing in jdk10.  Scheduled
events are serialised and deserialised with millisecond
precision, making test fail in jdk 10 and higher.

Fixes a problem introduced by elastic#38415 and the fix is
identical to the one that was made in elastic#38405.
  • Loading branch information
droberts195 committed Feb 6, 2019
1 parent f8ed6c1 commit 9009637
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.EnumSet;
Expand All @@ -28,7 +29,7 @@
public class ScheduledEventTests extends AbstractSerializingTestCase<ScheduledEvent> {

public static ScheduledEvent createScheduledEvent(String calendarId) {
ZonedDateTime start = Clock.systemUTC().instant().atZone(ZoneOffset.UTC);
ZonedDateTime start = nowWithMillisResolution();
return new ScheduledEvent(randomAlphaOfLength(10), start, start.plusSeconds(randomIntBetween(1, 10000)),
calendarId, null);
}
Expand Down Expand Up @@ -119,4 +120,8 @@ public void testLenientParser() throws IOException {
ScheduledEvent.LENIENT_PARSER.apply(parser, null);
}
}

private static ZonedDateTime nowWithMillisResolution() {
return Instant.ofEpochMilli(Clock.systemUTC().millis()).atZone(ZoneOffset.UTC);
}
}

0 comments on commit 9009637

Please sign in to comment.