[Test] IndexLifecycleActionTests - set minimum master node earlier to make sure it's in effect when needed.

This commit is contained in:
Boaz Leskes 2014-03-17 09:40:36 +01:00
parent c6915ef4d6
commit 6f0b15a27a
2 changed files with 16 additions and 14 deletions

View File

@ -958,9 +958,11 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
class ApplySettings implements NodeSettingsService.Listener {
@Override
public void onRefreshSettings(Settings settings) {
int minimumMasterNodes = settings.getAsInt("discovery.zen.minimum_master_nodes", ZenDiscovery.this.electMaster.minimumMasterNodes());
int minimumMasterNodes = settings.getAsInt(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES,
ZenDiscovery.this.electMaster.minimumMasterNodes());
if (minimumMasterNodes != ZenDiscovery.this.electMaster.minimumMasterNodes()) {
logger.info("updating discovery.zen.minimum_master_nodes from [{}] to [{}]", ZenDiscovery.this.electMaster.minimumMasterNodes(), minimumMasterNodes);
logger.info("updating {} from [{}] to [{}]", ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES,
ZenDiscovery.this.electMaster.minimumMasterNodes(), minimumMasterNodes);
handleMinimumMasterNodesChanged(minimumMasterNodes);
}
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.zen.elect.ElectMasterService;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
@ -53,9 +54,15 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
@ClusterScope(scope=Scope.TEST, numNodes=0)
@ClusterScope(scope = Scope.TEST, numNodes = 0)
public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
protected void setMinimumMasterNodes(int n) {
assertTrue(client().admin().cluster().prepareUpdateSettings().setTransientSettings(
settingsBuilder().put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, n))
.get().isAcknowledged());
}
@Slow
@Test
public void testIndexLifecycleActions() throws Exception {
@ -105,10 +112,9 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
setMinimumMasterNodes(2);
final String node2 = getLocalNodeId(server_2);
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
client().admin().cluster().prepareReroute().execute().actionGet();
@ -177,9 +183,6 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
assertThat(routingNodeEntry3.numberOfShardsWithState(INITIALIZING), equalTo(0));
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(7));
client().admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder()
.put("discovery.zen.minimum_master_nodes", 2)) // we are shutting down a node - make sure we don't have 2 clusters if we test network
.get();
logger.info("Closing server1");
// kill the first server
cluster().stopRandomNode(TestCluster.nameFilter(server_1));
@ -233,7 +236,7 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
assertThat(nodeId, not(nullValue()));
return nodeId;
}
@Slow
@Nightly
@Test
@ -277,7 +280,7 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
setMinimumMasterNodes(2);
final String node2 = getLocalNodeId(server_2);
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
@ -344,9 +347,6 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
assertThat(routingNodeEntry3.numberOfShardsWithState(INITIALIZING), equalTo(0));
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(3));
client().admin().cluster().prepareUpdateSettings().setTransientSettings(settingsBuilder()
.put("discovery.zen.minimum_master_nodes", 2)) // we are shutting down a node - make sure we don't have 2 clusters if we test network
.get();
logger.info("Closing server1");
// kill the first server
cluster().stopRandomNode(TestCluster.nameFilter(server_1));
@ -399,7 +399,7 @@ public class IndexLifecycleActionTests extends ElasticsearchIntegrationTest {
assertThat(routingNodeEntry3.isEmpty(), equalTo(true));
}
private void assertNodesPresent(RoutingNodes routingNodes, String...nodes) {
private void assertNodesPresent(RoutingNodes routingNodes, String... nodes) {
final Set<String> keySet = Sets.newHashSet(Iterables.transform(routingNodes, new Function<RoutingNode, String>() {
@Override
public String apply(RoutingNode input) {