From cb32841d9a703bb433f987e66f3b6cc3d4246324 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Thu, 25 Jul 2013 18:30:10 +0200 Subject: [PATCH] Added regression tests for #3381 --- .../indices/mapping/UpdateMappingTests.java | 69 ++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/integration/indices/mapping/UpdateMappingTests.java b/src/test/java/org/elasticsearch/test/integration/indices/mapping/UpdateMappingTests.java index f68b9437639..803dc43f4e2 100644 --- a/src/test/java/org/elasticsearch/test/integration/indices/mapping/UpdateMappingTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indices/mapping/UpdateMappingTests.java @@ -1,20 +1,20 @@ package org.elasticsearch.test.integration.indices.mapping; +import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.test.integration.AbstractSharedClusterTest; import org.junit.Test; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; public class UpdateMappingTests extends AbstractSharedClusterTest { @Test public void dynamicUpdates() throws Exception { - client().admin().indices().prepareDelete().execute().actionGet(); client().admin().indices().prepareCreate("test") .setSettings( @@ -35,4 +35,69 @@ public class UpdateMappingTests extends AbstractSharedClusterTest { assertThat(response.getCount(), equalTo(recCount)); } + @Test(expected = MergeMappingException.class) + public void updateMappingWithConflicts() throws Exception { + + client().admin().indices().prepareCreate("test") + .setSettings( + ImmutableSettings.settingsBuilder() + .put("index.number_of_shards", 2) + .put("index.number_of_replicas", 0) + ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}") + .execute().actionGet(); + client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + + PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type") + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}") + .execute().actionGet(); + + assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); + } + + /* + First regression test for https://github.com/elasticsearch/elasticsearch/issues/3381 + */ + @Test + public void updateMappingWithIgnoredConflicts() throws Exception { + + client().admin().indices().prepareCreate("test") + .setSettings( + ImmutableSettings.settingsBuilder() + .put("index.number_of_shards", 2) + .put("index.number_of_replicas", 0) + ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}") + .execute().actionGet(); + client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + + PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type") + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}") + .setIgnoreConflicts(true) + .execute().actionGet(); + + //no changes since the only one had a conflict and was ignored, we return + assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); + } + + /* + Second regression test for https://github.com/elasticsearch/elasticsearch/issues/3381 + */ + @Test + public void updateMappingNoChanges() throws Exception { + + client().admin().indices().prepareCreate("test") + .setSettings( + ImmutableSettings.settingsBuilder() + .put("index.number_of_shards", 2) + .put("index.number_of_replicas", 0) + ).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}") + .execute().actionGet(); + client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); + + PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type") + .setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}") + .execute().actionGet(); + + //no changes, we return + assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); + } }