Skip to content

Add support for switching distribution for all integration tests #30874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public class PluginBuildPlugin extends BuildPlugin {
if (isModule) {
project.integTestCluster.module(project)
project.tasks.run.clusterConfig.module(project)
project.tasks.run.clusterConfig.distribution = 'integ-test-zip'
project.tasks.run.clusterConfig.distribution = System.getProperty(
'run.distribution', 'integ-test-zip'
)
} else {
project.integTestCluster.plugin(project.path)
project.tasks.run.clusterConfig.plugin(project.path)
Expand Down Expand Up @@ -111,7 +113,7 @@ public class PluginBuildPlugin extends BuildPlugin {
private static void createIntegTestTask(Project project) {
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
integTest.mustRunAfter(project.precommit, project.test)
project.integTestCluster.distribution = 'integ-test-zip'
project.integTestCluster.distribution = System.getProperty('tests.distribution', 'integ-test-zip')
project.check.dependsOn(integTest)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ class ClusterFormationTasks {

static Task configureInstallModuleTask(String name, Project project, Task setup, NodeInfo node, Project module) {
if (node.config.distribution != 'integ-test-zip') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using a non integ-test-zip distribution, modules need to not be installed at all. This looks like it allows installing them over what the distribution installs, which could create craziness. I think we need to skip setting up install module tasks if the distribution is not integ-test-zip.

throw new GradleException("Module ${module.path} not allowed be installed distributions other than integ-test-zip because they should already have all modules bundled!")
project.logger.lifecycle("Not installing modules for $name, ${node.config.distribution} already has them")
return setup
}
if (module.plugins.hasPlugin(PluginBuildPlugin) == false) {
throw new GradleException("Task ${name} cannot include module ${module.path} which is not an esplugin")
Expand Down Expand Up @@ -643,6 +644,9 @@ class ClusterFormationTasks {
BuildPlugin.requireJavaHome(start, node.javaVersion)
}
start.doLast(elasticsearchRunner)
start.doFirst {
project.logger.info("Starting node in ${node.clusterName} distribution: ${node.config.distribution}")
}
return start
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: aggs-matrix-stats }
- match: { nodes.$master.modules: { name: aggs-matrix-stats } }
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: analysis-common }
- match: { nodes.$master.modules: { name: analysis-common } }
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: ingest-common }
- match: { nodes.$master.ingest.processors.0.type: append }
- match: { nodes.$master.ingest.processors.1.type: convert }
- match: { nodes.$master.ingest.processors.2.type: date }
- match: { nodes.$master.ingest.processors.3.type: date_index_name }
- match: { nodes.$master.ingest.processors.4.type: dot_expander }
- match: { nodes.$master.ingest.processors.5.type: fail }
- match: { nodes.$master.ingest.processors.6.type: foreach }
- match: { nodes.$master.ingest.processors.7.type: grok }
- match: { nodes.$master.ingest.processors.8.type: gsub }
- match: { nodes.$master.ingest.processors.9.type: join }
- match: { nodes.$master.ingest.processors.10.type: json }
- match: { nodes.$master.ingest.processors.11.type: kv }
- match: { nodes.$master.ingest.processors.12.type: lowercase }
- match: { nodes.$master.ingest.processors.13.type: remove }
- match: { nodes.$master.ingest.processors.14.type: rename }
- match: { nodes.$master.ingest.processors.15.type: script }
- match: { nodes.$master.ingest.processors.16.type: set }
- match: { nodes.$master.ingest.processors.17.type: sort }
- match: { nodes.$master.ingest.processors.18.type: split }
- match: { nodes.$master.ingest.processors.19.type: trim }
- match: { nodes.$master.ingest.processors.20.type: uppercase }
- match: { nodes.$master.modules: { name: ingest-common } }
- match: { nodes.$master.ingest.processors: { type: append } }
- match: { nodes.$master.ingest.processors: { type: convert } }
- match: { nodes.$master.ingest.processors: { type: date } }
- match: { nodes.$master.ingest.processors: { type: date_index_name } }
- match: { nodes.$master.ingest.processors: { type: dot_expander } }
- match: { nodes.$master.ingest.processors: { type: fail } }
- match: { nodes.$master.ingest.processors: { type: foreach } }
- match: { nodes.$master.ingest.processors: { type: grok } }
- match: { nodes.$master.ingest.processors: { type: gsub } }
- match: { nodes.$master.ingest.processors: { type: join } }
- match: { nodes.$master.ingest.processors: { type: json } }
- match: { nodes.$master.ingest.processors: { type: kv } }
- match: { nodes.$master.ingest.processors: { type: lowercase } }
- match: { nodes.$master.ingest.processors: { type: remove } }
- match: { nodes.$master.ingest.processors: { type: rename } }
- match: { nodes.$master.ingest.processors: { type: script } }
- match: { nodes.$master.ingest.processors: { type: set } }
- match: { nodes.$master.ingest.processors: { type: sort } }
- match: { nodes.$master.ingest.processors: { type: split } }
- match: { nodes.$master.ingest.processors: { type: trim } }
- match: { nodes.$master.ingest.processors: { type: uppercase } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: lang-expression }
- match: { nodes.$master.modules: { name: lang-expression } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: lang-mustache }
- match: { nodes.$master.modules: { name: lang-mustache } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: lang-painless }
- match: { nodes.$master.modules: { name: lang-painless } }
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ teardown:
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: repository-url }
- match: { nodes.$master.modules: { name: repository-url } }

---
"Restore with repository-url using http://":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- do:
nodes.info: {}

- match: { nodes.$master.modules.0.name: transport-netty4 }
- match: { nodes.$master.modules: { name: transport-netty4 } }

- do:
cluster.stats: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: discovery-azure-classic }
- match: { nodes.$master.plugins: { name: discovery-azure-classic } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: discovery-ec2 }
- match: { nodes.$master.plugins: { name: discovery-ec2 } }
2 changes: 1 addition & 1 deletion plugins/discovery-file/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task setupSeedNodeAndUnicastHostsFile(type: DefaultTask) {
// setup the initial cluster with one node that will serve as the seed node
// for unicast discovery
ClusterConfiguration config = new ClusterConfiguration(project)
config.distribution = 'integ-test-zip'
config.distribution = System.getProperty('tests.distribution', 'integ-test-zip')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this line at all given your change to PluginBuildPlugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would take precedence and override that. So it would be set back to integ-test-zip regardless of the property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned this is fragile. I don't want to see this logic copied around to other projects. Can you please create an issue for making creating additional cluster fixtures easier, so that the default can be set by PluginBuildPlugin for this project and reused the we create this cluster?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on this being fragile. Fixing it in a followup is fine with me though.

config.clusterName = 'discovery-file-test-cluster'
List<NodeInfo> nodes = ClusterFormationTasks.setup(project, 'initialCluster', setupSeedNodeAndUnicastHostsFile, config)
File srcUnicastHostsFile = file('build/cluster/unicast_hosts.txt')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: discovery-gce }
- match: { nodes.$master.plugins: { name: discovery-gce } }
8 changes: 6 additions & 2 deletions plugins/examples/painless-whitelist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ dependencies {
compileOnly project(':modules:lang-painless')
}

