diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTest.java b/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTest.java index 2215d623ce3..5372e1ac5d1 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTest.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTest.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ElasticsearchTestCase; +import org.joda.time.DateTimeZone; import org.junit.Test; import java.util.ArrayList; @@ -35,7 +36,7 @@ public class EmailTest extends ElasticsearchTestCase { Email.AddressList possibleList = new Email.AddressList(addresses); Email.AddressList replyTo = randomFrom(possibleList, null); Email.Priority priority = randomFrom(Email.Priority.values()); - DateTime sentDate = new DateTime(randomInt()); + DateTime sentDate = new DateTime(randomInt(), DateTimeZone.getDefault()); Email.AddressList to = randomFrom(possibleList, null); Email.AddressList cc = randomFrom(possibleList, null); Email.AddressList bcc = randomFrom(possibleList, null); diff --git a/src/test/java/org/elasticsearch/watcher/actions/throttler/AckThrottlerTests.java b/src/test/java/org/elasticsearch/watcher/actions/throttler/AckThrottlerTests.java index 7e50fc6bfb6..bcf22f2da35 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/throttler/AckThrottlerTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/throttler/AckThrottlerTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.watcher.actions.throttler; +import org.elasticsearch.watcher.support.clock.SystemClock; import org.joda.time.DateTime; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.actions.ActionStatus; @@ -28,7 +29,7 @@ public class AckThrottlerTests extends ElasticsearchTestCase { @Test public void testWhenAcked() throws Exception { - DateTime timestamp = new DateTime(); + DateTime timestamp = SystemClock.INSTANCE.now(); WatchExecutionContext ctx = mockExecutionContext("_watch", EMPTY_PAYLOAD); Watch watch = ctx.watch(); ActionStatus actionStatus = mock(ActionStatus.class); @@ -44,7 +45,7 @@ public class AckThrottlerTests extends ElasticsearchTestCase { @Test public void testThrottle_When_AwaitsSuccessfulExecution() throws Exception { - DateTime timestamp = new DateTime(); + DateTime timestamp = SystemClock.INSTANCE.now(); WatchExecutionContext ctx = mockExecutionContext("_watch", EMPTY_PAYLOAD); Watch watch = ctx.watch(); ActionStatus actionStatus = mock(ActionStatus.class); @@ -60,7 +61,7 @@ public class AckThrottlerTests extends ElasticsearchTestCase { @Test public void testThrottle_When_Ackable() throws Exception { - DateTime timestamp = new DateTime(); + DateTime timestamp = SystemClock.INSTANCE.now(); WatchExecutionContext ctx = mockExecutionContext("_watch", EMPTY_PAYLOAD); Watch watch = ctx.watch(); ActionStatus actionStatus = mock(ActionStatus.class); diff --git a/src/test/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottlerTests.java b/src/test/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottlerTests.java index b253699b8aa..0f4d30e200d 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottlerTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottlerTests.java @@ -35,7 +35,7 @@ public class PeriodThrottlerTests extends ElasticsearchTestCase { WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD); ActionStatus actionStatus = mock(ActionStatus.class); - when(actionStatus.lastSuccessfulExecution()).thenReturn(ActionStatus.Execution.successful(new DateTime().minusSeconds((int) period.seconds() - 1))); + when(actionStatus.lastSuccessfulExecution()).thenReturn(ActionStatus.Execution.successful(SystemClock.INSTANCE.now().minusSeconds((int) period.seconds() - 1))); WatchStatus status = mock(WatchStatus.class); when(status.actionStatus("_action")).thenReturn(actionStatus); when(ctx.watch().status()).thenReturn(status); @@ -55,7 +55,7 @@ public class PeriodThrottlerTests extends ElasticsearchTestCase { WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD); ActionStatus actionStatus = mock(ActionStatus.class); - when(actionStatus.lastSuccessfulExecution()).thenReturn(ActionStatus.Execution.successful(new DateTime().minusSeconds((int) period.seconds() + 1))); + when(actionStatus.lastSuccessfulExecution()).thenReturn(ActionStatus.Execution.successful(SystemClock.INSTANCE.now().minusSeconds((int) period.seconds() + 1))); WatchStatus status = mock(WatchStatus.class); when(status.actionStatus("_action")).thenReturn(actionStatus); when(ctx.watch().status()).thenReturn(status); diff --git a/src/test/java/org/elasticsearch/watcher/execution/ManualExecutionTests.java b/src/test/java/org/elasticsearch/watcher/execution/ManualExecutionTests.java index d70f5696f31..e2033efd3a1 100644 --- a/src/test/java/org/elasticsearch/watcher/execution/ManualExecutionTests.java +++ b/src/test/java/org/elasticsearch/watcher/execution/ManualExecutionTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.watcher.execution; +import org.elasticsearch.watcher.support.clock.SystemClock; import org.joda.time.DateTime; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.common.unit.TimeValue; @@ -260,9 +261,9 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTests { .addAction("log", loggingAction("foobar")); watcherClient().putWatch(new PutWatchRequest("_id", watchBuilder)).actionGet(); - TriggerEvent triggerEvent = new ScheduleTriggerEvent(new DateTime(DateTimeZone.UTC), new DateTime(DateTimeZone.UTC)); + TriggerEvent triggerEvent = new ScheduleTriggerEvent(SystemClock.INSTANCE.nowUTC(), SystemClock.INSTANCE.nowUTC()); - Wid wid = new Wid("_watchId",1,new DateTime()); + Wid wid = new Wid("_watchId",1, SystemClock.INSTANCE.nowUTC()); Map executeWatchResult = watcherClient().prepareExecuteWatch() diff --git a/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java b/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java index d9418e45497..43fd3309dbd 100644 --- a/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java +++ b/src/test/java/org/elasticsearch/watcher/support/WatcherUtilsTests.java @@ -6,25 +6,29 @@ package org.elasticsearch.watcher.support; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.joda.time.DateTime; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.*; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.input.search.ExecutableSearchInput; +import org.elasticsearch.watcher.support.clock.SystemClock; import org.elasticsearch.watcher.support.template.Template; +import org.joda.time.DateTime; import org.junit.Test; import java.io.IOException; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.formatDate; @@ -40,7 +44,7 @@ public class WatcherUtilsTests extends ElasticsearchTestCase { @Test public void testFlattenModel() throws Exception { - DateTime now = new DateTime(); + DateTime now = SystemClock.INSTANCE.now(); Map map = ImmutableMap.builder() .put("a", ImmutableMap.builder().put("a1", new int[] { 0, 1, 2 }).build()) .put("b", new String[] { "b0", "b1", "b2" }) diff --git a/src/test/java/org/elasticsearch/watcher/support/clock/ClockMock.java b/src/test/java/org/elasticsearch/watcher/support/clock/ClockMock.java index 6c29beca8e2..ac625918dd5 100644 --- a/src/test/java/org/elasticsearch/watcher/support/clock/ClockMock.java +++ b/src/test/java/org/elasticsearch/watcher/support/clock/ClockMock.java @@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit; */ public class ClockMock implements Clock { - private DateTime now = DateTime.now(); + private DateTime now = DateTime.now(DateTimeZone.getDefault()); @Override public long millis() { diff --git a/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java b/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java index cf01361fbc5..ae74bf11f69 100644 --- a/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java +++ b/src/test/java/org/elasticsearch/watcher/test/integration/BasicWatcherTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.watcher.support.clock.SystemClock; import org.joda.time.DateTime; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; @@ -437,7 +438,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests { private void testConditionSearch(SearchRequest request) throws Exception { if (timeWarped()) { // reset, so we don't miss event docs when we filter over the _timestamp field. - timeWarp().clock().setTime(new DateTime()); + timeWarp().clock().setTime(SystemClock.INSTANCE.now()); } String watchName = "_name"; @@ -450,7 +451,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests { .condition(ConditionBuilders.scriptCondition("return ctx.payload.hits.total >= 3"))) .get(); - logger.info("created watch [{}] at [{}]", watchName, DateTime.now()); + logger.info("created watch [{}] at [{}]", watchName, SystemClock.INSTANCE.now()); client().prepareIndex("events", "event") .setCreate(true) diff --git a/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java b/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java index 2ac29970142..cb2d5710b45 100644 --- a/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java +++ b/src/test/java/org/elasticsearch/watcher/trigger/schedule/engine/BaseTriggerEngineTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.watcher.trigger.schedule.engine; import org.apache.lucene.util.LuceneTestCase.Slow; +import org.elasticsearch.watcher.support.clock.SystemClock; import org.joda.time.DateTime; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.trigger.Trigger; @@ -68,11 +69,11 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { for (TriggerEvent event : events) { int index = Integer.parseInt(event.jobName()); if (!bits.get(index)) { - logger.info("job [" + index + "] first fire: " + new DateTime()); + logger.info("job [{}] first fire: {}", index, SystemClock.INSTANCE.now()); bits.set(index); } else { latch.countDown(); - logger.info("job [" + index + "] second fire: " + new DateTime()); + logger.info("job [{}] second fire: {}", index, SystemClock.INSTANCE.now()); } } } @@ -96,7 +97,7 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { public void triggered(Iterable events) { for (TriggerEvent event : events) { assertThat(event.jobName(), is(name)); - logger.info("triggered job on [{}]", new DateTime()); + logger.info("triggered job on [{}]", SystemClock.INSTANCE.now()); } latch.countDown(); } @@ -130,7 +131,7 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { public void triggered(Iterable events) { for (TriggerEvent event : events) { assertThat(event.jobName(), is(name)); - logger.info("triggered job on [{}]", new DateTime()); + logger.info("triggered job on [{}]", SystemClock.INSTANCE.now()); latch.countDown(); } } @@ -166,7 +167,7 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { public void triggered(Iterable events) { for (TriggerEvent event : events) { assertThat(event.jobName(), is(name)); - logger.info("triggered job on [{}]", new DateTime()); + logger.info("triggered job on [{}]", SystemClock.INSTANCE.now()); } latch.countDown(); } @@ -200,7 +201,7 @@ public abstract class BaseTriggerEngineTests extends ElasticsearchTestCase { @Override public void triggered(Iterable events) { - logger.info("triggered job on [{}]", new DateTime()); + logger.info("triggered job on [{}]", SystemClock.INSTANCE.now()); } });