From be2ee21d1617b441252501a7ba85201e3464b7b6 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Fri, 3 Mar 2017 00:19:12 +0100 Subject: [PATCH] Tests: Ensure date is UTC to prevent failing tests This test used the local time zone to check for an assertion, and thus failed in US evenings, because the date in UTC rolled over. relates elastic/x-pack-elasticsearch#239 Original commit: elastic/x-pack-elasticsearch@6286b30407d3cd298b3faf3f89feaf5afbb3e11a --- .../support/DynamicIndexNameIntegrationTests.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java index 9ba86924143..1a4a13177b5 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; @@ -28,8 +29,12 @@ import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.search import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval; import static org.hamcrest.Matchers.is; +import static org.joda.time.DateTimeZone.UTC; public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegrationTestCase { + + private final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd"); + @Override protected boolean timeWarped() { return true; @@ -40,8 +45,8 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration return false; // reduce noise } - @AwaitsFix(bugUrl="https://github.com/elastic/x-plugins/issues/4090") public void testDynamicIndexAction() throws Exception { + final String indexName = "idx-" + formatter.print(new DateTime(timeWarp().clock().millis(), UTC)); WatcherClient watcherClient = watcherClient(); PutWatchResponse putWatchResponse = watcherClient.preparePutWatch("_id") .setSource(watchBuilder() @@ -58,7 +63,6 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration assertWatchWithMinimumPerformedActionsCount("_id", 1, false); - final String indexName = "idx-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(timeWarp().clock().millis())); logger.info("checking index [{}]", indexName); assertBusy(() -> { flush(); @@ -69,7 +73,7 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration } public void testDynamicIndexSearchInput() throws Exception { - final String indexName = "idx-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(timeWarp().clock().millis())); + final String indexName = "idx-" + formatter.print(new DateTime(timeWarp().clock().millis(), UTC)); createIndex(indexName); index(indexName, "type", "1", "key", "value"); flush(); @@ -95,7 +99,7 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration } public void testDynamicIndexSearchTransform() throws Exception { - String indexName = "idx-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(timeWarp().clock().millis())); + final String indexName = "idx-" + formatter.print(new DateTime(timeWarp().clock().millis(), UTC)); createIndex(indexName); index(indexName, "type", "1", "key", "value"); flush();