Fix UpdateSettingsIT and IndicesOptionsIntegrationIT to register strict settings

This commit is contained in:
Simon Willnauer 2016-01-16 14:30:56 +01:00
parent 359475fb0d
commit dbe76fb59b
3 changed files with 43 additions and 7 deletions

View File

@ -227,7 +227,7 @@ public class Setting<T> extends ToXContentToBytes {
} }
private class Updater implements AbstractScopedSettings.SettingUpdater<T> { private final class Updater implements AbstractScopedSettings.SettingUpdater<T> {
private final Consumer<T> consumer; private final Consumer<T> consumer;
private final ESLogger logger; private final ESLogger logger;
private final Consumer<T> accept; private final Consumer<T> accept;
@ -267,8 +267,8 @@ public class Setting<T> extends ToXContentToBytes {
} }
@Override @Override
public void apply(T value, Settings current, Settings previous) { public final void apply(T value, Settings current, Settings previous) {
logger.info("update [{}] from [{}] to [{}]", key, getRaw(previous), getRaw(current)); logger.info("updating [{}] from [{}] to [{}]", key, getRaw(previous), getRaw(current));
consumer.accept(value); consumer.accept(value);
} }
} }
@ -443,6 +443,7 @@ public class Setting<T> extends ToXContentToBytes {
@Override @Override
public void apply(Settings value, Settings current, Settings previous) { public void apply(Settings value, Settings current, Settings previous) {
logger.info("updating [{}] from [{}] to [{}]", key, getRaw(previous), getRaw(current));
consumer.accept(value); consumer.accept(value);
} }

View File

@ -46,11 +46,17 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.suggest.SuggestBuilders; import org.elasticsearch.search.suggest.SuggestBuilders;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import java.util.Collection;
import java.util.function.Function;
import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder; import static org.elasticsearch.action.percolate.PercolateSourceBuilder.docBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@ -60,6 +66,12 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;
public class IndicesOptionsIntegrationIT extends ESIntegTestCase { public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(TestPlugin.class); //
}
public void testSpecifiedIndexUnavailableMultipleIndices() throws Exception { public void testSpecifiedIndexUnavailableMultipleIndices() throws Exception {
createIndex("test1"); createIndex("test1");
ensureYellow(); ensureYellow();
@ -619,6 +631,29 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type4"), notNullValue()); assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type4"), notNullValue());
} }
public static final class TestPlugin extends Plugin {
@Override
public String name() {
return "index-a-setting";
}
@Override
public String description() {
return "a plugin that adds a dynamic tst setting";
}
private static final Setting<String> INDEX_A = new Setting<>("index.a", "", Function.identity(), true, Setting.Scope.INDEX);
private static final Setting<String> INDEX_C = new Setting<>("index.c", "", Function.identity(), true, Setting.Scope.INDEX);
private static final Setting<String> INDEX_E = new Setting<>("index.e", "", Function.identity(), false, Setting.Scope.INDEX);
public void onModule(SettingsModule module) {
module.registerSetting(INDEX_A);
module.registerSetting(INDEX_C);
module.registerSetting(INDEX_E);
}
}
public void testUpdateSettings() throws Exception { public void testUpdateSettings() throws Exception {
verify(client().admin().indices().prepareUpdateSettings("foo").setSettings(Settings.builder().put("a", "b")), true); verify(client().admin().indices().prepareUpdateSettings("foo").setSettings(Settings.builder().put("a", "b")), true);
verify(client().admin().indices().prepareUpdateSettings("_all").setSettings(Settings.builder().put("a", "b")), true); verify(client().admin().indices().prepareUpdateSettings("_all").setSettings(Settings.builder().put("a", "b")), true);

View File

@ -279,10 +279,10 @@ public class UpdateSettingsIT extends ESIntegTestCase {
if (event.getLevel() == Level.TRACE && if (event.getLevel() == Level.TRACE &&
event.getLoggerName().endsWith("lucene.iw")) { event.getLoggerName().endsWith("lucene.iw")) {
} }
if (event.getLevel() == Level.INFO && message.contains("update [index.merge.scheduler.max_thread_count] from [10000] to [1]")) { if (event.getLevel() == Level.INFO && message.contains("updating [index.merge.scheduler.max_thread_count] from [10000] to [1]")) {
sawUpdateMaxThreadCount = true; sawUpdateMaxThreadCount = true;
} }
if (event.getLevel() == Level.INFO && message.contains("update [index.merge.scheduler.auto_throttle] from [true] to [false]")) { if (event.getLevel() == Level.INFO && message.contains("updating [index.merge.scheduler.auto_throttle] from [true] to [false]")) {
sawUpdateAutoThrottle = true; sawUpdateAutoThrottle = true;
} }
} }
@ -323,7 +323,7 @@ public class UpdateSettingsIT extends ESIntegTestCase {
.indices() .indices()
.prepareUpdateSettings("test") .prepareUpdateSettings("test")
.setSettings(Settings.builder() .setSettings(Settings.builder()
.put(MergeSchedulerConfig.AUTO_THROTTLE_SETTING.getKey(), "no")) .put(MergeSchedulerConfig.AUTO_THROTTLE_SETTING.getKey(), "false"))
.get(); .get();
// Make sure we log the change: // Make sure we log the change:
@ -331,7 +331,7 @@ public class UpdateSettingsIT extends ESIntegTestCase {
// Make sure setting says it is in fact changed: // Make sure setting says it is in fact changed:
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get(); GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", MergeSchedulerConfig.AUTO_THROTTLE_SETTING.getKey()), equalTo("no")); assertThat(getSettingsResponse.getSetting("test", MergeSchedulerConfig.AUTO_THROTTLE_SETTING.getKey()), equalTo("false"));
} finally { } finally {
rootLogger.removeAppender(mockAppender); rootLogger.removeAppender(mockAppender);
rootLogger.setLevel(savedLevel); rootLogger.setLevel(savedLevel);