Refactors wait_for_active_shards index settings tests

This commit is contained in:
Ali Beyad 2016-08-01 19:14:37 -04:00
parent 6a7d005081
commit 4923da93c8
2 changed files with 10 additions and 15 deletions

View File

@ -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()

View File

@ -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));
}