|
| 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.discovery.zen; |
| 21 | + |
| 22 | +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; |
| 23 | +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; |
| 24 | +import org.elasticsearch.common.settings.Settings; |
| 25 | +import org.elasticsearch.test.ESIntegTestCase; |
| 26 | + |
| 27 | +import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; |
| 28 | +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; |
| 29 | +import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.LIMIT_LOCAL_PORTS_COUNT; |
| 30 | +import static org.elasticsearch.transport.TcpTransport.PORT; |
| 31 | + |
| 32 | +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) |
| 33 | +public class SettingsBasedHostProviderIT extends ESIntegTestCase { |
| 34 | + |
| 35 | + @Override |
| 36 | + protected Settings nodeSettings(int nodeOrdinal) { |
| 37 | + Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal)); |
| 38 | + |
| 39 | + // super.nodeSettings enables file-based discovery, but here we disable it again so we can test the static list: |
| 40 | + if (randomBoolean()) { |
| 41 | + builder.putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); |
| 42 | + } else { |
| 43 | + builder.remove(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); |
| 44 | + } |
| 45 | + |
| 46 | + // super.nodeSettings sets this to an empty list, which disables any search for other nodes, but here we want this to happen: |
| 47 | + builder.remove(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()); |
| 48 | + |
| 49 | + return builder.build(); |
| 50 | + } |
| 51 | + |
| 52 | + public void testClusterFormsWithSingleSeedHostInSettings() { |
| 53 | + final String seedNodeName = internalCluster().startNode(); |
| 54 | + final NodesInfoResponse nodesInfoResponse |
| 55 | + = client(seedNodeName).admin().cluster().nodesInfo(new NodesInfoRequest("_local")).actionGet(); |
| 56 | + final String seedNodeAddress = nodesInfoResponse.getNodes().get(0).getTransport().getAddress().publishAddress().toString(); |
| 57 | + logger.info("--> using seed node address {}", seedNodeAddress); |
| 58 | + |
| 59 | + int extraNodes = randomIntBetween(1, 5); |
| 60 | + internalCluster().startNodes(extraNodes, |
| 61 | + Settings.builder().putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), seedNodeAddress).build()); |
| 62 | + |
| 63 | + ensureStableCluster(extraNodes + 1); |
| 64 | + } |
| 65 | + |
| 66 | + public void testClusterFormsByScanningPorts() { |
| 67 | + // This test will fail if all 4 ports just less than the one used by the first node are already bound by something else. It's hard |
| 68 | + // to know how often this might happen in reality, so let's try it and see. |
| 69 | + |
| 70 | + final String seedNodeName = internalCluster().startNode(); |
| 71 | + final NodesInfoResponse nodesInfoResponse |
| 72 | + = client(seedNodeName).admin().cluster().nodesInfo(new NodesInfoRequest("_local")).actionGet(); |
| 73 | + final int seedNodePort = nodesInfoResponse.getNodes().get(0).getTransport().getAddress().publishAddress().getPort(); |
| 74 | + final int minPort = randomIntBetween(seedNodePort - LIMIT_LOCAL_PORTS_COUNT + 1, seedNodePort - 1); |
| 75 | + final String portSpec = minPort + "-" + seedNodePort; |
| 76 | + |
| 77 | + logger.info("--> using port specification [{}]", portSpec); |
| 78 | + internalCluster().startNode(Settings.builder().put(PORT.getKey(), portSpec)); |
| 79 | + ensureStableCluster(2); |
| 80 | + } |
| 81 | +} |
0 commit comments