integTestCluster {
distribution = 'zip'
if (System.getProperty('tests.distribution') == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit complicated to add to every project. I'm not 100% sure we need to support -Dtests.distribution=integ-test-zip. Maybe integ-test-zip is a thing we should only use when you don't override the property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be fairly simple to fail the build if someone sets distribution to integ-test-zip. If we did that then this project could do distribution = System.getProperty('tests.distribution', 'zip).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be cleaner to move the PluginBuildPlugin change to a gradle.projectsEvaluated and have it handle the logic all in one place.

Copy link
Contributor Author

@alpar-t alpar-t May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting distro integ-test-zip would offer a way to run some integration tests in a build that would be much quicker as it would skip a lot of the heavier integration tests (probably most of QA). I'm not sure how useful that would be during development, so can't decide if it's worth doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is generally useful. Plugins and modules are the projects which use integ-test-zip, and you can already cd into the plugins or modules dir and run tests from there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I don't think we should support setting -Dtests.distribution=integ-test-zip. It should be what you get when you run without setting it.

integTestCluster.distribution = 'oss-zip'
}

if (integTestCluster.distribution == 'integ-test-zip') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this line because we don't support setting the setting to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add something to cluster formation tasks to make sure we don't set the system property to integ-test-zip.

integTest.enabled = false
}

test.enabled = false
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: painless-whitelist }
- match: { nodes.$master.plugins: { name: painless-whitelist } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: example-rescore }
- match: { nodes.$master.plugins: { name: example-rescore } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: script-expert-scoring }
- match: { nodes.$master.plugins: { name: script-expert-scoring } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: ingest-attachment }
- match: { nodes.$master.ingest.processors.0.type: attachment }
- match: { 'nodes.$master.plugins': { name: ingest-attachment } }
- match: { 'nodes.$master.ingest.processors': { type: attachment } }

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: ingest-geoip }
- match: { nodes.$master.ingest.processors.0.type: geoip }
- match: { nodes.$master.plugins: { name: ingest-geoip } }
- match: { nodes.$master.ingest.processors: { type: geoip } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: ingest-user-agent }
- match: { nodes.$master.ingest.processors.0.type: user_agent }
- match: { nodes.$master.plugins: { name: ingest-user-agent } }
- match: { nodes.$master.ingest.processors: { type: user_agent } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: repository-azure }
- match: { nodes.$master.plugins: { name: repository-azure } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: repository-gcs }
- match: { nodes.$master.plugins: { name: repository-gcs } }
1 change: 0 additions & 1 deletion plugins/repository-hdfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
project.afterEvaluate {
for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSecureHa']) {
ClusterConfiguration cluster = project.extensions.getByName("${integTestTaskName}Cluster") as ClusterConfiguration
cluster.distribution = 'integ-test-zip'
cluster.dependsOn(project.bundlePlugin)

Task restIntegTestTask = project.tasks.getByName(integTestTaskName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: repository-hdfs }
- match: { nodes.$master.plugins: { name: repository-hdfs } }
---
#
# Check that we can't use file:// repositories or anything like that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: repository-hdfs }
- match: { nodes.$master.plugins: { name: repository-hdfs } }
---
#
# Check that we can't use file:// repositories or anything like that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: repository-s3 }
- match: { nodes.$master.plugins: { name: repository-s3 } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- do:
nodes.info: {}

- match: { nodes.$master.plugins.0.name: store-smb }
- match: { nodes.$master.plugins: { name: store-smb } }
3 changes: 3 additions & 0 deletions qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ subprojects { Project subproj ->
subproj.tasks.withType(RestIntegTestTask) {
subproj.extensions.configure("${it.name}Cluster") { cluster ->
cluster.distribution = System.getProperty('tests.distribution', 'oss-zip')
if (cluster.distribution == 'integ-test-zip') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're better off checking if the system property is integ-test-zip in the cluster formation tasks and failing there. Basically, the only way you can get integ-test-zip is to not set the property.

throw new Exception("tests.distribution=integ.-test-zip is not supported")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@
import org.elasticsearch.test.NotEqualMessageBuilder;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like leftovers.


/**
* Represents a match assert section:
Expand Down Expand Up @@ -81,7 +90,36 @@ protected void doAssert(Object actualValue, Object expectedValue) {
}
}

if (expectedValue.equals(actualValue) == false) {
// add support for matching objects ({a:b}) against list of objects ([ {a:b, c:d} ])
if(expectedValue instanceof Map && actualValue instanceof List) {
Map<String, Object> expectedMap = (Map<String, Object>) expectedValue;
List<Object> actualList = (List<Object>) actualValue;
assertTrue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want match to be contains in some cases. If we want this we should make a new construct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics seemed to fit with me, but now that I think of it, match is in fact an exact match so it should be an exact match when dealing with lists as well. I'll add a new construct and call it contains.

getField() + " was expected to be a list with Map but it's " + actualValue,
actualList.stream()
.filter((each) -> each instanceof Map)
.findAny()
.isPresent()
);

List<Map<String, Object>> actualValues = actualList.stream()
.filter(each -> each instanceof Map)
.map((each -> (Map<String, Object>) each))
.filter(each -> each.keySet().containsAll(expectedMap.keySet()))
.collect(Collectors.toList());
assertThat(
getField() + " expected to be a list with at least one object that has keys: " +
expectedMap.keySet() + " but it was " + actualList,
actualValues,
is(not(empty()))
);
assertTrue(
getField() + " expected to be a list with at least on object that matches " + expectedMap +
" but was " + actualValues,
actualValues.stream()
.anyMatch(each -> each.entrySet().containsAll(expectedMap.entrySet()))
);
} else if (expectedValue.equals(actualValue) == false) {
NotEqualMessageBuilder message = new NotEqualMessageBuilder();
message.compare(getField(), actualValue, expectedValue);
throw new AssertionError(getField() + " didn't match expected value:\n" + message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ public void testParseMatchArray() throws Exception {
assertThat(strings.get(1).toString(), equalTo("test_percolator_2"));
}

@SuppressWarnings("unchecked")
public void testParseMatchArrayObject() throws Exception {
parser = createParser(YamlXContent.yamlXContent,
"{test: { someKey: someValue } }"
);

MatchAssertion matchAssertion = MatchAssertion.parse(parser);
assertThat(matchAssertion, notNullValue());
assertThat(matchAssertion.getField(), equalTo("test"));
assertThat(matchAssertion.getExpectedValue(), instanceOf(Map.class));
assertThat(
((Map<String, String>) matchAssertion.getExpectedValue()).get("someKey"),
equalTo("someValue")
);
}

@SuppressWarnings("unchecked")
public void testParseMatchSourceValues() throws Exception {
parser = createParser(YamlXContent.yamlXContent,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ integTestCluster {
return tmpFile.exists()
}
}
if (integTestCluster.distribution.startsWith("oss-") == false) {
integTest.enabled = false
}