From 4fd1bb290aa0ffeaf9f8845695701a26729308d2 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 22 Feb 2019 13:28:59 +0100 Subject: [PATCH] Adapt more tests suites to closed indices (#39186) * Adapt more tests suites to closed indices Similarly to #38631, this pull request modifies multiple test suites so that they runs the tests with opened or closed indices. The suites are testing: - shard allocation filtering - shard allocation awereness - Reroute API Relates to #33888 --- .../allocation/AwarenessAllocationIT.java | 109 ++++++++++++++---- .../cluster/allocation/ClusterRerouteIT.java | 70 +++++++---- .../allocation/FilteringAllocationIT.java | 57 ++++++--- .../allocation/SimpleAllocationIT.java | 18 +-- 4 files changed, 182 insertions(+), 72 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java b/server/src/test/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java index 083c914b37052..edcf4446dc2bf 100644 --- a/server/src/test/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/allocation/AwarenessAllocationIT.java @@ -24,6 +24,8 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.IndexMetaData.State; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; @@ -33,9 +35,11 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; @@ -54,7 +58,6 @@ public void testSimpleAwareness() throws Exception { .put("cluster.routing.allocation.awareness.attributes", "rack_id") .build(); - logger.info("--> starting 2 nodes on the same rack"); internalCluster().startNodes(2, Settings.builder().put(commonSettings).put("node.attr.rack_id", "rack_1").build()); @@ -68,6 +71,9 @@ public void testSimpleAwareness() throws Exception { ensureGreen(); + final List indicesToClose = randomSubsetOf(Arrays.asList("test1", "test2")); + indicesToClose.forEach(indexToClose -> assertAcked(client().admin().indices().prepareClose(indexToClose).get())); + logger.info("--> starting 1 node on a different rack"); final String node3 = internalCluster().startNode(Settings.builder().put(commonSettings).put("node.attr.rack_id", "rack_2").build()); @@ -75,14 +81,23 @@ public void testSimpleAwareness() throws Exception { assertThat(awaitBusy( () -> { logger.info("--> waiting for no relocation"); - ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID) - .setWaitForGreenStatus().setWaitForNodes("3").setWaitForNoRelocatingShards(true).get(); + ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth() + .setIndices("test1", "test2") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("3") + .setWaitForNoRelocatingShards(true) + .get(); if (clusterHealth.isTimedOut()) { return false; } logger.info("--> checking current state"); ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); + // check that closed indices are effectively closed + if (indicesToClose.stream().anyMatch(index -> clusterState.metaData().index(index).getState() != State.CLOSE)) { + return false; + } // verify that we have all the primaries on node3 ObjectIntHashMap counts = new ObjectIntHashMap<>(); for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) { @@ -99,7 +114,7 @@ public void testSimpleAwareness() throws Exception { ), equalTo(true)); } - public void testAwarenessZones() throws Exception { + public void testAwarenessZones() { Settings commonSettings = Settings.builder() .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a,b") .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "zone") @@ -121,12 +136,20 @@ public void testAwarenessZones() throws Exception { ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("4").execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); - client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.number_of_shards", 5) - .put("index.number_of_replicas", 1)).execute().actionGet(); + createIndex("test", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .build()); + + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test")); + } logger.info("--> waiting for shards to be allocated"); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() .setWaitForNoRelocatingShards(true).execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); @@ -146,7 +169,7 @@ public void testAwarenessZones() throws Exception { assertThat(counts.get(B_0), anyOf(equalTo(2),equalTo(3))); } - public void testAwarenessZonesIncrementalNodes() throws Exception { + public void testAwarenessZonesIncrementalNodes() { Settings commonSettings = Settings.builder() .put("cluster.routing.allocation.awareness.force.zone.values", "a,b") .put("cluster.routing.allocation.awareness.attributes", "zone") @@ -159,11 +182,23 @@ public void testAwarenessZonesIncrementalNodes() throws Exception { ); String A_0 = nodes.get(0); String B_0 = nodes.get(1); - client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.number_of_shards", 5) - .put("index.number_of_replicas", 1)).execute().actionGet(); - ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID) - .setWaitForGreenStatus().setWaitForNodes("2").setWaitForNoRelocatingShards(true).execute().actionGet(); + + createIndex("test", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .build()); + + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test")); + } + + ClusterHealthResponse health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("2") + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); ObjectIntHashMap counts = new ObjectIntHashMap<>(); @@ -180,12 +215,22 @@ public void testAwarenessZonesIncrementalNodes() throws Exception { logger.info("--> starting another node in zone 'b'"); String B_1 = internalCluster().startNode(Settings.builder().put(commonSettings).put("node.attr.zone", "b").build()); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() - .setWaitForNodes("3").execute().actionGet(); + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("3") + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); client().admin().cluster().prepareReroute().get(); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() - .setWaitForNodes("3").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet(); + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("3") + .setWaitForActiveShards(10) + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); @@ -204,12 +249,22 @@ public void testAwarenessZonesIncrementalNodes() throws Exception { assertThat(counts.get(B_1), equalTo(2)); String noZoneNode = internalCluster().startNode(); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() - .setWaitForNodes("4").execute().actionGet(); + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("4") + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); client().admin().cluster().prepareReroute().get(); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() - .setWaitForNodes("4").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet(); + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("4") + .setWaitForActiveShards(10) + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); @@ -231,8 +286,14 @@ public void testAwarenessZonesIncrementalNodes() throws Exception { client().admin().cluster().prepareUpdateSettings() .setTransientSettings(Settings.builder().put("cluster.routing.allocation.awareness.attributes", "").build()).get(); - health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus() - .setWaitForNodes("4").setWaitForActiveShards(10).setWaitForNoRelocatingShards(true).execute().actionGet(); + health = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForGreenStatus() + .setWaitForNodes("4") + .setWaitForActiveShards(10) + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(health.isTimedOut(), equalTo(false)); clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); diff --git a/server/src/test/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java b/server/src/test/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java index 71c9f5a15ba4d..95cb09df0f68c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/allocation/ClusterRerouteIT.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction; @@ -34,6 +33,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; +import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingExplanations; import org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand; @@ -48,6 +48,7 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; @@ -102,6 +103,10 @@ private void rerouteWithCommands(Settings commonSettings) throws Exception { .setSettings(Settings.builder().put("index.number_of_shards", 1)) .execute().actionGet(); + if (randomBoolean()) { + client().admin().indices().prepareClose("test").get(); + } + ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.getRoutingNodes().unassigned().size(), equalTo(2)); @@ -128,8 +133,11 @@ private void rerouteWithCommands(Settings commonSettings) throws Exception { assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING)); - ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID) - .setWaitForYellowStatus().execute().actionGet(); + ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForYellowStatus() + .execute().actionGet(); assertThat(healthResponse.isTimedOut(), equalTo(false)); logger.info("--> get the state, verify shard 1 primary allocated"); @@ -149,9 +157,12 @@ private void rerouteWithCommands(Settings commonSettings) throws Exception { assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_2).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING)); - - healthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus() - .setWaitForNoRelocatingShards(true).execute().actionGet(); + healthResponse = client().admin().cluster().prepareHealth() + .setIndices("test") + .setWaitForEvents(Priority.LANGUID) + .setWaitForYellowStatus() + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(healthResponse.isTimedOut(), equalTo(false)); logger.info("--> get the state, verify shard 1 primary moved from node1 to node2"); @@ -193,11 +204,15 @@ public void testDelayWithALargeAmountOfShards() throws Exception { logger.info("--> create indices"); for (int i = 0; i < 25; i++) { - client().admin().indices().prepareCreate("test" + i) - .setSettings(Settings.builder() - .put("index.number_of_shards", 5).put("index.number_of_replicas", 1) - .put("index.unassigned.node_left.delayed_timeout", randomIntBetween(250, 1000) + "ms")) - .execute().actionGet(); + final String indexName = "test" + i; + createIndex(indexName, Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 5) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), randomIntBetween(250, 1000) + "ms") + .build()); + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose(indexName)); + } } ensureGreen(TimeValue.timeValueMinutes(1)); @@ -294,10 +309,14 @@ public void testRerouteExplain() { assertThat(healthResponse.isTimedOut(), equalTo(false)); logger.info("--> create an index with 1 shard"); - client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)) - .execute().actionGet(); + createIndex("test", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build()); + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test")); + } ensureGreen("test"); logger.info("--> disable allocation"); @@ -403,12 +422,18 @@ public void testMessageLogging() throws Exception{ Loggers.removeAppender(actionLogger, allocateMockLog); } - public void testClusterRerouteWithBlocks() throws Exception { + public void testClusterRerouteWithBlocks() { List nodesIds = internalCluster().startNodes(2); logger.info("--> create an index with 1 shard and 0 replicas"); - assertAcked(prepareCreate("test-blocks").setSettings(Settings.builder().put("index.number_of_shards", 1) - .put("index.number_of_replicas", 0))); + createIndex("test-blocks", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build()); + + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test-blocks")); + } ensureGreen("test-blocks"); logger.info("--> check that the index has 1 shard"); @@ -432,11 +457,14 @@ public void testClusterRerouteWithBlocks() throws Exception { SETTING_READ_ONLY_ALLOW_DELETE)) { try { enableIndexBlock("test-blocks", blockSetting); - assertAcked(client().admin().cluster().prepareReroute().add(new MoveAllocationCommand("test-blocks", 0, - nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2)))); + assertAcked(client().admin().cluster().prepareReroute() + .add(new MoveAllocationCommand("test-blocks", 0, nodesIds.get(toggle % 2), nodesIds.get(++toggle % 2)))); - ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForYellowStatus() - .setWaitForNoRelocatingShards(true).execute().actionGet(); + ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth() + .setIndices("test-blocks") + .setWaitForYellowStatus() + .setWaitForNoRelocatingShards(true) + .execute().actionGet(); assertThat(healthResponse.isTimedOut(), equalTo(false)); } finally { disableIndexBlock("test-blocks", blockSetting); diff --git a/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java b/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java index 6e5af59c2aeab..93bdd674180bf 100644 --- a/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/allocation/FilteringAllocationIT.java @@ -19,10 +19,9 @@ package org.elasticsearch.cluster.allocation; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; @@ -41,14 +40,13 @@ import java.util.List; import java.util.Set; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @ClusterScope(scope= Scope.TEST, numDataNodes =0) public class FilteringAllocationIT extends ESIntegTestCase { - private final Logger logger = LogManager.getLogger(FilteringAllocationIT.class); - - public void testDecommissionNodeNoReplicas() throws Exception { + public void testDecommissionNodeNoReplicas() { logger.info("--> starting 2 nodes"); List nodesIds = internalCluster().startNodes(2); final String node_0 = nodesIds.get(0); @@ -56,10 +54,10 @@ public void testDecommissionNodeNoReplicas() throws Exception { assertThat(cluster().size(), equalTo(2)); logger.info("--> creating an index with no replicas"); - client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.number_of_replicas", 0)) - .execute().actionGet(); - ensureGreen(); + createIndex("test", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build()); + ensureGreen("test"); logger.info("--> index some data"); for (int i = 0; i < 100; i++) { client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value" + i).execute().actionGet(); @@ -68,11 +66,17 @@ public void testDecommissionNodeNoReplicas() throws Exception { assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet() .getHits().getTotalHits().value, equalTo(100L)); + final boolean closed = randomBoolean(); + if (closed) { + assertAcked(client().admin().indices().prepareClose("test")); + ensureGreen("test"); + } + logger.info("--> decommission the second node"); client().admin().cluster().prepareUpdateSettings() .setTransientSettings(Settings.builder().put("cluster.routing.allocation.exclude._name", node_1)) .execute().actionGet(); - waitForRelocation(); + ensureGreen("test"); logger.info("--> verify all are allocated on node1 now"); ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); @@ -84,12 +88,16 @@ public void testDecommissionNodeNoReplicas() throws Exception { } } + if (closed) { + assertAcked(client().admin().indices().prepareOpen("test")); + } + client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()) .execute().actionGet().getHits().getTotalHits().value, equalTo(100L)); } - public void testDisablingAllocationFiltering() throws Exception { + public void testDisablingAllocationFiltering() { logger.info("--> starting 2 nodes"); List nodesIds = internalCluster().startNodes(2); final String node_0 = nodesIds.get(0); @@ -97,11 +105,11 @@ public void testDisablingAllocationFiltering() throws Exception { assertThat(cluster().size(), equalTo(2)); logger.info("--> creating an index with no replicas"); - client().admin().indices().prepareCreate("test") - .setSettings(Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0)) - .execute().actionGet(); - - ensureGreen(); + createIndex("test", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .build()); + ensureGreen("test"); logger.info("--> index some data"); for (int i = 0; i < 100; i++) { @@ -110,6 +118,13 @@ public void testDisablingAllocationFiltering() throws Exception { client().admin().indices().prepareRefresh().execute().actionGet(); assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()) .execute().actionGet().getHits().getTotalHits().value, equalTo(100L)); + + final boolean closed = randomBoolean(); + if (closed) { + assertAcked(client().admin().indices().prepareClose("test")); + ensureGreen("test"); + } + ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); IndexRoutingTable indexRoutingTable = clusterState.routingTable().index("test"); int numShardsOnNode1 = 0; @@ -133,7 +148,7 @@ public void testDisablingAllocationFiltering() throws Exception { .setSettings(Settings.builder().put("index.routing.allocation.exclude._name", node_0)) .execute().actionGet(); client().admin().cluster().prepareReroute().get(); - ensureGreen(); + ensureGreen("test"); logger.info("--> verify all shards are allocated on node_1 now"); clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); @@ -149,7 +164,7 @@ public void testDisablingAllocationFiltering() throws Exception { .setSettings(Settings.builder().put("index.routing.allocation.exclude._name", "")) .execute().actionGet(); client().admin().cluster().prepareReroute().get(); - ensureGreen(); + ensureGreen("test"); logger.info("--> verify that there are shards allocated on both nodes now"); clusterState = client().admin().cluster().prepareState().execute().actionGet().getState(); @@ -166,7 +181,7 @@ public void testInvalidIPFilterClusterSettings() { assertEquals("invalid IP address [192.168.1.1.] for [" + filterSetting.getKey() + ipKey + "]", e.getMessage()); } - public void testTransientSettingsStillApplied() throws Exception { + public void testTransientSettingsStillApplied() { List nodes = internalCluster().startNodes(6); Set excludeNodes = new HashSet<>(nodes.subList(0, 3)); Set includeNodes = new HashSet<>(nodes.subList(3, 6)); @@ -177,6 +192,10 @@ public void testTransientSettingsStillApplied() throws Exception { client().admin().indices().prepareCreate("test").get(); ensureGreen("test"); + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test")); + } + Settings exclude = Settings.builder().put("cluster.routing.allocation.exclude._name", Strings.collectionToCommaDelimitedString(excludeNodes)).build(); diff --git a/server/src/test/java/org/elasticsearch/cluster/allocation/SimpleAllocationIT.java b/server/src/test/java/org/elasticsearch/cluster/allocation/SimpleAllocationIT.java index f9c0691576f2b..8f6473b0e359d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/allocation/SimpleAllocationIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/allocation/SimpleAllocationIT.java @@ -39,13 +39,12 @@ protected int numberOfReplicas() { return 1; } - /** - * Test for - * https://groups.google.com/d/msg/elasticsearch/y-SY_HyoB-8/EZdfNt9VO44J - */ public void testSaneAllocation() { assertAcked(prepareCreate("test", 3)); - ensureGreen(); + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test")); + } + ensureGreen("test"); ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0)); @@ -56,7 +55,7 @@ public void testSaneAllocation() { } client().admin().indices().prepareUpdateSettings("test") .setSettings(Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 0)).execute().actionGet(); - ensureGreen(); + ensureGreen("test"); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0)); @@ -68,11 +67,14 @@ public void testSaneAllocation() { // create another index assertAcked(prepareCreate("test2", 3)); - ensureGreen(); + if (randomBoolean()) { + assertAcked(client().admin().indices().prepareClose("test2")); + } + ensureGreen("test2"); client().admin().indices().prepareUpdateSettings("test") .setSettings(Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 1)).execute().actionGet(); - ensureGreen(); + ensureGreen("test"); state = client().admin().cluster().prepareState().execute().actionGet().getState(); assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0));