Skip to content

Commit a5c35f9

Browse files
authored
Fix HistoryIntegrationTests timestamp comparsion (#38505)
When the millisecond part of a timestamp is 0 the toString representation in java-time is omitting the millisecond part (joda was not). The Search response is returning timestamps formatted with WatcherDateTimeUtils, therefore comparisons of strings should be done with the same formatter relates #27330
1 parent 861eee7 commit a5c35f9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
import org.elasticsearch.xpack.core.watcher.actions.ActionStatus;
1818
import org.elasticsearch.xpack.core.watcher.client.WatchSourceBuilder;
1919
import org.elasticsearch.xpack.core.watcher.input.Input;
20+
import org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils;
2021
import org.elasticsearch.xpack.core.watcher.support.xcontent.XContentSource;
2122
import org.elasticsearch.xpack.core.watcher.watch.WatchStatus;
2223
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
2324
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
2425
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
26+
import org.hamcrest.Matcher;
2527

28+
import java.time.ZonedDateTime;
2629
import java.util.Locale;
2730

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

174177
String timestamp = source.getValue("status.state.timestamp");
175-
assertThat(timestamp, is(status.state().getTimestamp().toString()));
178+
assertThat(timestamp, isSameDate(status.state().getTimestamp()));
176179

177180
String lastChecked = source.getValue("status.last_checked");
178-
assertThat(lastChecked, is(status.lastChecked().toString()));
181+
assertThat(lastChecked, isSameDate(status.lastChecked()));
179182

180183
Integer version = source.getValue("status.version");
181184
int expectedVersion = (int) (status.version() - 1);
@@ -196,4 +199,14 @@ public void testThatHistoryContainsStatus() throws Exception {
196199
assertThat(mappingSource.getValue("doc.properties.status.properties.status"), is(nullValue()));
197200
assertThat(mappingSource.getValue("doc.properties.status.properties.status.properties.active"), is(nullValue()));
198201
}
202+
203+
204+
private Matcher<String> isSameDate(ZonedDateTime zonedDateTime) {
205+
/*
206+
When comparing timestamps returned from _search/.watcher-history* the same format of date has to be used
207+
during serialisation to json on index time.
208+
The toString of ZonedDateTime is omitting the millisecond part when is 0. This was not the case in joda.
209+
*/
210+
return is(WatcherDateTimeUtils.formatDate(zonedDateTime));
211+
}
199212
}

0 commit comments

Comments
 (0)