From ee2f6ccf32bc972581934c295d61ec6d92cafecc Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 28 Feb 2017 17:55:44 -0500 Subject: [PATCH] Add convenience method for asserting deprecations This commit adds a convenience method for simultaneously asserting settings deprecations and other warnings and fixes some tests where setting deprecations and general warnings were present. --- .../azure/AzureRepositorySettingsTests.java | 2 + .../cloud/aws/AwsS3ServiceImplTests.java | 41 +++++++++++-------- .../repositories/s3/S3RepositoryTests.java | 3 +- .../org/elasticsearch/test/ESTestCase.java | 21 +++++++--- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java index 014fa88cc4d..0765ea919ad 100644 --- a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java +++ b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java @@ -23,6 +23,7 @@ import com.microsoft.azure.storage.LocationMode; import com.microsoft.azure.storage.StorageException; import org.elasticsearch.cloud.azure.storage.AzureStorageService; import org.elasticsearch.cluster.metadata.RepositoryMetaData; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; @@ -124,4 +125,5 @@ public class AzureRepositorySettingsTests extends ESTestCase { azureRepository(Settings.builder().put("chunk_size", "65mb").build())); assertEquals("Failed to parse value [65mb] for setting [chunk_size] must be <= 64mb", e.getMessage()); } + } diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AwsS3ServiceImplTests.java b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AwsS3ServiceImplTests.java index e13aa61f3a2..da62cd42e8b 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AwsS3ServiceImplTests.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/AwsS3ServiceImplTests.java @@ -24,6 +24,7 @@ import com.amazonaws.Protocol; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; import org.elasticsearch.common.settings.MockSecureSettings; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.repositories.s3.S3Repository; import org.elasticsearch.test.ESTestCase; @@ -64,7 +65,7 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(AwsS3Service.SECRET_SETTING.getKey(), "aws_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "aws_key", "aws_secret"); - assertSettingDeprecations(AwsS3Service.KEY_SETTING, AwsS3Service.SECRET_SETTING); + assertSettingDeprecationsAndWarnings(new Setting[]{AwsS3Service.KEY_SETTING, AwsS3Service.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchS3SettingsBackcompat() { @@ -73,7 +74,7 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(AwsS3Service.CLOUD_S3.SECRET_SETTING.getKey(), "s3_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "s3_key", "s3_secret"); - assertSettingDeprecations(AwsS3Service.CLOUD_S3.KEY_SETTING, AwsS3Service.CLOUD_S3.SECRET_SETTING); + assertSettingDeprecationsAndWarnings(new Setting[]{AwsS3Service.CLOUD_S3.KEY_SETTING, AwsS3Service.CLOUD_S3.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchAwsAndS3SettingsBackcompat() { @@ -84,11 +85,11 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(AwsS3Service.CLOUD_S3.SECRET_SETTING.getKey(), "s3_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "s3_key", "s3_secret"); - assertSettingDeprecations( + assertSettingDeprecationsAndWarnings(new Setting[]{ AwsS3Service.KEY_SETTING, AwsS3Service.SECRET_SETTING, AwsS3Service.CLOUD_S3.KEY_SETTING, - AwsS3Service.CLOUD_S3.SECRET_SETTING); + AwsS3Service.CLOUD_S3.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchRepositoriesSettingsBackcompat() { @@ -97,7 +98,8 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "repositories_key", "repositories_secret"); - assertSettingDeprecations(S3Repository.Repositories.KEY_SETTING, S3Repository.Repositories.SECRET_SETTING); + assertSettingDeprecationsAndWarnings( + new Setting[]{S3Repository.Repositories.KEY_SETTING, S3Repository.Repositories.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchAwsAndRepositoriesSettingsBackcompat() { @@ -108,11 +110,11 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "repositories_key", "repositories_secret"); - assertSettingDeprecations( + assertSettingDeprecationsAndWarnings(new Setting[]{ AwsS3Service.KEY_SETTING, AwsS3Service.SECRET_SETTING, S3Repository.Repositories.KEY_SETTING, - S3Repository.Repositories.SECRET_SETTING); + S3Repository.Repositories.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchAwsAndS3AndRepositoriesSettingsBackcompat() { @@ -125,13 +127,13 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(Settings.EMPTY, settings, "repositories_key", "repositories_secret"); - assertSettingDeprecations( + assertSettingDeprecationsAndWarnings(new Setting[]{ AwsS3Service.KEY_SETTING, AwsS3Service.SECRET_SETTING, AwsS3Service.CLOUD_S3.KEY_SETTING, AwsS3Service.CLOUD_S3.SECRET_SETTING, S3Repository.Repositories.KEY_SETTING, - S3Repository.Repositories.SECRET_SETTING); + S3Repository.Repositories.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchRepositoriesSettingsAndRepositorySettingsBackcompat() { @@ -141,7 +143,8 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(repositorySettings, settings, "repository_key", "repository_secret"); - assertSettingDeprecations(S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING); + assertSettingDeprecationsAndWarnings( + new Setting[]{S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchAwsAndRepositoriesSettingsAndRepositorySettingsBackcompat() { @@ -153,7 +156,8 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(repositorySettings, settings, "repository_key", "repository_secret"); - assertSettingDeprecations(S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING); + assertSettingDeprecationsAndWarnings( + new Setting[]{S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING}); } public void testAWSCredentialsWithElasticsearchAwsAndS3AndRepositoriesSettingsAndRepositorySettingsBackcompat() { @@ -167,7 +171,8 @@ public class AwsS3ServiceImplTests extends ESTestCase { .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret") .build(); launchAWSCredentialsWithElasticsearchSettingsTest(repositorySettings, settings, "repository_key", "repository_secret"); - assertSettingDeprecations(S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING); + assertSettingDeprecationsAndWarnings( + new Setting[]{S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING}); } protected void launchAWSCredentialsWithElasticsearchSettingsTest(Settings singleRepositorySettings, Settings settings, @@ -211,14 +216,14 @@ public class AwsS3ServiceImplTests extends ESTestCase { .build(); launchAWSConfigurationTest(settings, Settings.EMPTY, Protocol.HTTP, "aws_proxy_host", 8080, "aws_proxy_username", "aws_proxy_password", "AWS3SignerType", 3, false, 10000); - assertSettingDeprecations( + assertSettingDeprecationsAndWarnings(new Setting[]{ AwsS3Service.PROXY_USERNAME_SETTING, AwsS3Service.PROXY_PASSWORD_SETTING, AwsS3Service.PROTOCOL_SETTING, AwsS3Service.PROXY_HOST_SETTING, AwsS3Service.PROXY_PORT_SETTING, AwsS3Service.SIGNER_SETTING, - AwsS3Service.READ_TIMEOUT); + AwsS3Service.READ_TIMEOUT}); } public void testAWSConfigurationWithAwsAndS3SettingsBackcompat() { @@ -240,7 +245,7 @@ public class AwsS3ServiceImplTests extends ESTestCase { .build(); launchAWSConfigurationTest(settings, Settings.EMPTY, Protocol.HTTPS, "s3_proxy_host", 8081, "s3_proxy_username", "s3_proxy_password", "NoOpSignerType", 3, false, 10000); - assertSettingDeprecations( + assertSettingDeprecationsAndWarnings(new Setting[] { AwsS3Service.PROXY_USERNAME_SETTING, AwsS3Service.PROXY_PASSWORD_SETTING, AwsS3Service.PROTOCOL_SETTING, @@ -254,7 +259,7 @@ public class AwsS3ServiceImplTests extends ESTestCase { AwsS3Service.CLOUD_S3.PROXY_HOST_SETTING, AwsS3Service.CLOUD_S3.PROXY_PORT_SETTING, AwsS3Service.CLOUD_S3.SIGNER_SETTING, - AwsS3Service.CLOUD_S3.READ_TIMEOUT); + AwsS3Service.CLOUD_S3.READ_TIMEOUT}); } public void testGlobalMaxRetries() { @@ -336,13 +341,13 @@ public class AwsS3ServiceImplTests extends ESTestCase { public void testEndpointSettingBackcompat() { assertEndpoint(generateRepositorySettings("repository_key", "repository_secret", "repository.endpoint", null), Settings.EMPTY, "repository.endpoint"); - assertSettingDeprecations(S3Repository.Repository.ENDPOINT_SETTING); + assertSettingDeprecationsAndWarnings(new Setting[]{S3Repository.Repository.ENDPOINT_SETTING}); Settings settings = Settings.builder() .put(S3Repository.Repositories.ENDPOINT_SETTING.getKey(), "repositories.endpoint") .build(); assertEndpoint(generateRepositorySettings("repository_key", "repository_secret", null, null), settings, "repositories.endpoint"); - assertSettingDeprecations(S3Repository.Repositories.ENDPOINT_SETTING); + assertSettingDeprecationsAndWarnings(new Setting[]{S3Repository.Repositories.ENDPOINT_SETTING}); } private void assertEndpoint(Settings repositorySettings, Settings settings, diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3RepositoryTests.java b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3RepositoryTests.java index f20c2a7ad30..cc9e766aecb 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3RepositoryTests.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3RepositoryTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.cloud.aws.AwsS3Service; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.SecureString; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; @@ -78,7 +79,7 @@ public class S3RepositoryTests extends ESTestCase { getValue(Settings.EMPTY, globalSettings, Repository.KEY_SETTING, Repositories.KEY_SETTING)); assertEquals(new SecureString("".toCharArray()), getValue(Settings.EMPTY, Settings.EMPTY, Repository.KEY_SETTING, Repositories.KEY_SETTING)); - assertSettingDeprecations(Repository.KEY_SETTING, Repositories.KEY_SETTING); + assertSettingDeprecationsAndWarnings(new Setting[]{Repository.KEY_SETTING, Repositories.KEY_SETTING}); } public void testInvalidChunkBufferSizeSettings() throws IOException { diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 1a349ff0ef2..07707f1796e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -131,6 +131,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -303,13 +304,21 @@ public abstract class ESTestCase extends LuceneTestCase { } } - protected final void assertSettingDeprecations(Setting... settings) { + /** + * Convenience method to assert warnings for settings deprecations and general deprecation warnings. + * + * @param settings the settings that are expected to be deprecated + * @param warnings other expected general deprecation warnings + */ + protected final void assertSettingDeprecationsAndWarnings(final Setting[] settings, final String... warnings) { assertWarnings( - Arrays - .stream(settings) - .map(Setting::getKey) - .map(k -> "[" + k + "] setting was deprecated in Elasticsearch and will be removed in a future release! " + - "See the breaking changes documentation for the next major version.") + Stream.concat( + Arrays + .stream(settings) + .map(Setting::getKey) + .map(k -> "[" + k + "] setting was deprecated in Elasticsearch and will be removed in a future release! " + + "See the breaking changes documentation for the next major version."), + Arrays.stream(warnings)) .toArray(String[]::new)); }