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'
@@ -72,164 +44,42 @@ dependencies {
72
44
compile " com.fasterxml.jackson.module:jackson-module-jaxb-annotations:${ versions.jackson} "
73
45
compile " org.apache.logging.log4j:log4j-api:${ versions.log4j} "
74
46
compile " org.apache.logging.log4j:log4j-core:${ versions.log4j} "
75
- compile project(path : ' :client:transport' , configuration : ' runtime' )
76
- wildfly " org.jboss:wildfly:${ wildflyVersion} @zip"
47
+ compile project(path : ' :client:rest-high-level' )
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
- " transport.uri=${ -> testClusters.integTest.getAllTransportPortURI().get(0)} " ,
100
- " cluster.name=integTest"
101
- ]. 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
102
61
}
103
62
}
104
63
105
- // the default configuration ships with IPv6 disabled but our cluster could be bound to IPv6 if the host supports it
106
- task enableIPv6 {
107
- dependsOn unzipWildfly
108
- doLast {
109
- final File standaloneConf = file(" ${ wildflyInstall} /bin/standalone.conf" )
110
- final List<String > lines =
111
- Files . readAllLines(standaloneConf. toPath())
112
- .collect { line -> line. replace(" -Djava.net.preferIPv4Stack=true" , " -Djava.net.preferIPv4Stack=false" ) }
113
- standaloneConf. write(lines. join(" \n " ))
114
- }
64
+ preProcessFixture {
65
+ dependsOn war, elasticsearch_distributions. docker
115
66
}
116
67
117
- task startWildfly {
118
- dependsOn enableIPv6, writeElasticsearchProperties
119
- doLast {
120
- // we skip these tests on Windows so we do no need to worry about compatibility here
121
- final ProcessBuilder wildfly = new ProcessBuilder (
122
- " ${ wildflyInstall} /bin/standalone.sh" ,
123
- " -Djboss.http.port=0" ,
124
- " -Djboss.https.port=0" ,
125
- " -Djboss.management.http.port=0" )
126
- final Process process = wildfly. start()
127
- new BufferedReader (new InputStreamReader (process. getInputStream())). withReader { br ->
128
- String line
129
- int httpPort = 0
130
- while ((line = br. readLine()) != null ) {
131
- logger. info(line)
132
- if (line. matches(' .*Undertow HTTP listener default listening on .*:\\ d+$' )) {
133
- assert httpPort == 0
134
- final int index = line. lastIndexOf(" :" )
135
- assert index >= 0
136
- httpPort = Integer . parseInt(line. substring(index + 1 ))
137
- // set this system property so the test runner knows the port Wildfly is listening for HTTP requests on
138
- integTestRunner. systemProperty(" tests.jboss.root" , " http://localhost:$httpPort /wildfly-$version /transport" )
139
- } else if (line. matches(' .*Http management interface listening on http://.*:\\ d+/management$' )) {
140
- assert managementPort == 0
141
- final int colonIndex = line. lastIndexOf(" :" )
142
- assert colonIndex >= 0
143
- final int slashIndex = line. lastIndexOf(" /" )
144
- assert slashIndex >= 0
145
- managementPort = Integer . parseInt(line. substring(colonIndex + 1 , slashIndex))
146
-
147
- /*
148
- * As soon as we know the management port, we fork a process that will ensure the Wildfly process is killed if we
149
- * teardown abnormally. We skip these tests on Windows so we do not need to worry about CLI compatibility here.
150
- */
151
- final File script = new File (project. buildDir, " wildfly/wildfly.killer.sh" )
152
- script. setText(
153
- [" function shutdown {" ,
154
- " ${ wildflyInstall} /bin/jboss-cli.sh --controller=localhost:${ -> managementPort} --connect command=shutdown" ,
155
- " }" ,
156
- " trap shutdown EXIT" ,
157
- // will wait indefinitely for input, but we never pass input, and the pipe is only closed when the build dies
158
- " read line\n " ]. join(' \n ' ), ' UTF-8' )
159
- final ProcessBuilder killer = new ProcessBuilder (" bash" , script. absolutePath)
160
- killer. start()
161
-
162
- } else if (line. matches(" .*WildFly Full \\ d+\\ .\\ d+\\ .\\ d+\\ .Final \\ (WildFly Core \\ d+\\ .\\ d+\\ .\\ d+\\ .Final\\ ) started.*" )) {
163
- break
164
- }
165
- }
166
-
167
- if (httpPort == 0 || managementPort == 0 ) {
168
- String portType = httpPort == 0 ? " http" : " management"
169
- throw new GradleException (" Failed to find ${ portType} port in wildfly log" )
170
- }
171
- }
68
+ dockerCompose {
69
+ if (' default' . equalsIgnoreCase(System . getProperty(' tests.distribution' , ' default' ))) {
70
+ useComposeFiles = [' docker-compose.yml' ]
71
+ } else {
72
+ useComposeFiles = [' docker-compose-oss.yml' ]
172
73
}
173
74
}
174
75
175
- task configureTransportClient (type : LoggedExec ) {
176
- dependsOn startWildfly
177
- // we skip these tests on Windows so we do not need to worry about compatibility here
178
- commandLine " ${ wildflyInstall} /bin/jboss-cli.sh" ,
179
- " --controller=localhost:${ -> managementPort} " ,
180
- " --connect" ,
181
- " --command=/system-property=elasticsearch.properties:add(value=\$ {jboss.server.config.dir}/elasticsearch.properties)"
182
- }
183
-
184
- task stopWildfly (type : LoggedExec ) {
185
- // we skip these tests on Windows so we do not need to worry about CLI compatibility here
186
- commandLine " ${ wildflyInstall} /bin/jboss-cli.sh" , " --controller=localhost:${ -> managementPort} " , " --connect" , " command=shutdown"
187
- }
188
-
189
- if (! Os . isFamily(Os . FAMILY_WINDOWS )) {
190
- integTestRunner. dependsOn(configureTransportClient)
191
- final TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter () {
192
- @Override
193
- void afterExecute (final Task task , final TaskState state ) {
194
- if (task != startWildfly && task != integTestRunner) {
195
- // we might have been called from a parallel, unrelated task
196
- return
197
- }
198
- if (state. failure != null ) {
199
- final File logFile = new File (wildflyInstall, " standalone/log/server.log" )
200
- println (" \n Wildfly server log (from ${ logFile} ):" )
201
- println (' -----------------------------------------' )
202
- final Stream<String > stream = Files . lines(logFile. toPath(), StandardCharsets . UTF_8 )
203
- try {
204
- for (String line : stream) {
205
- println (line)
206
- }
207
- } finally {
208
- stream. close()
209
- }
210
- println (' =========================================' )
211
- }
212
- }
213
- }
214
- startWildfly. doFirst {
215
- project. gradle. addListener(logDumpListener)
216
- }
217
- integTestRunner. doFirst {
218
- project. gradle. addListener(logDumpListener)
219
- }
220
- integTestRunner. doLast {
221
- project. gradle. removeListener(logDumpListener)
222
- }
223
- startWildfly. doLast {
224
- project. gradle. removeListener(logDumpListener)
225
- }
226
- integTestRunner. finalizedBy(stopWildfly)
227
- } else {
228
- integTest. enabled = false
229
- 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'
230
80
}
231
81
232
- check. dependsOn( integTest)
82
+ check. dependsOn integTest
233
83
234
84
test. enabled = false
235
85
0 commit comments