|
9 | 9 | package org.elasticsearch.validate; |
10 | 10 |
|
11 | 11 | import org.elasticsearch.action.admin.indices.alias.Alias; |
| 12 | +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; |
12 | 13 | import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse; |
| 14 | +import org.elasticsearch.action.support.IndicesOptions; |
13 | 15 | import org.elasticsearch.client.internal.Client; |
14 | 16 | import org.elasticsearch.common.bytes.BytesArray; |
15 | 17 | import org.elasticsearch.common.settings.Settings; |
16 | 18 | import org.elasticsearch.common.unit.Fuzziness; |
17 | | -import org.elasticsearch.index.IndexNotFoundException; |
18 | 19 | import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item; |
19 | 20 | import org.elasticsearch.index.query.QueryBuilder; |
20 | 21 | import org.elasticsearch.index.query.QueryBuilders; |
21 | 22 | import org.elasticsearch.index.query.TermsQueryBuilder; |
| 23 | +import org.elasticsearch.indices.IndexClosedException; |
22 | 24 | import org.elasticsearch.indices.TermsLookup; |
23 | 25 | import org.elasticsearch.test.ESIntegTestCase; |
24 | 26 | import org.elasticsearch.test.ESIntegTestCase.ClusterScope; |
@@ -207,12 +209,8 @@ public void testExplainDateRangeInQueryString() { |
207 | 209 | } |
208 | 210 |
|
209 | 211 | public void testValidateEmptyCluster() { |
210 | | - try { |
211 | | - indicesAdmin().prepareValidateQuery().get(); |
212 | | - fail("Expected IndexNotFoundException"); |
213 | | - } catch (IndexNotFoundException e) { |
214 | | - assertThat(e.getMessage(), is("no such index [_all] and no indices exist")); |
215 | | - } |
| 212 | + ValidateQueryResponse response = indicesAdmin().prepareValidateQuery().get(); |
| 213 | + assertThat(response.getTotalShards(), is(0)); |
216 | 214 | } |
217 | 215 |
|
218 | 216 | public void testExplainNoQuery() { |
@@ -379,4 +377,52 @@ public void testExplainTermsQueryWithLookup() { |
379 | 377 | ValidateQueryResponse response = indicesAdmin().prepareValidateQuery("twitter").setQuery(termsLookupQuery).setExplain(true).get(); |
380 | 378 | assertThat(response.isValid(), is(true)); |
381 | 379 | } |
| 380 | + |
| 381 | + public void testOneClosedIndex() { |
| 382 | + createIndex("test"); |
| 383 | + |
| 384 | + boolean ignoreUnavailable = false; |
| 385 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 386 | + client().admin().indices().close(new CloseIndexRequest("test")).actionGet(); |
| 387 | + IndexClosedException ex = expectThrows( |
| 388 | + IndexClosedException.class, |
| 389 | + indicesAdmin().prepareValidateQuery("test").setIndicesOptions(options) |
| 390 | + ); |
| 391 | + assertEquals("closed", ex.getMessage()); |
| 392 | + } |
| 393 | + |
| 394 | + public void testOneClosedIndexIgnoreUnavailable() { |
| 395 | + createIndex("test"); |
| 396 | + |
| 397 | + boolean ignoreUnavailable = true; |
| 398 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 399 | + client().admin().indices().close(new CloseIndexRequest("test")).actionGet(); |
| 400 | + ValidateQueryResponse response = indicesAdmin().prepareValidateQuery("test").setIndicesOptions(options).get(); |
| 401 | + assertThat(response.getTotalShards(), is(0)); |
| 402 | + } |
| 403 | + |
| 404 | + public void testTwoIndicesOneClosed() { |
| 405 | + createIndex("test1"); |
| 406 | + createIndex("test2"); |
| 407 | + |
| 408 | + boolean ignoreUnavailable = false; |
| 409 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 410 | + client().admin().indices().close(new CloseIndexRequest("test1")).actionGet(); |
| 411 | + IndexClosedException ex = expectThrows( |
| 412 | + IndexClosedException.class, |
| 413 | + indicesAdmin().prepareValidateQuery("test1", "test2").setIndicesOptions(options) |
| 414 | + ); |
| 415 | + assertEquals("closed", ex.getMessage()); |
| 416 | + } |
| 417 | + |
| 418 | + public void testTwoIndicesOneClosedIgnoreUnavailable() { |
| 419 | + createIndex("test1"); |
| 420 | + createIndex("test2"); |
| 421 | + |
| 422 | + boolean ignoreUnavailable = true; |
| 423 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 424 | + client().admin().indices().close(new CloseIndexRequest("test1")).actionGet(); |
| 425 | + ValidateQueryResponse response = indicesAdmin().prepareValidateQuery("test1", "test2").setIndicesOptions(options).get(); |
| 426 | + assertThat(response.getTotalShards(), is(1)); |
| 427 | + } |
382 | 428 | } |
0 commit comments