20
20
21
21
import org.elasticsearch.gradle.MavenFilteringHack
22
22
import org.elasticsearch.gradle.info.BuildParams
23
- import org.elasticsearch.gradle.test.AntFixture
24
23
25
24
import java.nio.file.Files
26
25
import java.security.KeyPair
@@ -30,12 +29,14 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
30
29
31
30
apply plugin : ' elasticsearch.standalone-rest-test'
32
31
apply plugin : ' elasticsearch.rest-test'
32
+ apply plugin : ' elasticsearch.test.fixtures'
33
33
34
34
// TODO think about flattening qa:google-cloud-storage project into parent
35
35
dependencies {
36
36
testCompile project(path : ' :plugins:repository-gcs' )
37
37
}
38
38
39
+ testFixtures. useFixture(' :test:fixtures:gcs-fixture' )
39
40
boolean useFixture = false
40
41
41
42
String gcsServiceAccount = System . getenv(" google_storage_service_account" )
@@ -45,7 +46,7 @@ String gcsBasePath = System.getenv("google_storage_base_path")
45
46
File serviceAccountFile = null
46
47
if (! gcsServiceAccount && ! gcsBucket && ! gcsBasePath) {
47
48
serviceAccountFile = new File (project. buildDir, ' generated-resources/service_account_test.json' )
48
- gcsBucket = ' bucket_test '
49
+ gcsBucket = ' bucket '
49
50
gcsBasePath = ' integration_test'
50
51
useFixture = true
51
52
} else if (! gcsServiceAccount || ! gcsBucket || ! gcsBasePath) {
@@ -58,12 +59,11 @@ def encodedCredentials = {
58
59
Base64 . encoder. encodeToString(Files . readAllBytes(serviceAccountFile. toPath()))
59
60
}
60
61
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
67
67
}
68
68
69
69
/* * A service account file that points to the Google Cloud Storage service emulated by the fixture **/
@@ -87,6 +87,19 @@ task createServiceAccountFile() {
87
87
}
88
88
89
89
task 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
+
90
103
include ' **/GoogleCloudStorageThirdPartyTests.class'
91
104
systemProperty ' tests.security.manager' , false
92
105
systemProperty ' test.google.bucket' , gcsBucket
@@ -98,32 +111,6 @@ task gcsThirdPartyTests {
98
111
dependsOn check
99
112
}
100
113
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
-
127
114
integTest. mustRunAfter(thirdPartyTest)
128
115
check. dependsOn thirdPartyTest
129
116
@@ -147,10 +134,10 @@ testClusters.integTest {
147
134
keystore ' gcs.client.integration_test.credentials_file' , serviceAccountFile, IGNORE_VALUE
148
135
149
136
if (useFixture) {
150
- tasks. integTest. dependsOn createServiceAccountFile, googleCloudStorageFixture
137
+ tasks. integTest. dependsOn createServiceAccountFile
151
138
/* 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
154
141
} else {
155
142
println " Using an external service to test the repository- gcs plugin"
156
143
}
0 commit comments