Skip to content

Commit b439127

Browse files
committed
Revert "Replace usages RandomizedTestingTask with built-in Gradle Test (#40564)"
This reverts commit 2b2a3f5
1 parent b8a4c13 commit b439127

File tree

97 files changed

+1552
-666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1552
-666
lines changed

benchmarks/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mainClassName = 'org.openjdk.jmh.Main'
2424
assemble.enabled = false
2525
archivesBaseName = 'elasticsearch-benchmarks'
2626

27-
test.enabled = false
27+
unitTest.enabled = false
2828

2929
dependencies {
3030
compile("org.elasticsearch:elasticsearch:${version}") {

buildSrc/build.gradle

+11-4
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,24 @@ if (project != rootProject) {
199199
into localDownloads
200200
}
201201

202-
test {
202+
unitTest {
203203
// The test task is configured to runtimeJava version, but build-tools doesn't support all of them, so test
204204
// with compiler instead on the ones that are too old.
205205
if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_10) {
206-
executable = "${project.compilerJavaHome}/bin/java"
206+
jvm = "${project.compilerJavaHome}/bin/java"
207207
}
208208
}
209-
209+
210+
// This can't be an RandomizedTestingTask because we can't yet reference it
210211
task integTest(type: Test) {
211212
// integration test requires the local testing repo for example plugin builds
212213
dependsOn project.rootProject.allprojects.collect {
213214
it.tasks.matching { it.name == 'publishNebulaPublicationToLocalTestRepository'}
214215
}
215216
dependsOn setupLocalDownloads
216217
exclude "**/*Tests.class"
218+
testClassesDirs = sourceSets.test.output.classesDirs
219+
classpath = sourceSets.test.runtimeClasspath
217220
inputs.dir(file("src/testKit"))
218221
// tell BuildExamplePluginsIT where to find the example plugins
219222
systemProperty (
@@ -229,7 +232,11 @@ if (project != rootProject) {
229232
if (isLuceneSnapshot) {
230233
systemProperty 'test.lucene-snapshot-revision', isLuceneSnapshot[0][1]
231234
}
232-
maxParallelForks System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer
235+
String defaultParallel = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel)
236+
if (defaultParallel == "auto") {
237+
defaultParallel = Math.max(Runtime.getRuntime().availableProcessors(), 4)
238+
}
239+
maxParallelForks defaultParallel as Integer
233240
}
234241
check.dependsOn(integTest)
235242

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.carrotsearch.gradle.junit4
2+
3+
import com.carrotsearch.ant.tasks.junit4.SuiteBalancer
4+
import com.carrotsearch.ant.tasks.junit4.balancers.ExecutionTimeBalancer
5+
import com.carrotsearch.ant.tasks.junit4.listeners.ExecutionTimesReport
6+
import org.apache.tools.ant.types.FileSet
7+
8+
class BalancersConfiguration {
9+
// parent task, so executionTime can register an additional listener
10+
RandomizedTestingTask task
11+
List<SuiteBalancer> balancers = new ArrayList<>()
12+
13+
void executionTime(Map<String,Object> properties) {
14+
ExecutionTimeBalancer balancer = new ExecutionTimeBalancer()
15+
16+
FileSet fileSet = new FileSet()
17+
Object filename = properties.remove('cacheFilename')
18+
if (filename == null) {
19+
throw new IllegalArgumentException('cacheFilename is required for executionTime balancer')
20+
}
21+
fileSet.setIncludes(filename.toString())
22+
23+
File cacheDir = task.project.projectDir
24+
Object dir = properties.remove('cacheDir')
25+
if (dir != null) {
26+
cacheDir = new File(dir.toString())
27+
}
28+
fileSet.setDir(cacheDir)
29+
balancer.add(fileSet)
30+
31+
int historySize = 10
32+
Object size = properties.remove('historySize')
33+
if (size instanceof Integer) {
34+
historySize = (Integer)size
35+
} else if (size != null) {
36+
throw new IllegalArgumentException('historySize must be an integer')
37+
}
38+
ExecutionTimesReport listener = new ExecutionTimesReport()
39+
listener.setFile(new File(cacheDir, filename.toString()))
40+
listener.setHistoryLength(historySize)
41+
42+
if (properties.isEmpty() == false) {
43+
throw new IllegalArgumentException('Unknown properties for executionTime balancer: ' + properties.keySet())
44+
}
45+
46+
task.listenersConfig.listeners.add(listener)
47+
balancers.add(balancer)
48+
}
49+
50+
void custom(SuiteBalancer balancer) {
51+
balancers.add(balancer)
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.carrotsearch.gradle.junit4
2+
3+
import com.carrotsearch.ant.tasks.junit4.listeners.AggregatedEventListener
4+
import com.carrotsearch.ant.tasks.junit4.listeners.antxml.AntXmlReport
5+
6+
7+
class ListenersConfiguration {
8+
RandomizedTestingTask task
9+
List<AggregatedEventListener> listeners = new ArrayList<>()
10+
11+
void junitReport(Map<String, Object> props) {
12+
AntXmlReport reportListener = new AntXmlReport()
13+
Object dir = props == null ? null : props.get('dir')
14+
if (dir != null) {
15+
reportListener.setDir(task.project.file(dir))
16+
} else {
17+
reportListener.setDir(new File(task.project.buildDir, 'reports' + File.separator + "${task.name}Junit"))
18+
}
19+
listeners.add(reportListener)
20+
}
21+
22+
void custom(AggregatedEventListener listener) {
23+
listeners.add(listener)
24+
}
25+
}

buildSrc/src/main/groovy/org/elasticsearch/gradle/LoggingOutputStream.groovy renamed to buildSrc/src/main/groovy/com/carrotsearch/gradle/junit4/LoggingOutputStream.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.elasticsearch.gradle
1+
package com.carrotsearch.gradle.junit4
22

33
import org.gradle.api.logging.LogLevel
44
import org.gradle.api.logging.Logger
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.carrotsearch.gradle.junit4
2+
3+
import com.carrotsearch.ant.tasks.junit4.JUnit4
4+
import org.gradle.api.Plugin
5+
import org.gradle.api.Project
6+
import org.gradle.api.tasks.TaskContainer
7+
8+
class RandomizedTestingPlugin implements Plugin<Project> {
9+
10+
void apply(Project project) {
11+
String seed = setupSeed(project)
12+
createUnitTestTask(project.tasks)
13+
configureAnt(project.ant, seed)
14+
}
15+
16+
/**
17+
* Pins the test seed at configuration time so it isn't different on every
18+
* {@link RandomizedTestingTask} execution. This is useful if random
19+
* decisions in one run of {@linkplain RandomizedTestingTask} influence the
20+
* outcome of subsequent runs. Pinning the seed up front like this makes
21+
* the reproduction line from one run be useful on another run.
22+
*/
23+
static String setupSeed(Project project) {
24+
if (project.rootProject.ext.has('testSeed')) {
25+
/* Skip this if we've already pinned the testSeed. It is important
26+
* that this checks the rootProject so that we know we've only ever
27+
* initialized one time. */
28+
return project.rootProject.ext.testSeed
29+
}
30+
String testSeed = System.getProperty('tests.seed')
31+
if (testSeed == null) {
32+
long seed = new Random(System.currentTimeMillis()).nextLong()
33+
testSeed = Long.toUnsignedString(seed, 16).toUpperCase(Locale.ROOT)
34+
}
35+
/* Set the testSeed on the root project first so other projects can use
36+
* it during initialization. */
37+
project.rootProject.ext.testSeed = testSeed
38+
project.rootProject.subprojects {
39+
project.ext.testSeed = testSeed
40+
}
41+
42+
return testSeed
43+
}
44+
45+
static void createUnitTestTask(TaskContainer tasks) {
46+
// only create a unitTest task if the `test` task exists as some project don't make use of it.
47+
tasks.matching { it.name == "test" }.all {
48+
// We don't want to run any tests with the Gradle test runner since we add our own randomized runner
49+
it.enabled = false
50+
RandomizedTestingTask unitTest = tasks.create('unitTest', RandomizedTestingTask)
51+
unitTest.description = 'Runs unit tests with the randomized testing framework'
52+
it.dependsOn unitTest
53+
}
54+
}
55+
56+
static void configureAnt(AntBuilder ant, String seed) {
57+
ant.project.addTaskDefinition('junit4:junit4', JUnit4.class)
58+
ant.properties.put('tests.seed', seed)
59+
}
60+
}

0 commit comments

Comments
 (0)