Skip to content

Commit 7c6566e

Browse files
authored
Migrate SpecificMasterNodesIT to Zen2 (#37532)
1. testSimpleOnlyMasterNodeElection - requires cluster bootstrap when the first master node is started. 2. testElectOnlyBetweenMasterNodes - requires cluster bootstrap when the first master node is started and requires adding voting exclusion before shutting down the first master node. 3. testAliasFilterValidation - requires cluster bootstrap when the first master node is started.
1 parent e2e00cd commit 7c6566e

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

server/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package org.elasticsearch.cluster;
2121

2222
import org.apache.lucene.search.join.ScoreMode;
23+
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
24+
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
25+
import org.elasticsearch.cluster.coordination.ClusterBootstrapService;
2326
import org.elasticsearch.common.settings.Settings;
2427
import org.elasticsearch.common.xcontent.XContentType;
2528
import org.elasticsearch.discovery.MasterNotDiscoveredException;
@@ -28,10 +31,12 @@
2831
import org.elasticsearch.test.ESIntegTestCase;
2932
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
3033
import org.elasticsearch.test.ESIntegTestCase.Scope;
31-
import org.elasticsearch.test.discovery.TestZenDiscovery;
3234
import org.elasticsearch.test.junit.annotations.TestLogging;
3335

3436
import java.io.IOException;
37+
import java.util.Collections;
38+
import java.util.List;
39+
import java.util.concurrent.ExecutionException;
3540

3641
import static org.elasticsearch.discovery.zen.ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING;
3742
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@@ -45,10 +50,22 @@ public class SpecificMasterNodesIT extends ESIntegTestCase {
4550
@Override
4651
protected Settings nodeSettings(int nodeOrdinal) {
4752
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
48-
.put(TestZenDiscovery.USE_ZEN2.getKey(), false) // does unsafe things
4953
.put(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), 1).build();
5054
}
5155

56+
@Override
57+
protected List<Settings> addExtraClusterBootstrapSettings(List<Settings> allNodesSettings) {
58+
// if it's the first master in the cluster bootstrap the cluster with this node name
59+
Settings settings = allNodesSettings.get(0);
60+
if (internalCluster().numMasterNodes() == 0 && settings.getAsBoolean(Node.NODE_MASTER_SETTING.getKey(), false)) {
61+
return Collections.singletonList(Settings.builder()
62+
.put(settings)
63+
.put(ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING.getKey(), settings.get(Node.NODE_NAME_SETTING.getKey()))
64+
.build());
65+
}
66+
return allNodesSettings;
67+
}
68+
5269
public void testSimpleOnlyMasterNodeElection() throws IOException {
5370
logger.info("--> start data node / non master node");
5471
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true)
@@ -89,7 +106,7 @@ public void testSimpleOnlyMasterNodeElection() throws IOException {
89106
.execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligibleNodeName));
90107
}
91108

92-
public void testElectOnlyBetweenMasterNodes() throws IOException {
109+
public void testElectOnlyBetweenMasterNodes() throws IOException, ExecutionException, InterruptedException {
93110
logger.info("--> start data node / non master node");
94111
internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), true)
95112
.put(Node.NODE_MASTER_SETTING.getKey(), false).put("discovery.initial_state_timeout", "1s"));
@@ -119,14 +136,16 @@ public void testElectOnlyBetweenMasterNodes() throws IOException {
119136
.execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName));
120137

121138
logger.info("--> closing master node (1)");
139+
client().execute(AddVotingConfigExclusionsAction.INSTANCE,
140+
new AddVotingConfigExclusionsRequest(new String[]{masterNodeName})).get();
122141
internalCluster().stopCurrentMasterNode();
123142
assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState()
124143
.execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName));
125144
assertThat(internalCluster().masterClient().admin().cluster().prepareState()
126145
.execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName));
127146
}
128147

129-
public void testAliasFilterValidation() throws Exception {
148+
public void testAliasFilterValidation() {
130149
logger.info("--> start master node / non data");
131150
internalCluster().startNode(Settings.builder()
132151
.put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true));

0 commit comments

Comments
 (0)