Skip to content

Commit ca4f55f

Browse files
authored
Add docker-compose fixtures for S3 integration tests (#49107) (#49229)
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 fcde1e7 commit ca4f55f

File tree

12 files changed

+814
-848
lines changed

12 files changed

+814
-848
lines changed

plugins/repository-s3/build.gradle

Lines changed: 26 additions & 56 deletions
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 {
@@ -111,7 +111,7 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
111111
s3PermanentAccessKey = 'access_key'
112112
s3PermanentSecretKey = 'secret_key'
113113
s3PermanentBucket = 'bucket'
114-
s3PermanentBasePath = ''
114+
s3PermanentBasePath = 'base_path'
115115

116116
useFixture = true
117117

@@ -120,21 +120,21 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
120120
}
121121

122122
if (!s3TemporaryAccessKey && !s3TemporarySecretKey && !s3TemporaryBucket && !s3TemporaryBasePath && !s3TemporarySessionToken) {
123-
s3TemporaryAccessKey = 's3_integration_test_temporary_access_key'
124-
s3TemporarySecretKey = 's3_integration_test_temporary_secret_key'
125-
s3TemporaryBucket = 'temporary-bucket-test'
126-
s3TemporaryBasePath = 'integration_test'
127-
s3TemporarySessionToken = 's3_integration_test_temporary_session_token'
123+
s3TemporaryAccessKey = 'session_token_access_key'
124+
s3TemporarySecretKey = 'session_token_secret_key'
125+
s3TemporaryBucket = 'session_token_bucket'
126+
s3TemporaryBasePath = 'session_token_base_path'
127+
s3TemporarySessionToken = 'session_token'
128128

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

133133
if (!s3EC2Bucket && !s3EC2BasePath && !s3ECSBucket && !s3ECSBasePath) {
134-
s3EC2Bucket = 'ec2-bucket-test'
135-
s3EC2BasePath = 'integration_test'
136-
s3ECSBucket = 'ecs-bucket-test'
137-
s3ECSBasePath = 'integration_test'
134+
s3EC2Bucket = 'ec2_bucket'
135+
s3EC2BasePath = 'ec2_base_path'
136+
s3ECSBucket = 'ecs_bucket'
137+
s3ECSBasePath = 'ecs_base_path'
138138
} else if (!s3EC2Bucket || !s3EC2BasePath || !s3ECSBucket || !s3ECSBasePath) {
139139
throw new IllegalArgumentException("not all options specified to run EC2/ECS tests are present")
140140
}
@@ -148,8 +148,6 @@ task thirdPartyTest(type: Test) {
148148
}
149149

150150
if (useFixture) {
151-
apply plugin: 'elasticsearch.test.fixtures'
152-
153151
testFixtures.useFixture(':test:fixtures:minio-fixture')
154152

155153
def minioAddress = {
@@ -207,39 +205,6 @@ if (useFixture) {
207205

208206
check.dependsOn(thirdPartyTest)
209207

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

259-
integTest {
260-
dependsOn s3Fixture
224+
testFixtures.useFixture(':test:fixtures:s3-fixture')
225+
226+
def fixtureAddress = { fixture ->
227+
assert useFixture: 'closure should not be used without a fixture'
228+
int ephemeralPort = project(':test:fixtures:s3-fixture').postProcessFixture.ext."test.fixtures.${fixture}.tcp.80"
229+
assert ephemeralPort > 0
230+
'http://127.0.0.1:' + ephemeralPort
261231
}
262232

263233
testClusters.integTest {
@@ -269,12 +239,12 @@ testClusters.integTest {
269239
keystore 's3.client.integration_test_temporary.session_token', s3TemporarySessionToken
270240

271241
if (useFixture) {
272-
setting 's3.client.integration_test_permanent.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
273-
setting 's3.client.integration_test_temporary.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
274-
setting 's3.client.integration_test_ec2.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
242+
setting 's3.client.integration_test_permanent.endpoint', { "${-> fixtureAddress('s3-fixture')}" }, IGNORE_VALUE
243+
setting 's3.client.integration_test_temporary.endpoint', { "${-> fixtureAddress('s3-fixture-with-session-token')}" }, IGNORE_VALUE
244+
setting 's3.client.integration_test_ec2.endpoint', { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
275245
276246
// to redirect InstanceProfileCredentialsProvider to custom auth point
277-
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
247+
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
278248
} else {
279249
println "Using an external service to test the repository-s3 plugin"
280250
}
@@ -287,7 +257,7 @@ task s3ThirdPartyTests {
287257
if (useFixture) {
288258
task integTestECS(type: RestIntegTestTask.class) {
289259
description = "Runs tests using the ECS repository."
290-
dependsOn(project.s3Fixture)
260+
dependsOn('bundlePlugin')
291261
runner {
292262
systemProperty 'tests.rest.blacklist', [
293263
'repository_s3/10_basic/*',
@@ -300,9 +270,9 @@ if (useFixture) {
300270
check.dependsOn(integTestECS)
301271
302272
testClusters.integTestECS {
303-
setting 's3.client.integration_test_ecs.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
273+
setting 's3.client.integration_test_ecs.endpoint', { "${-> fixtureAddress('s3-fixture-with-ecs')}" }, IGNORE_VALUE
304274
plugin file(tasks.bundlePlugin.archiveFile)
305-
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "http://${s3Fixture.addressAndPort}/ecs_credentials_endpoint" }, IGNORE_VALUE
275+
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "${-> fixtureAddress('s3-fixture-with-ecs')}/ecs_credentials_endpoint" }, IGNORE_VALUE
306276
}
307277
308278
gradle.taskGraph.whenReady {

0 commit comments

Comments
 (0)