Skip to content
Merged
Changes from 1 commit
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 @@ -13,26 +13,27 @@
import org.elasticsearch.xpack.watcher.condition.NeverCondition;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.test.WatcherTestUtils;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval.Unit.SECONDS;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class WatchStatusIntegrationTests extends AbstractWatcherIntegrationTestCase {

public void testThatStatusGetsUpdated() {
timeWarp().clock().setTime(
ZonedDateTime.of(2019,02,9,15,9,50,687670, ZoneOffset.UTC));

WatcherClient watcherClient = watcherClient();
watcherClient.preparePutWatch("_name")
.setSource(watchBuilder()
Expand All @@ -54,11 +55,21 @@ public void testThatStatusGetsUpdated() {

String lastChecked = source.getValue("status.last_checked");
assertThat(lastChecked, WatcherTestUtils.isSameDate(getWatchResponse.getStatus().lastChecked()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also assert that the nano seconds are not present here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure - updated the PR


assertThat(getWatchResponse.getStatus().lastChecked(), isMillisResolution());
// not started yet, so both nulls
String lastMetCondition = source.getValue("status.last_met_condition");
assertThat(lastMetCondition, is(nullValue()));
assertThat(getWatchResponse.getStatus().lastMetCondition(), is(nullValue()));
}

private Matcher<ZonedDateTime> isMillisResolution() {
return new FeatureMatcher<ZonedDateTime,Boolean>(equalTo(true), "has millisecond precision", "precission") {
@Override
protected Boolean featureValueOf(ZonedDateTime actual) {
//if date has millisecond precision its nanosecond field will be rounded to millis (equal millis * 10^6)
return actual.getNano() == actual.get(ChronoField.MILLI_OF_SECOND) * 1000_000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively just actual.getNano() % 1000 == 0 - not sure if it is more readable to be honest, so feel free to ignore me :-)

}
};
}

}