Skip to content

Commit 3e56901

Browse files
authored
Add docker-compose fixtures for S3 integration tests (#49107)
Similarly to what has been done for Azure (#48636) and GCS (#48762), this committ removes the existing Ant fixture that emulates a S3 storage service in favor of multiple docker-compose based fixtures. The goals here are multiple: be able to reuse a s3-fixture outside of the repository-s3 plugin; allow parallel execution of integration tests; removes the existing AmazonS3Fixture that has evolved in a weird beast in dedicated, more maintainable fixtures. The server side logic that emulates S3 mostly comes from the latest HttpHandler made for S3 blob store repository tests, with additional features extracted from the (now removed) AmazonS3Fixture: authentication checks, session token checks and improved response errors. Chunked upload request support for S3 object has been added too. The server side logic of all tests now reside in a single S3HttpHandler class. Whereas AmazonS3Fixture contained logic for basic tests, session token tests, EC2 tests or ECS tests, the S3 fixtures are now dedicated to each kind of test. Fixtures are inheriting from each other, making things easier to maintain.
1 parent 3bddd39 commit 3e56901

File tree

12 files changed

+814
-848
lines changed

12 files changed

+814
-848
lines changed

plugins/repository-s3/build.gradle

+26-56
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.elasticsearch.gradle.MavenFilteringHack
22
import org.elasticsearch.gradle.info.BuildParams
3-
import org.elasticsearch.gradle.test.AntFixture
43
import org.elasticsearch.gradle.test.RestIntegTestTask
54

65
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
@@ -23,6 +22,7 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
2322
* specific language governing permissions and limitations
2423
* under the License.
2524
*/
25+
apply plugin: 'elasticsearch.test.fixtures'
2626

2727
esplugin {
2828
description 'The S3 repository plugin adds S3 repositories'
@@ -52,7 +52,7 @@ dependencies {
5252
// and whitelist this hack in JarHell
5353
compile 'javax.xml.bind:jaxb-api:2.2.2'
5454

55-
testCompile project(':test:fixtures:minio-fixture')
55+
testCompile project(':test:fixtures:s3-fixture')
5656
}
5757

5858
dependencyLicenses {
@@ -104,7 +104,7 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
104104
s3PermanentAccessKey = 'access_key'
105105
s3PermanentSecretKey = 'secret_key'
106106
s3PermanentBucket = 'bucket'
107-
s3PermanentBasePath = ''
107+
s3PermanentBasePath = 'base_path'
108108

109109
useFixture = true
110110

@@ -113,21 +113,21 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
113113
}
114114

115115
if (!s3TemporaryAccessKey && !s3TemporarySecretKey && !s3TemporaryBucket && !s3TemporaryBasePath && !s3TemporarySessionToken) {
116-
s3TemporaryAccessKey = 's3_integration_test_temporary_access_key'
117-
s3TemporarySecretKey = 's3_integration_test_temporary_secret_key'
118-
s3TemporaryBucket = 'temporary-bucket-test'
119-
s3TemporaryBasePath = 'integration_test'
120-
s3TemporarySessionToken = 's3_integration_test_temporary_session_token'
116+
s3TemporaryAccessKey = 'session_token_access_key'
117+
s3TemporarySecretKey = 'session_token_secret_key'
118+
s3TemporaryBucket = 'session_token_bucket'
119+
s3TemporaryBasePath = 'session_token_base_path'
120+
s3TemporarySessionToken = 'session_token'
121121

122122
} else if (!s3TemporaryAccessKey || !s3TemporarySecretKey || !s3TemporaryBucket || !s3TemporaryBasePath || !s3TemporarySessionToken) {
123123
throw new IllegalArgumentException("not all options specified to run against external S3 service as temporary credentials are present")
124124
}
125125

126126
if (!s3EC2Bucket && !s3EC2BasePath && !s3ECSBucket && !s3ECSBasePath) {
127-
s3EC2Bucket = 'ec2-bucket-test'
128-
s3EC2BasePath = 'integration_test'
129-
s3ECSBucket = 'ecs-bucket-test'
130-
s3ECSBasePath = 'integration_test'
127+
s3EC2Bucket = 'ec2_bucket'
128+
s3EC2BasePath = 'ec2_base_path'
129+
s3ECSBucket = 'ecs_bucket'
130+
s3ECSBasePath = 'ecs_base_path'
131131
} else if (!s3EC2Bucket || !s3EC2BasePath || !s3ECSBucket || !s3ECSBasePath) {
132132
throw new IllegalArgumentException("not all options specified to run EC2/ECS tests are present")
133133
}
@@ -141,8 +141,6 @@ task thirdPartyTest(type: Test) {
141141
}
142142

143143
if (useFixture) {
144-
apply plugin: 'elasticsearch.test.fixtures'
145-
146144
testFixtures.useFixture(':test:fixtures:minio-fixture')
147145

148146
def minioAddress = {
@@ -200,39 +198,6 @@ if (useFixture) {
200198

201199
check.dependsOn(thirdPartyTest)
202200

203-
File parentFixtures = new File(project.buildDir, "fixtures")
204-
File s3FixtureFile = new File(parentFixtures, 's3Fixture.properties')
205-
206-
task s3FixtureProperties {
207-
outputs.file(s3FixtureFile)
208-
def s3FixtureOptions = [
209-
"tests.seed" : BuildParams.testSeed,
210-
"s3Fixture.permanent_bucket_name" : s3PermanentBucket,
211-
"s3Fixture.permanent_key" : s3PermanentAccessKey,
212-
"s3Fixture.temporary_bucket_name" : s3TemporaryBucket,
213-
"s3Fixture.temporary_key" : s3TemporaryAccessKey,
214-
"s3Fixture.temporary_session_token": s3TemporarySessionToken,
215-
"s3Fixture.ec2_bucket_name" : s3EC2Bucket,
216-
"s3Fixture.ecs_bucket_name" : s3ECSBucket,
217-
"s3Fixture.disableChunkedEncoding" : s3DisableChunkedEncoding
218-
]
219-
220-
doLast {
221-
file(s3FixtureFile).text = s3FixtureOptions.collect { k, v -> "$k = $v" }.join("\n")
222-
}
223-
}
224-
225-
/** A task to start the AmazonS3Fixture which emulates an S3 service **/
226-
task s3Fixture(type: AntFixture) {
227-
dependsOn testClasses
228-
dependsOn s3FixtureProperties
229-
inputs.file(s3FixtureFile)
230-
231-
env 'CLASSPATH', "${-> project.sourceSets.test.runtimeClasspath.asPath}"
232-
executable = "${BuildParams.runtimeJavaHome}/bin/java"
233-
args 'org.elasticsearch.repositories.s3.AmazonS3Fixture', baseDir, s3FixtureFile.getAbsolutePath()
234-
}
235-
236201
processTestResources {
237202
Map<String, Object> expansions = [
238203
'permanent_bucket' : s3PermanentBucket,
@@ -249,8 +214,13 @@ processTestResources {
249214
MavenFilteringHack.filter(it, expansions)
250215
}
251216

252-
integTest {
253-
dependsOn s3Fixture
217+
testFixtures.useFixture(':test:fixtures:s3-fixture')
218+
219+
def fixtureAddress = { fixture ->
220+
assert useFixture: 'closure should not be used without a fixture'
221+
int ephemeralPort = project(':test:fixtures:s3-fixture').postProcessFixture.ext."test.fixtures.${fixture}.tcp.80"
222+
assert ephemeralPort > 0
223+
'http://127.0.0.1:' + ephemeralPort
254224
}
255225

256226
testClusters.integTest {
@@ -262,12 +232,12 @@ testClusters.integTest {
262232
keystore 's3.client.integration_test_temporary.session_token', s3TemporarySessionToken
263233

264234
if (useFixture) {
265-
setting 's3.client.integration_test_permanent.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
266-
setting 's3.client.integration_test_temporary.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
267-
setting 's3.client.integration_test_ec2.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
235+
setting 's3.client.integration_test_permanent.endpoint', { "${-> fixtureAddress('s3-fixture')}" }, IGNORE_VALUE
236+
setting 's3.client.integration_test_temporary.endpoint', { "${-> fixtureAddress('s3-fixture-with-session-token')}" }, IGNORE_VALUE
237+
setting 's3.client.integration_test_ec2.endpoint', { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
268238
269239
// to redirect InstanceProfileCredentialsProvider to custom auth point
270-
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
240+
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
271241
} else {
272242
println "Using an external service to test the repository-s3 plugin"
273243
}
@@ -280,7 +250,7 @@ task s3ThirdPartyTests {
280250
if (useFixture) {
281251
task integTestECS(type: RestIntegTestTask.class) {
282252
description = "Runs tests using the ECS repository."
283-
dependsOn(project.s3Fixture, 'bundlePlugin')
253+
dependsOn('bundlePlugin')
284254
runner {
285255
systemProperty 'tests.rest.blacklist', [
286256
'repository_s3/10_basic/*',
@@ -293,9 +263,9 @@ if (useFixture) {
293263
check.dependsOn(integTestECS)
294264
295265
testClusters.integTestECS {
296-
setting 's3.client.integration_test_ecs.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
266+
setting 's3.client.integration_test_ecs.endpoint', { "${-> fixtureAddress('s3-fixture-with-ecs')}" }, IGNORE_VALUE
297267
plugin file(tasks.bundlePlugin.archiveFile)
298-
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "http://${s3Fixture.addressAndPort}/ecs_credentials_endpoint" }, IGNORE_VALUE
268+
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "${-> fixtureAddress('s3-fixture-with-ecs')}/ecs_credentials_endpoint" }, IGNORE_VALUE
299269
}
300270
301271
gradle.taskGraph.whenReady {

0 commit comments

Comments
 (0)