Skip to content

Commit

Permalink
Refactors wait_for_active_shards index settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Beyad committed Aug 1, 2016
1 parent 6a7d005 commit 4923da9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public void testCreateShrinkIndexFails() throws Exception {
/**
* 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,21 @@ protected ReplicaResult shardOperationOnReplica(Request request) {
* 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);
Expand All @@ -705,16 +710,6 @@ public void testChangeWaitForActiveShardsSetting() throws Exception {
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));
}
Expand Down

0 comments on commit 4923da9

Please sign in to comment.