Refactors wait_for_active_shards index settings tests
This commit is contained in:
parent
6a7d005081
commit
4923da93c8
|
@ -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}.
|
* 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 String indexName = "test";
|
||||||
final int numReplicas = internalCluster().numDataNodes();
|
final int numReplicas = internalCluster().numDataNodes();
|
||||||
Settings settings = Settings.builder()
|
Settings settings = Settings.builder()
|
||||||
|
|
|
@ -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
|
* 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.
|
* 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 String indexName = "test";
|
||||||
final ShardId shardId = new ShardId(indexName, "_na_", 0);
|
final ShardId shardId = new ShardId(indexName, "_na_", 0);
|
||||||
|
|
||||||
// test wait_for_active_shards index setting used when the default is set on the request
|
// test wait_for_active_shards index setting used when the default is set on the request
|
||||||
int numReplicas = randomIntBetween(0, 5);
|
int numReplicas = randomIntBetween(0, 5);
|
||||||
int idxSettingWaitForActiveShards = randomIntBetween(0, numReplicas + 1);
|
int idxSettingWaitForActiveShards = randomIntBetween(0, numReplicas + 1);
|
||||||
ClusterState state = changeWaitForActiveShardsSetting(indexName,
|
ClusterState state = stateWithActivePrimary(indexName, randomBoolean(), numReplicas);
|
||||||
stateWithActivePrimary(indexName, randomBoolean(), numReplicas),
|
IndexMetaData indexMetaData = state.metaData().index(indexName);
|
||||||
idxSettingWaitForActiveShards);
|
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);
|
setState(clusterService, state);
|
||||||
Request request = new Request(shardId).waitForActiveShards(ActiveShardCount.DEFAULT); // set to default so index settings are used
|
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);
|
action.resolveRequest(state.metaData(), state.metaData().index(indexName), request);
|
||||||
|
@ -705,16 +710,6 @@ public class TransportReplicationActionTests extends ESTestCase {
|
||||||
assertEquals(ActiveShardCount.from(requestWaitForActiveShards), request.waitForActiveShards());
|
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) {
|
private void assertIndexShardCounter(int expected) {
|
||||||
assertThat(count.get(), equalTo(expected));
|
assertThat(count.get(), equalTo(expected));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue