Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HistoryIntegrationTests timestamp comparsion BackPort#38505 #38566

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Changes from all commits
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 @@ -17,12 +17,15 @@
import org.elasticsearch.xpack.core.watcher.actions.ActionStatus;
import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder;
import org.elasticsearch.xpack.core.watcher.input.Input;
import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.core.watcher.watch.WatchStatus;
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
import org.hamcrest.Matcher;

import java.time.ZonedDateTime;
import java.util.Locale;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
Expand Down Expand Up @@ -172,10 +175,10 @@ public void testThatHistoryContainsStatus() throws Exception {
assertThat(active, is(status.state().isActive()));

String timestamp = source.getValue("status.state.timestamp");
assertThat(timestamp, is(status.state().getTimestamp().toString()));
assertThat(timestamp, isSameDate(status.state().getTimestamp()));

String lastChecked = source.getValue("status.last_checked");
assertThat(lastChecked, is(status.lastChecked().toString()));
assertThat(lastChecked, isSameDate(status.lastChecked()));

Integer version = source.getValue("status.version");
int expectedVersion = (int) (status.version() - 1);
Expand All @@ -196,4 +199,14 @@ public void testThatHistoryContainsStatus() throws Exception {
assertThat(mappingSource.getValue("doc.properties.status.properties.status"), is(nullValue()));
assertThat(mappingSource.getValue("doc.properties.status.properties.status.properties.active"), is(nullValue()));
}


private Matcher<String> isSameDate(ZonedDateTime zonedDateTime) {
/*
When comparing timestamps returned from _search/.watcher-history* the same format of date has to be used
during serialisation to json on index time.
The toString of ZonedDateTime is omitting the millisecond part when is 0. This was not the case in joda.
*/
return is(WatcherDateTimeUtils.formatDate(zonedDateTime));
}
}