Skip to content

Commit

Permalink
Cleanup minio container
Browse files Browse the repository at this point in the history
  • Loading branch information
breskeby committed Nov 21, 2023
1 parent c66c98e commit 0f68251
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 41 deletions.
6 changes: 6 additions & 0 deletions build-tools-internal/version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,11 @@
<sha256 value="7966dcd73078250f38595223b1e807cd7566188a56236def031e265426056fc8" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.slf4j" name="slf4j-simple" version="2.0.6">
<artifact name="slf4j-simple-2.0.6.jar">
<sha256 value="547f06226cfcbcca198669e7498f6a6d2a55a84de5dd6eb46579f11fc40fc5d8" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.sonatype.plexus" name="plexus-cipher" version="1.4">
<artifact name="plexus-cipher-1.4.jar">
<sha256 value="5a15fdba22669e0fdd06e10dcce6320879e1f7398fbc910cd0677b50672a78c4" origin="Generated by Gradle"/>
Expand Down
2 changes: 2 additions & 0 deletions modules/repository-s3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Class<? extends Plugin>> getPlugins() {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
17 changes: 9 additions & 8 deletions test/fixtures/minio-fixture/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MinioTestContainer> 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")
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,8 +122,16 @@ interface LocalSpecBuilder<T extends 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<String> supplier);

/**
* Register a {@link SystemPropertyProvider}.
*/
T systemProperty(SystemPropertyProvider systemPropertyProvider);

/**
* Adds an additional command line argument to node JVM arguments.
*/
Expand Down

0 comments on commit 0f68251

Please sign in to comment.