|
@@ -12,6 +12,12 @@ import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource;
|
|
|
import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse;
|
|
|
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.ZonedDateTime;
|
|
|
+import java.time.temporal.ChronoField;
|
|
|
|
|
|
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
|
|
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
|
@@ -19,12 +25,13 @@ 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 {
|
|
|
|
|
|
- @AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/38619")
|
|
|
public void testThatStatusGetsUpdated() {
|
|
|
WatcherClient watcherClient = watcherClient();
|
|
|
watcherClient.preparePutWatch("_name")
|
|
@@ -44,10 +51,24 @@ public class WatchStatusIntegrationTests extends AbstractWatcherIntegrationTestC
|
|
|
GetResponse getResponse = client().prepareGet(".watches", "doc", "_name").get();
|
|
|
getResponse.getSource();
|
|
|
XContentSource source = new XContentSource(getResponse.getSourceAsBytesRef(), XContentType.JSON);
|
|
|
+
|
|
|
String lastChecked = source.getValue("status.last_checked");
|
|
|
+ assertThat(lastChecked, WatcherTestUtils.isSameDate(getWatchResponse.getStatus().lastChecked()));
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
|
|
|
- assertThat(lastChecked, is(notNullValue()));
|
|
|
- assertThat(getWatchResponse.getStatus().lastChecked().toString(), is(lastChecked));
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
}
|