From 6f0b15a27a018a6e91c3f3380d883cc8bf600824 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 17 Mar 2014 09:40:36 +0100 Subject: [PATCH] [Test] IndexLifecycleActionTests - set minimum master node earlier to make sure it's in effect when needed. --- .../discovery/zen/ZenDiscovery.java | 6 +++-- .../IndexLifecycleActionTests.java | 24 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 16bcb18b194..59b9ff5c66f 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -958,9 +958,11 @@ public class ZenDiscovery extends AbstractLifecycleComponent 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); } } diff --git a/src/test/java/org/elasticsearch/indexlifecycle/IndexLifecycleActionTests.java b/src/test/java/org/elasticsearch/indexlifecycle/IndexLifecycleActionTests.java index cab4e605fc8..2089e8333df 100644 --- a/src/test/java/org/elasticsearch/indexlifecycle/IndexLifecycleActionTests.java +++ b/src/test/java/org/elasticsearch/indexlifecycle/IndexLifecycleActionTests.java @@ -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 keySet = Sets.newHashSet(Iterables.transform(routingNodes, new Function() { @Override public String apply(RoutingNode input) {