From d94630d938e1c77f048b1eea514f59506f78a7b7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 21 Aug 2015 13:34:47 -0700 Subject: [PATCH 1/6] Fix importing into eclipse Renaming the distribution's artifactIds to "elasticsearch" caused the eclipse import process to balk. Fix those modules by moving their eclipse package to "[groupId].[artifactId]". --- distribution/pom.xml | 9 +++++++++ pom.xml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index 41a17293f45..4a22d12f458 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -90,6 +90,15 @@ + + org.apache.maven.plugins + maven-eclipse-plugin + + + [groupId].[artifactId] + + diff --git a/pom.xml b/pom.xml index 13bda58932d..614aa03793e 100644 --- a/pom.xml +++ b/pom.xml @@ -976,7 +976,7 @@ org.apache.maven.plugins maven-eclipse-plugin - 2.9 + 2.10 eclipse-build true From bb9e77f876b8fa12342c88c94a2f9d3b198107ef Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 21 Aug 2015 14:00:55 -0700 Subject: [PATCH 2/6] Eclipse: Fix launch configuration We had a file in dev-tools/ElasticSearch.launch which tried to launch elasticsearch but failed somewhat epically because of the security manager and files having moved. This recreates it with `-Des.security.manager.enabled=false` to get it working again. Its not as nice as testing with the security manager in place but its better than waiting minutes for maven to package and startup elasticsearch. --- .../{ElasticSearch.launch => Elasticsearch.launch} | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) rename dev-tools/{ElasticSearch.launch => Elasticsearch.launch} (67%) diff --git a/dev-tools/ElasticSearch.launch b/dev-tools/Elasticsearch.launch similarity index 67% rename from dev-tools/ElasticSearch.launch rename to dev-tools/Elasticsearch.launch index c501e4b8818..2016518cd23 100644 --- a/dev-tools/ElasticSearch.launch +++ b/dev-tools/Elasticsearch.launch @@ -6,12 +6,13 @@ - - - - + + + + + + - - + From 3efa6419f1baaa6bffc2892629c93006d0727433 Mon Sep 17 00:00:00 2001 From: Fabian Selles Rosa Date: Thu, 13 Aug 2015 17:44:15 +0200 Subject: [PATCH 3/6] [cloud-aws] Update AWS SDK to 1.10.10 Closes #12859. --- plugins/cloud-aws/pom.xml | 2 +- .../cloud/aws/AmazonS3Wrapper.java | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/plugins/cloud-aws/pom.xml b/plugins/cloud-aws/pom.xml index 157a35077d8..fce1fa91b3d 100644 --- a/plugins/cloud-aws/pom.xml +++ b/plugins/cloud-aws/pom.xml @@ -16,7 +16,7 @@ org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin - 1.10.0 + 1.10.10 1 cloud_aws false diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java index 0f52a318685..24c7196c681 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AmazonS3Wrapper.java @@ -34,7 +34,6 @@ import java.io.InputStream; import java.net.URL; import java.util.Date; import java.util.List; - import org.elasticsearch.common.SuppressForbidden; /** @@ -579,4 +578,54 @@ public class AmazonS3Wrapper implements AmazonS3 { public boolean isRequesterPaysEnabled(String bucketName) throws AmazonServiceException, AmazonClientException { return delegate.isRequesterPaysEnabled(bucketName); } + + @Override + public ObjectListing listNextBatchOfObjects(ListNextBatchOfObjectsRequest listNextBatchOfObjectsRequest) throws AmazonClientException, AmazonServiceException { + return delegate.listNextBatchOfObjects(listNextBatchOfObjectsRequest); + } + + @Override + public VersionListing listNextBatchOfVersions(ListNextBatchOfVersionsRequest listNextBatchOfVersionsRequest) throws AmazonClientException, AmazonServiceException { + return delegate.listNextBatchOfVersions(listNextBatchOfVersionsRequest); + } + + @Override + public Owner getS3AccountOwner(GetS3AccountOwnerRequest getS3AccountOwnerRequest) throws AmazonClientException, AmazonServiceException { + return delegate.getS3AccountOwner(getS3AccountOwnerRequest); + } + + @Override + public BucketLoggingConfiguration getBucketLoggingConfiguration(GetBucketLoggingConfigurationRequest getBucketLoggingConfigurationRequest) throws AmazonClientException, AmazonServiceException { + return delegate.getBucketLoggingConfiguration(getBucketLoggingConfigurationRequest); + } + + @Override + public BucketVersioningConfiguration getBucketVersioningConfiguration(GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationRequest) throws AmazonClientException, AmazonServiceException { + return delegate.getBucketVersioningConfiguration(getBucketVersioningConfigurationRequest); + } + + @Override + public BucketLifecycleConfiguration getBucketLifecycleConfiguration(GetBucketLifecycleConfigurationRequest getBucketLifecycleConfigurationRequest) { + return delegate.getBucketLifecycleConfiguration(getBucketLifecycleConfigurationRequest); + } + + @Override + public BucketCrossOriginConfiguration getBucketCrossOriginConfiguration(GetBucketCrossOriginConfigurationRequest getBucketCrossOriginConfigurationRequest) { + return delegate.getBucketCrossOriginConfiguration(getBucketCrossOriginConfigurationRequest); + } + + @Override + public BucketTaggingConfiguration getBucketTaggingConfiguration(GetBucketTaggingConfigurationRequest getBucketTaggingConfigurationRequest) { + return delegate.getBucketTaggingConfiguration(getBucketTaggingConfigurationRequest); + } + + @Override + public BucketNotificationConfiguration getBucketNotificationConfiguration(GetBucketNotificationConfigurationRequest getBucketNotificationConfigurationRequest) throws AmazonClientException, AmazonServiceException { + return delegate.getBucketNotificationConfiguration(getBucketNotificationConfigurationRequest); + } + + @Override + public BucketReplicationConfiguration getBucketReplicationConfiguration(GetBucketReplicationConfigurationRequest getBucketReplicationConfigurationRequest) throws AmazonServiceException, AmazonClientException { + return delegate.getBucketReplicationConfiguration(getBucketReplicationConfigurationRequest); + } } From 528b4389ac9eee5f4f8144350a91c1c4ff556559 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 24 Aug 2015 22:58:10 +0200 Subject: [PATCH 4/6] [cloud-aws] Update AWS SDK to 1.10.10 Update SHA1 files. Closes #12859. --- plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.0.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.0.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.0.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.0.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 | 1 + 8 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.0.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.0.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.0.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.0.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.0.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.0.jar.sha1 deleted file mode 100644 index c9a6d32ab96..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -9732a4e80aad23101faa442700c2172a37257c43 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 new file mode 100644 index 00000000000..5eb587b1c59 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 @@ -0,0 +1 @@ +bae5fd7d061f91486772f6c5858ccc99f2e16ca2 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.0.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.0.jar.sha1 deleted file mode 100644 index 4c132113999..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -b5dc3760021fba0ae67b4f11d37ffa52a4eac4f4 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 new file mode 100644 index 00000000000..31e5ca4c4b5 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 @@ -0,0 +1 @@ +f9431aa265f430f47fab4912a069e55fcb4dc579 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.0.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.0.jar.sha1 deleted file mode 100644 index 02adba33c64..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -48f0aab551fa9e2eb4c81e2debf40e9fff595405 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 new file mode 100644 index 00000000000..e7697647da1 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 @@ -0,0 +1 @@ +15c0f330e8c6535c9d5da799ad4fdb16619e8f59 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.0.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.0.jar.sha1 deleted file mode 100644 index a76faf74611..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -891e42d29e8f9474f83c050e4ee6a4512d4f4e71 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 new file mode 100644 index 00000000000..8c06b9dd73c --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 @@ -0,0 +1 @@ +2280741e399c7634d267aae8963b415af46fe440 From 8c4cecb41ba04794c75d0b412d37319750a38b3e Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 24 Aug 2015 23:06:28 +0200 Subject: [PATCH 5/6] [cloud-aws] Update AWS SDK to 1.10.12 Release notes: * [1.10.11](http://aws.amazon.com/releasenotes/Java/5199590350929641) * [1.10.12](http://aws.amazon.com/releasenotes/Java/6635368276326731) --- plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.12.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.12.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.12.jar.sha1 | 1 + plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 | 1 - plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.12.jar.sha1 | 1 + plugins/cloud-aws/pom.xml | 2 +- 9 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.12.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.12.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.12.jar.sha1 delete mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 create mode 100644 plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.12.jar.sha1 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 deleted file mode 100644 index 5eb587b1c59..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.10.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -bae5fd7d061f91486772f6c5858ccc99f2e16ca2 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.12.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.12.jar.sha1 new file mode 100644 index 00000000000..659b6cc62f5 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-core-1.10.12.jar.sha1 @@ -0,0 +1 @@ +7ff51040bbcc9085dcb9a24a2c2a3cc7ac995988 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 deleted file mode 100644 index 31e5ca4c4b5..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.10.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -f9431aa265f430f47fab4912a069e55fcb4dc579 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.12.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.12.jar.sha1 new file mode 100644 index 00000000000..60bae7e37ee --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-ec2-1.10.12.jar.sha1 @@ -0,0 +1 @@ +b0712cc659e72b9da0f5b03872d2476ab4a695f7 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 deleted file mode 100644 index e7697647da1..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.10.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -15c0f330e8c6535c9d5da799ad4fdb16619e8f59 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.12.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.12.jar.sha1 new file mode 100644 index 00000000000..1948b0d2b01 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-kms-1.10.12.jar.sha1 @@ -0,0 +1 @@ +31afbe46b65e9933316c7e8dfb8b88dc4b37b6ba diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 deleted file mode 100644 index 8c06b9dd73c..00000000000 --- a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.10.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -2280741e399c7634d267aae8963b415af46fe440 diff --git a/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.12.jar.sha1 b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.12.jar.sha1 new file mode 100644 index 00000000000..9814735f4d7 --- /dev/null +++ b/plugins/cloud-aws/licenses/aws-java-sdk-s3-1.10.12.jar.sha1 @@ -0,0 +1 @@ +c9e2593fdf398c5f8906a704db037d17b2de4b2a diff --git a/plugins/cloud-aws/pom.xml b/plugins/cloud-aws/pom.xml index fce1fa91b3d..7d0ea71940a 100644 --- a/plugins/cloud-aws/pom.xml +++ b/plugins/cloud-aws/pom.xml @@ -16,7 +16,7 @@ org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin - 1.10.10 + 1.10.12 1 cloud_aws false From a7af34022c32a8302f3117f5fd26ff4dc0a23e7b Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 24 Aug 2015 14:38:03 -0400 Subject: [PATCH 6/6] Detect duplicate settings keys on startup This commit changes the startup behavior of Elasticsearch to throw an exception if duplicate settings keys are detected in the Elasticsearch configuration file. Closes #13079 --- .../loader/PropertiesSettingsLoader.java | 16 ++++++- .../loader/XContentSettingsLoader.java | 16 +++++-- .../loader/JsonSettingsLoaderTests.java | 17 ++++++- .../loader/PropertiesSettingsLoaderTests.java | 47 +++++++++++++++++++ .../loader/YamlSettingsLoaderTests.java | 17 ++++++- 5 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java index 0bc97376bb0..8bff4ad0255 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoader.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.settings.loader; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.io.FastStringReader; import org.elasticsearch.common.io.stream.StreamInput; @@ -36,7 +37,7 @@ public class PropertiesSettingsLoader implements SettingsLoader { @Override public Map load(String source) throws IOException { - Properties props = new Properties(); + Properties props = new NoDuplicatesProperties(); FastStringReader reader = new FastStringReader(source); try { props.load(reader); @@ -52,7 +53,7 @@ public class PropertiesSettingsLoader implements SettingsLoader { @Override public Map load(byte[] source) throws IOException { - Properties props = new Properties(); + Properties props = new NoDuplicatesProperties(); StreamInput stream = StreamInput.wrap(source); try { props.load(stream); @@ -65,4 +66,15 @@ public class PropertiesSettingsLoader implements SettingsLoader { IOUtils.closeWhileHandlingException(stream); } } + + class NoDuplicatesProperties extends Properties { + @Override + public synchronized Object put(Object key, Object value) { + Object previousValue = super.put(key, value); + if (previousValue != null) { + throw new ElasticsearchParseException("duplicate settings key [{}] found, previous value [{}], current value [{}]", key, previousValue, value); + } + return previousValue; + } + } } diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java index e3e08fb93f2..23c5d447582 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.settings.loader; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; @@ -141,7 +140,18 @@ public abstract class XContentSettingsLoader implements SettingsLoader { sb.append(pathEle).append('.'); } sb.append(fieldName); - settings.put(sb.toString(), parser.text()); + String key = sb.toString(); + String currentValue = parser.text(); + String previousValue = settings.put(key, currentValue); + if (previousValue != null) { + throw new ElasticsearchParseException( + "duplicate settings key [{}] found at line number [{}], column number [{}], previous value [{}], current value [{}]", + key, + parser.getTokenLocation().lineNumber, + parser.getTokenLocation().columnNumber, + previousValue, + currentValue + ); + } } - } diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java index 142d60871aa..0f90b8c3728 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java @@ -19,19 +19,19 @@ package org.elasticsearch.common.settings.loader; +import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.test.ESTestCase; import org.junit.Test; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; /** * */ public class JsonSettingsLoaderTests extends ESTestCase { - @Test public void testSimpleJsonSettings() throws Exception { String json = "/org/elasticsearch/common/settings/loader/test-settings.json"; @@ -50,4 +50,17 @@ public class JsonSettingsLoaderTests extends ESTestCase { assertThat(settings.getAsArray("test1.test3")[0], equalTo("test3-1")); assertThat(settings.getAsArray("test1.test3")[1], equalTo("test3-2")); } + + public void testDuplicateKeysThrowsException() { + String json = "{\"foo\":\"bar\",\"foo\":\"baz\"}"; + try { + settingsBuilder() + .loadFromSource(json) + .build(); + fail("expected exception"); + } catch (SettingsException e) { + assertEquals(e.getCause().getClass(), ElasticsearchParseException.class); + assertTrue(e.toString().contains("duplicate settings key [foo] found at line number [1], column number [13], previous value [bar], current value [baz]")); + } + } } diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java new file mode 100644 index 00000000000..7a1897fbaf9 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/PropertiesSettingsLoaderTests.java @@ -0,0 +1,47 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.settings.loader; + +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.test.ESTestCase; + +import java.io.IOException; +import java.nio.charset.Charset; + +public class PropertiesSettingsLoaderTests extends ESTestCase { + public void testDuplicateKeyFromStringThrowsException() throws IOException { + PropertiesSettingsLoader loader = new PropertiesSettingsLoader(); + try { + loader.load("foo=bar\nfoo=baz"); + fail("expected exception"); + } catch (ElasticsearchParseException e) { + assertEquals(e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); + } + } + + public void testDuplicateKeysFromBytesThrowsException() throws IOException { + PropertiesSettingsLoader loader = new PropertiesSettingsLoader(); + try { + loader.load("foo=bar\nfoo=baz".getBytes(Charset.defaultCharset())); + } catch (ElasticsearchParseException e) { + assertEquals(e.getMessage(), "duplicate settings key [foo] found, previous value [bar], current value [baz]"); + } + } +} diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java index 49b5444a52b..60bf80a6e9d 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.common.settings.loader; +import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.test.ESTestCase; @@ -31,7 +32,6 @@ import static org.hamcrest.Matchers.equalTo; * */ public class YamlSettingsLoaderTests extends ESTestCase { - @Test public void testSimpleYamlSettings() throws Exception { String yaml = "/org/elasticsearch/common/settings/loader/test-settings.yml"; @@ -66,4 +66,17 @@ public class YamlSettingsLoaderTests extends ESTestCase { .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) .build(); } -} \ No newline at end of file + + public void testDuplicateKeysThrowsException() { + String yaml = "foo: bar\nfoo: baz"; + try { + settingsBuilder() + .loadFromSource(yaml) + .build(); + fail("expected exception"); + } catch (SettingsException e) { + assertEquals(e.getCause().getClass(), ElasticsearchParseException.class); + assertTrue(e.toString().contains("duplicate settings key [foo] found at line number [2], column number [6], previous value [bar], current value [baz]")); + } + } +}