|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.action.search; |
| 21 | + |
| 22 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
| 23 | +import org.elasticsearch.test.ESIntegTestCase; |
| 24 | + |
| 25 | +import java.util.Collections; |
| 26 | + |
| 27 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 28 | +import static org.hamcrest.Matchers.containsString; |
| 29 | + |
| 30 | +public class TransportSearchIT extends ESIntegTestCase { |
| 31 | + |
| 32 | + public void testShardCountLimit() throws Exception { |
| 33 | + try { |
| 34 | + final int numPrimaries1 = randomIntBetween(2, 10); |
| 35 | + final int numPrimaries2 = randomIntBetween(1, 10); |
| 36 | + assertAcked(prepareCreate("test1") |
| 37 | + .setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numPrimaries1)); |
| 38 | + assertAcked(prepareCreate("test2") |
| 39 | + .setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numPrimaries2)); |
| 40 | + ensureYellow("test1", "test2"); |
| 41 | + |
| 42 | + // no exception |
| 43 | + client().prepareSearch("test1").get(); |
| 44 | + |
| 45 | + assertAcked(client().admin().cluster().prepareUpdateSettings() |
| 46 | + .setTransientSettings(Collections.singletonMap( |
| 47 | + TransportSearchAction.SHARD_COUNT_LIMIT_SETTING.getKey(), numPrimaries1 - 1))); |
| 48 | + |
| 49 | + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, |
| 50 | + () -> client().prepareSearch("test1").get()); |
| 51 | + assertThat(e.getMessage(), containsString("Trying to query " + numPrimaries1 |
| 52 | + + " shards, which is over the limit of " + (numPrimaries1 - 1))); |
| 53 | + |
| 54 | + assertAcked(client().admin().cluster().prepareUpdateSettings() |
| 55 | + .setTransientSettings(Collections.singletonMap( |
| 56 | + TransportSearchAction.SHARD_COUNT_LIMIT_SETTING.getKey(), numPrimaries1))); |
| 57 | + |
| 58 | + // no exception |
| 59 | + client().prepareSearch("test1").get(); |
| 60 | + |
| 61 | + e = expectThrows(IllegalArgumentException.class, |
| 62 | + () -> client().prepareSearch("test1", "test2").get()); |
| 63 | + assertThat(e.getMessage(), containsString("Trying to query " + (numPrimaries1 + numPrimaries2) |
| 64 | + + " shards, which is over the limit of " + numPrimaries1)); |
| 65 | + |
| 66 | + } finally { |
| 67 | + assertAcked(client().admin().cluster().prepareUpdateSettings() |
| 68 | + .setTransientSettings(Collections.singletonMap( |
| 69 | + TransportSearchAction.SHARD_COUNT_LIMIT_SETTING.getKey(), null))); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments