|
21 | 21 |
|
22 | 22 | import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
23 | 23 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
| 24 | +import org.elasticsearch.action.support.IndicesOptions; |
24 | 25 | import org.elasticsearch.client.Client;
|
| 26 | +import org.elasticsearch.client.Requests; |
25 | 27 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
26 | 28 | import org.elasticsearch.cluster.metadata.MappingMetaData;
|
27 | 29 | import org.elasticsearch.common.Strings;
|
28 | 30 | import org.elasticsearch.common.unit.ByteSizeValue;
|
29 | 31 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
30 | 32 | import org.elasticsearch.common.xcontent.XContentFactory;
|
| 33 | +import org.elasticsearch.indices.IndexMissingException; |
31 | 34 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
32 | 35 | import org.elasticsearch.test.hamcrest.CollectionAssertions;
|
33 | 36 | import org.junit.Before;
|
@@ -157,4 +160,51 @@ public void testLargeClusterStatePublishing() throws Exception {
|
157 | 160 | assertThat(mappingMetadata, equalTo(masterMappingMetaData));
|
158 | 161 | }
|
159 | 162 | }
|
| 163 | + |
| 164 | + @Test |
| 165 | + public void testIndicesOptions() throws Exception { |
| 166 | + ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*") |
| 167 | + .get(); |
| 168 | + assertThat(clusterStateResponse.getState().metaData().indices().size(), is(2)); |
| 169 | + |
| 170 | + // close one index |
| 171 | + client().admin().indices().close(Requests.closeIndexRequest("fuu")).get(); |
| 172 | + clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*").get(); |
| 173 | + assertThat(clusterStateResponse.getState().metaData().indices().size(), is(1)); |
| 174 | + assertThat(clusterStateResponse.getState().metaData().index("foo").state(), equalTo(IndexMetaData.State.OPEN)); |
| 175 | + |
| 176 | + // expand_wildcards_closed should toggle return only closed index fuu |
| 177 | + IndicesOptions expandCloseOptions = IndicesOptions.fromOptions(false, true, false, true); |
| 178 | + clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("f*") |
| 179 | + .setIndicesOptions(expandCloseOptions).get(); |
| 180 | + assertThat(clusterStateResponse.getState().metaData().indices().size(), is(1)); |
| 181 | + assertThat(clusterStateResponse.getState().metaData().index("fuu").state(), equalTo(IndexMetaData.State.CLOSE)); |
| 182 | + |
| 183 | + // ignore_unavailable set to true should not raise exception on fzzbzz |
| 184 | + IndicesOptions ignoreUnavailabe = IndicesOptions.fromOptions(true, true, true, false); |
| 185 | + clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("fzzbzz") |
| 186 | + .setIndicesOptions(ignoreUnavailabe).get(); |
| 187 | + assertThat(clusterStateResponse.getState().metaData().indices().isEmpty(), is(true)); |
| 188 | + |
| 189 | + // empty wildcard expansion result should work when allowNoIndices is |
| 190 | + // turned on |
| 191 | + IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false); |
| 192 | + clusterStateResponse = client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*") |
| 193 | + .setIndicesOptions(allowNoIndices).get(); |
| 194 | + assertThat(clusterStateResponse.getState().metaData().indices().isEmpty(), is(true)); |
| 195 | + } |
| 196 | + |
| 197 | + @Test(expected=IndexMissingException.class) |
| 198 | + public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception { |
| 199 | + // empty wildcard expansion throws exception when allowNoIndices is turned off |
| 200 | + IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, false, true, false); |
| 201 | + client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*").setIndicesOptions(allowNoIndices).get(); |
| 202 | + } |
| 203 | + |
| 204 | + @Test(expected=IndexMissingException.class) |
| 205 | + public void testIndicesIgnoreUnavailableFalse() throws Exception { |
| 206 | + // ignore_unavailable set to false throws exception when allowNoIndices is turned off |
| 207 | + IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false); |
| 208 | + client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("fzzbzz").setIndicesOptions(allowNoIndices).get(); |
| 209 | + } |
160 | 210 | }
|
0 commit comments