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