|
19 | 19 |
|
20 | 20 | package org.elasticsearch.indices.mapping;
|
21 | 21 |
|
| 22 | +import com.google.common.base.Predicate; |
22 | 23 | import org.elasticsearch.action.ActionRequestValidationException;
|
23 | 24 | import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
24 | 25 | import org.elasticsearch.action.count.CountResponse;
|
25 | 26 | import org.elasticsearch.cluster.ClusterState;
|
| 27 | +import org.elasticsearch.cluster.metadata.MappingMetaData; |
| 28 | +import org.elasticsearch.common.collect.ImmutableOpenMap; |
26 | 29 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
27 | 30 | import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
28 | 31 | import org.junit.Test;
|
@@ -53,24 +56,33 @@ public void simpleDeleteMapping() throws Exception {
|
53 | 56 | assertThat(countResponse.getCount(), equalTo(10l));
|
54 | 57 | }
|
55 | 58 |
|
56 |
| - ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); |
57 |
| - |
58 |
| - assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(true)); |
| 59 | + waitForMappingOnMaster("test", "type1"); |
59 | 60 |
|
60 | 61 | GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet();
|
61 | 62 | assertThat(mappingsResponse.getMappings().get("test").get("type1"), notNullValue());
|
62 | 63 |
|
63 |
| - ElasticsearchAssertions.assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("test").setType("type1")); |
| 64 | + assertAcked(client().admin().indices().prepareDeleteMapping().setIndices("test").setType("type1")); |
64 | 65 |
|
65 | 66 | for (int i = 0; i < 10; i++) {
|
66 | 67 | CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
|
67 | 68 | assertThat(countResponse.getCount(), equalTo(0l));
|
68 | 69 | }
|
69 | 70 |
|
70 |
| - clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); |
71 |
| - assertThat(clusterState.metaData().index("test").mappings().containsKey("type1"), equalTo(false)); |
72 |
| - mappingsResponse = client().admin().indices().prepareGetMappings("test").setTypes("type1").execute().actionGet(); |
73 |
| - assertThat(mappingsResponse.getMappings().get("test"), nullValue()); |
| 71 | + boolean applied = awaitBusy(new Predicate<Object>() { |
| 72 | + @Override |
| 73 | + public boolean apply(Object input) { |
| 74 | + GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").setTypes("type1").get(); |
| 75 | + ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get("test"); |
| 76 | + if (mappings == null) { |
| 77 | + return true; |
| 78 | + } |
| 79 | + return !mappings.containsKey("type1"); |
| 80 | + } |
| 81 | + }); |
| 82 | + if (!applied) { |
| 83 | + fail("failed to wait for the mapping to be removed from the master cluster state"); |
| 84 | + } |
| 85 | + |
74 | 86 | }
|
75 | 87 |
|
76 | 88 |
|
|
0 commit comments