Skip to content

Commit 2d852b9

Browse files
committed
Add QA project and fixture based test for discovery-ec2 plugin
This commit adds a new QA sub project to the discovery-ec2 plugin. This project uses a fixture to test the plugin using a multi-node cluster. Once all nodes are started, the nodes transport addresses are written in a file that is later read by the fixture.
1 parent bbfe1ec commit 2d852b9

File tree

6 files changed

+266
-108
lines changed

6 files changed

+266
-108
lines changed

plugins/discovery-ec2/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ test {
5353
systemProperty 'tests.artifact', project.name
5454
}
5555

56+
check {
57+
// also execute the QA tests when testing the plugin
58+
dependsOn 'qa:amazon-ec2:check'
59+
}
60+
5661
thirdPartyAudit.excludes = [
5762
// classes are missing
5863
'com.amazonaws.jmespath.JmesPathEvaluationVisitor',
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
21+
import org.elasticsearch.gradle.MavenFilteringHack
22+
import org.elasticsearch.gradle.test.AntFixture
23+
24+
apply plugin: 'elasticsearch.standalone-rest-test'
25+
apply plugin: 'elasticsearch.rest-test'
26+
27+
dependencies {
28+
testCompile project(path: ':plugins:discovery-ec2', configuration: 'runtime')
29+
}
30+
31+
forbiddenApisTest {
32+
// we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage
33+
bundledSignatures -= 'jdk-non-portable'
34+
bundledSignatures += 'jdk-internal'
35+
}
36+
37+
final int ec2NumberOfNodes = 3
38+
File ec2DiscoveryFile = new File(project.buildDir, 'generated-resources/nodes.uri')
39+
40+
/** A task to start the AmazonEC2Fixture which emulates an EC2 service **/
41+
task ec2Fixture(type: AntFixture) {
42+
dependsOn compileTestJava
43+
env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
44+
executable = new File(project.runtimeJavaHome, 'bin/java')
45+
args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, ec2DiscoveryFile.absolutePath
46+
}
47+
48+
Map<String, Object> expansions = [
49+
'expected_nodes': ec2NumberOfNodes
50+
]
51+
52+
processTestResources {
53+
inputs.properties(expansions)
54+
MavenFilteringHack.filter(it, expansions)
55+
}
56+
57+
integTestCluster {
58+
dependsOn ec2Fixture
59+
numNodes = ec2NumberOfNodes
60+
plugin ':plugins:discovery-ec2'
61+
keystoreSetting 'discovery.ec2.access_key', 'ec2_integration_test_access_key'
62+
keystoreSetting 'discovery.ec2.secret_key', 'ec2_integration_test_secret_key'
63+
setting 'discovery.zen.hosts_provider', 'ec2'
64+
setting 'discovery.ec2.endpoint', "http://${-> ec2Fixture.addressAndPort}"
65+
unicastTransportUri = { seedNode, node, ant -> return null }
66+
67+
waitCondition = { node, ant ->
68+
ec2DiscoveryFile.parentFile.mkdirs()
69+
ec2DiscoveryFile.setText(integTest.nodes.collect { n -> "${n.transportUri()}" }.join('\n'), 'UTF-8')
70+
71+
File tmpFile = new File(node.cwd, 'wait.success')
72+
ant.get(src: "http://${node.httpUri()}/_cluster/health?wait_for_nodes=>=${ec2NumberOfNodes}&wait_for_status=yellow",
73+
dest: tmpFile.toString(),
74+
ignoreerrors: true,
75+
retries: 10)
76+
return tmpFile.exists()
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.discovery.ec2;
21+
22+
import com.carrotsearch.randomizedtesting.annotations.Name;
23+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
24+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
25+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
26+
27+
public class AmazonEC2DiscoveryClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
28+
29+
public AmazonEC2DiscoveryClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
30+
super(testCandidate);
31+
}
32+
33+
@ParametersFactory
34+
public static Iterable<Object[]> parameters() throws Exception {
35+
return ESClientYamlSuiteTestCase.createParameters();
36+
}
37+
}

0 commit comments

Comments
 (0)