removed all timezone'less DateTime constructions
Now as this rule was added to the forbidden APIs in core, this is required for the build to run. Original commit: elastic/x-pack-elasticsearch@a3b570e7f1
This commit is contained in:
parent
aef6ad5c12
commit
8af461daaf
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String, Object> executeWatchResult = watcherClient().prepareExecuteWatch()
|
||||
|
|
|
@ -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<String, Object> map = ImmutableMap.<String, Object>builder()
|
||||
.put("a", ImmutableMap.builder().put("a1", new int[] { 0, 1, 2 }).build())
|
||||
.put("b", new String[] { "b0", "b1", "b2" })
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<TriggerEvent> 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<TriggerEvent> 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<TriggerEvent> 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<TriggerEvent> events) {
|
||||
logger.info("triggered job on [{}]", new DateTime());
|
||||
logger.info("triggered job on [{}]", SystemClock.INSTANCE.now());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue