Added regression tests for #3381

This commit is contained in:
Luca Cavanna 2013-07-25 18:30:10 +02:00
parent bb43636190
commit cb32841d9a
1 changed files with 67 additions and 2 deletions

View File

@ -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));
}
}