simple specific master nodes test
This commit is contained in:
parent
20b6688b0a
commit
8def6f59b3
|
@ -53,6 +53,13 @@ public abstract class MasterNodeOperationRequest implements ActionRequest {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A timeout value in case the master has not been discovered yet or disconnected.
|
||||
*/
|
||||
public MasterNodeOperationRequest masterNodeTimeout(String timeout) {
|
||||
return masterNodeTimeout(TimeValue.parseTimeValue(timeout, null));
|
||||
}
|
||||
|
||||
public TimeValue masterNodeTimeout() {
|
||||
return this.masterNodeTimeout;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
|||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
|
@ -70,6 +71,22 @@ public class ClusterStateRequestBuilder extends BaseClusterRequestBuilder<Cluste
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the master node timeout in case the master has not yet been discovered.
|
||||
*/
|
||||
public ClusterStateRequestBuilder setMasterNodeTimeout(TimeValue timeout) {
|
||||
request.masterNodeTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the master node timeout in case the master has not yet been discovered.
|
||||
*/
|
||||
public ClusterStateRequestBuilder setMasterNodeTimeout(String timeout) {
|
||||
request.masterNodeTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override protected void doExecute(ActionListener<ClusterStateResponse> listener) {
|
||||
client.state(request, listener);
|
||||
}
|
||||
|
|
|
@ -138,6 +138,14 @@ public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder<CreateI
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the master node timeout in case the master has not yet been discovered.
|
||||
*/
|
||||
public CreateIndexRequestBuilder setMasterNodeTimeout(String timeout) {
|
||||
request.masterNodeTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override protected void doExecute(ActionListener<CreateIndexResponse> listener) {
|
||||
client.create(request, listener);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,13 @@ public class DeleteIndexRequestBuilder extends BaseIndicesRequestBuilder<DeleteI
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the master node timeout in case the master has not yet been discovered.
|
||||
*/
|
||||
public DeleteIndexRequestBuilder setMasterNodeTimeout(String timeout) {
|
||||
request.masterNodeTimeout(timeout);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override protected void doExecute(ActionListener<DeleteIndexResponse> listener) {
|
||||
client.delete(request, listener);
|
||||
|
|
|
@ -474,6 +474,9 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
|
|||
|
||||
private DiscoveryNode findMaster() {
|
||||
ZenPing.PingResponse[] pingResponses = pingService.pingAndWait(initialPingTimeout);
|
||||
if (pingResponses == null) {
|
||||
return null;
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
StringBuilder sb = new StringBuilder("ping responses:");
|
||||
if (pingResponses.length == 0) {
|
||||
|
|
|
@ -44,6 +44,10 @@ public abstract class AbstractNodesTests {
|
|||
return buildNode(id).start();
|
||||
}
|
||||
|
||||
public Node startNode(String id, Settings.Builder settings) {
|
||||
return startNode(id, settings.build());
|
||||
}
|
||||
|
||||
public Node startNode(String id, Settings settings) {
|
||||
return buildNode(id, settings).start();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.test.integration.masternode;
|
||||
|
||||
import org.elasticsearch.discovery.MasterNotDiscoveredException;
|
||||
import org.elasticsearch.test.integration.AbstractNodesTests;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public class SpecificMasterNodesTests extends AbstractNodesTests {
|
||||
|
||||
@AfterMethod public void closeNodes() {
|
||||
closeAllNodes();
|
||||
}
|
||||
|
||||
@Test public void simpleOnlyMasterNodesElection() {
|
||||
logger.info("--> start data node / non master node");
|
||||
startNode("data1", settingsBuilder().put("node.data", true).put("node.master", false).put("discovery.initial_state_timeout", "1s"));
|
||||
try {
|
||||
assertThat(client("data1").admin().cluster().prepareState().setMasterNodeTimeout("100ms").execute().actionGet().state().nodes().masterNodeId(), nullValue());
|
||||
assert false : "should not be able to find master";
|
||||
} catch (MasterNotDiscoveredException e) {
|
||||
// all is well, no master elected
|
||||
}
|
||||
logger.info("--> start master node");
|
||||
startNode("master1", settingsBuilder().put("node.data", false).put("node.master", true));
|
||||
assertThat(client("data1").admin().cluster().prepareState().execute().actionGet().state().nodes().masterNode().name(), equalTo("master1"));
|
||||
assertThat(client("master1").admin().cluster().prepareState().execute().actionGet().state().nodes().masterNode().name(), equalTo("master1"));
|
||||
|
||||
logger.info("--> stop master node");
|
||||
closeNode("master1");
|
||||
|
||||
try {
|
||||
assertThat(client("data1").admin().cluster().prepareState().setMasterNodeTimeout("100ms").execute().actionGet().state().nodes().masterNodeId(), nullValue());
|
||||
assert false : "should not be able to find master";
|
||||
} catch (MasterNotDiscoveredException e) {
|
||||
// all is well, no master elected
|
||||
}
|
||||
|
||||
logger.info("--> start master node");
|
||||
startNode("master1", settingsBuilder().put("node.data", false).put("node.master", true));
|
||||
assertThat(client("data1").admin().cluster().prepareState().execute().actionGet().state().nodes().masterNode().name(), equalTo("master1"));
|
||||
assertThat(client("master1").admin().cluster().prepareState().execute().actionGet().state().nodes().masterNode().name(), equalTo("master1"));
|
||||
|
||||
logger.info("--> stop all nodes");
|
||||
closeNode("data1");
|
||||
closeNode("master1");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue