1
- import org.elasticsearch.gradle.LoggedExec
2
- import org.elasticsearch.gradle.VersionProperties
3
- import org.apache.tools.ant.taskdefs.condition.Os
4
- import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
5
-
6
- import java.nio.charset.StandardCharsets
7
- import java.nio.file.Files
8
- import java.util.stream.Stream
9
-
10
1
/*
11
2
* Licensed to Elasticsearch under one or more contributor
12
3
* license agreements. See the NOTICE file distributed with
@@ -26,33 +17,14 @@ import java.util.stream.Stream
26
17
* under the License.
27
18
*/
28
19
20
+ import org.elasticsearch.gradle.VersionProperties
21
+
29
22
apply plugin : ' war'
30
- apply plugin : ' elasticsearch.testclusters'
31
23
apply plugin : ' elasticsearch.build'
32
- apply plugin : ' elasticsearch.rest-test'
24
+ apply plugin : ' elasticsearch.test.fixtures'
25
+ apply plugin : ' elasticsearch.distribution-download'
33
26
34
- final String wildflyVersion = ' 11.0.0.Final'
35
- final String wildflyDir = " ${ buildDir} /wildfly"
36
- final String wildflyInstall = " ${ buildDir} /wildfly/wildfly-${ wildflyVersion} "
37
- int managementPort
38
-
39
- repositories {
40
- // the Wildfly distribution is not available via a repository, so we fake an Ivy repository on top of the download site
41
- ivy {
42
- name " wildfly"
43
- url " https://download.jboss.org"
44
- metadataSources {
45
- artifact()
46
- }
47
- patternLayout {
48
- artifact ' wildfly/[revision]/[module]-[revision].[ext]'
49
- }
50
- }
51
- }
52
-
53
- configurations {
54
- wildfly
55
- }
27
+ testFixtures. useFixture()
56
28
57
29
dependencies {
58
30
providedCompile ' javax.enterprise:cdi-api:1.2'
@@ -73,162 +45,41 @@ dependencies {
73
45
compile " org.apache.logging.log4j:log4j-api:${ versions.log4j} "
74
46
compile " org.apache.logging.log4j:log4j-core:${ versions.log4j} "
75
47
compile project(path : ' :client:rest-high-level' , configuration : ' shadow' )
76
- wildfly " org.jboss:wildfly:${ wildflyVersion} @zip"
77
48
testCompile project(' :test:framework' )
78
49
}
79
50
80
- task unzipWildfly (type : Sync ) {
81
- into wildflyDir
82
- from { zipTree(configurations. wildfly. singleFile) }
51
+ war {
52
+ archiveName ' example-app.war'
83
53
}
84
54
85
- task deploy (type : Copy ) {
86
- dependsOn unzipWildfly, war
87
- from war
88
- into " ${ wildflyInstall} /standalone/deployments"
89
- }
90
-
91
- task writeElasticsearchProperties (type : DefaultTestClustersTask ) {
92
- onlyIf { ! Os . isFamily(Os . FAMILY_WINDOWS ) }
93
- useCluster testClusters. integTest
94
- dependsOn deploy
95
- doLast {
96
- final File elasticsearchProperties = file(" ${ wildflyInstall} /standalone/configuration/elasticsearch.properties" )
97
- elasticsearchProperties. write(
98
- [
99
- " http.uri=${ -> testClusters.integTest.getAllHttpSocketURI().get(0)} "
100
- ]. join(" \n " ))
55
+ elasticsearch_distributions {
56
+ docker {
57
+ type = ' docker'
58
+ flavor = System . getProperty(' tests.distribution' , ' default' )
59
+ version = VersionProperties . getElasticsearch()
60
+ failIfUnavailable = false // This ensures we skip this testing if Docker is unavailable
101
61
}
102
62
}
103
63
104
- // the default configuration ships with IPv6 disabled but our cluster could be bound to IPv6 if the host supports it
105
- task enableIPv6 {
106
- dependsOn unzipWildfly
107
- doLast {
108
- final File standaloneConf = file(" ${ wildflyInstall} /bin/standalone.conf" )
109
- final List<String > lines =
110
- Files . readAllLines(standaloneConf. toPath())
111
- .collect { line -> line. replace(" -Djava.net.preferIPv4Stack=true" , " -Djava.net.preferIPv4Stack=false" ) }
112
- standaloneConf. write(lines. join(" \n " ))
113
- }
64
+ preProcessFixture {
65
+ dependsOn war, elasticsearch_distributions. docker
114
66
}
115
67
116
- task startWildfly {
117
- dependsOn enableIPv6, writeElasticsearchProperties
118
- doLast {
119
- // we skip these tests on Windows so we do no need to worry about compatibility here
120
- final ProcessBuilder wildfly = new ProcessBuilder (
121
- " ${ wildflyInstall} /bin/standalone.sh" ,
122
- " -Djboss.http.port=0" ,
123
- " -Djboss.https.port=0" ,
124
- " -Djboss.management.http.port=0" )
125
- final Process process = wildfly. start()
126
- new BufferedReader (new InputStreamReader (process. getInputStream())). withReader { br ->
127
- String line
128
- int httpPort = 0
129
- while ((line = br. readLine()) != null ) {
130
- logger. info(line)
131
- if (line. matches(' .*Undertow HTTP listener default listening on .*:\\ d+$' )) {
132
- assert httpPort == 0
133
- final int index = line. lastIndexOf(" :" )
134
- assert index >= 0
135
- httpPort = Integer . parseInt(line. substring(index + 1 ))
136
- // set this system property so the test runner knows the port Wildfly is listening for HTTP requests on
137
- integTestRunner. systemProperty(" tests.jboss.root" , " http://localhost:$httpPort /wildfly-$version /transport" )
138
- } else if (line. matches(' .*Http management interface listening on http://.*:\\ d+/management$' )) {
139
- assert managementPort == 0
140
- final int colonIndex = line. lastIndexOf(" :" )
141
- assert colonIndex >= 0
142
- final int slashIndex = line. lastIndexOf(" /" )
143
- assert slashIndex >= 0
144
- managementPort = Integer . parseInt(line. substring(colonIndex + 1 , slashIndex))
145
-
146
- /*
147
- * As soon as we know the management port, we fork a process that will ensure the Wildfly process is killed if we
148
- * teardown abnormally. We skip these tests on Windows so we do not need to worry about CLI compatibility here.
149
- */
150
- final File script = new File (project. buildDir, " wildfly/wildfly.killer.sh" )
151
- script. setText(
152
- [" function shutdown {" ,
153
- " ${ wildflyInstall} /bin/jboss-cli.sh --controller=localhost:${ -> managementPort} --connect command=shutdown" ,
154
- " }" ,
155
- " trap shutdown EXIT" ,
156
- // will wait indefinitely for input, but we never pass input, and the pipe is only closed when the build dies
157
- " read line\n " ]. join(' \n ' ), ' UTF-8' )
158
- final ProcessBuilder killer = new ProcessBuilder (" bash" , script. absolutePath)
159
- killer. start()
160
-
161
- } else if (line. matches(" .*WildFly Full \\ d+\\ .\\ d+\\ .\\ d+\\ .Final \\ (WildFly Core \\ d+\\ .\\ d+\\ .\\ d+\\ .Final\\ ) started.*" )) {
162
- break
163
- }
164
- }
165
-
166
- if (httpPort == 0 || managementPort == 0 ) {
167
- String portType = httpPort == 0 ? " http" : " management"
168
- throw new GradleException (" Failed to find ${ portType} port in wildfly log" )
169
- }
170
- }
68
+ dockerCompose {
69
+ if (' default' . equalsIgnoreCase(System . getProperty(' tests.distribution' , ' default' ))) {
70
+ useComposeFiles = [' docker-compose.yml' ]
71
+ } else {
72
+ useComposeFiles = [' docker-compose-oss.yml' ]
171
73
}
172
74
}
173
75
174
- task configureClient (type : LoggedExec ) {
175
- dependsOn startWildfly
176
- // we skip these tests on Windows so we do not need to worry about compatibility here
177
- commandLine " ${ wildflyInstall} /bin/jboss-cli.sh" ,
178
- " --controller=localhost:${ -> managementPort} " ,
179
- " --connect" ,
180
- " --command=/system-property=elasticsearch.properties:add(value=\$ {jboss.server.config.dir}/elasticsearch.properties)"
181
- }
182
-
183
- task stopWildfly (type : LoggedExec ) {
184
- // we skip these tests on Windows so we do not need to worry about CLI compatibility here
185
- commandLine " ${ wildflyInstall} /bin/jboss-cli.sh" , " --controller=localhost:${ -> managementPort} " , " --connect" , " command=shutdown"
186
- }
187
-
188
- if (! Os . isFamily(Os . FAMILY_WINDOWS )) {
189
- integTestRunner. dependsOn(configureClient)
190
- final TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter () {
191
- @Override
192
- void afterExecute (final Task task , final TaskState state ) {
193
- if (task != startWildfly && task != integTestRunner) {
194
- // we might have been called from a parallel, unrelated task
195
- return
196
- }
197
- if (state. failure != null ) {
198
- final File logFile = new File (wildflyInstall, " standalone/log/server.log" )
199
- println (" \n Wildfly server log (from ${ logFile} ):" )
200
- println (' -----------------------------------------' )
201
- final Stream<String > stream = Files . lines(logFile. toPath(), StandardCharsets . UTF_8 )
202
- try {
203
- for (String line : stream) {
204
- println (line)
205
- }
206
- } finally {
207
- stream. close()
208
- }
209
- println (' =========================================' )
210
- }
211
- }
212
- }
213
- startWildfly. doFirst {
214
- project. gradle. addListener(logDumpListener)
215
- }
216
- integTestRunner. doFirst {
217
- project. gradle. addListener(logDumpListener)
218
- }
219
- integTestRunner. doLast {
220
- project. gradle. removeListener(logDumpListener)
221
- }
222
- startWildfly. doLast {
223
- project. gradle. removeListener(logDumpListener)
224
- }
225
- integTestRunner. finalizedBy(stopWildfly)
226
- } else {
227
- integTest. enabled = false
228
- testingConventions. enabled = false
76
+ task integTest (type : Test ) {
77
+ outputs. doNotCacheIf(' Build cache is disabled for Docker tests' ) { true }
78
+ maxParallelForks = ' 1'
79
+ include ' **/*IT.class'
229
80
}
230
81
231
- check. dependsOn( integTest)
82
+ check. dependsOn integTest
232
83
233
84
test. enabled = false
234
85
0 commit comments