From 4923da93c83b0b0708747105f427aab03047168b Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Mon, 1 Aug 2016 19:14:37 -0400 Subject: [PATCH] Refactors wait_for_active_shards index settings tests --- .../admin/indices/create/CreateIndexIT.java | 2 +- .../TransportReplicationActionTests.java | 23 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index eaac8d53509..57adec340ac 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -480,7 +480,7 @@ public class CreateIndexIT extends ESIntegTestCase { /** * This test ensures that index creation adheres to the {@link IndexMetaData#SETTING_WAIT_FOR_ACTIVE_SHARDS}. */ - public void testChangeWaitForActiveShardsSetting() throws Exception { + public void testDefaultWaitForActiveShardsUsesIndexSetting() throws Exception { final String indexName = "test"; final int numReplicas = internalCluster().numDataNodes(); Settings settings = Settings.builder() diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java index a16a60391ea..bca17fb143b 100644 --- a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java @@ -683,16 +683,21 @@ public class TransportReplicationActionTests extends ESTestCase { * This test ensures that replication operations adhere to the {@link IndexMetaData#SETTING_WAIT_FOR_ACTIVE_SHARDS} setting * when the request is using the default value for waitForActiveShards. */ - public void testChangeWaitForActiveShardsSetting() throws Exception { + public void testDefaultWaitForActiveShardsUsesIndexSetting() throws Exception { final String indexName = "test"; final ShardId shardId = new ShardId(indexName, "_na_", 0); // test wait_for_active_shards index setting used when the default is set on the request int numReplicas = randomIntBetween(0, 5); int idxSettingWaitForActiveShards = randomIntBetween(0, numReplicas + 1); - ClusterState state = changeWaitForActiveShardsSetting(indexName, - stateWithActivePrimary(indexName, randomBoolean(), numReplicas), - idxSettingWaitForActiveShards); + ClusterState state = stateWithActivePrimary(indexName, randomBoolean(), numReplicas); + IndexMetaData indexMetaData = state.metaData().index(indexName); + Settings indexSettings = Settings.builder().put(indexMetaData.getSettings()) + .put(SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey(), Integer.toString(idxSettingWaitForActiveShards)) + .build(); + MetaData.Builder metaDataBuilder = MetaData.builder(state.metaData()) + .put(IndexMetaData.builder(indexMetaData).settings(indexSettings).build(), true); + state = ClusterState.builder(state).metaData(metaDataBuilder).build(); setState(clusterService, state); Request request = new Request(shardId).waitForActiveShards(ActiveShardCount.DEFAULT); // set to default so index settings are used action.resolveRequest(state.metaData(), state.metaData().index(indexName), request); @@ -705,16 +710,6 @@ public class TransportReplicationActionTests extends ESTestCase { assertEquals(ActiveShardCount.from(requestWaitForActiveShards), request.waitForActiveShards()); } - private ClusterState changeWaitForActiveShardsSetting(String indexName, ClusterState state, int waitForActiveShards) { - IndexMetaData indexMetaData = state.metaData().index(indexName); - Settings indexSettings = Settings.builder().put(indexMetaData.getSettings()) - .put(SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey(), Integer.toString(waitForActiveShards)) - .build(); - MetaData.Builder metaDataBuilder = MetaData.builder(state.metaData()) - .put(IndexMetaData.builder(indexMetaData).settings(indexSettings).build(), true); - return ClusterState.builder(state).metaData(metaDataBuilder).build(); - } - private void assertIndexShardCounter(int expected) { assertThat(count.get(), equalTo(expected)); }