|
63 | 63 | import static org.hamcrest.Matchers.equalTo;
|
64 | 64 | import static org.hamcrest.Matchers.hasKey;
|
65 | 65 | import static org.hamcrest.Matchers.instanceOf;
|
| 66 | +import static org.hamcrest.Matchers.is; |
| 67 | +import static org.hamcrest.Matchers.oneOf; |
66 | 68 |
|
67 | 69 | public class DynamicMappingIT extends ESIntegTestCase {
|
68 | 70 |
|
@@ -190,6 +192,35 @@ private Map<String, Object> indexConcurrently(int numberOfFieldsToCreate, Settin
|
190 | 192 | return properties;
|
191 | 193 | }
|
192 | 194 |
|
| 195 | + public void testConcurrentDynamicMappingsWithConflictingType() throws Throwable { |
| 196 | + int numberOfDocsToCreate = 16; |
| 197 | + indicesAdmin().prepareCreate("index").setSettings(Settings.builder()).get(); |
| 198 | + ensureGreen("index"); |
| 199 | + final AtomicReference<Throwable> error = new AtomicReference<>(); |
| 200 | + startInParallel(numberOfDocsToCreate, i -> { |
| 201 | + try { |
| 202 | + assertEquals( |
| 203 | + DocWriteResponse.Result.CREATED, |
| 204 | + prepareIndex("index").setId(Integer.toString(i)).setSource("field" + i, 0, "field" + (i + 1), 0.1).get().getResult() |
| 205 | + ); |
| 206 | + } catch (Exception e) { |
| 207 | + error.compareAndSet(null, e); |
| 208 | + } |
| 209 | + }); |
| 210 | + if (error.get() != null) { |
| 211 | + throw error.get(); |
| 212 | + } |
| 213 | + client().admin().indices().prepareRefresh("index").get(); |
| 214 | + for (int i = 0; i < numberOfDocsToCreate; ++i) { |
| 215 | + assertTrue(client().prepareGet("index", Integer.toString(i)).get().isExists()); |
| 216 | + } |
| 217 | + Map<String, Object> index = indicesAdmin().prepareGetMappings("index").get().getMappings().get("index").getSourceAsMap(); |
| 218 | + for (int i = 0, j = 1; i < numberOfDocsToCreate; i++, j++) { |
| 219 | + assertThat(new WriteField("properties.field" + i + ".type", () -> index).get(null), is(oneOf("long", "float"))); |
| 220 | + assertThat(new WriteField("properties.field" + j + ".type", () -> index).get(null), is(oneOf("long", "float"))); |
| 221 | + } |
| 222 | + } |
| 223 | + |
193 | 224 | public void testPreflightCheckAvoidsMaster() throws InterruptedException, IOException {
|
194 | 225 | // can't use INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING nor INDEX_MAPPING_DEPTH_LIMIT_SETTING as a check here, as that is already
|
195 | 226 | // checked at parse time, see testTotalFieldsLimitForDynamicMappingsUpdateCheckedAtDocumentParseTime
|
|
0 commit comments