1
- import org.apache.tools.ant.filters.ReplaceTokens
2
- import org.elasticsearch.gradle.internal.info.BuildParams
3
- import org.elasticsearch.gradle.internal.test.RestIntegTestTask
4
- import org.elasticsearch.gradle.internal.test.rest.LegacyYamlRestTestPlugin
5
- import org.elasticsearch.gradle.internal.test.InternalClusterTestPlugin
6
-
7
- import java.nio.file.Files
8
- import java.security.KeyPair
9
- import java.security.KeyPairGenerator
10
-
11
- import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
12
1
/*
13
2
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
14
3
* or more contributor license agreements. Licensed under the Elastic License
15
4
* 2.0 and the Server Side Public License, v 1; you may not use this file except
16
5
* in compliance with, at your election, the Elastic License 2.0 or the Server
17
6
* Side Public License, v 1.
18
7
*/
19
- apply plugin : ' elasticsearch.legacy-yaml-rest-test'
8
+
9
+
10
+ import org.apache.tools.ant.filters.ReplaceTokens
11
+ import org.elasticsearch.gradle.internal.info.BuildParams
12
+ import org.elasticsearch.gradle.internal.test.InternalClusterTestPlugin
13
+
14
+ import java.nio.file.Files
15
+
16
+ apply plugin : ' elasticsearch.internal-yaml-rest-test'
20
17
apply plugin : ' elasticsearch.internal-cluster-test'
21
18
apply plugin : ' elasticsearch.internal-test-artifact-base'
22
19
@@ -61,6 +58,7 @@ dependencies {
61
58
testImplementation " org.apache.httpcomponents:httpcore:${ versions.httpcore} "
62
59
63
60
testImplementation project(' :test:fixtures:gcs-fixture' )
61
+ yamlRestTestImplementation project(' :test:fixtures:gcs-fixture' )
64
62
}
65
63
66
64
testArtifacts {
@@ -202,60 +200,23 @@ tasks.named("thirdPartyAudit").configure {
202
200
}
203
201
204
202
boolean useFixture = false
205
-
206
- def fixtureAddress = { fixture ->
207
- assert useFixture: ' closure should not be used without a fixture'
208
- int ephemeralPort = project(' :test:fixtures:gcs-fixture' ). postProcessFixture. ext. " test.fixtures.${ fixture} .tcp.80"
209
- assert ephemeralPort > 0
210
- ' http://127.0.0.1:' + ephemeralPort
211
- }
212
-
213
203
String gcsServiceAccount = System . getenv(" google_storage_service_account" )
214
204
String gcsBucket = System . getenv(" google_storage_bucket" )
215
205
String gcsBasePath = System . getenv(" google_storage_base_path" )
216
- File serviceAccountFile = null
206
+ File serviceAccountFile = gcsServiceAccount != null ? new File (gcsServiceAccount) : null
217
207
218
208
if (! gcsServiceAccount && ! gcsBucket && ! gcsBasePath) {
219
- serviceAccountFile = new File (project. buildDir, ' generated-resources/service_account_test.json' )
220
209
gcsBucket = ' bucket'
221
210
gcsBasePath = ' integration_test'
222
211
useFixture = true
223
-
224
- apply plugin : ' elasticsearch.test.fixtures'
225
- testFixtures. useFixture(' :test:fixtures:gcs-fixture' , ' gcs-fixture' )
226
- testFixtures. useFixture(' :test:fixtures:gcs-fixture' , ' gcs-fixture-third-party' )
227
- testFixtures. useFixture(' :test:fixtures:gcs-fixture' , ' gcs-fixture-with-application-default-credentials' )
228
-
229
212
} else if (! gcsServiceAccount || ! gcsBucket || ! gcsBasePath) {
230
213
throw new IllegalArgumentException (" not all options specified to run tests against external GCS service are present" )
231
- } else {
232
- serviceAccountFile = new File (gcsServiceAccount)
233
214
}
234
215
235
216
def encodedCredentials = {
236
217
Base64 . encoder. encodeToString(Files . readAllBytes(serviceAccountFile. toPath()))
237
218
}
238
219
239
- /* * A service account file that points to the Google Cloud Storage service emulated by the fixture **/
240
- tasks. register(" createServiceAccountFile" ) {
241
- doLast {
242
- KeyPairGenerator keyPairGenerator = KeyPairGenerator . getInstance(" RSA" )
243
- keyPairGenerator. initialize(2048 )
244
- KeyPair keyPair = keyPairGenerator. generateKeyPair()
245
- String encodedKey = Base64 . getEncoder(). encodeToString(keyPair. private . getEncoded())
246
-
247
- serviceAccountFile. parentFile. mkdirs()
248
- serviceAccountFile. setText(" {\n " +
249
- ' "type": "service_account",\n ' +
250
- ' "project_id": "integration_test",\n ' +
251
- ' "private_key_id": "' + UUID . randomUUID(). toString() + ' ",\n ' +
252
- ' "private_key": "-----BEGIN PRIVATE KEY-----\\ n' + encodedKey + ' \\ n-----END PRIVATE KEY-----\\ n",\n ' +
253
- ' "client_email": "[email protected] ",\n ' +
254
- ' "client_id": "123456789101112130594"\n ' +
255
- ' }' , ' UTF-8' )
256
- }
257
- }
258
-
259
220
Map<String , Object > expansions = [
260
221
' bucket' : gcsBucket,
261
222
' base_path' : gcsBasePath + " _integration_tests"
@@ -271,86 +232,34 @@ tasks.named("internalClusterTest").configure {
271
232
exclude ' **/GoogleCloudStorageThirdPartyTests.class'
272
233
}
273
234
274
- tasks. named(" yamlRestTest" ). configure {
275
- if (useFixture) {
276
- dependsOn " createServiceAccountFile"
235
+ tasks. named(" yamlRestTest" ) {
236
+ systemProperty ' test.google.fixture' , Boolean . toString(useFixture)
237
+ if (useFixture == false ) {
238
+ systemProperty ' test.google.account' , serviceAccountFile
239
+ // We can't run these test in parallel against a real bucket since the tests will step on each other
240
+ maxParallelForks = 1
277
241
}
278
242
}
279
243
280
- /*
281
- * We only use a small amount of data in these tests, which means that the resumable upload path is not tested. We add
282
- * an additional test that forces the large blob threshold to be small to exercise the resumable upload path.
283
- */
284
- def largeBlobYamlRestTest = tasks. register(" largeBlobYamlRestTest" , RestIntegTestTask ) {
285
- if (useFixture) {
286
- dependsOn " createServiceAccountFile"
287
- }
288
- SourceSetContainer sourceSets = project. getExtensions(). getByType(SourceSetContainer . class);
289
- SourceSet yamlRestTestSourceSet = sourceSets. getByName(LegacyYamlRestTestPlugin . SOURCE_SET_NAME )
290
- setTestClassesDirs(yamlRestTestSourceSet. getOutput(). getClassesDirs())
291
- setClasspath(yamlRestTestSourceSet. getRuntimeClasspath())
292
-
293
- // We have to wait for configure the cluster here as it might not have been created otherwise yet.
294
- testClusters {
295
- largeBlobYamlRestTest {
296
- module tasks. named(" explodedBundlePlugin" )
297
-
298
- // force large blob uploads by setting the threshold small, forcing this code path to be tested
299
- systemProperty ' es.repository_gcs.large_blob_threshold_byte_size' , ' 256'
300
- }
301
- }
302
- }
303
-
304
- def gcsThirdPartyTest = tasks. register(" gcsThirdPartyTest" , Test ) {
305
- SourceSetContainer sourceSets = project. getExtensions(). getByType(SourceSetContainer . class);
244
+ def gcsThirdPartyTest = tasks. register(" gcsThirdPartyUnitTest" , Test ) {
245
+ SourceSetContainer sourceSets = project. getExtensions(). getByType(SourceSetContainer . class)
306
246
SourceSet internalTestSourceSet = sourceSets. getByName(InternalClusterTestPlugin . SOURCE_SET_NAME )
307
247
setTestClassesDirs(internalTestSourceSet. getOutput(). getClassesDirs())
308
248
setClasspath(internalTestSourceSet. getRuntimeClasspath())
309
249
include ' **/GoogleCloudStorageThirdPartyTests.class'
310
250
systemProperty ' tests.security.manager' , false
311
251
systemProperty ' test.google.bucket' , gcsBucket
252
+ systemProperty ' test.google.fixture' , Boolean . toString(useFixture)
312
253
nonInputProperties. systemProperty ' test.google.base' , gcsBasePath + " _third_party_tests_" + BuildParams . testSeed
313
- nonInputProperties. systemProperty ' test.google.account' , " ${ -> encodedCredentials.call()} "
314
- if (useFixture) {
315
- dependsOn " createServiceAccountFile"
316
- nonInputProperties. systemProperty ' test.google.endpoint' , " ${ -> fixtureAddress('gcs-fixture-third-party')} "
317
- nonInputProperties. systemProperty ' test.google.tokenURI' , " ${ -> fixtureAddress('gcs-fixture-third-party')} /o/oauth2/token"
318
- }
319
- }
320
-
321
- testClusters. matching {
322
- it. name == " yamlRestTest" ||
323
- it. name == " largeBlobYamlRestTest" ||
324
- it. name == " gcsThirdPartyTest" }. configureEach {
325
- keystore ' gcs.client.integration_test.credentials_file' , serviceAccountFile, IGNORE_VALUE
326
-
327
- if (useFixture) {
328
- /* Use a closure on the string to delay evaluation until tests are executed */
329
- setting ' gcs.client.integration_test.endpoint' , { "${-> fixtureAddress(' gcs-fixture' )}" }, IGNORE_VALUE
330
- setting 'gcs.client.integration_test.token_uri', { " ${-> fixtureAddress(' gcs-fixture' )}/ o/ oauth2/ token" }, IGNORE_VALUE
331
- } else {
332
- println " Using an external service to test the repository- gcs plugin"
254
+ if (useFixture == false ) {
255
+ nonInputProperties. systemProperty ' test.google.account' , " ${ -> encodedCredentials.call()} "
333
256
}
334
257
}
335
258
336
-
337
- // Application Default Credentials
338
- if (useFixture) {
339
- tasks.register(" yamlRestTestApplicationDefaultCredentials" , RestIntegTestTask.class) {
340
- SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
341
- SourceSet yamlRestTestSourceSet = sourceSets.getByName(LegacyYamlRestTestPlugin.SOURCE_SET_NAME)
342
- setTestClassesDirs(yamlRestTestSourceSet.getOutput().getClassesDirs())
343
- setClasspath(yamlRestTestSourceSet.getRuntimeClasspath())
344
- }
345
- tasks.named(" check" ).configure { dependsOn(" yamlRestTestApplicationDefaultCredentials" ) }
346
-
347
- testClusters.matching { it.name == " yamlRestTestApplicationDefaultCredentials" }.configureEach {
348
- setting 'gcs.client.integration_test.endpoint', { " ${-> fixtureAddress(' gcs-fixture-with-application-default-credentials' )}" }, IGNORE_VALUE
349
- module tasks.named(" explodedBundlePlugin" )
350
- environment 'GCE_METADATA_HOST', { " ${-> fixtureAddress(' gcs-fixture-with-application-default-credentials' )}" .replace(" http :// ", "") }, IGNORE_VALUE
351
- }
259
+ tasks. register(' gcsThirdPartyTest' ) {
260
+ dependsOn ' yamlRestTest' , gcsThirdPartyTest
352
261
}
353
262
354
- tasks. named(" check" ) . configure {
355
- dependsOn(largeBlobYamlRestTest, gcsThirdPartyTest)
263
+ tasks. named(' check' ) {
264
+ dependsOn gcsThirdPartyTest
356
265
}
0 commit comments