From caa5af4bf6f2f03e88c30b0e241cd50ea1189694 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 5 Dec 2014 14:40:15 +0100 Subject: [PATCH] [TESTS] Use a _default_ template to load field data lazily Previously it was possible for the field data clearing in this test to take too long, causing the test to time out. This also switches to using `scaledRandomIntBetween` for the number of fields. --- .../ConcurrentDynamicTemplateTests.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java index 37f3d0d14da..98306b8aa27 100644 --- a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java +++ b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java @@ -24,6 +24,10 @@ import com.google.common.collect.Sets; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.fielddata.FieldDataType; +import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Test; @@ -92,9 +96,50 @@ public class ConcurrentDynamicTemplateTests extends ElasticsearchIntegrationTest @Test public void testDynamicMappingIntroductionPropagatesToAll() throws Exception { int numDocs = randomIntBetween(100, 1000); - int numberOfFields = randomIntBetween(1, 50); + int numberOfFields = scaledRandomIntBetween(1, 50); Set fieldsIdx = Sets.newHashSet(); IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs]; + + XContentBuilder mappings = XContentFactory.jsonBuilder().startObject().startObject("_default_"); + mappings.startArray("dynamic_templates") + .startObject() + .startObject("template-strings") + .field("match_mapping_type", "string") + .startObject("mapping") + .startObject("fielddata") + .field(FieldDataType.FORMAT_KEY, randomFrom("paged_bytes", "fst")) + .field(FieldMapper.Loading.KEY, FieldMapper.Loading.LAZY) // always use lazy loading + .endObject() + .endObject() + .endObject() + .endObject() + .startObject() + .startObject("template-longs") + .field("match_mapping_type", "long") + .startObject("mapping") + .startObject("fielddata") + .field(FieldDataType.FORMAT_KEY, randomFrom("array", "doc_values")) + .field(FieldMapper.Loading.KEY, FieldMapper.Loading.LAZY) + .endObject() + .endObject() + .endObject() + .endObject() + .startObject() + .startObject("template-doubles") + .field("match_mapping_type", "double") + .startObject("mapping") + .startObject("fielddata") + .field(FieldDataType.FORMAT_KEY, randomFrom("array", "doc_values")) + .field(FieldMapper.Loading.KEY, FieldMapper.Loading.LAZY) + .endObject() + .endObject() + .endObject() + .endObject() + .endArray(); + mappings.endObject().endObject(); + + assertAcked(client().admin().indices().prepareCreate("idx").addMapping("_default_", mappings)); + ensureGreen("idx"); for (int i = 0; i < numDocs; ++i) { int fieldIdx = i % numberOfFields; fieldsIdx.add(fieldIdx); @@ -102,7 +147,7 @@ public class ConcurrentDynamicTemplateTests extends ElasticsearchIntegrationTest .startObject() .field("str_value_" + fieldIdx, "s" + i) .field("l_value_" + fieldIdx, i) - .field("d_value_" + fieldIdx, i) + .field("d_value_" + fieldIdx, (double)i + 0.01) .endObject()); } indexRandom(false, builders);