Require either BuildPlugin or StandaloneTestBasePlugin to use RestTestPlugin

It used to be that RestTestPlugin "came with" StandaloneTestBasePlugin
but we'd like to use it with BuildPlugin for the high level rest client.
This commit is contained in:
Nik Everett 2017-01-03 15:39:36 -05:00 committed by Luca Cavanna
parent f0181b19f5
commit 812f63e5ef
15 changed files with 80 additions and 15 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.gradle
import nebula.plugin.extraconfigurations.ProvidedBasePlugin
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
@ -54,6 +55,9 @@ class BuildPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
if (project.pluginManager.hasPlugin('elasticsearch.standalone-test')) {
throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive')
}
project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing')
// these plugins add lots of info to our jars

View File

@ -30,6 +30,7 @@ public class DocsTestPlugin extends RestTestPlugin {
@Override
public void apply(Project project) {
project.pluginManager.apply('elasticsearch.standalone-test')
super.apply(project)
Map<String, String> defaultSubstitutions = [
/* These match up with the asciidoc syntax for substitutions but

View File

@ -18,15 +18,29 @@
*/
package org.elasticsearch.gradle.test
import org.elasticsearch.gradle.BuildPlugin
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Plugin
import org.gradle.api.Project
/** A plugin to add rest integration tests. Used for qa projects. */
/**
* Adds support for starting an Elasticsearch cluster before running integration
* tests. Used in conjunction with {@link StandaloneTestBasePlugin} for qa
* projects and in conjunction with {@link BuildPlugin} for testing the rest
* client.
*/
public class RestTestPlugin implements Plugin<Project> {
List REQUIRED_PLUGINS = [
'elasticsearch.build',
'elasticsearch.standalone-test']
@Override
public void apply(Project project) {
project.pluginManager.apply(StandaloneTestBasePlugin)
if (false == REQUIRED_PLUGINS.any {project.pluginManager.hasPlugin(it)}) {
throw new InvalidUserDataException('elasticsearch.rest-test '
+ 'requires either elasticsearch.build or '
+ 'elasticsearch.standalone-test')
}
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class)
integTest.cluster.distribution = 'zip' // rest tests should run with the real zip

View File

@ -24,6 +24,7 @@ import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
@ -34,6 +35,9 @@ public class StandaloneTestBasePlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
if (project.pluginManager.hasPlugin('elasticsearch.build')) {
throw new InvalidUserDataException('elasticsearch.standalone-test and elasticsearch.build are mutually exclusive')
}
project.pluginManager.apply(JavaBasePlugin)
project.pluginManager.apply(RandomizedTestingPlugin)
@ -41,7 +45,7 @@ public class StandaloneTestBasePlugin implements Plugin<Project> {
BuildPlugin.configureRepositories(project)
// only setup tests to build
project.sourceSets.maybeCreate('test')
project.sourceSets.create('test')
project.dependencies.add('testCompile', "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}")
project.eclipse.classpath.sourceSets = [project.sourceSets.test]
@ -49,10 +53,7 @@ public class StandaloneTestBasePlugin implements Plugin<Project> {
project.idea.module.testSourceDirs += project.sourceSets.test.java.srcDirs
project.idea.module.scopes['TEST'] = [plus: [project.configurations.testRuntime]]
Task precommitTask = project.tasks.findByName('precommit')
if (precommitTask == null) {
PrecommitTasks.create(project, false)
project.check.dependsOn(project.precommit)
}
PrecommitTasks.create(project, false)
project.check.dependsOn(project.precommit)
}
}

View File

@ -79,7 +79,7 @@ project.rootProject.subprojects.findAll { it.path.startsWith(':modules:') }.each
restTestExpansions['expected.modules.count'] += 1
}
// Integ tests work over the rest http layer, so we need a transport included with the integ test zip.
// Integ tests work over the rest http layer, so we need a transport included with the integ test zip.
// All transport modules are included so that they may be randomized for testing
task buildTransportModules(type: Sync) {
into 'build/transport-modules'
@ -104,6 +104,7 @@ subprojects {
/*****************************************************************************
* Rest test config *
*****************************************************************************/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
project.integTest {
dependsOn project.assemble
@ -116,7 +117,7 @@ subprojects {
mustRunAfter ':distribution:integ-test-zip:integTest#stop'
}
}
processTestResources {
inputs.properties(project(':distribution').restTestExpansions)
MavenFilteringHack.filter(it, project(':distribution').restTestExpansions)

View File

@ -1,3 +1,23 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
/* This project runs the core REST tests against a 2 node cluster where one of the nodes has a different minor.

View File

@ -17,10 +17,11 @@
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
// TODO: this test works, but it isn't really a rest test...should we have another plugin for "non rest test that just needs N clusters?"
dependencies {
testCompile project(path: ':client:transport', configuration: 'runtime') // randomly swapped in as a transport
}
}

View File

@ -17,8 +17,9 @@
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
dependencies {
testCompile project(path: ':modules:transport-netty4', configuration: 'runtime') // for http
}
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.http;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.index.IndexRequest;
@ -317,7 +316,7 @@ public class ContextAndHeaderTransportIT extends HttpSmokeTestCase {
}
@Override
protected boolean apply(String action, ActionRequest request, ActionListener listener) {
protected boolean apply(String action, ActionRequest request, ActionListener<?> listener) {
requests.add(new RequestAndHeaders(threadPool.getThreadContext().getHeaders(), request));
return true;
}

View File

@ -17,6 +17,7 @@
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
dependencies {

View File

@ -17,6 +17,7 @@
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
dependencies {

View File

@ -1,4 +1,23 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
integTest {

View File

@ -19,6 +19,7 @@
import org.elasticsearch.gradle.MavenFilteringHack
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
ext.pluginsCount = 0
@ -40,4 +41,3 @@ processTestResources {
inputs.properties(expansions)
MavenFilteringHack.filter(it, expansions)
}

View File

@ -17,6 +17,7 @@
* under the License.
*/
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
integTest {

View File

@ -21,6 +21,7 @@ import org.elasticsearch.gradle.test.ClusterConfiguration
import org.elasticsearch.gradle.test.ClusterFormationTasks
import org.elasticsearch.gradle.test.NodeInfo
apply plugin: 'elasticsearch.standalone-test'
apply plugin: 'elasticsearch.rest-test'
List<NodeInfo> oneNodes