Skip to content

Commit 05560c7

Browse files
authored
Testclusters: convert left-overs from checkPart1 (#43370)
* Testclusters: convert left-overs from checkPart1
1 parent 2a8cb74 commit 05560c7

File tree

10 files changed

+64
-48
lines changed

10 files changed

+64
-48
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,19 @@ public void setJavaHome(File javaHome) {
217217

218218
@Override
219219
public void start() {
220-
String nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
220+
final String nodeNames;
221+
if (nodes.stream().map(ElasticsearchNode::getName).anyMatch( name -> name == null)) {
222+
nodeNames = null;
223+
} else {
224+
nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
225+
};
221226
for (ElasticsearchNode node : nodes) {
222-
if (Version.fromString(node.getVersion()).getMajor() >= 7) {
223-
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
224-
node.defaultConfig.put("discovery.seed_providers", "file");
227+
if (nodeNames != null) {
228+
// Can only configure master nodes if we have node names defined
229+
if (Version.fromString(node.getVersion()).getMajor() >= 7) {
230+
node.defaultConfig.put("cluster.initial_master_nodes", "[" + nodeNames + "]");
231+
node.defaultConfig.put("discovery.seed_providers", "file");
232+
}
225233
}
226234
node.start();
227235
}

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,10 @@ private void syncWithLinks(Path sourceRoot, Path destinationRoot) {
732732
}
733733

734734
private void createConfiguration() {
735-
defaultConfig.put("node.name", nameCustomization.apply(safeName(name)));
735+
String nodeName = nameCustomization.apply(safeName(name));
736+
if (nodeName != null) {
737+
defaultConfig.put("node.name", nodeName);
738+
}
736739
defaultConfig.put("path.repo", confPathRepo.toAbsolutePath().toString());
737740
defaultConfig.put("path.data", confPathData.toAbsolutePath().toString());
738741
defaultConfig.put("path.logs", confPathLogs.toAbsolutePath().toString());

qa/build.gradle

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11

22
import org.elasticsearch.gradle.test.RestIntegTestTask
3+
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
34

45
subprojects { Project subproj ->
56
subproj.tasks.withType(RestIntegTestTask) {
6-
subproj.extensions.configure("${it.name}Cluster") { cluster ->
7-
cluster.distribution = System.getProperty('tests.distribution', 'oss')
8-
if (cluster.distribution == 'default') {
9-
/*
10-
* Add Elastic's repositories so we can resolve older versions of the
11-
* default distribution. Those aren't in maven central.
12-
*/
13-
repositories {
14-
maven {
15-
name "elastic"
16-
url "https://artifacts.elastic.co/maven"
17-
}
18-
maven {
19-
name "elastic-snapshots"
20-
url "https://snapshots.elastic.co/maven"
21-
}
22-
}
7+
if (subproj.extensions.findByName("${it.name}Cluster")) {
8+
subproj.extensions.configure("${it.name}Cluster") { cluster ->
9+
cluster.distribution = System.getProperty('tests.distribution', 'oss')
10+
}
11+
}
12+
}
13+
plugins.withType(TestClustersPlugin).whenPluginAdded {
14+
afterEvaluate {
15+
// We need to delay this so it's not overwritten in RestIntegTestTask
16+
testClusters.all {
17+
distribution = System.getProperty('tests.distribution', 'oss').toUpperCase()
2318
}
2419
}
2520
}

qa/logging-config/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
* under the License.
1818
*/
1919

20-
20+
apply plugin: 'elasticsearch.testclusters'
2121
apply plugin: 'elasticsearch.standalone-rest-test'
2222
apply plugin: 'elasticsearch.rest-test'
2323
apply plugin: 'elasticsearch.standalone-test'
2424

25-
integTestCluster {
25+
testClusters.integTest {
2626
/**
2727
* Provide a custom log4j configuration where layout is an old style pattern and confirm that Elasticsearch
2828
* can successfully startup.
2929
*/
30-
extraConfigFile 'log4j2.properties', 'custom-log4j2.properties'
30+
extraConfigFile 'log4j2.properties', file('custom-log4j2.properties')
3131
}
3232

33-
integTestRunner {
33+
integTest.runner {
3434
nonInputProperties.systemProperty 'tests.logfile',
35-
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_server.log"
35+
"${ -> testClusters.integTest.singleNode().getServerLog().absolutePath.replaceAll(".json", ".log")}"
3636
}
3737

3838
test {

qa/logging-config/src/test/java/org/elasticsearch/qa/custom_logging/CustomLoggingConfigIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* The intention is to confirm that users can still run their Elasticsearch instances with previous configurations.
4141
*/
4242
public class CustomLoggingConfigIT extends ESRestTestCase {
43-
private static final String NODE_STARTED = ".*node-0.*cluster.uuid.*node.id.*recovered.*cluster_state.*";
43+
private static final String NODE_STARTED = ".*integTest-0.*cluster.uuid.*node.id.*recovered.*cluster_state.*";
4444

4545
public void testSuccessfulStartupWithCustomConfig() throws Exception {
4646
assertBusy(() -> {

qa/smoke-test-ingest-disabled/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
* under the License.
1818
*/
1919

20+
apply plugin: 'elasticsearch.testclusters'
2021
apply plugin: 'elasticsearch.standalone-rest-test'
2122
apply plugin: 'elasticsearch.rest-test'
2223

2324
dependencies {
2425
testCompile project(path: ':modules:ingest-common', configuration: 'runtime')
2526
}
2627

27-
integTestCluster {
28+
testClusters.integTest {
2829
setting 'node.ingest', 'false'
2930
}

qa/smoke-test-multinode/build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@
1717
* under the License.
1818
*/
1919

20+
apply plugin: 'elasticsearch.testclusters'
2021
apply plugin: 'elasticsearch.standalone-rest-test'
2122
apply plugin: 'elasticsearch.rest-test'
2223

2324
integTest {
2425
includePackaged = true
2526
}
2627

27-
integTestCluster {
28-
numNodes = 2
28+
File repo = file("$buildDir/testclusters/repo")
29+
testClusters.integTest {
30+
numberOfNodes = 2
31+
setting 'path.repo', repo.absolutePath
2932
}
3033

31-
integTestRunner {
32-
if ('default'.equals(integTestCluster.distribution)) {
34+
integTest.runner {
35+
doFirst {
36+
project.delete(repo)
37+
repo.mkdirs()
38+
}
39+
if ('default'.equalsIgnoreCase(System.getProperty('tests.distribution', 'oss'))) {
3340
systemProperty 'tests.rest.blacklist', [
3441
'cat.templates/10_basic/No templates',
3542
'cat.templates/10_basic/Sort templates',

qa/smoke-test-plugins/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
import org.elasticsearch.gradle.MavenFilteringHack
2121

22+
apply plugin: 'elasticsearch.testclusters'
2223
apply plugin: 'elasticsearch.standalone-rest-test'
2324
apply plugin: 'elasticsearch.rest-test'
2425

25-
ext.pluginsCount = 0
26-
project(':plugins').getChildProjects().each { pluginName, pluginProject ->
27-
integTestCluster {
28-
plugin pluginProject.path
26+
int pluginsCount = 0
27+
28+
testClusters.integTest {
29+
project(':plugins').getChildProjects().each { pluginName, pluginProject ->
30+
plugin file(pluginProject.tasks.bundlePlugin.archiveFile)
31+
tasks.integTest.dependsOn pluginProject.tasks.bundlePlugin
32+
pluginsCount += 1
2933
}
30-
pluginsCount += 1
3134
}
3235
assert pluginsCount > 0
3336

qa/unconfigured-node-name/build.gradle

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
* under the License.
1818
*/
1919

20+
apply plugin: 'elasticsearch.testclusters'
2021
apply plugin: 'elasticsearch.standalone-rest-test'
2122
apply plugin: 'elasticsearch.rest-test'
2223

23-
integTestCluster {
24-
setting 'node.name', null
25-
// Run with no discovery configuration at all, demonstrating that a node in its
26-
// "out-of-the-box" configuration can automatically bootstrap a cluster
27-
autoSetInitialMasterNodes = false
28-
autoSetHostsProvider = false
24+
testClusters.integTest {
25+
nameCustomization = { null }
2926
}
3027

31-
integTestRunner {
28+
integTest.runner {
3229
nonInputProperties.systemProperty 'tests.logfile',
33-
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_server.json"
30+
"${ -> testClusters.integTest.singleNode().getServerLog() }"
3431
}

qa/wildfly/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import java.util.stream.Stream
2626
*/
2727

2828
apply plugin: 'war'
29+
apply plugin: 'elasticsearch.testclusters'
2930
apply plugin: 'elasticsearch.build'
3031
apply plugin: 'elasticsearch.rest-test'
3132

@@ -88,12 +89,13 @@ task deploy(type: Copy) {
8889

8990
task writeElasticsearchProperties {
9091
onlyIf { !Os.isFamily(Os.FAMILY_WINDOWS) }
91-
dependsOn 'integTestCluster#wait', deploy
92+
useCluster testClusters.integTest
93+
dependsOn deploy
9294
doLast {
9395
final File elasticsearchProperties = file("${wildflyInstall}/standalone/configuration/elasticsearch.properties")
9496
elasticsearchProperties.write(
9597
[
96-
"http.uri=${-> integTest.getNodes().get(0).httpUri()}"
98+
"http.uri=${-> testClusters.integTest.getAllHttpSocketURI().get(0)}"
9799
].join("\n"))
98100
}
99101
}

0 commit comments

Comments
 (0)