diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/AwsS3ServiceImplTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/AwsS3ServiceImplTests.java index 7670c940046d4..47c77b909c12c 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/AwsS3ServiceImplTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/AwsS3ServiceImplTests.java @@ -39,14 +39,12 @@ import com.amazonaws.http.IdleConnectionReaper; import org.junit.AfterClass; -import org.opensearch.common.io.PathUtils; import org.opensearch.common.settings.MockSecureSettings; import org.opensearch.common.settings.Settings; import org.opensearch.test.OpenSearchTestCase; import java.io.Closeable; import java.io.IOException; -import java.nio.file.Path; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -57,7 +55,7 @@ import static org.opensearch.repositories.s3.S3ClientSettings.PROTOCOL_SETTING; import static org.opensearch.repositories.s3.S3ClientSettings.PROXY_TYPE_SETTING; -public class AwsS3ServiceImplTests extends OpenSearchTestCase { +public class AwsS3ServiceImplTests extends OpenSearchTestCase implements ConfigPathSupport { @AfterClass public static void shutdownIdleConnectionReaper() { // created by default STS client @@ -368,8 +366,4 @@ private void assertEndpoint(Settings repositorySettings, Settings settings, Stri final S3ClientSettings clientSettings = S3ClientSettings.getClientSettings(settings, configName, configPath()); assertThat(clientSettings.endpoint, is(expectedEndpoint)); } - - private Path configPath() { - return PathUtils.get("config"); - } } diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/ConfigPathSupport.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/ConfigPathSupport.java new file mode 100644 index 0000000000000..890dd245c67fd --- /dev/null +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/ConfigPathSupport.java @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.repositories.s3; + +import org.opensearch.common.io.PathUtils; + +import java.nio.file.Path; + +/** + * The trait that adds the config path to the test cases + */ +interface ConfigPathSupport { + default Path configPath() { + return PathUtils.get("config"); + } +} diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobContainerRetriesTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobContainerRetriesTests.java index 241fc7c550da4..b847890f1ea89 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobContainerRetriesTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobContainerRetriesTests.java @@ -41,7 +41,6 @@ import org.opensearch.common.blobstore.BlobContainer; import org.opensearch.common.blobstore.BlobPath; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.io.PathUtils; import org.opensearch.common.io.Streams; import org.opensearch.common.lucene.store.ByteArrayIndexInput; import org.opensearch.common.lucene.store.InputStreamIndexInput; @@ -64,7 +63,6 @@ import java.net.InetSocketAddress; import java.net.SocketTimeoutException; import java.nio.charset.StandardCharsets; -import java.nio.file.Path; import java.util.Locale; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; @@ -83,7 +81,7 @@ * This class tests how a {@link S3BlobContainer} and its underlying AWS S3 client are retrying requests when reading or writing blobs. */ @SuppressForbidden(reason = "use a http server") -public class S3BlobContainerRetriesTests extends AbstractBlobContainerRetriesTestCase { +public class S3BlobContainerRetriesTests extends AbstractBlobContainerRetriesTestCase implements ConfigPathSupport { private S3Service service; @@ -403,8 +401,4 @@ public void close() throws IOException { } } } - - private Path configPath() { - return PathUtils.get("config"); - } } diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ClientSettingsTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ClientSettingsTests.java index 7e76a656c2d1d..1f25023bf8bd9 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ClientSettingsTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ClientSettingsTests.java @@ -36,7 +36,6 @@ import com.amazonaws.Protocol; import com.amazonaws.services.s3.AmazonS3Client; -import org.opensearch.common.io.PathUtils; import org.opensearch.common.settings.MockSecureSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.SettingsException; @@ -44,7 +43,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; -import java.nio.file.Path; import java.util.Locale; import java.util.Map; @@ -54,7 +52,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -public class S3ClientSettingsTests extends OpenSearchTestCase { +public class S3ClientSettingsTests extends OpenSearchTestCase implements ConfigPathSupport { public void testThereIsADefaultClientByDefault() { final Map settings = S3ClientSettings.load(Settings.EMPTY, configPath()); assertThat(settings.keySet(), contains("default")); @@ -375,8 +373,4 @@ public void testSocksDoesNotSupportForHttpProtocol() { .build(); expectThrows(SettingsException.class, () -> S3ClientSettings.load(settings, configPath())); } - - private Path configPath() { - return PathUtils.get("config"); - } } diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java index 10c28cdf7ce43..673ee36f01eb7 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3RepositoryTests.java @@ -34,7 +34,6 @@ import com.amazonaws.services.s3.AbstractAmazonS3; import org.opensearch.cluster.metadata.RepositoryMetadata; -import org.opensearch.common.io.PathUtils; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; @@ -54,7 +53,7 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; -public class S3RepositoryTests extends OpenSearchTestCase { +public class S3RepositoryTests extends OpenSearchTestCase implements ConfigPathSupport { private static class DummyS3Client extends AbstractAmazonS3 { @@ -155,8 +154,4 @@ protected void assertSnapshotOrGenericThread() { } }; } - - private Path configPath() { - return PathUtils.get("config"); - } } diff --git a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ServiceTests.java b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ServiceTests.java index e8a1b6a9ea0cc..9f6c5e51309c5 100644 --- a/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ServiceTests.java +++ b/plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3ServiceTests.java @@ -32,15 +32,13 @@ package org.opensearch.repositories.s3; import org.opensearch.cluster.metadata.RepositoryMetadata; -import org.opensearch.common.io.PathUtils; import org.opensearch.common.settings.MockSecureSettings; import org.opensearch.common.settings.Settings; import org.opensearch.test.OpenSearchTestCase; -import java.nio.file.Path; import java.util.Map; -public class S3ServiceTests extends OpenSearchTestCase { +public class S3ServiceTests extends OpenSearchTestCase implements ConfigPathSupport { public void testCachedClientsAreReleased() { final S3Service s3Service = new S3Service(configPath()); @@ -86,8 +84,4 @@ public void testCachedClientsWithCredentialsAreReleased() { final S3ClientSettings clientSettingsReloaded = s3Service.settings(metadata1); assertNotSame(clientSettings, clientSettingsReloaded); } - - private Path configPath() { - return PathUtils.get("config"); - } }