use of org.elasticsearch.common.settings.AbstractScopedSettings.SettingUpdater in project crate by crate.
the class SettingTests method testAffixMapUpdateWithNullSettingValue.
@Test
public void testAffixMapUpdateWithNullSettingValue() {
// GIVEN an affix setting changed from "prefix._foo"="bar" to "prefix._foo"=null
final Settings current = Settings.builder().put("prefix._foo", (String) null).build();
final Settings previous = Settings.builder().put("prefix._foo", "bar").build();
final Setting.AffixSetting<String> affixSetting = Setting.prefixKeySetting("prefix" + ".", key -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope));
final Consumer<Map<String, String>> consumer = (map) -> {
};
final BiConsumer<String, String> validator = (s1, s2) -> {
};
// WHEN creating an affix updater
final SettingUpdater<Map<String, String>> updater = affixSetting.newAffixMapUpdater(consumer, logger, validator);
// THEN affix updater is always expected to have changed (even when defaults are omitted)
assertTrue(updater.hasChanged(current, previous));
// THEN changes are expected when defaults aren't omitted
final Map<String, String> updatedSettings = updater.getValue(current, previous);
assertNotNull(updatedSettings);
assertEquals(1, updatedSettings.size());
// THEN changes are reported when defaults aren't omitted
final String key = updatedSettings.keySet().iterator().next();
final String value = updatedSettings.get(key);
assertEquals("_foo", key);
assertEquals("", value);
}
use of org.elasticsearch.common.settings.AbstractScopedSettings.SettingUpdater in project crate by crate.
the class SettingTests method testMemorySize.
public void testMemorySize() {
Setting<ByteSizeValue> memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", new ByteSizeValue(1024), Property.Dynamic, Property.NodeScope);
assertFalse(memorySizeValueSetting.isGroupSetting());
ByteSizeValue memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
assertEquals(memorySizeValue.getBytes(), 1024);
memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", s -> "2048b", Property.Dynamic, Property.NodeScope);
memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
assertEquals(memorySizeValue.getBytes(), 2048);
memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", "50%", Property.Dynamic, Property.NodeScope);
assertFalse(memorySizeValueSetting.isGroupSetting());
memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
assertEquals(memorySizeValue.getBytes(), JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.5, 1.0);
memorySizeValueSetting = Setting.memorySizeSetting("a.byte.size", s -> "25%", Property.Dynamic, Property.NodeScope);
memorySizeValue = memorySizeValueSetting.get(Settings.EMPTY);
assertEquals(memorySizeValue.getBytes(), JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.25, 1.0);
AtomicReference<ByteSizeValue> value = new AtomicReference<>(null);
ClusterSettings.SettingUpdater<ByteSizeValue> settingUpdater = memorySizeValueSetting.newUpdater(value::set, logger);
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12").build(), Settings.EMPTY));
assertEquals(new ByteSizeValue(12), value.get());
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "12b").build(), Settings.EMPTY));
assertEquals(new ByteSizeValue(12), value.get());
assertTrue(settingUpdater.apply(Settings.builder().put("a.byte.size", "20%").build(), Settings.EMPTY));
assertEquals(new ByteSizeValue((int) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.2)), value.get());
}
Aggregations