[Backport] Replace usages RandomizedTestingTask with built-in Gradle Test (#40978) (#40993)

* Replace usages RandomizedTestingTask with built-in Gradle Test (#40978)

This commit replaces the existing RandomizedTestingTask and supporting code with Gradle's built-in JUnit support via the Test task type. Additionally, the previous workaround to disable all tasks named "test" and create new unit testing tasks named "unitTest" has been removed such that the "test" task now runs unit tests as per the normal Gradle Java plugin conventions.

(cherry picked from commit 323f312bbc829a63056a79ebe45adced5099f6e6)

* Fix forking JVM runner

* Don't bump shadow plugin version
This commit is contained in:
Mark Vieira 2019-04-09 11:52:50 -07:00 committed by GitHub
parent 321f93c4f9
commit 1287c7d91f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
98 changed files with 747 additions and 1551 deletions

View File

@ -24,7 +24,7 @@ mainClassName = 'org.openjdk.jmh.Main'
assemble.enabled = false
archivesBaseName = 'elasticsearch-benchmarks'
unitTest.enabled = false
test.enabled = false
dependencies {
compile("org.elasticsearch:elasticsearch:${version}") {

View File

@ -199,11 +199,11 @@ if (project != rootProject) {
into localDownloads
}
unitTest {
test {
// The test task is configured to runtimeJava version, but build-tools doesn't support all of them, so test
// with compiler instead on the ones that are too old.
if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_10) {
jvm = "${project.compilerJavaHome}/bin/java"
executable = "${project.compilerJavaHome}/bin/java"
}
}
@ -215,8 +215,6 @@ if (project != rootProject) {
}
dependsOn setupLocalDownloads
exclude "**/*Tests.class"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
inputs.dir(file("src/testKit"))
// tell BuildExamplePluginsIT where to find the example plugins
systemProperty (
@ -232,11 +230,7 @@ if (project != rootProject) {
if (isLuceneSnapshot) {
systemProperty 'test.lucene-snapshot-revision', isLuceneSnapshot[0][1]
}
String defaultParallel = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
if (defaultParallel == "auto") {
defaultParallel = Math.max(Runtime.getRuntime().availableProcessors(), 4)
}
maxParallelForks defaultParallel as Integer
maxParallelForks System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
}
check.dependsOn(integTest)

View File

@ -1,53 +0,0 @@
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.SuiteBalancer
import com.carrotsearch.ant.tasks.junit4.balancers.ExecutionTimeBalancer
import com.carrotsearch.ant.tasks.junit4.listeners.ExecutionTimesReport
import org.apache.tools.ant.types.FileSet
class BalancersConfiguration {
// parent task, so executionTime can register an additional listener
RandomizedTestingTask task
List<SuiteBalancer> balancers = new ArrayList<>()
void executionTime(Map<String,Object> properties) {
ExecutionTimeBalancer balancer = new ExecutionTimeBalancer()
FileSet fileSet = new FileSet()
Object filename = properties.remove('cacheFilename')
if (filename == null) {
throw new IllegalArgumentException('cacheFilename is required for executionTime balancer')
}
fileSet.setIncludes(filename.toString())
File cacheDir = task.project.projectDir
Object dir = properties.remove('cacheDir')
if (dir != null) {
cacheDir = new File(dir.toString())
}
fileSet.setDir(cacheDir)
balancer.add(fileSet)
int historySize = 10
Object size = properties.remove('historySize')
if (size instanceof Integer) {
historySize = (Integer)size
} else if (size != null) {
throw new IllegalArgumentException('historySize must be an integer')
}
ExecutionTimesReport listener = new ExecutionTimesReport()
listener.setFile(new File(cacheDir, filename.toString()))
listener.setHistoryLength(historySize)
if (properties.isEmpty() == false) {
throw new IllegalArgumentException('Unknown properties for executionTime balancer: ' + properties.keySet())
}
task.listenersConfig.listeners.add(listener)
balancers.add(balancer)
}
void custom(SuiteBalancer balancer) {
balancers.add(balancer)
}
}

View File

@ -1,25 +0,0 @@
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import com.carrotsearch.ant.tasks.junit4.listeners.antxml.AntXmlReport
class ListenersConfiguration {
RandomizedTestingTask task
List<AggregatedEventListener> listeners = new ArrayList<>()
void junitReport(Map<String, Object> props) {
AntXmlReport reportListener = new AntXmlReport()
Object dir = props == null ? null : props.get('dir')
if (dir != null) {
reportListener.setDir(task.project.file(dir))
} else {
reportListener.setDir(new File(task.project.buildDir, 'reports' + File.separator + "${task.name}Junit"))
}
listeners.add(reportListener)
}
void custom(AggregatedEventListener listener) {
listeners.add(listener)
}
}

View File

@ -1,60 +0,0 @@
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.JUnit4
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskContainer
class RandomizedTestingPlugin implements Plugin<Project> {
void apply(Project project) {
String seed = setupSeed(project)
createUnitTestTask(project.tasks)
configureAnt(project.ant, seed)
}
/**
* Pins the test seed at configuration time so it isn't different on every
* {@link RandomizedTestingTask} execution. This is useful if random
* decisions in one run of {@linkplain RandomizedTestingTask} influence the
* outcome of subsequent runs. Pinning the seed up front like this makes
* the reproduction line from one run be useful on another run.
*/
static String setupSeed(Project project) {
if (project.rootProject.ext.has('testSeed')) {
/* Skip this if we've already pinned the testSeed. It is important
* that this checks the rootProject so that we know we've only ever
* initialized one time. */
return project.rootProject.ext.testSeed
}
String testSeed = System.getProperty('tests.seed')
if (testSeed == null) {
long seed = new Random(System.currentTimeMillis()).nextLong()
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
}
/* Set the testSeed on the root project first so other projects can use
* it during initialization. */
project.rootProject.ext.testSeed = testSeed
project.rootProject.subprojects {
project.ext.testSeed = testSeed
}
return testSeed
}
static void createUnitTestTask(TaskContainer tasks) {
// only create a unitTest task if the `test` task exists as some project don't make use of it.
tasks.matching { it.name == "test" }.all {
// We don't want to run any tests with the Gradle test runner since we add our own randomized runner
it.enabled = false
RandomizedTestingTask unitTest = tasks.create('unitTest', RandomizedTestingTask)
unitTest.description = 'Runs unit tests with the randomized testing framework'
it.dependsOn unitTest
}
}
static void configureAnt(AntBuilder ant, String seed) {
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class)
ant.properties.put('tests.seed', seed)
}
}

View File

@ -1,330 +0,0 @@
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.ListenersList
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import groovy.xml.NamespaceBuilder
import groovy.xml.NamespaceBuilderSupport
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.DefaultLogger
import org.apache.tools.ant.Project
import org.apache.tools.ant.RuntimeConfigurable
import org.apache.tools.ant.UnknownElement
import org.elasticsearch.gradle.BuildPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.InvalidUserDataException
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTreeElement
import org.gradle.api.specs.Spec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.gradle.util.ConfigureUtil
import javax.inject.Inject
class RandomizedTestingTask extends DefaultTask {
// TODO: change to "executable" to match gradle test params?
@Optional
@Input
String jvm = 'java'
@Optional
@Input
File workingDir = new File(project.buildDir, 'testrun' + File.separator + name)
@Optional
@Input
FileCollection classpath
@Input
String parallelism = '1'
@Input
FileCollection testClassesDirs
@Optional
@Input
boolean haltOnFailure = true
@Optional
@Input
boolean shuffleOnSlave = true
@Optional
@Input
boolean enableAssertions = true
@Optional
@Input
boolean enableSystemAssertions = true
@Optional
@Input
boolean leaveTemporary = false
@Optional
@Input
String ifNoTests = 'ignore'
@Optional
@Input
String onNonEmptyWorkDirectory = 'fail'
TestLoggingConfiguration testLoggingConfig = new TestLoggingConfiguration()
BalancersConfiguration balancersConfig = new BalancersConfiguration(task: this)
ListenersConfiguration listenersConfig = new ListenersConfiguration(task: this)
List<String> jvmArgs = new ArrayList<>()
@Optional
@Input
String argLine = null
Map<String, Object> systemProperties = new HashMap<>()
Map<String, Object> environmentVariables = new HashMap<>()
PatternFilterable patternSet = new PatternSet()
RandomizedTestingTask() {
outputs.upToDateWhen {false} // randomized tests are never up to date
listenersConfig.listeners.add(new TestProgressLogger(factory: getProgressLoggerFactory()))
listenersConfig.listeners.add(new TestReportLogger(logger: logger, config: testLoggingConfig))
}
@Inject
ProgressLoggerFactory getProgressLoggerFactory() {
throw new UnsupportedOperationException()
}
void jvmArgs(Iterable<String> arguments) {
jvmArgs.addAll(arguments)
}
void jvmArg(String argument) {
jvmArgs.add(argument)
}
void systemProperty(String property, Object value) {
systemProperties.put(property, value)
}
void environment(String key, Object value) {
environmentVariables.put(key, value)
}
void include(String... includes) {
this.patternSet.include(includes);
}
void include(Iterable<String> includes) {
this.patternSet.include(includes);
}
void include(Spec<FileTreeElement> includeSpec) {
this.patternSet.include(includeSpec);
}
void include(Closure includeSpec) {
this.patternSet.include(includeSpec);
}
void exclude(String... excludes) {
this.patternSet.exclude(excludes);
}
void exclude(Iterable<String> excludes) {
this.patternSet.exclude(excludes);
}
void exclude(Spec<FileTreeElement> excludeSpec) {
this.patternSet.exclude(excludeSpec);
}
void exclude(Closure excludeSpec) {
this.patternSet.exclude(excludeSpec);
}
@Input
void testLogging(Closure closure) {
ConfigureUtil.configure(closure, testLoggingConfig)
}
@Input
void balancers(Closure closure) {
ConfigureUtil.configure(closure, balancersConfig)
}
@Input
void listeners(Closure closure) {
ConfigureUtil.configure(closure, listenersConfig)
}
@Option(
option = "tests",
description = "Sets test class or method name to be included. This is for IDEs. Use -Dtests.class and -Dtests.method"
)
void setTestNameIncludePattern(String testNamePattern) {
// This is only implemented to give support for IDEs running tests. There are 3 patterns expected:
// * An exact test class and method
// * An exact test class
// * A package name prefix, ending with .*
// There is no way to distinguish the first two without looking at classes, so we use the rule
// that class names start with an uppercase letter...
// TODO: this doesn't work yet, but not sure why...intellij says it is using --tests, and this work from the command line...
String[] parts = testNamePattern.split('\\.')
String lastPart = parts[parts.length - 1]
String classname
String methodname = null
if (lastPart.equals('*') || lastPart.charAt(0).isUpperCase()) {
// package name or class name, just pass through
classname = testNamePattern
} else {
// method name, need to separate
methodname = lastPart
classname = testNamePattern.substring(0, testNamePattern.length() - lastPart.length() - 1)
}
ant.setProperty('tests.class', classname)
if (methodname != null) {
ant.setProperty('tests.method', methodname)
}
}
@TaskAction
void executeTests() {
Map attributes = [
jvm: jvm,
parallelism: parallelism,
heartbeat: testLoggingConfig.slowTests.heartbeat,
dir: workingDir,
tempdir: new File(workingDir, 'temp'),
haltOnFailure: true, // we want to capture when a build failed, but will decide whether to rethrow later
shuffleOnSlave: shuffleOnSlave,
leaveTemporary: leaveTemporary,
ifNoTests: ifNoTests,
onNonEmptyWorkDirectory: onNonEmptyWorkDirectory,
newenvironment: true
]
DefaultLogger listener = null
ByteArrayOutputStream antLoggingBuffer = null
if (logger.isInfoEnabled() == false) {
// in info logging, ant already outputs info level, so we see everything
// but on errors or when debugging, we want to see info level messages
// because junit4 emits jvm output with ant logging
if (testLoggingConfig.outputMode == TestLoggingConfiguration.OutputMode.ALWAYS) {
// we want all output, so just stream directly
listener = new DefaultLogger(
errorPrintStream: System.err,
outputPrintStream: System.out,
messageOutputLevel: Project.MSG_INFO)
} else {
// we want to buffer the info, and emit it if the test fails
antLoggingBuffer = new ByteArrayOutputStream()
PrintStream stream = new PrintStream(antLoggingBuffer, true, "UTF-8")
listener = new DefaultLogger(
errorPrintStream: stream,
outputPrintStream: stream,
messageOutputLevel: Project.MSG_INFO)
}
project.ant.project.addBuildListener(listener)
}
NamespaceBuilderSupport junit4 = NamespaceBuilder.newInstance(ant, 'junit4')
try {
junit4.junit4(attributes) {
classpath {
pathElement(path: classpath.asPath)
}
if (enableAssertions) {
jvmarg(value: '-ea')
}
if (enableSystemAssertions) {
jvmarg(value: '-esa')
}
for (String arg : jvmArgs) {
jvmarg(value: arg)
}
if (argLine != null) {
jvmarg(line: argLine)
}
testClassesDirs.each { testClassDir ->
fileset(dir: testClassDir) {
patternSet.getIncludes().each { include(name: it) }
patternSet.getExcludes().each { exclude(name: it) }
}
}
for (Map.Entry<String, Object> prop : systemProperties) {
if (prop.getKey().equals('tests.seed')) {
throw new InvalidUserDataException('Seed should be ' +
'set on the project instead of a system property')
}
if (prop.getValue() instanceof Closure) {
sysproperty key: prop.getKey(), value: (prop.getValue() as Closure).call().toString()
} else {
sysproperty key: prop.getKey(), value: prop.getValue().toString()
}
}
systemProperty 'tests.seed', project.testSeed
for (Map.Entry<String, Object> envvar : environmentVariables) {
env key: envvar.getKey(), value: envvar.getValue().toString()
}
makeListeners()
}
} catch (BuildException e) {
if (antLoggingBuffer != null) {
logger.error('JUnit4 test failed, ant output was:')
logger.error(antLoggingBuffer.toString('UTF-8'))
}
if (haltOnFailure) {
throw e;
}
}
if (listener != null) {
// remove the listener we added so other ant tasks dont have verbose logging!
project.ant.project.removeBuildListener(listener)
}
}
static class ListenersElement extends UnknownElement {
AggregatedEventListener[] listeners
ListenersElement() {
super('listeners')
setNamespace('junit4')
setQName('listeners')
}
public void handleChildren(Object realThing, RuntimeConfigurable wrapper) {
assert realThing instanceof ListenersList
ListenersList list = (ListenersList)realThing
for (AggregatedEventListener listener : listeners) {
list.addConfigured(listener)
}
}
}
/**
* Makes an ant xml element for 'listeners' just as AntBuilder would, except configuring
* the element adds the already created children.
*/
def makeListeners() {
def context = ant.getAntXmlContext()
def parentWrapper = context.currentWrapper()
def parent = parentWrapper.getProxy()
UnknownElement element = new ListenersElement(listeners: listenersConfig.listeners)
element.setProject(context.getProject())
element.setRealThing(logger)
((UnknownElement)parent).addChild(element)
RuntimeConfigurable wrapper = new RuntimeConfigurable(element, element.getQName())
parentWrapper.addChild(wrapper)
return wrapper.getProxy()
}
}

View File

@ -1,14 +0,0 @@
package com.carrotsearch.gradle.junit4
class SlowTestsConfiguration {
int heartbeat = 0
int summarySize = 0
void heartbeat(int heartbeat) {
this.heartbeat = heartbeat
}
void summarySize(int summarySize) {
this.summarySize = summarySize
}
}

View File

@ -1,14 +0,0 @@
package com.carrotsearch.gradle.junit4
class StackTraceFiltersConfiguration {
List<String> patterns = new ArrayList<>()
List<String> contains = new ArrayList<>()
void regex(String pattern) {
patterns.add(pattern)
}
void contains(String contain) {
contains.add(contain)
}
}

View File

@ -1,43 +0,0 @@
package com.carrotsearch.gradle.junit4
import org.gradle.api.tasks.Input
import org.gradle.util.ConfigureUtil
class TestLoggingConfiguration {
/** Display mode for output streams. */
static enum OutputMode {
/** Always display the output emitted from tests. */
ALWAYS,
/**
* Display the output only if a test/ suite failed. This requires internal buffering
* so the output will be shown only after a test completes.
*/
ONERROR,
/** Don't display the output, even on test failures. */
NEVER
}
OutputMode outputMode = OutputMode.ONERROR
SlowTestsConfiguration slowTests = new SlowTestsConfiguration()
StackTraceFiltersConfiguration stackTraceFilters = new StackTraceFiltersConfiguration()
/** Summarize the first N failures at the end of the test. */
@Input
int showNumFailuresAtEnd = 3 // match TextReport default
void slowTests(Closure closure) {
ConfigureUtil.configure(closure, slowTests)
}
void stackTraceFilters(Closure closure) {
ConfigureUtil.configure(closure, stackTraceFilters)
}
void outputMode(String mode) {
outputMode = mode.toUpperCase() as OutputMode
}
void showNumFailuresAtEnd(int n) {
showNumFailuresAtEnd = n
}
}

View File

@ -1,193 +0,0 @@
/*
* 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.
*/
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.JUnit4
import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.eventbus.Subscribe
import com.carrotsearch.ant.tasks.junit4.events.TestStartedEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedStartEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteStartedEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.ChildBootstrap
import com.carrotsearch.ant.tasks.junit4.events.aggregated.HeartBeatEvent
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import org.gradle.internal.logging.progress.ProgressLogger
import org.gradle.internal.logging.progress.ProgressLoggerFactory
import org.junit.runner.Description
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.ERROR
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.FAILURE
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.IGNORED
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.IGNORED_ASSUMPTION
import static com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus.OK
/**
* Adapts junit4's event listeners into gradle's ProgressLogger. Note that
* junit4 guarantees (via guava) that methods on this class won't be called by
* multiple threads simultaneously which is helpful in making it simpler.
*
* Every time a test finishes this class will update the logger. It will log
* the last finished test method on the logger line until the first suite
* finishes. Once the first suite finishes it always logs the last finished
* suite. This means that in test runs with a single suite the logger will be
* updated with the test name the whole time which is useful because these runs
* usually have longer individual tests. For test runs with lots of suites the
* majority of the time is spent showing the last suite that finished which is
* more useful for those test runs because test methods there tend to be very
* quick.
*/
class TestProgressLogger implements AggregatedEventListener {
/** Factory to build a progress logger when testing starts */
ProgressLoggerFactory factory
ProgressLogger parentProgressLogger
ProgressLogger suiteLogger
ProgressLogger testLogger
ProgressLogger[] slaveLoggers
int totalSuites
int totalSlaves
// Counters incremented test completion.
volatile int suitesCompleted = 0
volatile int testsCompleted = 0
volatile int testsFailed = 0
volatile int testsIgnored = 0
@Subscribe
void onStart(AggregatedStartEvent e) throws IOException {
totalSuites = e.suiteCount
totalSlaves = e.slaveCount
parentProgressLogger = factory.newOperation(TestProgressLogger)
parentProgressLogger.setDescription('Randomized test runner')
parentProgressLogger.started()
suiteLogger = factory.newOperation(TestProgressLogger, parentProgressLogger)
suiteLogger.setDescription('Suite logger')
suiteLogger.started("Suites: 0/" + totalSuites)
testLogger = factory.newOperation(TestProgressLogger, parentProgressLogger)
testLogger.setDescription('Test logger')
testLogger.started('Tests: completed: 0, failed: 0, ignored: 0')
slaveLoggers = new ProgressLogger[e.slaveCount]
for (int i = 0; i < e.slaveCount; ++i) {
slaveLoggers[i] = factory.newOperation(TestProgressLogger, parentProgressLogger)
slaveLoggers[i].setDescription("J${i} test logger")
slaveLoggers[i].started("J${i}: initializing...")
}
}
@Subscribe
void onChildBootstrap(ChildBootstrap e) throws IOException {
slaveLoggers[e.getSlave().id].progress("J${e.slave.id}: starting (pid ${e.slave.pidString})")
}
@Subscribe
void onQuit(AggregatedQuitEvent e) throws IOException {
// if onStart was never called (eg no matching tests), suiteLogger and all the other loggers will be null
if (suiteLogger != null) {
suiteLogger.completed()
testLogger.completed()
for (ProgressLogger slaveLogger : slaveLoggers) {
slaveLogger.completed()
}
parentProgressLogger.completed()
}
}
@Subscribe
void onSuiteStart(AggregatedSuiteStartedEvent e) throws IOException {
String suiteName = simpleName(e.suiteStartedEvent.description)
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${suiteName} - initializing")
}
@Subscribe
void onSuiteResult(AggregatedSuiteResultEvent e) throws IOException {
suitesCompleted++
suiteLogger.progress("Suites: " + suitesCompleted + "/" + totalSuites)
}
@Subscribe
void onTestResult(AggregatedTestResultEvent e) throws IOException {
String statusMessage
testsCompleted++
switch (e.status) {
case ERROR:
case FAILURE:
testsFailed++
statusMessage = "failed"
break
case IGNORED:
case IGNORED_ASSUMPTION:
testsIgnored++
statusMessage = "ignored"
break
case OK:
String time = formatDurationInSeconds(e.executionTime)
statusMessage = "completed [${time}]"
break
default:
throw new IllegalArgumentException("Unknown test status: [${e.status}]")
}
testLogger.progress("Tests: completed: ${testsCompleted}, failed: ${testsFailed}, ignored: ${testsIgnored}")
String testName = testName(e.description)
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ${statusMessage}")
}
@Subscribe
void onTestStarted(TestStartedEvent e) throws IOException {
String testName = testName(e.description)
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} ...")
}
@Subscribe
void onHeartbeat(HeartBeatEvent e) throws IOException {
String testName = testName(e.description)
String time = formatDurationInSeconds(e.getNoEventDuration())
slaveLoggers[e.slave.id].progress("J${e.slave.id}: ${testName} stalled for ${time}")
}
/**
* Build the test name in the format of <className>.<methodName>
*/
private static String testName(Description description) {
String className = simpleName(description)
if (description == null) {
return className + "." + "<unknownMethod>"
}
return className + "." + description.methodName
}
/**
* Extract a Class#getSimpleName style name from Class#getName style
* string. We can't just use Class#getSimpleName because junit descriptions
* don't always set the class field but they always set the className
* field.
*/
private static String simpleName(Description description) {
if (description == null) {
return "<unknownClass>"
}
return description.className.substring(description.className.lastIndexOf('.') + 1)
}
@Override
void setOuter(JUnit4 junit) {}
}

View File

@ -1,369 +0,0 @@
package com.carrotsearch.gradle.junit4
import com.carrotsearch.ant.tasks.junit4.JUnit4
import com.carrotsearch.ant.tasks.junit4.Pluralize
import com.carrotsearch.ant.tasks.junit4.TestsSummaryEventListener
import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.base.Strings
import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.eventbus.Subscribe
import com.carrotsearch.ant.tasks.junit4.events.EventType
import com.carrotsearch.ant.tasks.junit4.events.IEvent
import com.carrotsearch.ant.tasks.junit4.events.IStreamEvent
import com.carrotsearch.ant.tasks.junit4.events.SuiteStartedEvent
import com.carrotsearch.ant.tasks.junit4.events.TestFinishedEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedStartEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedSuiteStartedEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedTestResultEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.ChildBootstrap
import com.carrotsearch.ant.tasks.junit4.events.aggregated.HeartBeatEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.PartialOutputEvent
import com.carrotsearch.ant.tasks.junit4.events.aggregated.TestStatus
import com.carrotsearch.ant.tasks.junit4.events.mirrors.FailureMirror
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
import com.carrotsearch.ant.tasks.junit4.listeners.StackTraceFilter
import org.apache.tools.ant.filters.TokenFilter
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
import org.junit.runner.Description
import java.util.concurrent.atomic.AtomicInteger
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDescription
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatDurationInSeconds
import static com.carrotsearch.ant.tasks.junit4.FormattingUtils.formatTime
import static com.carrotsearch.gradle.junit4.TestLoggingConfiguration.OutputMode
class TestReportLogger extends TestsSummaryEventListener implements AggregatedEventListener {
static final String FAILURE_MARKER = " <<< FAILURES!"
/** Status names column. */
static EnumMap<? extends TestStatus, String> statusNames;
static {
statusNames = new EnumMap<>(TestStatus.class);
for (TestStatus s : TestStatus.values()) {
statusNames.put(s,
s == TestStatus.IGNORED_ASSUMPTION
? "IGNOR/A" : s.toString());
}
}
JUnit4 owner
/** Logger to write the report to */
Logger logger
TestLoggingConfiguration config
/** Forked concurrent JVM count. */
int forkedJvmCount
/** Format line for JVM ID string. */
String jvmIdFormat
/** Output stream that logs messages to the given logger */
LoggingOutputStream outStream
LoggingOutputStream errStream
/** A list of failed tests, if to be displayed at the end. */
List<Description> failedTests = new ArrayList<>()
/** Stack trace filters. */
StackTraceFilter stackFilter = new StackTraceFilter()
Map<String, Long> suiteTimes = new HashMap<>()
boolean slowTestsFound = false
int totalSuites
AtomicInteger suitesCompleted = new AtomicInteger()
@Subscribe
void onStart(AggregatedStartEvent e) throws IOException {
this.totalSuites = e.getSuiteCount();
StringBuilder info = new StringBuilder('==> Test Info: ')
info.append('seed=' + owner.getSeed() + '; ')
info.append(Pluralize.pluralize(e.getSlaveCount(), 'jvm') + '=' + e.getSlaveCount() + '; ')
info.append(Pluralize.pluralize(e.getSuiteCount(), 'suite') + '=' + e.getSuiteCount())
logger.lifecycle(info.toString())
forkedJvmCount = e.getSlaveCount();
jvmIdFormat = " J%-" + (1 + (int) Math.floor(Math.log10(forkedJvmCount))) + "d";
outStream = new LoggingOutputStream(logger: logger, level: LogLevel.LIFECYCLE, prefix: " 1> ")
errStream = new LoggingOutputStream(logger: logger, level: LogLevel.ERROR, prefix: " 2> ")
for (String contains : config.stackTraceFilters.contains) {
TokenFilter.ContainsString containsFilter = new TokenFilter.ContainsString()
containsFilter.setContains(contains)
stackFilter.addContainsString(containsFilter)
}
for (String pattern : config.stackTraceFilters.patterns) {
TokenFilter.ContainsRegex regexFilter = new TokenFilter.ContainsRegex()
regexFilter.setPattern(pattern)
stackFilter.addContainsRegex(regexFilter)
}
}
@Subscribe
void onChildBootstrap(ChildBootstrap e) throws IOException {
logger.info("Started J" + e.getSlave().id + " PID(" + e.getSlave().getPidString() + ").");
}
@Subscribe
void onHeartbeat(HeartBeatEvent e) throws IOException {
logger.warn("HEARTBEAT J" + e.getSlave().id + " PID(" + e.getSlave().getPidString() + "): " +
formatTime(e.getCurrentTime()) + ", stalled for " +
formatDurationInSeconds(e.getNoEventDuration()) + " at: " +
(e.getDescription() == null ? "<unknown>" : formatDescription(e.getDescription())))
slowTestsFound = true
}
@Subscribe
void onQuit(AggregatedQuitEvent e) throws IOException {
if (config.showNumFailuresAtEnd > 0 && !failedTests.isEmpty()) {
List<Description> sublist = this.failedTests
StringBuilder b = new StringBuilder()
b.append('Tests with failures')
if (sublist.size() > config.showNumFailuresAtEnd) {
sublist = sublist.subList(0, config.showNumFailuresAtEnd)
b.append(" (first " + config.showNumFailuresAtEnd + " out of " + failedTests.size() + ")")
}
b.append(':\n')
for (Description description : sublist) {
b.append(" - ").append(formatDescription(description, true)).append('\n')
}
logger.warn(b.toString())
}
if (config.slowTests.summarySize > 0) {
List<Map.Entry<String, Long>> sortedSuiteTimes = new ArrayList<>(suiteTimes.entrySet())
Collections.sort(sortedSuiteTimes, new Comparator<Map.Entry<String, Long>>() {
@Override
int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
return o2.value - o1.value // sort descending
}
})
LogLevel level = slowTestsFound ? LogLevel.WARN : LogLevel.INFO
int numToLog = Math.min(config.slowTests.summarySize, sortedSuiteTimes.size())
logger.log(level, 'Slow Tests Summary:')
for (int i = 0; i < numToLog; ++i) {
logger.log(level, String.format(Locale.ENGLISH, '%6.2fs | %s',
sortedSuiteTimes.get(i).value / 1000.0,
sortedSuiteTimes.get(i).key));
}
logger.log(level, '') // extra vertical separation
}
if (failedTests.isEmpty()) {
// summary is already printed for failures
logger.lifecycle('==> Test Summary: ' + getResult().toString())
}
}
@Subscribe
void onSuiteStart(AggregatedSuiteStartedEvent e) throws IOException {
if (isPassthrough()) {
SuiteStartedEvent evt = e.getSuiteStartedEvent();
emitSuiteStart(LogLevel.LIFECYCLE, evt.getDescription());
}
}
@Subscribe
void onOutput(PartialOutputEvent e) throws IOException {
if (isPassthrough()) {
// We only allow passthrough output if there is one JVM.
switch (e.getEvent().getType()) {
case EventType.APPEND_STDERR:
((IStreamEvent) e.getEvent()).copyTo(errStream);
break;
case EventType.APPEND_STDOUT:
((IStreamEvent) e.getEvent()).copyTo(outStream);
break;
default:
break;
}
}
}
@Subscribe
void onTestResult(AggregatedTestResultEvent e) throws IOException {
if (isPassthrough() && e.getStatus() != TestStatus.OK) {
flushOutput();
emitStatusLine(LogLevel.ERROR, e, e.getStatus(), e.getExecutionTime());
}
if (!e.isSuccessful()) {
failedTests.add(e.getDescription());
}
}
@Subscribe
void onSuiteResult(AggregatedSuiteResultEvent e) throws IOException {
final int completed = suitesCompleted.incrementAndGet();
if (e.isSuccessful() && e.getTests().isEmpty()) {
return;
}
if (config.slowTests.summarySize > 0) {
suiteTimes.put(e.getDescription().getDisplayName(), e.getExecutionTime())
}
LogLevel level = e.isSuccessful() && config.outputMode != OutputMode.ALWAYS ? LogLevel.INFO : LogLevel.LIFECYCLE
// We must emit buffered test and stream events (in case of failures).
if (!isPassthrough()) {
emitSuiteStart(level, e.getDescription())
emitBufferedEvents(level, e)
}
// Emit a synthetic failure for suite-level errors, if any.
if (!e.getFailures().isEmpty()) {
emitStatusLine(level, e, TestStatus.ERROR, 0)
}
if (!e.getFailures().isEmpty()) {
failedTests.add(e.getDescription())
}
emitSuiteEnd(level, e, completed)
}
/** Suite prologue. */
void emitSuiteStart(LogLevel level, Description description) throws IOException {
logger.log(level, 'Suite: ' + description.getDisplayName());
}
void emitBufferedEvents(LogLevel level, AggregatedSuiteResultEvent e) throws IOException {
if (config.outputMode == OutputMode.NEVER) {
return
}
final IdentityHashMap<TestFinishedEvent,AggregatedTestResultEvent> eventMap = new IdentityHashMap<>();
for (AggregatedTestResultEvent tre : e.getTests()) {
eventMap.put(tre.getTestFinishedEvent(), tre)
}
final boolean emitOutput = config.outputMode == OutputMode.ALWAYS && isPassthrough() == false ||
config.outputMode == OutputMode.ONERROR && e.isSuccessful() == false
for (IEvent event : e.getEventStream()) {
switch (event.getType()) {
case EventType.APPEND_STDOUT:
if (emitOutput) ((IStreamEvent) event).copyTo(outStream);
break;
case EventType.APPEND_STDERR:
if (emitOutput) ((IStreamEvent) event).copyTo(errStream);
break;
case EventType.TEST_FINISHED:
assert eventMap.containsKey(event)
final AggregatedTestResultEvent aggregated = eventMap.get(event);
if (aggregated.getStatus() != TestStatus.OK) {
flushOutput();
emitStatusLine(level, aggregated, aggregated.getStatus(), aggregated.getExecutionTime());
}
default:
break;
}
}
if (emitOutput) {
flushOutput()
}
}
void emitSuiteEnd(LogLevel level, AggregatedSuiteResultEvent e, int suitesCompleted) throws IOException {
final StringBuilder b = new StringBuilder();
b.append(String.format(Locale.ENGLISH, 'Completed [%d/%d]%s in %.2fs, ',
suitesCompleted,
totalSuites,
e.getSlave().slaves > 1 ? ' on J' + e.getSlave().id : '',
e.getExecutionTime() / 1000.0d));
b.append(e.getTests().size()).append(Pluralize.pluralize(e.getTests().size(), ' test'));
int failures = e.getFailureCount();
if (failures > 0) {
b.append(', ').append(failures).append(Pluralize.pluralize(failures, ' failure'));
}
int errors = e.getErrorCount();
if (errors > 0) {
b.append(', ').append(errors).append(Pluralize.pluralize(errors, ' error'));
}
int ignored = e.getIgnoredCount();
if (ignored > 0) {
b.append(', ').append(ignored).append(' skipped');
}
if (!e.isSuccessful()) {
b.append(' <<< FAILURES!');
}
b.append('\n')
logger.log(level, b.toString());
}
/** Emit status line for an aggregated event. */
void emitStatusLine(LogLevel level, AggregatedResultEvent result, TestStatus status, long timeMillis) throws IOException {
final StringBuilder line = new StringBuilder();
line.append(Strings.padEnd(statusNames.get(status), 8, ' ' as char))
line.append(formatDurationInSeconds(timeMillis))
if (forkedJvmCount > 1) {
line.append(String.format(Locale.ENGLISH, jvmIdFormat, result.getSlave().id))
}
line.append(' | ')
line.append(formatDescription(result.getDescription()))
if (!result.isSuccessful()) {
line.append(FAILURE_MARKER)
}
logger.log(level, line.toString())
PrintWriter writer = new PrintWriter(new LoggingOutputStream(logger: logger, level: level, prefix: ' > '))
if (status == TestStatus.IGNORED && result instanceof AggregatedTestResultEvent) {
writer.write('Cause: ')
writer.write(((AggregatedTestResultEvent) result).getCauseForIgnored())
writer.flush()
}
final List<FailureMirror> failures = result.getFailures();
if (!failures.isEmpty()) {
int count = 0;
for (FailureMirror fm : failures) {
count++;
if (fm.isAssumptionViolation()) {
writer.write(String.format(Locale.ENGLISH,
'Assumption #%d: %s',
count, fm.getMessage() == null ? '(no message)' : fm.getMessage()));
} else {
writer.write(String.format(Locale.ENGLISH,
'Throwable #%d: %s',
count,
stackFilter.apply(fm.getTrace())));
}
}
writer.flush()
}
}
void flushOutput() throws IOException {
outStream.flush()
errStream.flush()
}
/** Returns true if output should be logged immediately. */
boolean isPassthrough() {
return forkedJvmCount == 1 && config.outputMode == OutputMode.ALWAYS
}
@Override
void setOuter(JUnit4 task) {
owner = task
}
}

View File

@ -18,13 +18,13 @@
*/
package org.elasticsearch.gradle
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.apache.commons.io.IOUtils
import org.apache.tools.ant.taskdefs.condition.Os
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.RepositoryBuilder
import org.elasticsearch.gradle.precommit.PrecommitTasks
import org.elasticsearch.gradle.test.ErrorReportingTestListener
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
@ -40,8 +40,8 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.credentials.HttpHeaderCredentials
import org.gradle.api.execution.TaskActionListener
import org.gradle.api.execution.TaskExecutionGraph
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
@ -51,6 +51,7 @@ import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.GroovyCompile
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.tasks.testing.Test
import org.gradle.authentication.http.HttpHeaderAuthentication
import org.gradle.internal.jvm.Jvm
import org.gradle.process.ExecResult
@ -83,7 +84,6 @@ class BuildPlugin implements Plugin<Project> {
)
}
project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing')
configureConfigurations(project)
configureJars(project) // jar config must be added before info broker
// these plugins add lots of info to our jars
@ -93,8 +93,12 @@ class BuildPlugin implements Plugin<Project> {
project.pluginManager.apply('nebula.info-scm')
project.pluginManager.apply('nebula.info-jar')
// apply global test task failure listener
project.rootProject.pluginManager.apply(TestFailureReportingPlugin)
project.getTasks().create("buildResources", ExportElasticsearchBuildResourcesTask)
setupSeed(project)
globalBuildInfo(project)
configureRepositories(project)
project.ext.versions = VersionProperties.versions
@ -103,9 +107,7 @@ class BuildPlugin implements Plugin<Project> {
configureJavadoc(project)
configureSourcesJar(project)
configurePomGeneration(project)
applyCommonTestConfig(project)
configureTest(project)
configureTestTasks(project)
configurePrecommit(project)
configureDependenciesInfo(project)
}
@ -904,128 +906,107 @@ class BuildPlugin implements Plugin<Project> {
}
}
static void applyCommonTestConfig(Project project) {
project.tasks.withType(RandomizedTestingTask) {task ->
jvm "${project.runtimeJavaHome}/bin/java"
parallelism System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
ifNoTests 'fail'
onNonEmptyWorkDirectory 'wipe'
leaveTemporary true
project.sourceSets.matching { it.name == "test" }.all { test ->
task.testClassesDirs = test.output.classesDirs
task.classpath = test.runtimeClasspath
}
group = JavaBasePlugin.VERIFICATION_GROUP
dependsOn 'testClasses'
static void configureTestTasks(Project project) {
// Default test task should run only unit tests
project.tasks.withType(Test).matching { it.name == 'test' }.all {
include '**/*Tests.class'
}
// Make sure all test tasks are configured properly
if (name != "test") {
project.tasks.matching { it.name == "test"}.all { testTask ->
task.shouldRunAfter testTask
}
}
if (name == "unitTest") {
include("**/*Tests.class")
}
// TODO: why are we not passing maxmemory to junit4?
jvmArg '-Xmx' + System.getProperty('tests.heap.size', '512m')
jvmArg '-Xms' + System.getProperty('tests.heap.size', '512m')
jvmArg '-XX:+HeapDumpOnOutOfMemoryError'
// none of this stuff is applicable to the `:buildSrc` project tests
if (project.path != ':build-tools') {
File heapdumpDir = new File(project.buildDir, 'heapdump')
heapdumpDir.mkdirs()
jvmArg '-XX:HeapDumpPath=' + heapdumpDir
if (project.runtimeJavaVersion >= JavaVersion.VERSION_1_9) {
jvmArg '--illegal-access=warn'
}
argLine System.getProperty('tests.jvm.argline')
// we use './temp' since this is per JVM and tests are forbidden from writing to CWD
systemProperty 'java.io.tmpdir', './temp'
systemProperty 'java.awt.headless', 'true'
systemProperty 'tests.gradle', 'true'
systemProperty 'tests.artifact', project.name
systemProperty 'tests.task', path
systemProperty 'tests.security.manager', 'true'
systemProperty 'jna.nosys', 'true'
systemProperty 'compiler.java', project.ext.compilerJavaVersion.getMajorVersion()
if (project.ext.inFipsJvm) {
systemProperty 'runtime.java', project.ext.runtimeJavaVersion.getMajorVersion() + "FIPS"
} else {
systemProperty 'runtime.java', project.ext.runtimeJavaVersion.getMajorVersion()
}
// TODO: remove setting logging level via system property
systemProperty 'tests.logger.level', 'WARN'
for (Map.Entry<String, String> property : System.properties.entrySet()) {
if (property.getKey().startsWith('tests.') ||
property.getKey().startsWith('es.')) {
if (property.getKey().equals('tests.seed')) {
/* The seed is already set on the project so we
* shouldn't attempt to override it. */
continue;
}
systemProperty property.getKey(), property.getValue()
project.tasks.withType(Test) { Test test ->
File testOutputDir = new File(test.reports.junitXml.getDestination(), "output")
doFirst {
project.mkdir(testOutputDir)
project.mkdir(heapdumpDir)
project.mkdir(test.workingDir)
}
}
// TODO: remove this once ctx isn't added to update script params in 7.0
systemProperty 'es.scripting.update.ctx_in_params', 'false'
def listener = new ErrorReportingTestListener(test.testLogging, testOutputDir)
test.extensions.add(ErrorReportingTestListener, 'errorReportingTestListener', listener)
addTestOutputListener(listener)
addTestListener(listener)
// Set the system keystore/truststore password if we're running tests in a FIPS-140 JVM
if (project.inFipsJvm) {
systemProperty 'javax.net.ssl.trustStorePassword', 'password'
systemProperty 'javax.net.ssl.keyStorePassword', 'password'
}
executable = "${project.runtimeJavaHome}/bin/java"
workingDir = project.file("${project.buildDir}/testrun/${test.name}")
maxParallelForks = project.rootProject.ext.defaultParallel
boolean assertionsEnabled = Boolean.parseBoolean(System.getProperty('tests.asserts', 'true'))
enableSystemAssertions assertionsEnabled
enableAssertions assertionsEnabled
exclude '**/*$*.class'
testLogging {
showNumFailuresAtEnd 25
slowTests {
heartbeat 10
summarySize 5
jvmArgs "-Xmx${System.getProperty('tests.heap.size', '512m')}",
"-Xms${System.getProperty('tests.heap.size', '512m')}",
'-XX:+HeapDumpOnOutOfMemoryError',
"-XX:HeapDumpPath=$heapdumpDir"
if (project.runtimeJavaVersion >= JavaVersion.VERSION_1_9) {
jvmArgs '--illegal-access=warn'
}
stackTraceFilters {
// custom filters: we carefully only omit test infra noise here
contains '.SlaveMain.'
regex(/^(\s+at )(org\.junit\.)/)
// also includes anonymous classes inside these two:
regex(/^(\s+at )(com\.carrotsearch\.randomizedtesting\.RandomizedRunner)/)
regex(/^(\s+at )(com\.carrotsearch\.randomizedtesting\.ThreadLeakControl)/)
regex(/^(\s+at )(com\.carrotsearch\.randomizedtesting\.rules\.)/)
regex(/^(\s+at )(org\.apache\.lucene\.util\.TestRule)/)
regex(/^(\s+at )(org\.apache\.lucene\.util\.AbstractBeforeAfterRule)/)
if (System.getProperty('tests.jvm.argline')) {
jvmArgs System.getProperty('tests.jvm.argline').split(" ")
}
if (System.getProperty('tests.class') != null && System.getProperty('tests.output') == null) {
// if you are debugging, you want to see the output!
outputMode 'always'
if (Boolean.parseBoolean(System.getProperty('tests.asserts', 'true'))) {
jvmArgs '-ea', '-esa'
}
// we use './temp' since this is per JVM and tests are forbidden from writing to CWD
systemProperties 'gradle.dist.lib': new File(project.class.location.toURI()).parent,
'gradle.worker.jar': "${project.gradle.getGradleUserHomeDir()}/caches/${project.gradle.gradleVersion}/workerMain/gradle-worker.jar",
'gradle.user.home': project.gradle.getGradleUserHomeDir(),
'java.io.tmpdir': './temp',
'java.awt.headless': 'true',
'tests.gradle': 'true',
'tests.artifact': project.name,
'tests.task': path,
'tests.security.manager': 'true',
'tests.seed': project.testSeed,
'jna.nosys': 'true',
'compiler.java': project.ext.compilerJavaVersion.getMajorVersion()
if (project.ext.inFipsJvm) {
systemProperty 'runtime.java', project.ext.runtimeJavaVersion.getMajorVersion() + "FIPS"
} else {
outputMode System.getProperty('tests.output', 'onerror')
systemProperty 'runtime.java', project.ext.runtimeJavaVersion.getMajorVersion()
}
// TODO: remove setting logging level via system property
systemProperty 'tests.logger.level', 'WARN'
System.getProperties().each { key, value ->
if ((key.startsWith('tests.') || key.startsWith('es.'))) {
systemProperty key, value
}
}
}
balancers {
executionTime cacheFilename: ".local-${project.version}-${name}-execution-times.log"
}
// TODO: remove this once ctx isn't added to update script params in 7.0
systemProperty 'es.scripting.update.ctx_in_params', 'false'
listeners {
junitReport()
}
// Set the system keystore/truststore password if we're running tests in a FIPS-140 JVM
if (project.inFipsJvm) {
systemProperty 'javax.net.ssl.trustStorePassword', 'password'
systemProperty 'javax.net.ssl.keyStorePassword', 'password'
}
exclude '**/*$*.class'
testLogging {
showExceptions = true
showCauses = true
exceptionFormat = 'full'
}
project.plugins.withType(ShadowPlugin).whenPluginAdded {
// Test against a shadow jar if we made one
classpath -= project.tasks.compileJava.outputs.files
classpath += project.tasks.shadowJar.outputs.files
dependsOn project.tasks.shadowJar
project.plugins.withType(ShadowPlugin).whenPluginAdded {
// Test against a shadow jar if we made one
classpath -= project.tasks.compileJava.outputs.files
classpath += project.tasks.shadowJar.outputs.files
dependsOn project.tasks.shadowJar
}
}
}
}
private static String findDefaultParallel(Project project) {
private static int findDefaultParallel(Project project) {
if (project.file("/proc/cpuinfo").exists()) {
// Count physical cores on any Linux distro ( don't count hyper-threading )
Map<String, Integer> socketToCore = [:]
@ -1046,7 +1027,7 @@ class BuildPlugin implements Plugin<Project> {
}
}
})
return socketToCore.values().sum().toString();
return socketToCore.values().sum()
} else if ('Mac OS X'.equals(System.getProperty('os.name'))) {
// Ask macOS to count physical CPUs for us
ByteArrayOutputStream stdout = new ByteArrayOutputStream()
@ -1055,16 +1036,9 @@ class BuildPlugin implements Plugin<Project> {
args '-n', 'hw.physicalcpu'
standardOutput = stdout
}
return stdout.toString('UTF-8').trim();
}
return 'auto';
}
/** Configures the test task */
static Task configureTest(Project project) {
project.tasks.getByName('test') {
include '**/*Tests.class'
return Integer.parseInt(stdout.toString('UTF-8').trim())
}
return Runtime.getRuntime().availableProcessors() / 2
}
private static configurePrecommit(Project project) {
@ -1094,4 +1068,58 @@ class BuildPlugin implements Plugin<Project> {
deps.mappings = project.dependencyLicenses.mappings
}
}
/**
* Pins the test seed at configuration time so it isn't different on every
* {@link Test} execution. This is useful if random
* decisions in one run of {@linkplain Test} influence the
* outcome of subsequent runs. Pinning the seed up front like this makes
* the reproduction line from one run be useful on another run.
*/
static String setupSeed(Project project) {
if (project.rootProject.ext.has('testSeed')) {
/* Skip this if we've already pinned the testSeed. It is important
* that this checks the rootProject so that we know we've only ever
* initialized one time. */
return project.rootProject.ext.testSeed
}
String testSeed = System.getProperty('tests.seed')
if (testSeed == null) {
long seed = new Random(System.currentTimeMillis()).nextLong()
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
}
project.rootProject.ext.testSeed = testSeed
return testSeed
}
private static class TestFailureReportingPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
if (project != project.rootProject) {
throw new IllegalStateException("${this.class.getName()} can only be applied to the root project.")
}
project.gradle.addListener(new TaskActionListener() {
@Override
void beforeActions(Task task) {
}
@Override
void afterActions(Task task) {
if (task instanceof Test) {
ErrorReportingTestListener listener = task.extensions.findByType(ErrorReportingTestListener)
if (listener != null && listener.getFailedTests().size() > 0) {
task.logger.lifecycle("\nTests with failures:")
listener.getFailedTests().each {
task.logger.lifecycle(" - ${it.getFullName()}")
}
}
}
}
})
}
}
}

View File

@ -1,4 +1,4 @@
package com.carrotsearch.gradle.junit4
package org.elasticsearch.gradle
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger

View File

@ -18,30 +18,36 @@
*/
package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.execution.TaskExecutionAdapter
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskState
import org.gradle.api.tasks.options.Option
import org.gradle.api.tasks.testing.Test
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.gradle.process.CommandLineArgumentProvider
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.stream.Stream
/**
* A wrapper task around setting up a cluster and running rest tests.
*/
public class RestIntegTestTask extends DefaultTask {
class RestIntegTestTask extends DefaultTask {
private static final Logger LOGGER = Logging.getLogger(RestIntegTestTask)
protected ClusterConfiguration clusterConfig
protected RandomizedTestingTask runner
protected Test runner
protected Task clusterInit
@ -52,8 +58,8 @@ public class RestIntegTestTask extends DefaultTask {
@Input
Boolean includePackaged = false
public RestIntegTestTask() {
runner = project.tasks.create("${name}Runner", RandomizedTestingTask.class)
RestIntegTestTask() {
runner = project.tasks.create("${name}Runner", Test.class)
super.dependsOn(runner)
clusterInit = project.tasks.create(name: "${name}Cluster#init", dependsOn: project.testClasses)
runner.dependsOn(clusterInit)
@ -71,35 +77,66 @@ public class RestIntegTestTask extends DefaultTask {
runner.useCluster project.testClusters."$name"
}
// disable the build cache for rest test tasks
// there are a number of inputs we aren't properly tracking here so we'll just not cache these for now
runner.outputs.doNotCacheIf('Caching is disabled for REST integration tests') { true }
// override/add more for rest tests
runner.parallelism = '1'
runner.maxParallelForks = 1
runner.include('**/*IT.class')
runner.systemProperty('tests.rest.load_packaged', 'false')
/*
* We use lazy-evaluated strings in order to configure system properties whose value will not be known until
* execution time (e.g. cluster port numbers). Adding these via the normal DSL doesn't work as these get treated
* as task inputs and therefore Gradle attempts to snapshot them before/after task execution. This fails due
* to the GStrings containing references to non-serializable objects.
*
* We bypass this by instead passing this system properties vi a CommandLineArgumentProvider. This has the added
* side-effect that these properties are NOT treated as inputs, therefore they don't influence things like the
* build cache key or up to date checking.
*/
def nonInputProperties = new CommandLineArgumentProvider() {
private final Map<String, Object> systemProperties = [:]
void systemProperty(String key, Object value) {
systemProperties.put(key, value)
}
@Override
Iterable<String> asArguments() {
return systemProperties.collect { key, value ->
"-D${key}=${value.toString()}".toString()
}
}
}
runner.jvmArgumentProviders.add(nonInputProperties)
runner.ext.nonInputProperties = nonInputProperties
if (System.getProperty("tests.rest.cluster") == null) {
if (System.getProperty("tests.cluster") != null) {
throw new IllegalArgumentException("tests.rest.cluster and tests.cluster must both be null or non-null")
}
if (usesTestclusters == true) {
ElasticsearchCluster cluster = project.testClusters."${name}"
runner.systemProperty('tests.rest.cluster', {cluster.allHttpSocketURI.join(",") })
runner.systemProperty('tests.config.dir', {cluster.singleNode().getConfigDir()})
runner.systemProperty('tests.cluster', {cluster.transportPortURI})
nonInputProperties.systemProperty('tests.rest.cluster', "${-> cluster.allHttpSocketURI.join(",") }")
nonInputProperties.systemProperty('tests.config.dir', "${-> cluster.singleNode().getConfigDir() }")
nonInputProperties.systemProperty('tests.cluster', "${-> cluster.transportPortURI }")
} else {
// we pass all nodes to the rest cluster to allow the clients to round-robin between them
// this is more realistic than just talking to a single node
runner.systemProperty('tests.rest.cluster', "${-> nodes.collect { it.httpUri() }.join(",")}")
runner.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
nonInputProperties.systemProperty('tests.rest.cluster', "${-> nodes.collect { it.httpUri() }.join(",")}")
nonInputProperties.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
// both as separate sysprops
runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
nonInputProperties.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
// dump errors and warnings from cluster log on failure
TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() {
@Override
void afterExecute(Task task, TaskState state) {
if (state.failure != null) {
if (task == runner && state.failure != null) {
for (NodeInfo nodeInfo : nodes) {
printLogExcerpt(nodeInfo)
}
@ -194,9 +231,9 @@ public class RestIntegTestTask extends DefaultTask {
/** Print out an excerpt of the log from the given node. */
protected static void printLogExcerpt(NodeInfo nodeInfo) {
File logFile = new File(nodeInfo.homeDir, "logs/${nodeInfo.clusterName}.log")
println("\nCluster ${nodeInfo.clusterName} - node ${nodeInfo.nodeNum} log excerpt:")
println("(full log at ${logFile})")
println('-----------------------------------------')
LOGGER.lifecycle("\nCluster ${nodeInfo.clusterName} - node ${nodeInfo.nodeNum} log excerpt:")
LOGGER.lifecycle("(full log at ${logFile})")
LOGGER.lifecycle('-----------------------------------------')
Stream<String> stream = Files.lines(logFile.toPath(), StandardCharsets.UTF_8)
try {
boolean inStartup = true
@ -211,9 +248,9 @@ public class RestIntegTestTask extends DefaultTask {
}
if (inStartup || inExcerpt) {
if (linesSkipped != 0) {
println("... SKIPPED ${linesSkipped} LINES ...")
LOGGER.lifecycle("... SKIPPED ${linesSkipped} LINES ...")
}
println(line)
LOGGER.lifecycle(line)
linesSkipped = 0
} else {
++linesSkipped
@ -225,7 +262,7 @@ public class RestIntegTestTask extends DefaultTask {
} finally {
stream.close()
}
println('=========================================')
LOGGER.lifecycle('=========================================')
}

View File

@ -20,7 +20,8 @@
package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingPlugin
import groovy.transform.CompileStatic
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
import org.elasticsearch.gradle.VersionProperties
@ -28,48 +29,66 @@ 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.artifacts.Configuration
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import org.gradle.plugins.ide.eclipse.model.EclipseModel
import org.gradle.plugins.ide.idea.model.IdeaModel
/**
* Configures the build to compile tests against Elasticsearch's test framework
* and run REST tests. Use BuildPlugin if you want to build main code as well
* as tests.
*/
public class StandaloneRestTestPlugin implements Plugin<Project> {
@CompileStatic
class StandaloneRestTestPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
void apply(Project project) {
if (project.pluginManager.hasPlugin('elasticsearch.build')) {
throw new InvalidUserDataException('elasticsearch.standalone-test '
+ 'elasticsearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
project.pluginManager.apply(JavaBasePlugin)
project.pluginManager.apply(RandomizedTestingPlugin)
project.getTasks().create("buildResources", ExportElasticsearchBuildResourcesTask)
BuildPlugin.globalBuildInfo(project)
BuildPlugin.configureRepositories(project)
BuildPlugin.applyCommonTestConfig(project)
BuildPlugin.configureTestTasks(project)
// only setup tests to build
project.sourceSets.create('test')
SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer)
SourceSet testSourceSet = sourceSets.create('test')
project.tasks.withType(Test) { Test test ->
test.testClassesDirs = testSourceSet.output.classesDirs
test.classpath = testSourceSet.runtimeClasspath
}
// create a compileOnly configuration as others might expect it
project.configurations.create("compileOnly")
project.dependencies.add('testCompile', "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}")
project.eclipse.classpath.sourceSets = [project.sourceSets.test]
project.eclipse.classpath.plusConfigurations = [project.configurations.testRuntime]
project.idea.module.testSourceDirs += project.sourceSets.test.java.srcDirs
project.idea.module.scopes['TEST'] = [plus: [project.configurations.testRuntime]]
EclipseModel eclipse = project.extensions.getByType(EclipseModel)
eclipse.classpath.sourceSets = [testSourceSet]
eclipse.classpath.plusConfigurations = [project.configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)]
IdeaModel idea = project.extensions.getByType(IdeaModel)
idea.module.testSourceDirs += testSourceSet.java.srcDirs
idea.module.scopes.put('TEST', [plus: [project.configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)]] as Map<String, Collection<Configuration>>)
PrecommitTasks.create(project, false)
project.check.dependsOn(project.precommit)
project.tasks.getByName('check').dependsOn(project.tasks.getByName('precommit'))
project.tasks.withType(JavaCompile) {
project.tasks.withType(JavaCompile) { JavaCompile task ->
// This will be the default in Gradle 5.0
if (options.compilerArgs.contains("-processor") == false) {
options.compilerArgs << '-proc:none'
if (task.options.compilerArgs.contains("-processor") == false) {
task.options.compilerArgs << '-proc:none'
}
}
}

View File

@ -19,34 +19,30 @@
package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import groovy.transform.CompileStatic
import org.elasticsearch.gradle.BuildPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.tasks.testing.Test
/**
* Configures the build to compile against Elasticsearch's test framework and
* run integration and unit tests. Use BuildPlugin if you want to build main
* code as well as tests. */
public class StandaloneTestPlugin implements Plugin<Project> {
@CompileStatic
class StandaloneTestPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
void apply(Project project) {
project.pluginManager.apply(StandaloneRestTestPlugin)
Map testOptions = [
name: 'test',
type: RandomizedTestingTask,
dependsOn: 'testClasses',
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Runs unit tests that are separate'
]
RandomizedTestingTask test = project.tasks.create(testOptions)
Test test = project.tasks.create('test', Test)
test.group = JavaBasePlugin.VERIFICATION_GROUP
test.description = 'Runs unit tests that are separate'
BuildPlugin.configureCompile(project)
test.classpath = project.sourceSets.test.runtimeClasspath
test.testClassesDirs = project.sourceSets.test.output.classesDirs
test.mustRunAfter(project.precommit)
project.check.dependsOn(test)
test.mustRunAfter(project.tasks.getByName('precommit'))
project.tasks.getByName('check').dependsOn(test)
}
}

View File

@ -18,7 +18,7 @@
*/
package org.elasticsearch.gradle.vagrant
import com.carrotsearch.gradle.junit4.LoggingOutputStream
import org.elasticsearch.gradle.LoggingOutputStream
import org.gradle.api.GradleScriptException
import org.gradle.api.logging.Logger
import org.gradle.internal.logging.progress.ProgressLogger

View File

@ -18,7 +18,7 @@
*/
package org.elasticsearch.gradle.vagrant
import com.carrotsearch.gradle.junit4.LoggingOutputStream
import org.elasticsearch.gradle.LoggingOutputStream
import org.gradle.internal.logging.progress.ProgressLogger
/**

View File

@ -31,12 +31,10 @@ import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.testing.Test;
import org.gradle.api.tasks.util.PatternFilterable;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
@ -75,17 +73,6 @@ public class TestingConventionsTasks extends DefaultTask {
public Map<String, Set<File>> classFilesPerEnabledTask(FileTree testClassFiles) {
Map<String, Set<File>> collector = new HashMap<>();
// RandomizedTestingTask
collector.putAll(
getProject().getTasks().withType(getRandomizedTestingTask()).stream()
.filter(Task::getEnabled)
.collect(Collectors.toMap(
Task::getPath,
task -> testClassFiles.matching(getRandomizedTestingPatternSet(task)).getFiles()
)
)
);
// Gradle Test
collector.putAll(
getProject().getTasks().withType(Test.class).stream()
@ -279,32 +266,6 @@ public class TestingConventionsTasks extends DefaultTask {
.collect(Collectors.joining("\n"));
}
@SuppressWarnings("unchecked")
private PatternFilterable getRandomizedTestingPatternSet(Task task) {
try {
if (
getRandomizedTestingTask().isAssignableFrom(task.getClass()) == false
) {
throw new IllegalStateException("Expected " + task + " to be RandomizedTestingTask or Test but it was " + task.getClass());
}
Method getPatternSet = task.getClass().getMethod("getPatternSet");
return (PatternFilterable) getPatternSet.invoke(task);
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Expecte task to have a `patternSet` " + task, e);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Failed to get pattern set from task" + task, e);
}
}
@SuppressWarnings("unchecked")
private Class<? extends Task> getRandomizedTestingTask() {
try {
return (Class<? extends Task>) Class.forName("com.carrotsearch.gradle.junit4.RandomizedTestingTask");
} catch (ClassNotFoundException | ClassCastException e) {
throw new IllegalStateException("Failed to load randomized testing class", e);
}
}
private String checkNoneExists(String message, Stream<? extends Class<?>> stream) {
String problem = stream
.map(each -> " * " + each.getName())

View File

@ -0,0 +1,266 @@
package org.elasticsearch.gradle.test;
import org.gradle.api.internal.tasks.testing.logging.FullExceptionFormatter;
import org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.testing.TestDescriptor;
import org.gradle.api.tasks.testing.TestListener;
import org.gradle.api.tasks.testing.TestOutputEvent;
import org.gradle.api.tasks.testing.TestOutputListener;
import org.gradle.api.tasks.testing.TestResult;
import org.gradle.api.tasks.testing.logging.TestLogging;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.io.Writer;
import java.util.Deque;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class ErrorReportingTestListener implements TestOutputListener, TestListener {
private static final Logger LOGGER = Logging.getLogger(ErrorReportingTestListener.class);
private static final String REPRODUCE_WITH_PREFIX = "REPRODUCE WITH";
private final TestExceptionFormatter formatter;
private final File outputDirectory;
private Map<Descriptor, EventWriter> eventWriters = new ConcurrentHashMap<>();
private Map<Descriptor, Deque<String>> reproductionLines = new ConcurrentHashMap<>();
private Set<Descriptor> failedTests = new LinkedHashSet<>();
public ErrorReportingTestListener(TestLogging testLogging, File outputDirectory) {
this.formatter = new FullExceptionFormatter(testLogging);
this.outputDirectory = outputDirectory;
}
@Override
public void onOutput(TestDescriptor testDescriptor, TestOutputEvent outputEvent) {
TestDescriptor suite = testDescriptor.getParent();
// Check if this is output from the test suite itself (e.g. afterTest or beforeTest)
if (testDescriptor.isComposite()) {
suite = testDescriptor;
}
// Hold on to any repro messages so we can report them immediately on test case failure
if (outputEvent.getMessage().startsWith(REPRODUCE_WITH_PREFIX)) {
Deque<String> lines = reproductionLines.computeIfAbsent(Descriptor.of(suite), d -> new LinkedList<>());
lines.add(outputEvent.getMessage());
}
EventWriter eventWriter = eventWriters.computeIfAbsent(Descriptor.of(suite), EventWriter::new);
eventWriter.write(outputEvent);
}
@Override
public void beforeSuite(TestDescriptor suite) {
}
@Override
public void afterSuite(final TestDescriptor suite, TestResult result) {
Descriptor descriptor = Descriptor.of(suite);
try {
// if the test suite failed, report all captured output
if (result.getResultType().equals(TestResult.ResultType.FAILURE)) {
EventWriter eventWriter = eventWriters.get(descriptor);
if (eventWriter != null) {
// It's not explicit what the threading guarantees are for TestListener method execution so we'll
// be explicitly safe here to avoid interleaving output from multiple test suites
synchronized (this) {
// make sure we've flushed everything to disk before reading
eventWriter.flush();
System.err.println("\n\nSuite: " + suite);
try (BufferedReader reader = eventWriter.reader()) {
PrintStream out = System.out;
for (String message = reader.readLine(); message != null; message = reader.readLine()) {
if (message.startsWith(" 1> ")) {
out = System.out;
} else if (message.startsWith(" 2> ")) {
out = System.err;
}
out.println(message);
}
}
}
}
}
} catch (IOException e) {
throw new UncheckedIOException("Error reading test suite output", e);
} finally {
reproductionLines.remove(descriptor);
EventWriter writer = eventWriters.remove(descriptor);
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
LOGGER.error("Failed to close test suite output stream", e);
}
}
}
}
@Override
public void beforeTest(TestDescriptor testDescriptor) {
}
@Override
public void afterTest(TestDescriptor testDescriptor, TestResult result) {
if (result.getResultType() == TestResult.ResultType.FAILURE) {
failedTests.add(Descriptor.of(testDescriptor));
if (testDescriptor.getParent() != null) {
// go back and fetch the reproduction line for this test failure
Deque<String> lines = reproductionLines.get(Descriptor.of(testDescriptor.getParent()));
if (lines != null) {
String line = lines.getLast();
if (line != null) {
System.err.print('\n' + line);
}
}
// include test failure exception stacktraces in test suite output log
if (result.getExceptions().size() > 0) {
String message = formatter.format(testDescriptor, result.getExceptions()).substring(4);
EventWriter eventWriter = eventWriters.computeIfAbsent(Descriptor.of(testDescriptor.getParent()), EventWriter::new);
eventWriter.write(new TestOutputEvent() {
@Override
public Destination getDestination() {
return Destination.StdErr;
}
@Override
public String getMessage() {
return message;
}
});
}
}
}
}
public Set<Descriptor> getFailedTests() {
return failedTests;
}
/**
* Class for identifying test output sources. We use this rather than Gradle's {@link TestDescriptor} as we want
* to avoid any nasty memory leak issues that come from keeping Gradle implementation types in memory. Since we
* use this a the key for our HashMap, it's best to control the implementation as there's no guarantee that Gradle's
* various {@link TestDescriptor} implementations reliably implement equals and hashCode.
*/
public static class Descriptor {
private final String name;
private final String className;
private final String parent;
private Descriptor(String name, String className, String parent) {
this.name = name;
this.className = className;
this.parent = parent;
}
public static Descriptor of(TestDescriptor d) {
return new Descriptor(d.getName(), d.getClassName(), d.getParent() == null ? null : d.getParent().toString());
}
public String getClassName() {
return className;
}
public String getFullName() {
return className + "." + name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Descriptor that = (Descriptor) o;
return Objects.equals(name, that.name) &&
Objects.equals(className, that.className) &&
Objects.equals(parent, that.parent);
}
@Override
public int hashCode() {
return Objects.hash(name, className, parent);
}
}
private class EventWriter implements Closeable {
private final File outputFile;
private final Writer writer;
EventWriter(Descriptor descriptor) {
this.outputFile = new File(outputDirectory, descriptor.getClassName() + ".out");
FileOutputStream fos;
try {
fos = new FileOutputStream(this.outputFile);
} catch (IOException e) {
throw new UncheckedIOException("Unable to create test suite output file", e);
}
this.writer = new PrintWriter(new BufferedOutputStream(fos));
}
public void write(TestOutputEvent event) {
String prefix;
if (event.getDestination() == TestOutputEvent.Destination.StdOut) {
prefix = " 1> ";
} else {
prefix = " 2> ";
}
try {
if (event.getMessage().equals("\n")) {
writer.write(event.getMessage());
} else {
writer.write(prefix + event.getMessage());
}
} catch (IOException e) {
throw new UncheckedIOException("Unable to write test suite output", e);
}
}
public void flush() throws IOException {
writer.flush();
}
public BufferedReader reader() {
try {
return new BufferedReader(new FileReader(outputFile));
} catch (IOException e) {
throw new UncheckedIOException("Unable to read test suite output file", e);
}
}
@Override
public void close() throws IOException {
writer.close();
// there's no need to keep this stuff on disk after suite execution
outputFile.delete();
}
}
}

View File

@ -32,9 +32,8 @@ import org.gradle.api.Task;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.ExtraPropertiesExtension;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.testing.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.function.BiConsumer;
@ -103,7 +102,7 @@ public class TestFixturesPlugin implements Plugin<Project> {
.matching(fixtureProject -> fixtureProject.equals(project) == false)
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));
conditionTaskByType(tasks, extension, getTaskClass("com.carrotsearch.gradle.junit4.RandomizedTestingTask"));
conditionTaskByType(tasks, extension, Test.class);
conditionTaskByType(tasks, extension, getTaskClass("org.elasticsearch.gradle.test.RestIntegTestTask"));
conditionTaskByType(tasks, extension, TestingConventionsTasks.class);
conditionTaskByType(tasks, extension, ComposeUp.class);
@ -116,18 +115,14 @@ public class TestFixturesPlugin implements Plugin<Project> {
return;
}
tasks.withType(getTaskClass("com.carrotsearch.gradle.junit4.RandomizedTestingTask"), task ->
tasks.withType(Test.class, task ->
extension.fixtures.all(fixtureProject -> {
fixtureProject.getTasks().matching(it -> it.getName().equals("buildFixture")).all(buildFixture ->
task.dependsOn(buildFixture)
);
fixtureProject.getTasks().matching(it -> it.getName().equals("composeDown")).all(composeDown ->
task.finalizedBy(composeDown)
);
fixtureProject.getTasks().matching(it -> it.getName().equals("buildFixture")).all(task::dependsOn);
fixtureProject.getTasks().matching(it -> it.getName().equals("composeDown")).all(task::finalizedBy);
configureServiceInfoForTask(
task,
fixtureProject,
(name, port) -> setSystemProperty(task, name, port)
task::systemProperty
);
task.dependsOn(fixtureProject.getTasks().getByName("postProcessFixture"));
})
@ -182,17 +177,6 @@ public class TestFixturesPlugin implements Plugin<Project> {
return hasDockerCompose && Boolean.parseBoolean(System.getProperty("tests.fixture.enabled", "true"));
}
private void setSystemProperty(Task task, String name, Object value) {
try {
Method systemProperty = task.getClass().getMethod("systemProperty", String.class, Object.class);
systemProperty.invoke(task, name, value);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Could not find systemProperty method on RandomizedTestingTask", e);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("Could not call systemProperty method on RandomizedTestingTask", e);
}
}
private void disableTaskByType(TaskContainer tasks, Class<? extends Task> type) {
tasks.withType(type, task -> task.setEnabled(false));
}

View File

@ -1 +0,0 @@
implementation-class=com.carrotsearch.gradle.junit4.RandomizedTestingPlugin

View File

@ -62,7 +62,7 @@ public class TestingConventionsTasksIT extends GradleIntegrationTestCase {
BuildResult result = runner.buildAndFail();
assertOutputContains(result.getOutput(),
"Expected at least one test class included in task :empty_test_task:emptyTest, but found none.",
"Expected at least one test class included in task :empty_test_task:emptyTestRandomized, but found none."
"Expected at least one test class included in task :empty_test_task:test, but found none."
);
}
@ -71,9 +71,8 @@ public class TestingConventionsTasksIT extends GradleIntegrationTestCase {
.withArguments("clean", ":all_classes_in_tasks:testingConventions", "-i", "-s");
BuildResult result = runner.buildAndFail();
assertOutputContains(result.getOutput(),
"Test classes are not included in any enabled task (:all_classes_in_tasks:emptyTestRandomized):",
" * org.elasticsearch.gradle.testkit.NamingConventionIT",
" * org.elasticsearch.gradle.testkit.NamingConventionTests"
"Test classes are not included in any enabled task (:all_classes_in_tasks:test):",
" * org.elasticsearch.gradle.testkit.NamingConventionIT"
);
}

View File

@ -27,7 +27,7 @@ forbiddenApisTest.enabled = false
// requires dependency on testing fw
jarHell.enabled = false
// we don't have tests for now
unitTest.enabled = false
test.enabled = false
task hello {
doFirst {

View File

@ -25,22 +25,16 @@ allprojects {
baseClasses = []
}
}
unitTest.enabled = false
}
project(':empty_test_task') {
task emptyTest(type: Test) {
}
task emptyTestRandomized(type: com.carrotsearch.gradle.junit4.RandomizedTestingTask) {
}
}
project(':all_classes_in_tasks') {
task emptyTestRandomized(type: com.carrotsearch.gradle.junit4.RandomizedTestingTask) {
test {
include "**/Convention*"
}
}
@ -54,14 +48,14 @@ project(':not_implementing_base') {
baseClass 'org.elasticsearch.gradle.testkit.Integration'
}
}
task randomized(type: com.carrotsearch.gradle.junit4.RandomizedTestingTask) {
test {
include "**/*IT.class"
include "**/*Tests.class"
}
}
project(':valid_setup_no_base') {
task randomized(type: com.carrotsearch.gradle.junit4.RandomizedTestingTask) {
test {
include "**/*IT.class"
include "**/*Tests.class"
}
@ -72,7 +66,7 @@ project(':tests_in_main') {
}
project (':valid_setup_with_base') {
task randomized(type: com.carrotsearch.gradle.junit4.RandomizedTestingTask) {
test {
include "**/*IT.class"
include "**/*Tests.class"
}

View File

@ -29,7 +29,7 @@ archivesBaseName = 'client-benchmarks'
mainClassName = 'org.elasticsearch.client.benchmark.BenchmarkMain'
// never try to invoke tests on the benchmark project - there aren't any
unitTest.enabled = false
test.enabled = false
dependencies {
compile 'org.apache.commons:commons-math3:3.2'

View File

@ -36,5 +36,5 @@ dependenciesInfo.enabled = false
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
// no unit tests
unitTest.enabled = false
test.enabled = false
integTest.enabled = false

View File

@ -53,4 +53,4 @@ dependenciesInfo.enabled = false
//we aren't releasing this jar
thirdPartyAudit.enabled = false
unitTest.enabled = false
test.enabled = false

View File

@ -26,7 +26,7 @@ integTestRunner {
* when running against an external cluster.
*/
if (System.getProperty("tests.rest.cluster") == null) {
systemProperty 'tests.logfile',
nonInputProperties.systemProperty 'tests.logfile',
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_server.json"
} else {
systemProperty 'tests.logfile', '--external--'

View File

@ -7,7 +7,7 @@ forbiddenApisMain {
replaceSignatureFiles 'jdk-signatures'
}
unitTest.enabled = false
test.enabled = false
javadoc.enabled = false
loggerUsageCheck.enabled = false
jarHell.enabled = false

View File

@ -35,7 +35,7 @@ dependencyLicenses {
mapping from: /bc.*/, to: 'bouncycastle'
}
unitTest {
test {
// TODO: find a way to add permissions for the tests in this module
systemProperty 'tests.security.manager', 'false'
}

View File

@ -26,7 +26,7 @@ dependencies {
compile "org.elasticsearch:elasticsearch-core:${version}"
}
unitTest.enabled = false
test.enabled = false
// Since CLI does not depend on :server, it cannot run the jarHell task
jarHell.enabled = false

View File

@ -196,18 +196,23 @@ public class JarHell {
// case for tests: where we have class files in the classpath
final Path root = PathUtils.get(url.toURI());
final String sep = root.getFileSystem().getSeparator();
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String entry = root.relativize(file).toString();
if (entry.endsWith(".class")) {
// normalize with the os separator, remove '.class'
entry = entry.replace(sep, ".").substring(0, entry.length() - ".class".length());
checkClass(clazzes, entry, path);
// don't try and walk class or resource directories that don't exist
// gradle will add these to the classpath even if they never get created
if (Files.exists(root)) {
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String entry = root.relativize(file).toString();
if (entry.endsWith(".class")) {
// normalize with the os separator, remove '.class'
entry = entry.replace(sep, ".").substring(0, entry.length() - ".class".length());
checkClass(clazzes, entry, path);
}
return super.visitFile(file, attrs);
}
return super.visitFile(file, attrs);
}
});
});
}
}
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
unitTest.enabled = false
test.enabled = false
// test depend on ES core...
forbiddenApisMain.enabled = false

View File

@ -37,8 +37,8 @@ dependencyLicenses {
mapping from: /asm-.*/, to: 'asm'
}
unitTest {
jvmArg '-XX:-OmitStackTraceInFastThrow'
test {
jvmArgs '-XX:-OmitStackTraceInFastThrow'
}
/* Build Javadoc for the Java classes in Painless's public API that are in the

View File

@ -37,4 +37,4 @@ dependencies {
}
// no tests...yet?
unitTest.enabled = false
test.enabled = false

View File

@ -45,7 +45,7 @@ run {
setting 'reindex.remote.whitelist', '127.0.0.1:*'
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the
* same JVM randomize processors and will step on each other if we allow them to
@ -148,8 +148,8 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
systemProperty "tests.fromOld", "true"
/* Use a closure on the string to delay evaluation until right before we
* run the integration tests so that we can be sure that the file is
* ready. */
systemProperty "es${version}.port", "${ -> fixture.addressAndPort }"
* ready. */
nonInputProperties.systemProperty "es${version}.port", "${ -> fixture.addressAndPort }"
}
}
}

View File

@ -46,7 +46,7 @@ dependencyLicenses {
mapping from: /netty-.*/, to: 'netty'
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.

View File

@ -64,7 +64,7 @@ task writeTestJavaPolicy {
}
}
unitTest {
test {
dependsOn writeTestJavaPolicy
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name

View File

@ -29,7 +29,7 @@ check {
dependsOn 'qa:gce:check'
}
unitTest {
test {
// this is needed for insecure plugins, remove if possible!
systemProperty 'tests.artifact', project.name
}

View File

@ -32,4 +32,4 @@ integTestCluster {
}
// this plugin has no unit tests, only rest tests
tasks.unitTest.enabled = false
tasks.test.enabled = false

View File

@ -35,4 +35,4 @@ if (System.getProperty('tests.distribution') == null) {
integTestCluster.distribution = 'oss'
}
unitTest.enabled = false
test.enabled = false

View File

@ -27,7 +27,7 @@ esplugin {
}
// No unit tests in this example
unitTest.enabled = false
test.enabled = false
task exampleFixture(type: org.elasticsearch.gradle.test.AntFixture) {
dependsOn testClasses
@ -40,7 +40,7 @@ integTestCluster {
dependsOn exampleFixture
}
integTestRunner {
systemProperty 'external.address', "${ -> exampleFixture.addressAndPort }"
nonInputProperties.systemProperty 'external.address', "${ -> exampleFixture.addressAndPort }"
}
testingConventions.naming {

View File

@ -26,5 +26,5 @@ esplugin {
noticeFile rootProject.file('NOTICE.txt')
}
unitTest.enabled = false
test.enabled = false

View File

@ -24,6 +24,7 @@ import org.elasticsearch.gradle.test.RestIntegTestTask
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
apply plugin: 'elasticsearch.test.fixtures'
esplugin {
@ -150,9 +151,9 @@ project.afterEvaluate {
Task restIntegTestTaskRunner = project.tasks.getByName("${integTestTaskName}Runner")
restIntegTestTaskRunner.systemProperty "test.krb5.principal.es", "elasticsearch@${realm}"
restIntegTestTaskRunner.systemProperty "test.krb5.principal.hdfs", "hdfs/hdfs.build.elastic.co@${realm}"
restIntegTestTaskRunner.jvmArg "-Djava.security.krb5.conf=${krb5conf}"
restIntegTestTaskRunner.jvmArgs "-Djava.security.krb5.conf=${krb5conf}"
if (project.runtimeJavaVersion == JavaVersion.VERSION_1_9) {
restIntegTestTaskRunner.jvmArg '--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED'
restIntegTestTaskRunner.jvmArgs '--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED'
}
restIntegTestTaskRunner.systemProperty (
"test.krb5.keytab.hdfs",
@ -221,7 +222,7 @@ if (fixtureSupported) {
integTestRunner.systemProperty 'tests.rest.suite', 'hdfs_repository'
// Only include the HA integration tests for the HA test task
integTestHaRunner.patternSet.setIncludes(['**/Ha*TestSuiteIT.class'])
integTestHaRunner.setIncludes(['**/Ha*TestSuiteIT.class'])
} else {
if (legalPath) {
logger.warn("hdfsFixture unsupported, please set HADOOP_HOME and put HADOOP_HOME\\bin in PATH")
@ -252,7 +253,7 @@ integTestSecureRunner.systemProperty 'tests.rest.suite', 'secure_hdfs_repository
// Ignore HA integration Tests. They are included below as part of integTestSecureHa test runner.
integTestSecureRunner.exclude('**/Ha*TestSuiteIT.class')
// Only include the HA integration tests for the HA test task
integTestSecureHaRunner.patternSet.setIncludes(['**/Ha*TestSuiteIT.class'])
integTestSecureHaRunner.setIncludes(['**/Ha*TestSuiteIT.class'])
thirdPartyAudit {
ignoreMissingClasses()

View File

@ -2,7 +2,6 @@ import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.MavenFilteringHack
import org.elasticsearch.gradle.test.AntFixture
import org.elasticsearch.gradle.test.RestIntegTestTask
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
/*
* Licensed to Elasticsearch under one or more contributor
@ -65,14 +64,14 @@ bundlePlugin {
}
}
task testRepositoryCreds(type: RandomizedTestingTask) {
task testRepositoryCreds(type: Test) {
include '**/RepositoryCredentialsTests.class'
include '**/S3BlobStoreRepositoryTests.class'
systemProperty 'es.allow_insecure_settings', 'true'
}
check.dependsOn(testRepositoryCreds)
unitTest {
test {
// these are tested explicitly in separate test tasks
exclude '**/*CredentialsTests.class'
exclude '**/S3BlobStoreRepositoryTests.class'

View File

@ -27,11 +27,11 @@ esplugin {
integTestRunner {
systemProperty 'tests.security.manager', 'false'
systemProperty 'tests.system_call_filter', 'false'
systemProperty 'pidfile', "${-> integTest.getNodes().get(0).pidFile}"
systemProperty 'log', "${-> integTest.getNodes().get(0).homeDir}/logs/${-> integTest.getNodes().get(0).clusterName}_server.json"
nonInputProperties.systemProperty 'pidfile', "${-> integTest.getNodes().get(0).pidFile}"
nonInputProperties.systemProperty 'log', "${-> integTest.getNodes().get(0).homeDir}/logs/${-> integTest.getNodes().get(0).clusterName}_server.json"
systemProperty 'runtime.java.home', "${project.runtimeJavaHome}"
}
unitTest.enabled = false
test.enabled = false
check.dependsOn integTest

View File

@ -31,7 +31,7 @@ dependencies {
// TODO: give each evil test its own fresh JVM for more isolation.
unitTest {
test {
systemProperty 'tests.security.manager', 'false'
}

View File

@ -92,7 +92,7 @@ for (Version version : bwcVersions.indexCompatible) {
}
}
unitTest.enabled = false // no unit tests for rolling upgrades, only the rest integration test
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
// basic integ tests includes testing bwc against the most recent version
task bwcTestSnapshots {

View File

@ -31,10 +31,10 @@ integTestCluster {
}
integTestRunner {
systemProperty 'tests.logfile',
nonInputProperties.systemProperty 'tests.logfile',
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_server.log"
}
unitTest {
test {
systemProperty 'tests.security.manager', 'false'
}

View File

@ -60,7 +60,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}
unitTest.enabled = false // no unit tests for rolling upgrades, only the rest integration test
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
// basic integ tests includes testing bwc against the most recent version
task bwcTestSnapshots {

View File

@ -57,6 +57,6 @@ task integTest {
dependsOn = [mixedClusterTest]
}
unitTest.enabled = false // no unit tests for multi-cluster-search, only integration tests
test.enabled = false // no unit tests for multi-cluster-search, only integration tests
check.dependsOn(integTest)

View File

@ -139,7 +139,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}
unitTest.enabled = false // no unit tests for rolling upgrades, only the rest integration test
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
// basic integ tests includes testing bwc against the most recent version
task bwcTestSnapshots {

View File

@ -29,6 +29,6 @@ integTestCluster {
}
integTestRunner {
systemProperty 'tests.logfile',
nonInputProperties.systemProperty 'tests.logfile',
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_server.json"
}

View File

@ -71,7 +71,7 @@ forbiddenApisMain {
}
// we don't have additional tests for the tests themselves
tasks.unitTest.enabled = false
tasks.test.enabled = false
// Tests are destructive and meant to run in a VM, they don't adhere to general conventions
testingConventions.enabled = false

View File

@ -52,7 +52,7 @@ for (Version version : bwcVersions.indexCompatible) {
bwcTest.dependsOn(versionBwcTest)
}
unitTest.enabled = false
test.enabled = false
task bwcTestSnapshots {
if (project.bwc_tests_enabled) {

View File

@ -211,7 +211,7 @@ if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
check.dependsOn(integTest)
unitTest.enabled = false
test.enabled = false
dependencyLicenses.enabled = false
dependenciesInfo.enabled = false

View File

@ -2,5 +2,5 @@ apply plugin: 'elasticsearch.build'
apply plugin: 'nebula.maven-base-publish'
apply plugin: 'nebula.maven-scm'
unitTest.enabled = false
test.enabled = false
jarHell.enabled = false

View File

@ -17,8 +17,6 @@
* under the License.
*/
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
apply plugin: 'elasticsearch.build'
apply plugin: 'nebula.optional-base'
apply plugin: 'nebula.maven-base-publish'
@ -331,14 +329,15 @@ dependencyLicenses {
}
if (isEclipse == false || project.path == ":server-tests") {
task integTest(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Multi-node tests',
dependsOn: unitTest.dependsOn) {
task integTest(type: Test) {
description = 'Multi-node tests'
mustRunAfter test
include '**/*IT.class'
}
check.dependsOn integTest
integTest.mustRunAfter test
task internalClusterTest {
dependsOn integTest
}

View File

@ -56,6 +56,8 @@ grant codeBase "${codebase.randomizedtesting-runner}" {
grant codeBase "${codebase.junit}" {
// needed for TestClass creation
permission java.lang.RuntimePermission "accessDeclaredMembers";
// needed for test listener notifications
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};
grant codeBase "${codebase.mocksocket}" {
@ -86,3 +88,20 @@ grant codeBase "${codebase.httpasyncclient}" {
// rest client uses system properties which gets the default proxy
permission java.net.NetPermission "getProxySelector";
};
grant codeBase "file:${gradle.dist.lib}/-" {
// gradle test worker code needs a slew of permissions, we give full access here since gradle isn't a production
// dependency and there's no point in exercising the security policy against it
permission java.security.AllPermission;
};
grant codeBase "file:${gradle.worker.jar}" {
// gradle test worker code needs a slew of permissions, we give full access here since gradle isn't a production
// dependency and there's no point in exercising the security policy against it
permission java.security.AllPermission;
};
grant {
// since the gradle test worker jar is on the test classpath, our tests should be able to read it
permission java.io.FilePermission "${gradle.worker.jar}", "read";
};

View File

@ -23,5 +23,5 @@ dependencies {
compile "org.apache.hadoop:hadoop-minicluster:2.8.1"
}
unitTest.enabled = false
test.enabled = false
thirdPartyAudit.enabled = false

View File

@ -53,4 +53,4 @@ buildFixture.enabled = false
project.ext.krb5Conf = { service -> file("$buildDir/shared/${service}/krb5.conf") }
project.ext.krb5Keytabs = { service, fileName -> file("$buildDir/shared/${service}/keytabs/${fileName}") }
unitTest.enabled = false
test.enabled = false

View File

@ -24,7 +24,7 @@ a "ports" file with the port on which Elasticsearch is running.
"""
apply plugin: 'elasticsearch.build'
unitTest.enabled = false
test.enabled = false
dependencies {
// Just for the constants....

View File

@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import com.carrotsearch.gradle.junit4.RandomizedTestingTask;
dependencies {
compile "org.elasticsearch.client:elasticsearch-rest-client:${version}"
@ -64,12 +63,12 @@ thirdPartyAudit.ignoreMissingClasses (
'org.jmock.core.Constraint'
)
unitTest {
test {
systemProperty 'tests.gradle_index_compat_versions', bwcVersions.indexCompatible.join(',')
systemProperty 'tests.gradle_wire_compat_versions', bwcVersions.wireCompatible.join(',')
systemProperty 'tests.gradle_unreleased_versions', bwcVersions.unreleased.join(',')
}
task integTest(type: RandomizedTestingTask) {
task integTest(type: Test) {
include "**/*IT.class"
}

View File

@ -37,6 +37,7 @@ import org.junit.Assert;
import java.io.InputStream;
import java.net.SocketPermission;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Permission;
import java.security.Permissions;
@ -252,9 +253,12 @@ public class BootstrapForTesting {
Set<URL> raw = JarHell.parseClassPath();
Set<URL> cooked = new HashSet<>(raw.size());
for (URL url : raw) {
boolean added = cooked.add(PathUtils.get(url.toURI()).toRealPath().toUri().toURL());
if (added == false) {
throw new IllegalStateException("Duplicate in classpath after resolving symlinks: " + url);
Path path = PathUtils.get(url.toURI());
if (Files.exists(path)) {
boolean added = cooked.add(path.toRealPath().toUri().toURL());
if (added == false) {
throw new IllegalStateException("Duplicate in classpath after resolving symlinks: " + url);
}
}
}
return raw;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.test.junit.listeners;
import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.Constants;
@ -38,6 +37,7 @@ import java.util.TimeZone;
import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_ITERATIONS;
import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_PREFIX;
import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_TESTCLASS;
import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_TESTMETHOD;
import static org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.REST_TESTS_BLACKLIST;
import static org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.REST_TESTS_SUITE;
@ -77,8 +77,14 @@ public class ReproduceInfoPrinter extends RunListener {
final String gradlew = Constants.WINDOWS ? "gradlew" : "./gradlew";
final StringBuilder b = new StringBuilder("REPRODUCE WITH: " + gradlew + " ");
String task = System.getProperty("tests.task");
// TODO: enforce (intellij still runs the runner?) or use default "test" but that won't work for integ
// append Gradle test runner test filter string
b.append(task);
b.append(" --tests \"");
b.append(failure.getDescription().getClassName());
b.append(".");
b.append(failure.getDescription().getMethodName());
b.append("\"");
GradleMessageBuilder gradleMessageBuilder = new GradleMessageBuilder(b);
gradleMessageBuilder.appendAllOpts(failure.getDescription());
@ -106,11 +112,6 @@ public class ReproduceInfoPrinter extends RunListener {
public ReproduceErrorMessageBuilder appendAllOpts(Description description) {
super.appendAllOpts(description);
if (description.getMethodName() != null) {
//prints out the raw method description instead of methodName(description) which filters out the parameters
super.appendOpt(SYSPROP_TESTMETHOD(), "\"" + description.getMethodName() + "\"");
}
return appendESProperties();
}
@ -128,6 +129,11 @@ public class ReproduceInfoPrinter extends RunListener {
if (sysPropName.equals(SYSPROP_ITERATIONS())) { // we don't want the iters to be in there!
return this;
}
if (sysPropName.equals(SYSPROP_TESTCLASS())) {
//don't print out the test class, we print it ourselves in appendAllOpts
//without filtering out the parameters (needed for REST tests)
return this;
}
if (sysPropName.equals(SYSPROP_TESTMETHOD())) {
//don't print out the test method, we print it ourselves in appendAllOpts
//without filtering out the parameters (needed for REST tests)
@ -143,7 +149,7 @@ public class ReproduceInfoPrinter extends RunListener {
return this;
}
public ReproduceErrorMessageBuilder appendESProperties() {
private ReproduceErrorMessageBuilder appendESProperties() {
appendProperties("tests.es.logger.level");
if (inVerifyPhase()) {
// these properties only make sense for integration tests

View File

@ -1,5 +1,3 @@
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
evaluationDependsOn(xpackModule('core'))
apply plugin: 'elasticsearch.esplugin'
@ -18,28 +16,27 @@ integTest.enabled = false
// Integration Test classes that cannot run with the security manager
String[] noSecurityManagerITClasses = [ "**/CloseFollowerIndexIT.class" ]
// Instead we create a separate task to run the
// tests based on ESIntegTestCase
task internalClusterTest(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Java fantasy integration tests',
dependsOn: unitTest.dependsOn) {
include '**/*IT.class'
exclude noSecurityManagerITClasses
systemProperty 'es.set.netty.runtime.available.processors', 'false'
}
check.dependsOn internalClusterTest
internalClusterTest.mustRunAfter test
task internalClusterTestNoSecurityManager(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Java fantasy integration tests with no security manager',
dependsOn: unitTest.dependsOn) {
task internalClusterTestNoSecurityManager(type: Test) {
description = 'Java fantasy integration tests with no security manager'
include noSecurityManagerITClasses
systemProperty 'es.set.netty.runtime.available.processors', 'false'
systemProperty 'tests.security.manager', 'false'
}
internalClusterTest.dependsOn internalClusterTestNoSecurityManager
// Instead we create a separate task to run the
// tests based on ESIntegTestCase
task internalClusterTest(type: Test) {
description = 'Java fantasy integration tests'
dependsOn internalClusterTestNoSecurityManager
mustRunAfter test
include '**/*IT.class'
exclude noSecurityManagerITClasses
systemProperty 'es.set.netty.runtime.available.processors', 'false'
}
check.dependsOn internalClusterTest
// add all sub-projects of the qa sub-project
gradle.projectsEvaluated {

View File

@ -1,7 +1,7 @@
import org.elasticsearch.gradle.test.RestIntegTestTask
apply plugin: 'elasticsearch.build'
unitTest.enabled = false
test.enabled = false
dependencies {
compile project(':test:framework')

View File

@ -53,11 +53,11 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'java.security.policy', "file://${buildDir}/tmp/java.policy"
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'log', "${-> followClusterTest.getNodes().get(0).homeDir}/logs/" +
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'log', "${-> followClusterTest.getNodes().get(0).homeDir}/logs/" +
"${-> followClusterTest.getNodes().get(0).clusterName}_server.json"
finalizedBy 'leaderClusterTestCluster#stop'
}
check.dependsOn followClusterTest
unitTest.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
test.enabled = false // no unit tests for multi-cluster-search, only the rest integration test

View File

@ -36,7 +36,7 @@ middleClusterTestCluster {
middleClusterTestRunner {
systemProperty 'tests.target_cluster', 'middle'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
}
task followClusterTest(type: RestIntegTestTask) {}
@ -54,11 +54,11 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.middle_host', "${-> middleClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.middle_host', "${-> middleClusterTest.nodes.get(0).httpUri()}"
finalizedBy 'leaderClusterTestCluster#stop'
finalizedBy 'middleClusterTestCluster#stop'
}
check.dependsOn followClusterTest
unitTest.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
test.enabled = false // no unit tests for multi-cluster-search, only the rest integration test

View File

@ -33,9 +33,9 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
finalizedBy 'leaderClusterTestCluster#stop'
}
check.dependsOn followClusterTest
unitTest.enabled = false
test.enabled = false

View File

@ -37,4 +37,4 @@ restTestCluster {
}
check.dependsOn restTest
unitTest.enabled = false
test.enabled = false

View File

@ -35,7 +35,7 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
}
task followClusterRestartTest(type: RestIntegTestTask) {}
@ -53,9 +53,9 @@ followClusterRestartTestCluster {
followClusterRestartTestRunner {
systemProperty 'tests.target_cluster', 'follow-restart'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
finalizedBy 'leaderClusterTestCluster#stop'
}
check.dependsOn followClusterRestartTest
unitTest.enabled = false
test.enabled = false

View File

@ -68,9 +68,9 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
finalizedBy 'leaderClusterTestCluster#stop'
}
check.dependsOn followClusterTest
unitTest.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
test.enabled = false // no unit tests for multi-cluster-search, only the rest integration test

View File

@ -2,7 +2,6 @@ import org.elasticsearch.gradle.MavenFilteringHack
import java.nio.file.Files
import java.nio.file.Paths
import com.carrotsearch.gradle.junit4.RandomizedTestingTask;
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'nebula.maven-base-publish'
@ -102,7 +101,7 @@ sourceSets.test.resources {
srcDir 'src/main/config'
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.
@ -142,6 +141,6 @@ thirdPartyAudit.ignoreMissingClasses (
integTest.enabled = false
// There are some integ tests that don't require a cluster, we still want to run those
task internalClusterTest(type: RandomizedTestingTask) {
task internalClusterTest(type: Test) {
include "**/*IT.class"
}

View File

@ -1,7 +1,7 @@
import org.elasticsearch.gradle.test.RestIntegTestTask
apply plugin: 'elasticsearch.build'
unitTest.enabled = false
test.enabled = false
dependencies {
compile project(':test:framework')

View File

@ -50,12 +50,12 @@ followClusterTestCluster {
followClusterTestRunner {
systemProperty 'tests.target_cluster', 'follow'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
/* To support taking index snapshots, we have to set path.repo setting */
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
finalizedBy 'leaderClusterTestCluster#stop'
}
check.dependsOn followClusterTest
unitTest.enabled = false // no unit tests for this module, only the rest integration test
test.enabled = false // no unit tests for this module, only the rest integration test

View File

@ -42,4 +42,4 @@ restTestCluster {
}
check.dependsOn restTest
unitTest.enabled = false
test.enabled = false

View File

@ -1,5 +1,3 @@
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
evaluationDependsOn(xpackModule('core'))
apply plugin: 'elasticsearch.esplugin'
@ -94,12 +92,11 @@ integTest.enabled = false
// Instead we create a separate task to run the
// tests based on ESIntegTestCase
task internalClusterTest(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Multi-node tests',
dependsOn: unitTest.dependsOn) {
include '**/*IT.class'
systemProperty 'es.set.netty.runtime.available.processors', 'false'
task internalClusterTest(type: Test) {
description = 'Multi-node tests'
include '**/*IT.class'
systemProperty 'es.set.netty.runtime.available.processors', 'false'
}
check.dependsOn internalClusterTest
internalClusterTest.mustRunAfter test

View File

@ -1,5 +1,3 @@
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
evaluationDependsOn(xpackModule('core'))
apply plugin: 'elasticsearch.esplugin'
@ -58,15 +56,15 @@ integTest.enabled = false
// Instead we create a separate task to run the
// tests based on ESIntegTestCase
task internalClusterTest(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
description: 'Multi-node tests',
dependsOn: unitTest.dependsOn) {
include '**/*IT.class'
systemProperty 'es.set.netty.runtime.available.processors', 'false'
task internalClusterTest(type: Test) {
description = 'Multi-node tests'
mustRunAfter test
include '**/*IT.class'
systemProperty 'es.set.netty.runtime.available.processors', 'false'
}
check.dependsOn internalClusterTest
internalClusterTest.mustRunAfter test
// also add an "alias" task to make typing on the command line easier task icTest {
task icTest {

View File

@ -288,7 +288,7 @@ run {
plugin xpackModule('core')
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.

View File

@ -23,7 +23,7 @@ dependencyLicenses {
}
if (project.inFipsJvm) {
unitTest.enabled = false
test.enabled = false
testingConventions.enabled = false
// Forbiden APIs non-portable checks fail because bouncy castle classes being used from the FIPS JDK since those are
// not part of the Java specification - all of this is as designed, so we have to relax this check for FIPS.

View File

@ -1,7 +1,7 @@
import org.elasticsearch.gradle.test.RestIntegTestTask
apply plugin: 'elasticsearch.build'
unitTest.enabled = false
test.enabled = false
dependencies {
compile project(':test:framework')

View File

@ -1,5 +1,3 @@
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
evaluationDependsOn(xpackModule('core'))
apply plugin: 'elasticsearch.esplugin'
@ -30,14 +28,13 @@ archivesBaseName = 'x-pack-sql'
// All integration tests live in qa modules
integTest.enabled = false
task internalClusterTest(type: RandomizedTestingTask,
group: JavaBasePlugin.VERIFICATION_GROUP,
dependsOn: unitTest.dependsOn) {
task internalClusterTest(type: Test) {
mustRunAfter test
include '**/*IT.class'
systemProperty 'es.set.netty.runtime.available.processors', 'false'
}
check.dependsOn internalClusterTest
internalClusterTest.mustRunAfter test
dependencies {
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here

View File

@ -37,7 +37,7 @@ dependencyLicenses {
ignoreSha 'elasticsearch'
}
unitTest {
test {
// don't use the shaded jar for tests
classpath += project.tasks.compileJava.outputs.files
classpath -= project.tasks.shadowJar.outputs.files

View File

@ -30,7 +30,7 @@ dependencies {
/* disable unit tests because these are all integration tests used
* other qa projects. */
unitTest.enabled = false
test.enabled = false
dependencyLicenses.enabled = false
dependenciesInfo.enabled = false

View File

@ -44,9 +44,9 @@ subprojects {
integTestRunner {
def today = new Date().format('yyyy-MM-dd')
systemProperty 'tests.audit.logfile',
nonInputProperties.systemProperty 'tests.audit.logfile',
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_audit.json"
systemProperty 'tests.audit.yesterday.logfile',
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
"${ -> integTest.nodes[0].homeDir}/logs/${ -> integTest.nodes[0].clusterName }_audit-${today}.json"
}

View File

@ -106,7 +106,7 @@ task runcli {
}
// Use the jar for testing so we can get the proper version information
unitTest {
test {
classpath -= compileJava.outputs.files
classpath -= configurations.compile
classpath -= configurations.runtime

View File

@ -115,7 +115,7 @@ run {
plugin xpackModule('core')
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.

View File

@ -5,7 +5,7 @@ dependencies {
testCompile project(path: xpackModule('security'), configuration: 'testArtifacts')
}
unitTest {
test {
systemProperty 'tests.security.manager', 'false'
include '**/*Tests.class'
}

View File

@ -7,7 +7,7 @@ import java.nio.charset.StandardCharsets
// Apply the java plugin to this project so the sources can be edited in an IDE
apply plugin: 'elasticsearch.standalone-test'
unitTest.enabled = false
test.enabled = false
dependencies {
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here

View File

@ -75,5 +75,5 @@ task integTest {
dependsOn = [mixedClusterTest]
}
unitTest.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
test.enabled = false // no unit tests for multi-cluster-search, only the rest integration test
check.dependsOn(integTest)

View File

@ -122,7 +122,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}
unitTest.enabled = false // no unit tests for rolling upgrades, only the rest integration test
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
// basic integ tests includes testing bwc against the most recent version
task bwcTestSnapshots {

View File

@ -45,8 +45,8 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'none'
systemProperty 'tests.rest.cluster_name', 'leader'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
}
// ============================================================================================
@ -76,11 +76,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'none'
systemProperty 'tests.rest.cluster_name', 'follower'
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(0).transportUri()}"
}
// ============================================================================================
@ -121,11 +121,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'one_third'
systemProperty 'tests.rest.cluster_name', 'follower'
systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(1).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(1).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(1).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(1).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
finalizedBy "${taskPrefix}#follower#clusterTestCluster#node1.stop"
}
@ -142,11 +142,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'two_third'
systemProperty 'tests.rest.cluster_name', 'follower'
systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(2).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(2).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerClusterTest.nodes.get(2).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerClusterTest.nodes.get(2).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
finalizedBy "${taskPrefix}#follower#clusterTestCluster#node2.stop"
}
@ -163,11 +163,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'all'
systemProperty 'tests.rest.cluster_name', 'follower'
systemProperty 'tests.follower_host', "${-> followerOneThirdUpgradedTest.nodes.get(0).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerOneThirdUpgradedTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerOneThirdUpgradedTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerOneThirdUpgradedTest.nodes.get(0).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(0).transportUri()}"
// This is needed, otherwise leader node 0 will stop after the leaderClusterTestRunner task has run.
// Here it is ok to stop, because in the next task, the leader node 0 gets upgraded.
@ -190,11 +190,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'one_third'
systemProperty 'tests.rest.cluster_name', 'leader'
systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(2).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(2).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderClusterTest.nodes.get(2).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderClusterTest.nodes.get(2).transportUri()}"
finalizedBy "${taskPrefix}#leader#clusterTestCluster#node1.stop"
}
@ -211,11 +211,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'two_third'
systemProperty 'tests.rest.cluster_name', 'leader'
systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderOneThirdUpgradedTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderOneThirdUpgradedTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderOneThirdUpgradedTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderOneThirdUpgradedTest.nodes.get(0).transportUri()}"
finalizedBy "${taskPrefix}#leader#clusterTestCluster#node2.stop"
}
@ -232,11 +232,11 @@ for (Version version : bwcVersions.wireCompatible) {
systemProperty 'tests.rest.upgrade_state', 'all'
systemProperty 'tests.rest.cluster_name', 'leader'
systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.follower_host', "${-> followerUpgradedClusterTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.follower_remote_cluster_seed', "${-> followerUpgradedClusterTest.nodes.get(0).transportUri()}"
systemProperty 'tests.leader_host', "${-> leaderTwoThirdsUpgradedTest.nodes.get(0).httpUri()}"
systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderTwoThirdsUpgradedTest.nodes.get(0).transportUri()}"
nonInputProperties.systemProperty 'tests.leader_host', "${-> leaderTwoThirdsUpgradedTest.nodes.get(0).httpUri()}"
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed', "${-> leaderTwoThirdsUpgradedTest.nodes.get(0).transportUri()}"
/*
* Force stopping all the upgraded nodes after the test runner
@ -257,7 +257,7 @@ for (Version version : bwcVersions.wireCompatible) {
}
}
unitTest.enabled = false // no unit tests for rolling upgrades, only the rest integration test
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
// basic integ tests includes testing bwc against the most recent version
task integTest {

View File

@ -7,7 +7,7 @@ import java.nio.charset.StandardCharsets
// Apply the java plugin to this project so the sources can be edited in an IDE
apply plugin: 'elasticsearch.standalone-test'
unitTest.enabled = false
test.enabled = false
dependencies {
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here

View File

@ -22,7 +22,7 @@ forbiddenPatterns {
exclude '**/*.der'
}
unitTest {
test {
/*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
* other if we allow them to set the number of available processors as it's set-once in Netty.

View File

@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.test.fixtures'
unitTest.enabled = false
test.enabled = false

View File

@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.test.fixtures'
unitTest.enabled = false
test.enabled = false