Add Random MergePolicy via index templates in integration tests

This commit adds support for random merge policies set for every
index created in an AbstractIntegrationTest. It will either set
'logbyte', 'logdoc' or 'tiered' merge policy as well as a random
value for compound files.
This commit is contained in:
Simon Willnauer 2013-10-10 15:12:35 +02:00
parent ec6539df37
commit ec809200f0
2 changed files with 26 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Settings;
public class MergePolicyModule extends AbstractModule {
private final Settings settings;
public static final String MERGE_POLICY_TYPE_KEY = "index.merge.policy.type";
public MergePolicyModule(Settings settings) {
this.settings = settings;

View File

@ -55,6 +55,7 @@ import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.merge.policy.*;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.indices.IndexTemplateMissingException;
@ -201,11 +202,33 @@ public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
client().admin().indices().preparePutTemplate("random_index_template")
.setTemplate("*")
.setOrder(0)
.setSettings(ImmutableSettings.builder()
.put(INDEX_SEED_SETTING, getRandom().nextLong()))
.setSettings(setRandomMergePolicy(getRandom(), ImmutableSettings.builder()
.put(INDEX_SEED_SETTING, getRandom().nextLong())))
.execute().actionGet();
}
}
private static ImmutableSettings.Builder setRandomMergePolicy(Random random, ImmutableSettings.Builder builder) {
if (random.nextBoolean()) {
builder.put(AbstractMergePolicyProvider.INDEX_COMPOUND_FORMAT,
random.nextBoolean() ? random.nextDouble() : random.nextBoolean());
}
Class<? extends MergePolicyProvider<?>> clazz = TieredMergePolicyProvider.class;
switch(random.nextInt(5)) {
case 4:
clazz = LogByteSizeMergePolicyProvider.class;
break;
case 3:
clazz = LogDocMergePolicyProvider.class;
break;
case 0:
return builder; // don't set the setting at all
}
assert clazz != null;
builder.put(MergePolicyModule.MERGE_POLICY_TYPE_KEY, clazz.getName());
return builder;
}
public static Iterable<Client> clients() {
return cluster();