summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/common
diff options
context:
space:
mode:
authorJason Tedor <jason@tedor.me>2017-04-13 06:34:58 -0400
committerGitHub <noreply@github.com>2017-04-13 06:34:58 -0400
commit32b2caad421cbd7f54b615f832c15b7575ad51d9 (patch)
treef40a21af7b52aaba48e13a4db5bc866614762e44 /core/src/test/java/org/elasticsearch/common
parentfb3a281755d1c8a113a796f1850139e8408f56b7 (diff)
Correct handling of default and array settings
In Elasticsearch 5.3.0 a bug was introduced in the merging of default settings when the target setting existed as an array. This arose due to the fact that when a target setting is an array, the setting key is broken into key.0, key.1, ..., key.n, one for each element of the array. When settings are replaced by default.key, we are looking for the target key but not the target key.0. This leads to key, and key.0, ..., key.n being present in the constructed settings object. This commit addresses two issues here. The first is that we fix the merging of the keys so that when we try to merge default.key, we also check for the presence of the flattened keys. The second is that when we try to get a setting value as an array from a settings object, we check whether or not the backing map contains the top-level key as well as the flattened keys. This latter check would have caught the first bug. For kicks, we add some tests. Relates #24074
Diffstat (limited to 'core/src/test/java/org/elasticsearch/common')
-rw-r--r--core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java
index c1dc07116e..6eec34a90e 100644
--- a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java
+++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java
@@ -562,4 +562,16 @@ public class SettingsTests extends ESTestCase {
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> setting.get(settings));
assertTrue(e.getMessage().contains("must be stored inside the Elasticsearch keystore"));
}
+
+ public void testGetAsArrayFailsOnDuplicates() {
+ final Settings settings =
+ Settings.builder()
+ .put("foobar.0", "bar")
+ .put("foobar.1", "baz")
+ .put("foobar", "foo")
+ .build();
+ final IllegalStateException e = expectThrows(IllegalStateException.class, () -> settings.getAsArray("foobar"));
+ assertThat(e, hasToString(containsString("settings object contains values for [foobar=foo] and [foobar.0=bar]")));
+ }
+
}