Merge pull request elastic/elasticsearch#361 from martijnvg/tests/fix/HistoryTemplateTimeMappingsTests

Fix HistoryTemplateTimeMappingsTests

Original commit: elastic/x-pack-elasticsearch@834e84c57d
This commit is contained in:
Martijn van Groningen 2015-05-04 13:24:19 +02:00
commit 1dcb61654c
1 changed files with 25 additions and 16 deletions

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.test.integration; package org.elasticsearch.watcher.test.integration;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
@ -15,6 +14,7 @@ import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
@ -43,7 +43,6 @@ public class HistoryTemplateTimeMappingsTests extends AbstractWatcherIntegration
} }
@Test @Test
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-watcher/issues/351")
public void testTimeFields() throws Exception { public void testTimeFields() throws Exception {
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder() PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder()
.trigger(schedule(interval("5s"))) .trigger(schedule(interval("5s")))
@ -60,20 +59,30 @@ public class HistoryTemplateTimeMappingsTests extends AbstractWatcherIntegration
// the action should fail as no email server is available // the action should fail as no email server is available
assertWatchWithMinimumActionsCount("_id", WatchRecord.State.EXECUTED, 1); assertWatchWithMinimumActionsCount("_id", WatchRecord.State.EXECUTED, 1);
refresh(); refresh();
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get(); assertBusy(new Runnable() {
assertThat(mappingsResponse, notNullValue()); @Override
assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); public void run() {
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> metadatas : mappingsResponse.getMappings()) { GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get();
if (!metadatas.key.startsWith(".watch_history")) { assertThat(mappingsResponse, notNullValue());
continue; assertThat(mappingsResponse.getMappings().isEmpty(), is(false));
for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> metadatas : mappingsResponse.getMappings()) {
if (!metadatas.key.startsWith(".watch_history")) {
continue;
}
MappingMetaData metadata = metadatas.value.get("watch_record");
assertThat(metadata, notNullValue());
try {
Map<String, Object> source = metadata.getSourceAsMap();
logger.info("checking index [{}] with metadata:\n[{}]", metadatas.key, metadata.source().toString());
assertThat(extractValue("properties.trigger_event.properties.schedule.properties.scheduled_time.type", source), is((Object) "date"));
assertThat(extractValue("properties.trigger_event.properties.schedule.properties.triggered_time.type", source), is((Object) "date"));
assertThat(extractValue("properties.watch_execution.properties.execution_time.type", source), is((Object) "date"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }
MappingMetaData metadata = metadatas.value.get("watch_record"); });
assertThat(metadata, notNullValue());
Map<String, Object> source = metadata.getSourceAsMap();
logger.info("metadata : [{}]", metadata.source().toString());
assertThat(extractValue("properties.trigger_event.properties.schedule.properties.scheduled_time.type", source), is((Object) "date"));
assertThat(extractValue("properties.trigger_event.properties.schedule.properties.triggered_time.type", source), is((Object) "date"));
assertThat(extractValue("properties.watch_execution.properties.execution_time.type", source), is((Object) "date"));
}
} }
} }