|
| 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.azure; |
| 21 | + |
| 22 | +import org.elasticsearch.common.settings.ImmutableSettings; |
| 23 | +import org.elasticsearch.common.settings.Settings; |
| 24 | +import org.elasticsearch.discovery.MasterNotDiscoveredException; |
| 25 | +import org.elasticsearch.test.ElasticsearchIntegrationTest; |
| 26 | +import org.junit.Test; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | + |
| 30 | +import static org.hamcrest.Matchers.notNullValue; |
| 31 | +import static org.hamcrest.Matchers.nullValue; |
| 32 | + |
| 33 | +/** |
| 34 | + * Reported issue in #15 |
| 35 | + * (https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/15) |
| 36 | + */ |
| 37 | +@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, |
| 38 | + numDataNodes = 0, |
| 39 | + transportClientRatio = 0.0, |
| 40 | + numClientNodes = 0) |
| 41 | +public class AzureMinimumMasterNodesTest extends AbstractAzureComputeServiceTest { |
| 42 | + |
| 43 | + public AzureMinimumMasterNodesTest() { |
| 44 | + super(AzureComputeServiceTwoNodesMock.class); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected final Settings settingsBuilder() { |
| 49 | + ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder() |
| 50 | + .put("discovery.zen.minimum_master_nodes", 2) |
| 51 | + .put(super.settingsBuilder()); |
| 52 | + return builder.build(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void simpleOnlyMasterNodeElection() throws IOException { |
| 57 | + logger.info("--> start data node / non master node"); |
| 58 | + internalCluster().startNode(settingsBuilder()); |
| 59 | + try { |
| 60 | + assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("100ms").execute().actionGet().getState().nodes().masterNodeId(), nullValue()); |
| 61 | + fail("should not be able to find master"); |
| 62 | + } catch (MasterNotDiscoveredException e) { |
| 63 | + // all is well, no master elected |
| 64 | + } |
| 65 | + logger.info("--> start another node"); |
| 66 | + internalCluster().startNode(settingsBuilder()); |
| 67 | + assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue()); |
| 68 | + |
| 69 | + logger.info("--> stop master node"); |
| 70 | + internalCluster().stopCurrentMasterNode(); |
| 71 | + |
| 72 | + try { |
| 73 | + assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), nullValue()); |
| 74 | + fail("should not be able to find master"); |
| 75 | + } catch (MasterNotDiscoveredException e) { |
| 76 | + // all is well, no master elected |
| 77 | + } |
| 78 | + |
| 79 | + logger.info("--> start another node"); |
| 80 | + internalCluster().startNode(settingsBuilder()); |
| 81 | + assertThat(client().admin().cluster().prepareState().setMasterNodeTimeout("1s").execute().actionGet().getState().nodes().masterNodeId(), notNullValue()); |
| 82 | + } |
| 83 | +} |
0 commit comments