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@6286b30407
This commit is contained in:
parent
b105118ef0
commit
be2ee21d16
|
@ -14,6 +14,7 @@ import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
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.matchAllQuery;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
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.TriggerBuilders.schedule;
|
||||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.joda.time.DateTimeZone.UTC;
|
||||||
|
|
||||||
public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegrationTestCase {
|
||||||
|
|
||||||
|
private final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY.MM.dd");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean timeWarped() {
|
protected boolean timeWarped() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -40,8 +45,8 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration
|
||||||
return false; // reduce noise
|
return false; // reduce noise
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl="https://github.com/elastic/x-plugins/issues/4090")
|
|
||||||
public void testDynamicIndexAction() throws Exception {
|
public void testDynamicIndexAction() throws Exception {
|
||||||
|
final String indexName = "idx-" + formatter.print(new DateTime(timeWarp().clock().millis(), UTC));
|
||||||
WatcherClient watcherClient = watcherClient();
|
WatcherClient watcherClient = watcherClient();
|
||||||
PutWatchResponse putWatchResponse = watcherClient.preparePutWatch("_id")
|
PutWatchResponse putWatchResponse = watcherClient.preparePutWatch("_id")
|
||||||
.setSource(watchBuilder()
|
.setSource(watchBuilder()
|
||||||
|
@ -58,7 +63,6 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration
|
||||||
|
|
||||||
assertWatchWithMinimumPerformedActionsCount("_id", 1, false);
|
assertWatchWithMinimumPerformedActionsCount("_id", 1, false);
|
||||||
|
|
||||||
final String indexName = "idx-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(new DateTime(timeWarp().clock().millis()));
|
|
||||||
logger.info("checking index [{}]", indexName);
|
logger.info("checking index [{}]", indexName);
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
flush();
|
flush();
|
||||||
|
@ -69,7 +73,7 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDynamicIndexSearchInput() throws Exception {
|
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);
|
createIndex(indexName);
|
||||||
index(indexName, "type", "1", "key", "value");
|
index(indexName, "type", "1", "key", "value");
|
||||||
flush();
|
flush();
|
||||||
|
@ -95,7 +99,7 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDynamicIndexSearchTransform() throws Exception {
|
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);
|
createIndex(indexName);
|
||||||
index(indexName, "type", "1", "key", "value");
|
index(indexName, "type", "1", "key", "value");
|
||||||
flush();
|
flush();
|
||||||
|
|
Loading…
Reference in New Issue