Skip to content

Commit 38ecfab

Browse files
authored
Convert Wildfly tests to run in Docker (#53126)
Closes #49374. Convert the Wildfly tests to run using Docker Compose. This drastically simplifies the build setup, and will hopefully make the tests more resilient.
1 parent 883104f commit 38ecfab

File tree

8 files changed

+149
-228
lines changed

8 files changed

+149
-228
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ subprojects {
115115
':distribution:tools:launchers',
116116
':distribution:tools:plugin-cli',
117117
':qa:os',
118+
':qa:wildfly',
118119
':x-pack:plugin:autoscaling',
119120
':x-pack:plugin:enrich'
120121
]

qa/wildfly/build.gradle

Lines changed: 25 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
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-
101
/*
112
* Licensed to Elasticsearch under one or more contributor
123
* license agreements. See the NOTICE file distributed with
@@ -26,33 +17,14 @@ import java.util.stream.Stream
2617
* under the License.
2718
*/
2819

20+
import org.elasticsearch.gradle.VersionProperties
21+
2922
apply plugin: 'war'
30-
apply plugin: 'elasticsearch.testclusters'
3123
apply plugin: 'elasticsearch.build'
32-
apply plugin: 'elasticsearch.rest-test'
24+
apply plugin: 'elasticsearch.test.fixtures'
25+
apply plugin: 'elasticsearch.distribution-download'
3326

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()
5628

5729
dependencies {
5830
providedCompile 'javax.enterprise:cdi-api:1.2'
@@ -73,162 +45,41 @@ dependencies {
7345
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
7446
compile "org.apache.logging.log4j:log4j-core:${versions.log4j}"
7547
compile project(path: ':client:rest-high-level', configuration: 'shadow')
76-
wildfly "org.jboss:wildfly:${wildflyVersion}@zip"
7748
testCompile project(':test:framework')
7849
}
7950

80-
task unzipWildfly(type: Sync) {
81-
into wildflyDir
82-
from { zipTree(configurations.wildfly.singleFile) }
51+
war {
52+
archiveName 'example-app.war'
8353
}
8454

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
10161
}
10262
}
10363

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
11466
}
11567

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']
17173
}
17274
}
17375

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("\nWildfly 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'
22980
}
23081

231-
check.dependsOn(integTest)
82+
check.dependsOn integTest
23283

23384
test.enabled = false
23485

qa/wildfly/docker-compose-oss.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3.7'
2+
services:
3+
4+
wildfly:
5+
image: jboss/wildfly:18.0.1.Final
6+
environment:
7+
JAVA_OPTS: -Delasticsearch.uri=elasticsearch:9200 -Djboss.http.port=8080 -Djava.net.preferIPv4Stack=true
8+
volumes:
9+
- ./build/distributions/example-app.war:/opt/jboss/wildfly/standalone/deployments/example-app.war
10+
ports:
11+
- "8080"
12+
healthcheck:
13+
start_period: 5s
14+
test: ["CMD", "grep", "Admin console listening on", "/opt/jboss/wildfly/standalone/log/server.log"]
15+
interval: 2s
16+
timeout: 1s
17+
retries: 5
18+
19+
elasticsearch:
20+
image: elasticsearch-oss:test
21+
environment:
22+
discovery.type: single-node
23+
ulimits:
24+
memlock:
25+
soft: -1
26+
hard: -1
27+
nofile:
28+
soft: 65536
29+
hard: 65536
30+
healthcheck:
31+
start_period: 15s
32+
test: ["CMD", "curl", "-f", "-k", "http://localhost:9200"]
33+
interval: 10s
34+
timeout: 2s
35+
retries: 5

qa/wildfly/docker-compose.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '3.7'
2+
services:
3+
4+
wildfly:
5+
image: jboss/wildfly:18.0.1.Final
6+
environment:
7+
JAVA_OPTS: -Delasticsearch.uri=elasticsearch:9200 -Djboss.http.port=8080 -Djava.net.preferIPv4Stack=true
8+
volumes:
9+
- ./build/distributions/example-app.war:/opt/jboss/wildfly/standalone/deployments/example-app.war
10+
ports:
11+
- "8080"
12+
healthcheck:
13+
start_period: 5s
14+
test: ["CMD", "grep", "Admin console listening on", "/opt/jboss/wildfly/standalone/log/server.log"]
15+
interval: 2s
16+
timeout: 1s
17+
retries: 5
18+
19+
elasticsearch:
20+
image: elasticsearch:test
21+
environment:
22+
discovery.type: single-node
23+
ulimits:
24+
memlock:
25+
soft: -1
26+
hard: -1
27+
nofile:
28+
soft: 65536
29+
hard: 65536
30+
healthcheck:
31+
start_period: 15s
32+
test: ["CMD", "curl", "-f", "-k", "http://localhost:9200"]
33+
interval: 10s
34+
timeout: 2s
35+
retries: 5

qa/wildfly/src/main/java/org/elasticsearch/wildfly/transport/RestHighLevelClientEmployeeResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public Response getEmployeeById(final @PathParam("id") Long id) throws IOExcepti
6464
employee.setLastName((String) source.get("last_name"));
6565
employee.setAge((Integer) source.get("age"));
6666
employee.setAbout((String) source.get("about"));
67-
@SuppressWarnings("unchecked") final List<String> interests = (List<String>) source.get("interests");
67+
@SuppressWarnings("unchecked")
68+
final List<String> interests = (List<String>) source.get("interests");
6869
employee.setInterests(interests);
6970
return Response.ok(employee).build();
7071
} else {

qa/wildfly/src/main/java/org/elasticsearch/wildfly/transport/RestHighLevelClientProducer.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@
2626
import org.elasticsearch.common.io.PathUtils;
2727

2828
import javax.enterprise.inject.Produces;
29-
import java.io.IOException;
30-
import java.io.InputStream;
31-
import java.nio.file.Files;
3229
import java.nio.file.Path;
33-
import java.util.Properties;
3430

3531
@SuppressWarnings("unused")
3632
public final class RestHighLevelClientProducer {
3733

3834
@Produces
39-
public RestHighLevelClient createRestHighLevelClient() throws IOException {
40-
final String elasticsearchProperties = System.getProperty("elasticsearch.properties");
41-
final Properties properties = new Properties();
42-
43-
final String httpUri;
44-
try (InputStream is = Files.newInputStream(getPath(elasticsearchProperties))) {
45-
properties.load(is);
46-
httpUri = properties.getProperty("http.uri");
47-
}
35+
public RestHighLevelClient createRestHighLevelClient() {
36+
String httpUri = System.getProperty("elasticsearch.uri");
4837

4938
return new RestHighLevelClient(RestClient.builder(HttpHost.create(httpUri)));
5039
}
@@ -53,5 +42,4 @@ public RestHighLevelClient createRestHighLevelClient() throws IOException {
5342
private Path getPath(final String elasticsearchProperties) {
5443
return PathUtils.get(elasticsearchProperties);
5544
}
56-
5745
}

qa/wildfly/src/main/java/org/elasticsearch/wildfly/transport/RestHighLevelJacksonJsonProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525

2626
@Provider
2727
public class RestHighLevelJacksonJsonProvider extends ResteasyJackson2Provider {
28+
2829
}

0 commit comments

Comments
 (0)