diff --git a/build-tools-internal/version.properties b/build-tools-internal/version.properties index dc43523b747b3..87de2c03e2e57 100644 --- a/build-tools-internal/version.properties +++ b/build-tools-internal/version.properties @@ -42,6 +42,12 @@ junit5 = 5.7.1 hamcrest = 2.1 mocksocket = 1.2 +# test container dependencies +testcontainer = 1.19.2 +docker = 3.3.4 +ductTape = 1.0.8 +commonsCompress = 1.24.0 + # benchmark dependencies jmh = 1.26 diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 4fb37401f52b0..8d2c13d9aa4cf 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -4147,6 +4147,11 @@ + + + + + diff --git a/modules/repository-s3/build.gradle b/modules/repository-s3/build.gradle index 6e854c593b4f2..3969eec4a14bd 100644 --- a/modules/repository-s3/build.gradle +++ b/modules/repository-s3/build.gradle @@ -46,6 +46,8 @@ dependencies { yamlRestTestImplementation project(':test:fixtures:s3-fixture') yamlRestTestImplementation project(':test:fixtures:minio-fixture') internalClusterTestImplementation project(':test:fixtures:minio-fixture') + + yamlRestTestRuntimeOnly "org.slf4j:slf4j-simple:${versions.slf4j}" testRuntimeOnly project(":test:framework") } diff --git a/modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3RepositoryThirdPartyTests.java b/modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3RepositoryThirdPartyTests.java index 72594e3329358..cd1e0d027fd1f 100644 --- a/modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3RepositoryThirdPartyTests.java +++ b/modules/repository-s3/src/internalClusterTest/java/org/elasticsearch/repositories/s3/S3RepositoryThirdPartyTests.java @@ -32,7 +32,7 @@ import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.telemetry.metric.MeterRegistry; import org.elasticsearch.test.ClusterServiceUtils; -import org.elasticsearch.test.fixtures.minio.MinioFixtureTestContainer; +import org.elasticsearch.test.fixtures.minio.MinioTestContainer; import org.elasticsearch.test.fixtures.testcontainers.TestContainersThreadFilter; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; @@ -56,7 +56,7 @@ public class S3RepositoryThirdPartyTests extends AbstractThirdPartyRepositoryTestCase { @ClassRule - public static MinioFixtureTestContainer minioFixtureTestContainer = new MinioFixtureTestContainer(true); + public static MinioTestContainer minio = new MinioTestContainer(true).withE @Override protected Collection> getPlugins() { @@ -100,7 +100,7 @@ protected void createRepository(String repoName) { Settings.Builder settings = Settings.builder() .put("bucket", System.getProperty("test.s3.bucket")) .put("base_path", System.getProperty("test.s3.base", "testpath")); - final String endpoint = minioFixtureTestContainer.getServiceUrl(); + final String endpoint = minio.getAddress(); if (endpoint != null) { settings.put("endpoint", endpoint); } else { diff --git a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3MinioClientYamlTestSuiteIT.java b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3MinioClientYamlTestSuiteIT.java index 8080e4c070855..d2882d4020d96 100644 --- a/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3MinioClientYamlTestSuiteIT.java +++ b/modules/repository-s3/src/yamlRestTest/java/org/elasticsearch/repositories/s3/RepositoryS3MinioClientYamlTestSuiteIT.java @@ -12,7 +12,7 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; import org.elasticsearch.test.cluster.ElasticsearchCluster; -import org.elasticsearch.test.fixtures.minio.MinioFixtureTestContainer; +import org.elasticsearch.test.fixtures.minio.MinioTestContainer; import org.elasticsearch.test.fixtures.testcontainers.TestContainersThreadFilter; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.junit.BeforeClass; @@ -25,17 +25,17 @@ @ThreadLeakFilters(filters = { TestContainersThreadFilter.class }) public class RepositoryS3MinioClientYamlTestSuiteIT extends AbstractRepositoryS3ClientYamlTestSuiteIT { - public static MinioFixtureTestContainer minioFixtureTestContainer = new MinioFixtureTestContainer(USE_FIXTURE); + public static MinioTestContainer minio = new MinioTestContainer(USE_FIXTURE); public static ElasticsearchCluster cluster = ElasticsearchCluster.local() .module("repository-s3") .keystore("s3.client.integration_test_permanent.access_key", System.getProperty("s3PermanentAccessKey")) .keystore("s3.client.integration_test_permanent.secret_key", System.getProperty("s3PermanentSecretKey")) - .setting("s3.client.integration_test_permanent.endpoint", () -> minioFixtureTestContainer.getServiceUrl()) + .setting("s3.client.integration_test_permanent.endpoint", () -> minio.getAddress()) .build(); @ClassRule - public static TestRule ruleChain = RuleChain.outerRule(minioFixtureTestContainer).around(cluster); + public static TestRule ruleChain = RuleChain.outerRule(minio).around(cluster); @BeforeClass public static void onlyWhenRunWithTestFixture() { diff --git a/test/fixtures/minio-fixture/build.gradle b/test/fixtures/minio-fixture/build.gradle index 5c775842074b1..228f064398da2 100644 --- a/test/fixtures/minio-fixture/build.gradle +++ b/test/fixtures/minio-fixture/build.gradle @@ -19,13 +19,14 @@ dependencies { testImplementation project(':test:framework') api "junit:junit:${versions.junit}" + api "org.testcontainers:testcontainers:${versions.testcontainer}" implementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" - implementation 'org.testcontainers:testcontainers:1.19.2' //replace with the latest version - implementation 'org.slf4j:slf4j-api:1.7.36' - implementation 'com.github.docker-java:docker-java-api:3.3.4' - runtimeOnly 'com.github.docker-java:docker-java-transport-zerodep:3.3.4' - runtimeOnly 'com.github.docker-java:docker-java-transport:3.3.4' - runtimeOnly 'com.github.docker-java:docker-java-core:3.3.4' - runtimeOnly 'org.apache.commons:commons-compress:1.24.0' - runtimeOnly 'org.rnorth.duct-tape:duct-tape:1.0.8' + implementation "org.slf4j:slf4j-api:${versions.slf4j}" + implementation "com.github.docker-java:docker-java-api:${versions.docker}" + runtimeOnly "com.github.docker-java:docker-java-transport-zerodep:${versions.docker}" + runtimeOnly "com.github.docker-java:docker-java-transport:${versions.docker}" + runtimeOnly "com.github.docker-java:docker-java-core:${versions.docker}" + runtimeOnly "org.apache.commons:commons-compress:${versions.commonsCompress}" + runtimeOnly "org.rnorth.duct-tape:duct-tape:${versions.ductTape}" + runtimeOnly "org.rnorth.duct-tape:duct-tape:${versions.ductTape}" } diff --git a/test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioFixtureTestContainer.java b/test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioTestContainer.java similarity index 55% rename from test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioFixtureTestContainer.java rename to test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioTestContainer.java index b6b63768fafff..d4bdc7de1f0e8 100644 --- a/test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioFixtureTestContainer.java +++ b/test/fixtures/minio-fixture/src/main/java/org/elasticsearch/test/fixtures/minio/MinioTestContainer.java @@ -9,18 +9,16 @@ package org.elasticsearch.test.fixtures.minio; import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import org.testcontainers.containers.GenericContainer; import org.testcontainers.images.builder.ImageFromDockerfile; -public class MinioFixtureTestContainer implements TestRule { +public class MinioTestContainer extends GenericContainer implements TestRule { private static final int servicePort = 9000; - private GenericContainer container; + private final boolean enabled; - private GenericContainer createContainer() { - return new GenericContainer<>( + public MinioTestContainer(boolean enabled) { + super( new ImageFromDockerfile().withDockerfileFromBuilder( builder -> builder.from("minio/minio:RELEASE.2021-03-01T04-20-55Z") .env("MINIO_ACCESS_KEY", "s3_test_access_key") @@ -29,33 +27,21 @@ private GenericContainer createContainer() { .cmd("server", "/minio/data") .build() ) - ).withExposedPorts(servicePort); - } - - public MinioFixtureTestContainer(boolean enabled) { + ); if (enabled) { - this.container = createContainer(); + addExposedPort(servicePort); } + this.enabled = enabled; } @Override - public Statement apply(Statement base, Description description) { - if (container != null) { - container.start(); + public void start() { + if (enabled) { + super.start(); } - return new Statement() { - @Override - public void evaluate() throws Throwable { - base.evaluate(); - } - }; - } - - private int getServicePort() { - return container.getMappedPort(servicePort); } - public String getServiceUrl() { - return "http://127.0.0.1:" + getServicePort(); + public String getAddress() { + return "http://127.0.0.1:" + getMappedPort(servicePort); } } diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalSpecBuilder.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalSpecBuilder.java index 3a251bc37d116..85cec80591288 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalSpecBuilder.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalSpecBuilder.java @@ -11,6 +11,7 @@ import org.elasticsearch.test.cluster.EnvironmentProvider; import org.elasticsearch.test.cluster.FeatureFlag; import org.elasticsearch.test.cluster.SettingsProvider; +import org.elasticsearch.test.cluster.SystemPropertyProvider; import org.elasticsearch.test.cluster.local.LocalClusterSpec.LocalNodeSpec; import org.elasticsearch.test.cluster.local.distribution.DistributionType; import org.elasticsearch.test.cluster.util.Version; @@ -121,8 +122,16 @@ interface LocalSpecBuilder> { */ T systemProperty(String property, String value); + /** + * Adds a system property to node JVM arguments computed by the given supplier. + */ T systemProperty(String property, Supplier supplier); + /** + * Register a {@link SystemPropertyProvider}. + */ + T systemProperty(SystemPropertyProvider systemPropertyProvider); + /** * Adds an additional command line argument to node JVM arguments. */