2020
2121import org.elasticsearch.gradle.MavenFilteringHack
2222import org.elasticsearch.gradle.info.BuildParams
23- import org.elasticsearch.gradle.test.AntFixture
2423
2524import java.nio.file.Files
2625import java.security.KeyPair
@@ -30,12 +29,14 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
3029
3130apply plugin : ' elasticsearch.standalone-rest-test'
3231apply plugin : ' elasticsearch.rest-test'
32+ apply plugin : ' elasticsearch.test.fixtures'
3333
3434// TODO think about flattening qa:google-cloud-storage project into parent
3535dependencies {
3636 testCompile project(path : ' :plugins:repository-gcs' )
3737}
3838
39+ testFixtures. useFixture(' :test:fixtures:gcs-fixture' )
3940boolean useFixture = false
4041
4142String gcsServiceAccount = System . getenv(" google_storage_service_account" )
@@ -45,7 +46,7 @@ String gcsBasePath = System.getenv("google_storage_base_path")
4546File serviceAccountFile = null
4647if (! gcsServiceAccount && ! gcsBucket && ! gcsBasePath) {
4748 serviceAccountFile = new File (project. buildDir, ' generated-resources/service_account_test.json' )
48- gcsBucket = ' bucket_test '
49+ gcsBucket = ' bucket '
4950 gcsBasePath = ' integration_test'
5051 useFixture = true
5152} else if (! gcsServiceAccount || ! gcsBucket || ! gcsBasePath) {
@@ -58,12 +59,11 @@ def encodedCredentials = {
5859 Base64 . encoder. encodeToString(Files . readAllBytes(serviceAccountFile. toPath()))
5960}
6061
61- /* * A task to start the GoogleCloudStorageFixture which emulates a Google Cloud Storage service **/
62- task googleCloudStorageFixture (type : AntFixture ) {
63- dependsOn testClasses
64- env ' CLASSPATH' , " ${ -> project.sourceSets.test.runtimeClasspath.asPath } "
65- executable = " ${ BuildParams.runtimeJavaHome} /bin/java"
66- args ' org.elasticsearch.repositories.gcs.GoogleCloudStorageFixture' , baseDir, ' bucket_test'
62+ def fixtureAddress = { fixture ->
63+ assert useFixture : ' closure should not be used without a fixture'
64+ int ephemeralPort = project(' :test:fixtures:gcs-fixture' ). postProcessFixture. ext. " test.fixtures.${ fixture} .tcp.80"
65+ assert ephemeralPort > 0
66+ ' http://127.0.0.1:' + ephemeralPort
6767}
6868
6969/* * A service account file that points to the Google Cloud Storage service emulated by the fixture **/
@@ -87,6 +87,19 @@ task createServiceAccountFile() {
8787}
8888
8989task thirdPartyTest (type : Test ) {
90+ if (useFixture) {
91+ thirdPartyTest. dependsOn createServiceAccountFile
92+ nonInputProperties. systemProperty ' test.google.endpoint' , " ${ -> fixtureAddress('gcs-fixture-third-party') } "
93+ nonInputProperties. systemProperty ' test.google.tokenURI' , " ${ -> fixtureAddress('gcs-fixture-third-party') } /o/oauth2/token"
94+
95+ gradle. taskGraph. whenReady {
96+ if (it. hasTask(gcsThirdPartyTests)) {
97+ throw new IllegalStateException (" Tried to run third party tests but not all of the necessary environment variables " +
98+ " 'google_storage_service_account', 'google_storage_bucket', 'google_storage_base_path' are set." )
99+ }
100+ }
101+ }
102+
90103 include ' **/GoogleCloudStorageThirdPartyTests.class'
91104 systemProperty ' tests.security.manager' , false
92105 systemProperty ' test.google.bucket' , gcsBucket
@@ -98,32 +111,6 @@ task gcsThirdPartyTests {
98111 dependsOn check
99112}
100113
101- if (useFixture) {
102- // TODO think about running the fixture in the same JVM as tests
103- thirdPartyTest. dependsOn createServiceAccountFile, googleCloudStorageFixture
104- thirdPartyTest. finalizedBy googleCloudStorageFixture. getStopTask()
105-
106- def fixtureEndpoint = {
107- " http://${ googleCloudStorageFixture.addressAndPort} "
108- }
109-
110- def tokenURI = {
111- " http://${ googleCloudStorageFixture.addressAndPort} /o/oauth2/token"
112- }
113-
114- thirdPartyTest {
115- nonInputProperties. systemProperty ' test.google.endpoint' , " ${ -> fixtureEndpoint.call() } "
116- nonInputProperties. systemProperty ' test.google.tokenURI' , " ${ -> tokenURI.call() } "
117- }
118-
119- gradle. taskGraph. whenReady {
120- if (it. hasTask(gcsThirdPartyTests)) {
121- throw new IllegalStateException (" Tried to run third party tests but not all of the necessary environment variables 'google_storage_service_account', " +
122- " 'google_storage_bucket', 'google_storage_base_path' are set." )
123- }
124- }
125- }
126-
127114integTest. mustRunAfter(thirdPartyTest)
128115check. dependsOn thirdPartyTest
129116
@@ -147,10 +134,10 @@ testClusters.integTest {
147134 keystore ' gcs.client.integration_test.credentials_file' , serviceAccountFile, IGNORE_VALUE
148135
149136 if (useFixture) {
150- tasks. integTest. dependsOn createServiceAccountFile, googleCloudStorageFixture
137+ tasks. integTest. dependsOn createServiceAccountFile
151138 /* Use a closure on the string to delay evaluation until tests are executed */
152- setting ' gcs.client.integration_test.endpoint' , { " http:// ${ googleCloudStorageFixture.addressAndPort } " }, IGNORE_VALUE
153- setting ' gcs.client.integration_test.token_uri' , { " http:// ${ googleCloudStorageFixture.addressAndPort } /o/oauth2/token" }, IGNORE_VALUE
139+ setting ' gcs.client.integration_test.endpoint' , { "${ -> fixtureAddress( ' gcs-fixture ' ) }" }, IGNORE_VALUE
140+ setting 'gcs.client.integration_test.token_uri', { " ${ -> fixtureAddress( ' gcs-fixture ' ) }/ o/ oauth2/ token" }, IGNORE_VALUE
154141 } else {
155142 println " Using an external service to test the repository- gcs plugin"
156143 }
0 commit comments